From 0709f92ac110678166a5a3d104e8a882bccb4ba1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 13 Oct 2022 17:32:51 +1000 Subject: [PATCH] Misc: Cleanup/deduplicate from c9cba5e --- src/core/gpu.cpp | 3 +- src/core/host_display.cpp | 18 +++++----- src/core/host_display.h | 18 ++-------- src/core/settings.cpp | 14 ++++---- src/core/settings.h | 40 ++++++++++++++++----- src/core/types.h | 5 +-- src/frontend-common/d3d11_host_display.cpp | 2 +- src/frontend-common/d3d12_host_display.cpp | 2 +- src/frontend-common/opengl_host_display.cpp | 2 +- src/frontend-common/vulkan_host_display.cpp | 2 +- 10 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 84bd33271..7d75421f2 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -977,8 +977,7 @@ bool GPU::ConvertScreenCoordinatesToBeamTicksAndLines(s32 window_x, s32 window_y u32* out_line) const { auto [display_x, display_y] = g_host_display->ConvertWindowCoordinatesToDisplayCoordinates( - window_x, window_y, g_host_display->GetWindowWidth(), g_host_display->GetWindowHeight(), - g_host_display->GetDisplayTopMargin()); + window_x, window_y, g_host_display->GetWindowWidth(), g_host_display->GetWindowHeight()); if (x_scale != 1.0f) { diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp index bfc642956..2c2990c36 100644 --- a/src/core/host_display.cpp +++ b/src/core/host_display.cpp @@ -295,14 +295,14 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, float* *out_scale = scale; } -std::tuple HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, s32 top_margin, +std::tuple HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, bool apply_aspect_ratio /* = true */) const { float left, top, width, height, left_padding, top_padding; - CalculateDrawRect(window_width, window_height - top_margin, &left, &top, &width, &height, &left_padding, &top_padding, - nullptr, nullptr, apply_aspect_ratio); + CalculateDrawRect(window_width, window_height, &left, &top, &width, &height, &left_padding, &top_padding, nullptr, + nullptr, apply_aspect_ratio); - return std::make_tuple(static_cast(left + left_padding), static_cast(top + top_padding) + top_margin, + return std::make_tuple(static_cast(left + left_padding), static_cast(top + top_padding), static_cast(width), static_cast(height)); } @@ -326,17 +326,17 @@ std::tuple HostDisplay::CalculateSoftwareCursorDrawRect(s32 } std::tuple HostDisplay::ConvertWindowCoordinatesToDisplayCoordinates(s32 window_x, s32 window_y, - s32 window_width, s32 window_height, - s32 top_margin) const + s32 window_width, + s32 window_height) const { float left, top, width, height, left_padding, top_padding; float scale, x_scale; - CalculateDrawRect(window_width, window_height - top_margin, &left, &top, &width, &height, &left_padding, &top_padding, - &scale, &x_scale); + CalculateDrawRect(window_width, window_height, &left, &top, &width, &height, &left_padding, &top_padding, &scale, + &x_scale); // convert coordinates to active display region, then to full display region const float scaled_display_x = static_cast(window_x) - left_padding; - const float scaled_display_y = static_cast(window_y) - top_padding + static_cast(top_margin); + const float scaled_display_y = static_cast(window_y) - top_padding; // scale back to internal resolution const float display_x = scaled_display_x / scale / x_scale; diff --git a/src/core/host_display.h b/src/core/host_display.h index 89ada874b..54ee8b864 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -23,13 +23,6 @@ enum class RenderAPI : u32 class HostDisplay { public: - enum class Alignment - { - LeftOrTop, - Center, - RightOrBottom - }; - struct AdapterAndModeList { std::vector adapter_names; @@ -62,7 +55,6 @@ public: } ALWAYS_INLINE const void* GetDisplayTextureHandle() const { return m_display_texture; } - ALWAYS_INLINE s32 GetDisplayTopMargin() const { return m_display_top_margin; } ALWAYS_INLINE s32 GetDisplayWidth() const { return m_display_width; } ALWAYS_INLINE s32 GetDisplayHeight() const { return m_display_height; } ALWAYS_INLINE float GetDisplayAspectRatio() const { return m_display_aspect_ratio; } @@ -177,9 +169,6 @@ public: /// Returns the amount of GPU time utilized since the last time this method was called. virtual float GetAndResetAccumulatedGPUTime(); - void SetDisplayTopMargin(s32 height) { m_display_top_margin = height; } - void SetDisplayAlignment(Alignment alignment) { m_display_alignment = alignment; } - /// Sets the software cursor to the specified texture. Ownership of the texture is transferred. void SetSoftwareCursor(std::unique_ptr texture, float scale = 1.0f); @@ -193,12 +182,12 @@ public: void ClearSoftwareCursor(); /// Helper function for computing the draw rectangle in a larger window. - std::tuple CalculateDrawRect(s32 window_width, s32 window_height, s32 top_margin, + std::tuple CalculateDrawRect(s32 window_width, s32 window_height, bool apply_aspect_ratio = true) const; /// Helper function for converting window coordinates to display coordinates. std::tuple ConvertWindowCoordinatesToDisplayCoordinates(s32 window_x, s32 window_y, s32 window_width, - s32 window_height, s32 top_margin) const; + s32 window_height) const; /// Helper function to save texture data to a PNG. If flip_y is set, the image will be flipped aka OpenGL. bool WriteTextureToFile(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, std::string filename, @@ -251,9 +240,6 @@ protected: s32 m_display_texture_view_width = 0; s32 m_display_texture_view_height = 0; - s32 m_display_top_margin = 0; - Alignment m_display_alignment = Alignment::Center; - std::unique_ptr m_cursor_texture; float m_cursor_texture_scale = 1.0f; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index c1a40e8f0..e05e15291 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -1033,9 +1033,8 @@ float Settings::GetDisplayAspectRatioValue() const if (!g_host_display) return s_display_aspect_ratio_values[static_cast(DEFAULT_DISPLAY_ASPECT_RATIO)]; - const u32 width = g_host_display->GetWindowWidth(); - const u32 height = g_host_display->GetWindowHeight() - g_host_display->GetDisplayTopMargin(); - return static_cast(width) / static_cast(height); + return static_cast(g_host_display->GetWindowWidth()) / + static_cast(g_host_display->GetWindowHeight()); } case DisplayAspectRatio::Custom: @@ -1051,10 +1050,11 @@ float Settings::GetDisplayAspectRatioValue() const } } -static std::array s_display_alignment_names = {{"LeftOrTop", "Center", "RightOrBottom"}}; -static std::array s_display_alignment_display_names = { - {TRANSLATABLE("DisplayAlignment", "LeftOrTop"), TRANSLATABLE("DisplayAlignment", "Center"), - TRANSLATABLE("DisplayAlignment", "RightOrBottom")}}; +static std::array(DisplayAlignment::Count)> s_display_alignment_names = { + {"LeftOrTop", "Center", "RightOrBottom"}}; +static std::array(DisplayAlignment::Count)> s_display_alignment_display_names = { + {TRANSLATABLE("DisplayAlignment", "Left / Top"), TRANSLATABLE("DisplayAlignment", "Center"), + TRANSLATABLE("DisplayAlignment", "Right / Bottom")}}; std::optional Settings::ParseDisplayAlignment(const char* str) { diff --git a/src/core/settings.h b/src/core/settings.h index 2b2ae9aae..3558e00f2 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -243,20 +243,44 @@ struct Settings bool log_to_window = false; bool log_to_file = false; - ALWAYS_INLINE bool IsUsingCodeCache() const { return (cpu_execution_mode != CPUExecutionMode::Interpreter); } - ALWAYS_INLINE bool IsUsingRecompiler() const { return (cpu_execution_mode == CPUExecutionMode::Recompiler); } - ALWAYS_INLINE bool IsUsingSoftwareRenderer() const { return (gpu_renderer == GPURenderer::Software); } - ALWAYS_INLINE bool IsRunaheadEnabled() const { return (runahead_frames > 0); } + ALWAYS_INLINE bool IsUsingCodeCache() const + { + return (cpu_execution_mode != CPUExecutionMode::Interpreter); + } + ALWAYS_INLINE bool IsUsingRecompiler() const + { + return (cpu_execution_mode == CPUExecutionMode::Recompiler); + } + ALWAYS_INLINE bool IsUsingSoftwareRenderer() const + { + return (gpu_renderer == GPURenderer::Software); + } + ALWAYS_INLINE bool IsRunaheadEnabled() const + { + return (runahead_frames > 0); + } ALWAYS_INLINE PGXPMode GetPGXPMode() { return gpu_pgxp_enable ? (gpu_pgxp_cpu ? PGXPMode::CPU : PGXPMode::Memory) : PGXPMode::Disabled; } - ALWAYS_INLINE bool UsingPGXPDepthBuffer() const { return gpu_pgxp_enable && gpu_pgxp_depth_buffer; } - ALWAYS_INLINE bool UsingPGXPCPUMode() const { return gpu_pgxp_enable && gpu_pgxp_cpu; } - ALWAYS_INLINE float GetPGXPDepthClearThreshold() const { return gpu_pgxp_depth_clear_threshold * 4096.0f; } - ALWAYS_INLINE void SetPGXPDepthClearThreshold(float value) { gpu_pgxp_depth_clear_threshold = value / 4096.0f; } + ALWAYS_INLINE bool UsingPGXPDepthBuffer() const + { + return gpu_pgxp_enable && gpu_pgxp_depth_buffer; + } + ALWAYS_INLINE bool UsingPGXPCPUMode() const + { + return gpu_pgxp_enable && gpu_pgxp_cpu; + } + ALWAYS_INLINE float GetPGXPDepthClearThreshold() const + { + return gpu_pgxp_depth_clear_threshold * 4096.0f; + } + ALWAYS_INLINE void SetPGXPDepthClearThreshold(float value) + { + gpu_pgxp_depth_clear_threshold = value / 4096.0f; + } ALWAYS_INLINE bool IsUsingFastmem() const { diff --git a/src/core/types.h b/src/core/types.h index c078f4d99..09faeb16f 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -109,11 +109,12 @@ enum class DisplayAspectRatio : u8 Count }; - enum class DisplayAlignment +enum class DisplayAlignment { LeftOrTop, Center, - RightOrBottom + RightOrBottom, + Count }; enum class AudioBackend : u8 diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index 6a00108e4..d33dc8ff9 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -785,7 +785,7 @@ void D3D11HostDisplay::RenderDisplay() if (!HasDisplayTexture()) return; - const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin); + const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight()); if (!m_post_processing_chain.IsEmpty()) { diff --git a/src/frontend-common/d3d12_host_display.cpp b/src/frontend-common/d3d12_host_display.cpp index 933c84374..3df04a459 100644 --- a/src/frontend-common/d3d12_host_display.cpp +++ b/src/frontend-common/d3d12_host_display.cpp @@ -687,7 +687,7 @@ void D3D12HostDisplay::RenderDisplay(ID3D12GraphicsCommandList* cmdlist) if (!HasDisplayTexture()) return; - const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin); + const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight()); // if (!m_post_processing_chain.IsEmpty()) // { diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index ff31b4df9..4daad42d7 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -696,7 +696,7 @@ void OpenGLHostDisplay::RenderDisplay() if (!HasDisplayTexture()) return; - const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin); + const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight()); if (!m_post_processing_chain.IsEmpty()) { diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index c005cabe2..93dada004 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -767,7 +767,7 @@ void VulkanHostDisplay::RenderDisplay() return; } - const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin); + const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight()); if (!m_post_processing_chain.IsEmpty()) {