From e1c978cfc21c6b5ff40dba64a9b0c6a04a9de33d Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Fri, 24 Jun 2022 03:21:20 +0200 Subject: [PATCH] Remove HostDisplay code unused by libretro - screenshot code in particular --- src/core/host_display.cpp | 359 ------------------ src/core/host_display.h | 29 -- src/core/system.cpp | 45 --- src/libretro/libretro_d3d11_host_display.cpp | 26 -- src/libretro/libretro_d3d11_host_display.h | 7 - src/libretro/libretro_host_display.cpp | 26 -- src/libretro/libretro_host_display.h | 7 - src/libretro/libretro_opengl_host_display.cpp | 49 --- src/libretro/libretro_opengl_host_display.h | 7 - src/libretro/libretro_vulkan_host_display.cpp | 77 ---- src/libretro/libretro_vulkan_host_display.h | 7 - 11 files changed, 639 deletions(-) diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp index d0469fd3..58efbba5 100644 --- a/src/core/host_display.cpp +++ b/src/core/host_display.cpp @@ -304,362 +304,3 @@ std::tuple HostDisplay::ConvertWindowCoordinatesToDisplayCoordinat return std::make_tuple(display_x, display_y); } - -bool HostDisplay::ConvertTextureDataToRGBA8(u32 width, u32 height, std::vector& texture_data, - u32& texture_data_stride, HostDisplayPixelFormat format) -{ - switch (format) - { - case HostDisplayPixelFormat::BGRA8: - { - for (u32 y = 0; y < height; y++) - { - u32* pixels = reinterpret_cast(reinterpret_cast(texture_data.data()) + (y * texture_data_stride)); - for (u32 x = 0; x < width; x++) - pixels[x] = (pixels[x] & 0xFF00FF00) | ((pixels[x] & 0xFF) << 16) | ((pixels[x] >> 16) & 0xFF); - } - - return true; - } - - case HostDisplayPixelFormat::RGBA8: - return true; - - case HostDisplayPixelFormat::RGB565: - { - std::vector temp(width * height); - - for (u32 y = 0; y < height; y++) - { - const u8* pixels_in = reinterpret_cast(texture_data.data()) + (y * texture_data_stride); - u32* pixels_out = &temp[y * width]; - - for (u32 x = 0; x < width; x++) - { - // RGB565 -> RGBA8 - u16 pixel_in; - std::memcpy(&pixel_in, pixels_in, sizeof(u16)); - pixels_in += sizeof(u16); - const u8 r5 = Truncate8(pixel_in >> 11); - const u8 g6 = Truncate8((pixel_in >> 5) & 0x3F); - const u8 b5 = Truncate8(pixel_in & 0x1F); - *(pixels_out++) = ZeroExtend32((r5 << 3) | (r5 & 7)) | (ZeroExtend32((g6 << 2) | (g6 & 3)) << 8) | - (ZeroExtend32((b5 << 3) | (b5 & 7)) << 16) | (0xFF000000u); - } - } - - texture_data = std::move(temp); - texture_data_stride = sizeof(u32) * width; - return true; - } - - case HostDisplayPixelFormat::RGBA5551: - { - std::vector temp(width * height); - - for (u32 y = 0; y < height; y++) - { - const u8* pixels_in = reinterpret_cast(texture_data.data()) + (y * texture_data_stride); - u32* pixels_out = &temp[y * width]; - - for (u32 x = 0; x < width; x++) - { - // RGBA5551 -> RGBA8 - u16 pixel_in; - std::memcpy(&pixel_in, pixels_in, sizeof(u16)); - pixels_in += sizeof(u16); - const u8 a1 = Truncate8(pixel_in >> 15); - const u8 r5 = Truncate8((pixel_in >> 10) & 0x1F); - const u8 g6 = Truncate8((pixel_in >> 5) & 0x1F); - const u8 b5 = Truncate8(pixel_in & 0x1F); - *(pixels_out++) = ZeroExtend32((r5 << 3) | (r5 & 7)) | (ZeroExtend32((g6 << 3) | (g6 & 7)) << 8) | - (ZeroExtend32((b5 << 3) | (b5 & 7)) << 16) | (a1 ? 0xFF000000u : 0u); - } - } - - texture_data = std::move(temp); - texture_data_stride = sizeof(u32) * width; - return true; - } - - default: - Log_ErrorPrintf("Unknown pixel format %u", static_cast(format)); - return false; - } -} - -void HostDisplay::FlipTextureDataRGBA8(u32 width, u32 height, std::vector& texture_data, u32 texture_data_stride) -{ - std::vector temp(width); - for (u32 flip_row = 0; flip_row < (height / 2); flip_row++) - { - u32* top_ptr = &texture_data[flip_row * width]; - u32* bottom_ptr = &texture_data[((height - 1) - flip_row) * width]; - std::memcpy(temp.data(), top_ptr, texture_data_stride); - std::memcpy(top_ptr, bottom_ptr, texture_data_stride); - std::memcpy(bottom_ptr, temp.data(), texture_data_stride); - } -} - -static bool CompressAndWriteTextureToFile(u32 width, u32 height, std::string filename, FileSystem::ManagedCFilePtr fp, - bool clear_alpha, bool flip_y, u32 resize_width, u32 resize_height, - std::vector texture_data, u32 texture_data_stride, - HostDisplayPixelFormat texture_format) -{ - - const char* extension = std::strrchr(filename.c_str(), '.'); - if (!extension) - { - Log_ErrorPrintf("Unable to determine file extension for '%s'", filename.c_str()); - return false; - } - - if (!HostDisplay::ConvertTextureDataToRGBA8(width, height, texture_data, texture_data_stride, texture_format)) - return false; - - if (clear_alpha) - { - for (u32& pixel : texture_data) - pixel |= 0xFF000000; - } - - if (flip_y) - HostDisplay::FlipTextureDataRGBA8(width, height, texture_data, texture_data_stride); - - if (resize_width > 0 && resize_height > 0 && (resize_width != width || resize_height != height)) - { - std::vector resized_texture_data(resize_width * resize_height); - u32 resized_texture_stride = sizeof(u32) * resize_width; - if (!stbir_resize_uint8(reinterpret_cast(texture_data.data()), width, height, texture_data_stride, - reinterpret_cast(resized_texture_data.data()), resize_width, resize_height, - resized_texture_stride, 4)) - { - Log_ErrorPrintf("Failed to resize texture data from %ux%u to %ux%u", width, height, resize_width, resize_height); - return false; - } - - width = resize_width; - height = resize_height; - texture_data = std::move(resized_texture_data); - texture_data_stride = resized_texture_stride; - } - - const auto write_func = [](void* context, void* data, int size) { - std::fwrite(data, 1, size, static_cast(context)); - }; - - bool result = false; - if (StringUtil::Strcasecmp(extension, ".png") == 0) - { - result = - (stbi_write_png_to_func(write_func, fp.get(), width, height, 4, texture_data.data(), texture_data_stride) != 0); - } - else if (StringUtil::Strcasecmp(extension, ".jpg") == 0) - { - result = (stbi_write_jpg_to_func(write_func, fp.get(), width, height, 4, texture_data.data(), 95) != 0); - } - else if (StringUtil::Strcasecmp(extension, ".tga") == 0) - { - result = (stbi_write_tga_to_func(write_func, fp.get(), width, height, 4, texture_data.data()) != 0); - } - else if (StringUtil::Strcasecmp(extension, ".bmp") == 0) - { - result = (stbi_write_bmp_to_func(write_func, fp.get(), width, height, 4, texture_data.data()) != 0); - } - - if (!result) - { - Log_ErrorPrintf("Unknown extension in filename '%s' or save error: '%s'", filename.c_str(), extension); - return false; - } - - return true; -} - -bool HostDisplay::WriteTextureToFile(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, - HostDisplayPixelFormat format, std::string filename, bool clear_alpha /* = true */, - bool flip_y /* = false */, u32 resize_width /* = 0 */, u32 resize_height /* = 0 */, - bool compress_on_thread /* = false */) -{ - std::vector texture_data(width * height); - u32 texture_data_stride = Common::AlignUpPow2(GetDisplayPixelFormatSize(format) * width, 4); - if (!DownloadTexture(texture_handle, format, x, y, width, height, texture_data.data(), texture_data_stride)) - { - Log_ErrorPrintf("Texture download failed"); - return false; - } - - auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "wb"); - if (!fp) - { - Log_ErrorPrintf("Can't open file '%s': errno %d", filename.c_str(), errno); - return false; - } - - if (!compress_on_thread) - { - return CompressAndWriteTextureToFile(width, height, std::move(filename), std::move(fp), clear_alpha, flip_y, - resize_width, resize_height, std::move(texture_data), texture_data_stride, - format); - } - - std::thread compress_thread(CompressAndWriteTextureToFile, width, height, std::move(filename), std::move(fp), - clear_alpha, flip_y, resize_width, resize_height, std::move(texture_data), - texture_data_stride, format); - compress_thread.detach(); - return true; -} - -bool HostDisplay::WriteDisplayTextureToFile(std::string filename, bool full_resolution /* = true */, - bool apply_aspect_ratio /* = true */, bool compress_on_thread /* = false */) -{ - if (!m_display_texture_handle) - return false; - - s32 resize_width = 0; - s32 resize_height = std::abs(m_display_texture_view_height); - if (apply_aspect_ratio) - { - const float ss_width_scale = static_cast(m_display_active_width) / static_cast(m_display_width); - const float ss_height_scale = static_cast(m_display_active_height) / static_cast(m_display_height); - const float ss_aspect_ratio = m_display_aspect_ratio * ss_width_scale / ss_height_scale; - resize_width = static_cast(static_cast(resize_height) * ss_aspect_ratio); - } - else - { - resize_width = m_display_texture_view_width; - } - - if (!full_resolution) - { - const s32 resolution_scale = std::abs(m_display_texture_view_height) / m_display_active_height; - resize_height /= resolution_scale; - resize_width /= resolution_scale; - } - - if (resize_width <= 0 || resize_height <= 0) - return false; - - const bool flip_y = (m_display_texture_view_height < 0); - s32 read_height = m_display_texture_view_height; - s32 read_y = m_display_texture_view_y; - if (flip_y) - { - read_height = -m_display_texture_view_height; - read_y = (m_display_texture_height - read_height) - (m_display_texture_height - m_display_texture_view_y); - } - - return WriteTextureToFile(m_display_texture_handle, m_display_texture_view_x, read_y, m_display_texture_view_width, - read_height, m_display_texture_format, std::move(filename), true, flip_y, - static_cast(resize_width), static_cast(resize_height), compress_on_thread); -} - -bool HostDisplay::WriteDisplayTextureToBuffer(std::vector* buffer, u32 resize_width /* = 0 */, - u32 resize_height /* = 0 */, bool clear_alpha /* = true */) -{ - if (!m_display_texture_handle) - return false; - - const bool flip_y = (m_display_texture_view_height < 0); - s32 read_width = m_display_texture_view_width; - s32 read_height = m_display_texture_view_height; - s32 read_x = m_display_texture_view_x; - s32 read_y = m_display_texture_view_y; - if (flip_y) - { - read_height = -m_display_texture_view_height; - read_y = (m_display_texture_height - read_height) - (m_display_texture_height - m_display_texture_view_y); - } - - u32 width = static_cast(read_width); - u32 height = static_cast(read_height); - std::vector texture_data(width * height); - u32 texture_data_stride = Common::AlignUpPow2(GetDisplayPixelFormatSize(m_display_texture_format) * width, 4); - if (!DownloadTexture(m_display_texture_handle, m_display_texture_format, read_x, read_y, width, height, - texture_data.data(), texture_data_stride)) - { - Log_ErrorPrintf("Failed to download texture from GPU."); - return false; - } - - if (!ConvertTextureDataToRGBA8(width, height, texture_data, texture_data_stride, m_display_texture_format)) - return false; - - if (clear_alpha) - { - for (u32& pixel : texture_data) - pixel |= 0xFF000000; - } - - if (flip_y) - { - std::vector temp(width); - for (u32 flip_row = 0; flip_row < (height / 2); flip_row++) - { - u32* top_ptr = &texture_data[flip_row * width]; - u32* bottom_ptr = &texture_data[((height - 1) - flip_row) * width]; - std::memcpy(temp.data(), top_ptr, texture_data_stride); - std::memcpy(top_ptr, bottom_ptr, texture_data_stride); - std::memcpy(bottom_ptr, temp.data(), texture_data_stride); - } - } - - if (resize_width > 0 && resize_height > 0 && (resize_width != width || resize_height != height)) - { - std::vector resized_texture_data(resize_width * resize_height); - u32 resized_texture_stride = sizeof(u32) * resize_width; - if (!stbir_resize_uint8(reinterpret_cast(texture_data.data()), width, height, texture_data_stride, - reinterpret_cast(resized_texture_data.data()), resize_width, resize_height, - resized_texture_stride, 4)) - { - Log_ErrorPrintf("Failed to resize texture data from %ux%u to %ux%u", width, height, resize_width, resize_height); - return false; - } - - width = resize_width; - height = resize_height; - *buffer = std::move(resized_texture_data); - texture_data_stride = resized_texture_stride; - } - else - { - *buffer = texture_data; - } - - return true; -} - -bool HostDisplay::WriteScreenshotToFile(std::string filename, bool compress_on_thread /*= false*/) -{ - const u32 width = m_window_info.surface_width; - const u32 height = m_window_info.surface_height; - if (width == 0 || height == 0) - return false; - - std::vector pixels; - u32 pixels_stride; - HostDisplayPixelFormat pixels_format; - if (!RenderScreenshot(width, height, &pixels, &pixels_stride, &pixels_format)) - { - Log_ErrorPrintf("Failed to render %ux%u screenshot", width, height); - return false; - } - - auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "wb"); - if (!fp) - { - Log_ErrorPrintf("Can't open file '%s': errno %d", filename.c_str(), errno); - return false; - } - - if (!compress_on_thread) - { - return CompressAndWriteTextureToFile(width, height, std::move(filename), std::move(fp), true, UsesLowerLeftOrigin(), - width, height, std::move(pixels), pixels_stride, pixels_format); - } - - std::thread compress_thread(CompressAndWriteTextureToFile, width, height, std::move(filename), std::move(fp), true, - UsesLowerLeftOrigin(), width, height, std::move(pixels), pixels_stride, pixels_format); - compress_thread.detach(); - return true; -} diff --git a/src/core/host_display.h b/src/core/host_display.h index e5c7df12..a86318b0 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -94,15 +94,10 @@ public: virtual void DestroyRenderDevice() = 0; virtual void DestroyRenderSurface() = 0; virtual bool ChangeRenderWindow(const WindowInfo& wi) = 0; - virtual bool SupportsFullscreen() const = 0; - virtual bool IsFullscreen() = 0; - virtual bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) = 0; virtual AdapterAndModeList GetAdapterAndModeList() = 0; virtual bool CreateResources() = 0; virtual void DestroyResources() = 0; - virtual bool SetPostProcessingChain(const std::string_view& config) = 0; - /// Call when the window size changes externally to recreate any resources. virtual void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) = 0; @@ -119,10 +114,6 @@ public: /// Returns false if the window was completely occluded. virtual bool Render() = 0; - /// Renders the display with postprocessing to the specified image. - virtual bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) = 0; - const void* GetDisplayTextureHandle() const { return m_display_texture_handle; } const s32 GetDisplayTopMargin() const { return m_display_top_margin; } const s32 GetDisplayWidth() const { return m_display_width; } @@ -182,9 +173,6 @@ public: } static u32 GetDisplayPixelFormatSize(HostDisplayPixelFormat format); - static bool ConvertTextureDataToRGBA8(u32 width, u32 height, std::vector& texture_data, u32& texture_data_stride, - HostDisplayPixelFormat format); - static void FlipTextureDataRGBA8(u32 width, u32 height, std::vector& texture_data, u32 texture_data_stride); virtual bool SupportsDisplayPixelFormat(HostDisplayPixelFormat format) const = 0; @@ -221,23 +209,6 @@ public: std::tuple ConvertWindowCoordinatesToDisplayCoordinates(s32 window_x, s32 window_y, s32 window_width, s32 window_height, s32 top_margin) const; - /// Helper function to save texture data to a PNG. If flip_y is set, the image will be flipped aka OpenGL. - bool WriteTextureToFile(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, - HostDisplayPixelFormat format, std::string filename, bool clear_alpha = true, - bool flip_y = false, u32 resize_width = 0, u32 resize_height = 0, - bool compress_on_thread = false); - - /// Helper function to save current display texture to PNG. - bool WriteDisplayTextureToFile(std::string filename, bool full_resolution = true, bool apply_aspect_ratio = true, - bool compress_on_thread = false); - - /// Helper function to save current display texture to a buffer. - bool WriteDisplayTextureToBuffer(std::vector* buffer, u32 resize_width = 0, u32 resize_height = 0, - bool clear_alpha = true); - - /// Helper function to save screenshot to PNG. - bool WriteScreenshotToFile(std::string filename, bool compress_on_thread = false); - protected: ALWAYS_INLINE bool HasSoftwareCursor() const { return static_cast(m_cursor_texture); } ALWAYS_INLINE bool HasDisplayTexture() const { return (m_display_texture_handle != nullptr); } diff --git a/src/core/system.cpp b/src/core/system.cpp index 4871d71f..97e79e8e 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1353,51 +1353,6 @@ bool SaveState(ByteStream* state, u32 screenshot_size /* = 256 */) return false; } - // save screenshot - if (screenshot_size > 0) - { - // assume this size is the width - HostDisplay* display = g_host_interface->GetDisplay(); - const float display_aspect_ratio = display->GetDisplayAspectRatio(); - const u32 screenshot_width = screenshot_size; - const u32 screenshot_height = - std::max(1u, static_cast(static_cast(screenshot_width) / - ((display_aspect_ratio > 0.0f) ? display_aspect_ratio : 1.0f))); - Log_VerbosePrintf("Saving %ux%u screenshot for state", screenshot_width, screenshot_height); - - std::vector screenshot_buffer; - u32 screenshot_stride; - HostDisplayPixelFormat screenshot_format; - if (display->RenderScreenshot(screenshot_width, screenshot_height, &screenshot_buffer, &screenshot_stride, - &screenshot_format) || - !display->ConvertTextureDataToRGBA8(screenshot_width, screenshot_height, screenshot_buffer, screenshot_stride, - HostDisplayPixelFormat::RGBA8)) - { - if (screenshot_stride != (screenshot_width * sizeof(u32))) - { - Log_WarningPrintf("Failed to save %ux%u screenshot for save state due to incorrect stride(%u)", - screenshot_width, screenshot_height, screenshot_stride); - } - else - { - if (display->UsesLowerLeftOrigin()) - display->FlipTextureDataRGBA8(screenshot_width, screenshot_height, screenshot_buffer, screenshot_stride); - - header.offset_to_screenshot = static_cast(state->GetPosition()); - header.screenshot_width = screenshot_width; - header.screenshot_height = screenshot_height; - header.screenshot_size = static_cast(screenshot_buffer.size() * sizeof(u32)); - if (!state->Write2(screenshot_buffer.data(), header.screenshot_size)) - return false; - } - } - else - { - Log_WarningPrintf("Failed to save %ux%u screenshot for save state due to render/conversion failure", - screenshot_width, screenshot_height); - } - } - // write data { header.offset_to_data = static_cast(state->GetPosition()); diff --git a/src/libretro/libretro_d3d11_host_display.cpp b/src/libretro/libretro_d3d11_host_display.cpp index d69a80bf..81c7bc08 100644 --- a/src/libretro/libretro_d3d11_host_display.cpp +++ b/src/libretro/libretro_d3d11_host_display.cpp @@ -318,26 +318,6 @@ bool LibretroD3D11HostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) void LibretroD3D11HostDisplay::DestroyRenderSurface() {} -bool LibretroD3D11HostDisplay::SetPostProcessingChain(const std::string_view& config) -{ - return false; -} - -bool LibretroD3D11HostDisplay::SupportsFullscreen() const -{ - return false; -} - -bool LibretroD3D11HostDisplay::IsFullscreen() -{ - return false; -} - -bool LibretroD3D11HostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) -{ - return false; -} - bool LibretroD3D11HostDisplay::CreateResources() { HRESULT hr; @@ -440,12 +420,6 @@ bool LibretroD3D11HostDisplay::Render() return true; } -bool LibretroD3D11HostDisplay::RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) -{ - return false; -} - void LibretroD3D11HostDisplay::RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, diff --git a/src/libretro/libretro_d3d11_host_display.h b/src/libretro/libretro_d3d11_host_display.h index 32382068..7bed6d47 100644 --- a/src/libretro/libretro_d3d11_host_display.h +++ b/src/libretro/libretro_d3d11_host_display.h @@ -33,14 +33,9 @@ public: bool ChangeRenderWindow(const WindowInfo& new_wi) override; - bool SupportsFullscreen() const override; - bool IsFullscreen() override; - bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; AdapterAndModeList GetAdapterAndModeList() override; void DestroyRenderSurface() override; - bool SetPostProcessingChain(const std::string_view& config) override; - std::unique_ptr CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, HostDisplayPixelFormat format, const void* data, u32 data_stride, bool dynamic = false) override; @@ -54,8 +49,6 @@ public: void EndSetDisplayPixels() override; bool Render() override; - bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) override; protected: static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16; diff --git a/src/libretro/libretro_host_display.cpp b/src/libretro/libretro_host_display.cpp index 22458d70..1c06fc04 100644 --- a/src/libretro/libretro_host_display.cpp +++ b/src/libretro/libretro_host_display.cpp @@ -123,31 +123,11 @@ void LibretroHostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_windo m_window_info.surface_height = new_window_height; } -bool LibretroHostDisplay::SupportsFullscreen() const -{ - return false; -} - -bool LibretroHostDisplay::IsFullscreen() -{ - return false; -} - -bool LibretroHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) -{ - return false; -} - HostDisplay::AdapterAndModeList LibretroHostDisplay::GetAdapterAndModeList() { return {}; } -bool LibretroHostDisplay::SetPostProcessingChain(const std::string_view& config) -{ - return false; -} - std::unique_ptr LibretroHostDisplay::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, HostDisplayPixelFormat format, const void* data, u32 data_stride, @@ -268,9 +248,3 @@ bool LibretroHostDisplay::Render() return true; } - -bool LibretroHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) -{ - return false; -} diff --git a/src/libretro/libretro_host_display.h b/src/libretro/libretro_host_display.h index ffcfcce0..d889319c 100644 --- a/src/libretro/libretro_host_display.h +++ b/src/libretro/libretro_host_display.h @@ -26,14 +26,9 @@ public: bool ChangeRenderWindow(const WindowInfo& wi) override; void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) override; - bool SupportsFullscreen() const override; - bool IsFullscreen() override; - bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; AdapterAndModeList GetAdapterAndModeList() override; void DestroyRenderSurface() override; - bool SetPostProcessingChain(const std::string_view& config) override; - bool CreateResources() override; void DestroyResources() override; @@ -46,8 +41,6 @@ public: u32 height, void* out_data, u32 out_data_stride) override; bool Render() override; - bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) override; bool SupportsDisplayPixelFormat(HostDisplayPixelFormat format) const override; diff --git a/src/libretro/libretro_opengl_host_display.cpp b/src/libretro/libretro_opengl_host_display.cpp index 1d04e071..25ed2ff4 100644 --- a/src/libretro/libretro_opengl_host_display.cpp +++ b/src/libretro/libretro_opengl_host_display.cpp @@ -436,21 +436,6 @@ bool LibretroOpenGLHostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) return true; } -bool LibretroOpenGLHostDisplay::SupportsFullscreen() const -{ - return false; -} - -bool LibretroOpenGLHostDisplay::IsFullscreen() -{ - return false; -} - -bool LibretroOpenGLHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) -{ - return false; -} - HostDisplay::AdapterAndModeList LibretroOpenGLHostDisplay::GetAdapterAndModeList() { return {}; @@ -458,11 +443,6 @@ HostDisplay::AdapterAndModeList LibretroOpenGLHostDisplay::GetAdapterAndModeList void LibretroOpenGLHostDisplay::DestroyRenderSurface() {} -bool LibretroOpenGLHostDisplay::SetPostProcessingChain(const std::string_view& config) -{ - return false; -} - bool LibretroOpenGLHostDisplay::CreateResources() { static constexpr char fullscreen_quad_vertex_shader[] = R"( @@ -601,35 +581,6 @@ bool LibretroOpenGLHostDisplay::Render() return true; } -bool LibretroOpenGLHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) -{ - GL::Texture texture; - if (!texture.Create(width, height, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, nullptr) || !texture.CreateFramebuffer()) - return false; - - glDisable(GL_SCISSOR_TEST); - texture.BindFramebuffer(GL_FRAMEBUFFER); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - if (HasDisplayTexture()) - { - const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0); - RenderDisplay(left, height - top - draw_height, draw_width, draw_height, m_display_texture_handle, - m_display_texture_width, m_display_texture_height, m_display_texture_view_x, m_display_texture_view_y, - m_display_texture_view_width, m_display_texture_view_height, m_display_linear_filtering); - } - - out_pixels->resize(width * height); - *out_stride = sizeof(u32) * width; - *out_format = HostDisplayPixelFormat::RGBA8; - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, out_pixels->data()); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - return true; -} - void LibretroOpenGLHostDisplay::RenderDisplay(s32 left, s32 bottom, s32 width, s32 height, void* texture_handle, u32 texture_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, diff --git a/src/libretro/libretro_opengl_host_display.h b/src/libretro/libretro_opengl_host_display.h index 60746f20..3939e7cf 100644 --- a/src/libretro/libretro_opengl_host_display.h +++ b/src/libretro/libretro_opengl_host_display.h @@ -44,14 +44,9 @@ public: bool ChangeRenderWindow(const WindowInfo& new_wi) override; - bool SupportsFullscreen() const override; - bool IsFullscreen() override; - bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; AdapterAndModeList GetAdapterAndModeList() override; void DestroyRenderSurface() override; - bool SetPostProcessingChain(const std::string_view& config) override; - std::unique_ptr CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, HostDisplayPixelFormat format, const void* data, u32 data_stride, bool dynamic = false) override; @@ -66,8 +61,6 @@ public: bool SetDisplayPixels(HostDisplayPixelFormat format, u32 width, u32 height, const void* buffer, u32 pitch) override; bool Render() override; - bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) override; protected: const char* GetGLSLVersionString() const; diff --git a/src/libretro/libretro_vulkan_host_display.cpp b/src/libretro/libretro_vulkan_host_display.cpp index c243feed..cbb54579 100644 --- a/src/libretro/libretro_vulkan_host_display.cpp +++ b/src/libretro/libretro_vulkan_host_display.cpp @@ -59,21 +59,6 @@ void* LibretroVulkanHostDisplay::GetRenderContext() const return nullptr; } -bool LibretroVulkanHostDisplay::SupportsFullscreen() const -{ - return false; -} - -bool LibretroVulkanHostDisplay::IsFullscreen() -{ - return false; -} - -bool LibretroVulkanHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) -{ - return false; -} - HostDisplay::AdapterAndModeList LibretroVulkanHostDisplay::GetAdapterAndModeList() { return {}; @@ -81,11 +66,6 @@ HostDisplay::AdapterAndModeList LibretroVulkanHostDisplay::GetAdapterAndModeList void LibretroVulkanHostDisplay::DestroyRenderSurface() {} -bool LibretroVulkanHostDisplay::SetPostProcessingChain(const std::string_view& config) -{ - return false; -} - static constexpr std::array(HostDisplayPixelFormat::Count)> s_display_pixel_format_mapping = {{VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R5G6B5_UNORM_PACK16, VK_FORMAT_A1R5G5B5_UNORM_PACK16}}; @@ -597,63 +577,6 @@ bool LibretroVulkanHostDisplay::Render() return true; } -bool LibretroVulkanHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) -{ - *out_format = HostDisplayPixelFormat::RGBA8; - *out_stride = sizeof(u32) * width; - out_pixels->resize(width * height); - - // if we don't have a texture (display off), then just write out nothing. - if (!HasDisplayTexture()) - { - std::fill(out_pixels->begin(), out_pixels->end(), static_cast(0)); - return true; - } - - Vulkan::Texture tex; - Vulkan::StagingTexture staging_tex; - if (!tex.Create(width, height, 1, 1, FRAMEBUFFER_FORMAT, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_VIEW_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT) || - !staging_tex.Create(Vulkan::StagingBuffer::Type::Readback, FRAMEBUFFER_FORMAT, width, height)) - { - return false; - } - - const VkFramebuffer fb = tex.CreateFramebuffer(m_frame_render_pass); - if (!fb) - return false; - - tex.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - - const VkClearValue clear_value = {}; - const VkRenderPassBeginInfo rp = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, - nullptr, - m_frame_render_pass, - fb, - {{0, 0}, {width, height}}, - 1u, - &clear_value}; - vkCmdBeginRenderPass(g_vulkan_context->GetCurrentCommandBuffer(), &rp, VK_SUBPASS_CONTENTS_INLINE); - - const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0); - RenderDisplay(left, top, draw_width, draw_height, m_display_texture_handle, m_display_texture_width, - m_display_texture_height, m_display_texture_view_x, m_display_texture_view_y, - m_display_texture_view_width, m_display_texture_view_height, m_display_linear_filtering); - - vkCmdEndRenderPass(g_vulkan_context->GetCurrentCommandBuffer()); - tex.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - staging_tex.CopyFromTexture(tex, 0, 0, 0, 0, 0, 0, width, height); - staging_tex.ReadTexels(0, 0, width, height, out_pixels->data(), *out_stride); - - // destroying these immediately should be safe since nothing's going to access them, and it's not part of the command - // stream - vkDestroyFramebuffer(g_vulkan_context->GetDevice(), fb, nullptr); - staging_tex.Destroy(false); - tex.Destroy(false); - return true; -} - void LibretroVulkanHostDisplay::RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, diff --git a/src/libretro/libretro_vulkan_host_display.h b/src/libretro/libretro_vulkan_host_display.h index f0e980a7..623bf0b0 100644 --- a/src/libretro/libretro_vulkan_host_display.h +++ b/src/libretro/libretro_vulkan_host_display.h @@ -36,14 +36,9 @@ public: bool ChangeRenderWindow(const WindowInfo& new_wi) override; - bool SupportsFullscreen() const override; - bool IsFullscreen() override; - bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; AdapterAndModeList GetAdapterAndModeList() override; void DestroyRenderSurface() override; - bool SetPostProcessingChain(const std::string_view& config) override; - std::unique_ptr CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, HostDisplayPixelFormat format, const void* data, u32 data_stride, bool dynamic = false) override; @@ -58,8 +53,6 @@ public: void EndSetDisplayPixels() override; bool Render() override; - bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) override; protected: bool CreateResources() override;