From 8cd9e0887e06bfdf174ecaa0c9de116ccd6a0d16 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 1 Jul 2020 00:43:17 +1000 Subject: [PATCH] libretro: Use framebuffer view dimensions not texture dimensions --- src/core/host_display.cpp | 9 +++++++-- src/core/host_display.h | 1 + .../libretro_d3d11_host_display.cpp | 10 ++++++---- .../libretro_opengl_host_display.cpp | 10 ++++++---- src/frontend-common/opengl_host_display.cpp | 6 +++--- src/frontend-common/opengl_host_display.h | 2 +- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp index 0090157b3..682f82535 100644 --- a/src/core/host_display.cpp +++ b/src/core/host_display.cpp @@ -128,13 +128,18 @@ std::tuple HostDisplay::CalculateDrawRect(s32 window_width, } std::tuple HostDisplay::CalculateSoftwareCursorDrawRect() const +{ + return CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y); +} + +std::tuple HostDisplay::CalculateSoftwareCursorDrawRect(s32 cursor_x, s32 cursor_y) const { const float scale = m_window_info.surface_scale * m_cursor_texture_scale; const u32 cursor_extents_x = static_cast(static_cast(m_cursor_texture->GetWidth()) * scale * 0.5f); const u32 cursor_extents_y = static_cast(static_cast(m_cursor_texture->GetHeight()) * scale * 0.5f); - const s32 out_left = m_mouse_position_x - cursor_extents_x; - const s32 out_top = m_mouse_position_y - cursor_extents_y; + const s32 out_left = cursor_x - cursor_extents_x; + const s32 out_top = cursor_y - cursor_extents_y; const s32 out_width = cursor_extents_x * 2u; const s32 out_height = cursor_extents_y * 2u; diff --git a/src/core/host_display.h b/src/core/host_display.h index 40f9087d8..80fe35df8 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -160,6 +160,7 @@ protected: float* out_y_scale) const; std::tuple CalculateSoftwareCursorDrawRect() const; + std::tuple CalculateSoftwareCursorDrawRect(s32 cursor_x, s32 cursor_y) const; WindowInfo m_window_info; diff --git a/src/duckstation-libretro/libretro_d3d11_host_display.cpp b/src/duckstation-libretro/libretro_d3d11_host_display.cpp index e4004f48c..0a02a2276 100644 --- a/src/duckstation-libretro/libretro_d3d11_host_display.cpp +++ b/src/duckstation-libretro/libretro_d3d11_host_display.cpp @@ -76,7 +76,7 @@ void LibretroD3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_ bool LibretroD3D11HostDisplay::Render() { // TODO: Skip framebuffer when offset is (0,0). - if (!CheckFramebufferSize(m_display_texture_width, m_display_texture_height)) + if (!CheckFramebufferSize(m_display_texture_view_width, m_display_texture_view_height)) return false; // Ensure we're not currently bound. @@ -86,21 +86,23 @@ bool LibretroD3D11HostDisplay::Render() if (HasDisplayTexture()) { - RenderDisplay(0, 0, m_display_texture_width, m_display_texture_height, m_display_texture_handle, + RenderDisplay(0, 0, m_display_texture_view_width, m_display_texture_view_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); } if (HasSoftwareCursor()) { - const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(); + // TODO: Scale mouse x/y + const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y); RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get()); } // NOTE: libretro frontend expects the data bound to PS SRV slot 0. m_context->OMSetRenderTargets(0, nullptr, nullptr); m_context->PSSetShaderResources(0, 1, m_framebuffer.GetD3DSRVArray()); - g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_width, m_display_texture_height, 0); + g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_view_width, + m_display_texture_view_height, 0); return true; } diff --git a/src/duckstation-libretro/libretro_opengl_host_display.cpp b/src/duckstation-libretro/libretro_opengl_host_display.cpp index 080d4fbbd..b456b0303 100644 --- a/src/duckstation-libretro/libretro_opengl_host_display.cpp +++ b/src/duckstation-libretro/libretro_opengl_host_display.cpp @@ -125,18 +125,20 @@ bool LibretroOpenGLHostDisplay::Render() if (HasDisplayTexture()) { - RenderDisplay(0, 0, m_display_texture_width, m_display_texture_height, m_display_texture_handle, + RenderDisplay(0, 0, m_display_texture_view_width, m_display_texture_view_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); } if (HasSoftwareCursor()) { - const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(); - RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get()); + // TODO: Scale mouse x/y + const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y); + RenderSoftwareCursor(left, m_display_texture_view_height - top - height, width, height, m_cursor_texture.get()); } - g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_width, m_display_texture_height, 0); + g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_view_width, + m_display_texture_view_height, 0); GL::Program::ResetLastProgram(); return true; diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index 3d81ba9bb..c8afe2bfa 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -461,13 +461,13 @@ void OpenGLHostDisplay::RenderSoftwareCursor() return; const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(); - RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get()); + RenderSoftwareCursor(left, GetWindowHeight() - top - height, width, height, m_cursor_texture.get()); } -void OpenGLHostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, +void OpenGLHostDisplay::RenderSoftwareCursor(s32 left, s32 bottom, s32 width, s32 height, HostDisplayTexture* texture_handle) { - glViewport(left, GetWindowHeight() - top - height, width, height); + glViewport(left, bottom, width, height); glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); diff --git a/src/frontend-common/opengl_host_display.h b/src/frontend-common/opengl_host_display.h index 9bd51624d..5db6d12d8 100644 --- a/src/frontend-common/opengl_host_display.h +++ b/src/frontend-common/opengl_host_display.h @@ -69,7 +69,7 @@ protected: void 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, bool linear_filter); - void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle); + void RenderSoftwareCursor(s32 left, s32 bottom, s32 width, s32 height, HostDisplayTexture* texture_handle); std::unique_ptr m_gl_context;