mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
Misc: Cleanup/deduplicate from c9cba5e
This commit is contained in:
parent
1538f26013
commit
0709f92ac1
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -295,14 +295,14 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, float*
|
|||
*out_scale = scale;
|
||||
}
|
||||
|
||||
std::tuple<s32, s32, s32, s32> HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, s32 top_margin,
|
||||
std::tuple<s32, s32, s32, s32> 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<s32>(left + left_padding), static_cast<s32>(top + top_padding) + top_margin,
|
||||
return std::make_tuple(static_cast<s32>(left + left_padding), static_cast<s32>(top + top_padding),
|
||||
static_cast<s32>(width), static_cast<s32>(height));
|
||||
}
|
||||
|
||||
|
@ -326,17 +326,17 @@ std::tuple<s32, s32, s32, s32> HostDisplay::CalculateSoftwareCursorDrawRect(s32
|
|||
}
|
||||
|
||||
std::tuple<float, float> 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<float>(window_x) - left_padding;
|
||||
const float scaled_display_y = static_cast<float>(window_y) - top_padding + static_cast<float>(top_margin);
|
||||
const float scaled_display_y = static_cast<float>(window_y) - top_padding;
|
||||
|
||||
// scale back to internal resolution
|
||||
const float display_x = scaled_display_x / scale / x_scale;
|
||||
|
|
|
@ -23,13 +23,6 @@ enum class RenderAPI : u32
|
|||
class HostDisplay
|
||||
{
|
||||
public:
|
||||
enum class Alignment
|
||||
{
|
||||
LeftOrTop,
|
||||
Center,
|
||||
RightOrBottom
|
||||
};
|
||||
|
||||
struct AdapterAndModeList
|
||||
{
|
||||
std::vector<std::string> 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<GPUTexture> 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<s32, s32, s32, s32> CalculateDrawRect(s32 window_width, s32 window_height, s32 top_margin,
|
||||
std::tuple<s32, s32, s32, s32> CalculateDrawRect(s32 window_width, s32 window_height,
|
||||
bool apply_aspect_ratio = true) const;
|
||||
|
||||
/// Helper function for converting window coordinates to display coordinates.
|
||||
std::tuple<float, float> 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<GPUTexture> m_cursor_texture;
|
||||
float m_cursor_texture_scale = 1.0f;
|
||||
|
||||
|
|
|
@ -1033,9 +1033,8 @@ float Settings::GetDisplayAspectRatioValue() const
|
|||
if (!g_host_display)
|
||||
return s_display_aspect_ratio_values[static_cast<int>(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<float>(width) / static_cast<float>(height);
|
||||
return static_cast<float>(g_host_display->GetWindowWidth()) /
|
||||
static_cast<float>(g_host_display->GetWindowHeight());
|
||||
}
|
||||
|
||||
case DisplayAspectRatio::Custom:
|
||||
|
@ -1051,10 +1050,11 @@ float Settings::GetDisplayAspectRatioValue() const
|
|||
}
|
||||
}
|
||||
|
||||
static std::array<const char*, 3> s_display_alignment_names = {{"LeftOrTop", "Center", "RightOrBottom"}};
|
||||
static std::array<const char*, 3> s_display_alignment_display_names = {
|
||||
{TRANSLATABLE("DisplayAlignment", "LeftOrTop"), TRANSLATABLE("DisplayAlignment", "Center"),
|
||||
TRANSLATABLE("DisplayAlignment", "RightOrBottom")}};
|
||||
static std::array<const char*, static_cast<size_t>(DisplayAlignment::Count)> s_display_alignment_names = {
|
||||
{"LeftOrTop", "Center", "RightOrBottom"}};
|
||||
static std::array<const char*, static_cast<size_t>(DisplayAlignment::Count)> s_display_alignment_display_names = {
|
||||
{TRANSLATABLE("DisplayAlignment", "Left / Top"), TRANSLATABLE("DisplayAlignment", "Center"),
|
||||
TRANSLATABLE("DisplayAlignment", "Right / Bottom")}};
|
||||
|
||||
std::optional<DisplayAlignment> Settings::ParseDisplayAlignment(const char* str)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -109,11 +109,12 @@ enum class DisplayAspectRatio : u8
|
|||
Count
|
||||
};
|
||||
|
||||
enum class DisplayAlignment
|
||||
enum class DisplayAlignment
|
||||
{
|
||||
LeftOrTop,
|
||||
Center,
|
||||
RightOrBottom
|
||||
RightOrBottom,
|
||||
Count
|
||||
};
|
||||
|
||||
enum class AudioBackend : u8
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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())
|
||||
// {
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue