mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-03-06 14:27:44 +00:00
WindowInfo: Add surface_scale field
This commit is contained in:
parent
e374853cf5
commit
bf08385051
|
@ -29,6 +29,7 @@ struct WindowInfo
|
||||||
void* window_handle = nullptr;
|
void* window_handle = nullptr;
|
||||||
u32 surface_width = 0;
|
u32 surface_width = 0;
|
||||||
u32 surface_height = 0;
|
u32 surface_height = 0;
|
||||||
|
float surface_scale = 1.0f;
|
||||||
SurfaceFormat surface_format = SurfaceFormat::RGB8;
|
SurfaceFormat surface_format = SurfaceFormat::RGB8;
|
||||||
|
|
||||||
// Needed for macOS.
|
// Needed for macOS.
|
||||||
|
|
|
@ -767,6 +767,7 @@ void LibretroHostInterface::SwitchToHardwareRenderer()
|
||||||
wi.display_connection = &g_libretro_host_interface.m_hw_render_callback;
|
wi.display_connection = &g_libretro_host_interface.m_hw_render_callback;
|
||||||
wi.surface_width = avi.geometry.base_width;
|
wi.surface_width = avi.geometry.base_width;
|
||||||
wi.surface_height = avi.geometry.base_height;
|
wi.surface_height = avi.geometry.base_height;
|
||||||
|
wi.surface_scale = 1.0f;
|
||||||
if (!display || !display->CreateRenderDevice(wi, {}, g_libretro_host_interface.m_settings.gpu_use_debug_device))
|
if (!display || !display->CreateRenderDevice(wi, {}, g_libretro_host_interface.m_settings.gpu_use_debug_device))
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Failed to create hardware host display");
|
Log_ErrorPrintf("Failed to create hardware host display");
|
||||||
|
|
|
@ -86,6 +86,7 @@ std::optional<WindowInfo> QtDisplayWidget::getWindowInfo() const
|
||||||
|
|
||||||
wi.surface_width = scaledWindowWidth();
|
wi.surface_width = scaledWindowWidth();
|
||||||
wi.surface_height = scaledWindowHeight();
|
wi.surface_height = scaledWindowHeight();
|
||||||
|
wi.surface_scale = devicePixelRatioFromScreen();
|
||||||
wi.surface_format = WindowInfo::SurfaceFormat::RGB8;
|
wi.surface_format = WindowInfo::SurfaceFormat::RGB8;
|
||||||
|
|
||||||
return wi;
|
return wi;
|
||||||
|
|
|
@ -47,36 +47,6 @@ ALWAYS_INLINE static TinyString GetWindowTitle()
|
||||||
return TinyString::FromFormat("DuckStation %s (%s)", g_scm_tag_str, g_scm_branch_str);
|
return TinyString::FromFormat("DuckStation %s (%s)", g_scm_tag_str, g_scm_branch_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SDLHostInterface::GetDPIScaleFactor(SDL_Window* window)
|
|
||||||
{
|
|
||||||
#ifdef __APPLE__
|
|
||||||
static constexpr float DEFAULT_DPI = 72.0f;
|
|
||||||
#else
|
|
||||||
static constexpr float DEFAULT_DPI = 96.0f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!window)
|
|
||||||
{
|
|
||||||
SDL_Window* dummy_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1,
|
|
||||||
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN);
|
|
||||||
if (!dummy_window)
|
|
||||||
return 1.0f;
|
|
||||||
|
|
||||||
const float scale = GetDPIScaleFactor(dummy_window);
|
|
||||||
|
|
||||||
SDL_DestroyWindow(dummy_window);
|
|
||||||
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
int display_index = SDL_GetWindowDisplayIndex(window);
|
|
||||||
float display_dpi = DEFAULT_DPI;
|
|
||||||
if (SDL_GetDisplayDPI(display_index, &display_dpi, nullptr, nullptr) != 0)
|
|
||||||
return 1.0f;
|
|
||||||
|
|
||||||
return display_dpi / DEFAULT_DPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDLHostInterface::CreateSDLWindow()
|
bool SDLHostInterface::CreateSDLWindow()
|
||||||
{
|
{
|
||||||
static constexpr u32 DEFAULT_WINDOW_WIDTH = 900;
|
static constexpr u32 DEFAULT_WINDOW_WIDTH = 900;
|
||||||
|
@ -92,7 +62,7 @@ bool SDLHostInterface::CreateSDLWindow()
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
{
|
{
|
||||||
// scale by default monitor's DPI
|
// scale by default monitor's DPI
|
||||||
float scale = GetDPIScaleFactor(nullptr);
|
float scale = SDLUtil::GetDPIScaleFactor(nullptr);
|
||||||
window_width = static_cast<u32>(std::round(static_cast<float>(window_width) * scale));
|
window_width = static_cast<u32>(std::round(static_cast<float>(window_width) * scale));
|
||||||
window_height = static_cast<u32>(std::round(static_cast<float>(window_height) * scale));
|
window_height = static_cast<u32>(std::round(static_cast<float>(window_height) * scale));
|
||||||
}
|
}
|
||||||
|
@ -214,7 +184,7 @@ void SDLHostInterface::DestroyDisplay()
|
||||||
|
|
||||||
void SDLHostInterface::CreateImGuiContext()
|
void SDLHostInterface::CreateImGuiContext()
|
||||||
{
|
{
|
||||||
const float framebuffer_scale = GetDPIScaleFactor(m_window);
|
const float framebuffer_scale = SDLUtil::GetDPIScaleFactor(m_window);
|
||||||
|
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui::GetIO().IniFilename = nullptr;
|
ImGui::GetIO().IniFilename = nullptr;
|
||||||
|
@ -229,7 +199,7 @@ void SDLHostInterface::CreateImGuiContext()
|
||||||
|
|
||||||
void SDLHostInterface::UpdateFramebufferScale()
|
void SDLHostInterface::UpdateFramebufferScale()
|
||||||
{
|
{
|
||||||
const float framebuffer_scale = GetDPIScaleFactor(m_window);
|
const float framebuffer_scale = SDLUtil::GetDPIScaleFactor(m_window);
|
||||||
ImGui::GetIO().DisplayFramebufferScale.x = framebuffer_scale;
|
ImGui::GetIO().DisplayFramebufferScale.x = framebuffer_scale;
|
||||||
ImGui::GetIO().DisplayFramebufferScale.y = framebuffer_scale;
|
ImGui::GetIO().DisplayFramebufferScale.y = framebuffer_scale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
bool HasSystem() const { return static_cast<bool>(m_system); }
|
bool HasSystem() const { return static_cast<bool>(m_system); }
|
||||||
|
|
||||||
static float GetDPIScaleFactor(SDL_Window* window);
|
|
||||||
|
|
||||||
bool CreateSDLWindow();
|
bool CreateSDLWindow();
|
||||||
void DestroySDLWindow();
|
void DestroySDLWindow();
|
||||||
bool CreateDisplay();
|
bool CreateDisplay();
|
||||||
|
|
|
@ -32,6 +32,7 @@ std::optional<WindowInfo> GetWindowInfoForSDLWindow(SDL_Window* window)
|
||||||
WindowInfo wi;
|
WindowInfo wi;
|
||||||
wi.surface_width = static_cast<u32>(window_width);
|
wi.surface_width = static_cast<u32>(window_width);
|
||||||
wi.surface_height = static_cast<u32>(window_height);
|
wi.surface_height = static_cast<u32>(window_height);
|
||||||
|
wi.surface_scale = GetDPIScaleFactor(window);
|
||||||
wi.surface_format = WindowInfo::SurfaceFormat::RGB8;
|
wi.surface_format = WindowInfo::SurfaceFormat::RGB8;
|
||||||
|
|
||||||
switch (syswm.subsystem)
|
switch (syswm.subsystem)
|
||||||
|
@ -65,4 +66,34 @@ std::optional<WindowInfo> GetWindowInfoForSDLWindow(SDL_Window* window)
|
||||||
|
|
||||||
return wi;
|
return wi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetDPIScaleFactor(SDL_Window* window)
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
static constexpr float DEFAULT_DPI = 72.0f;
|
||||||
|
#else
|
||||||
|
static constexpr float DEFAULT_DPI = 96.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
SDL_Window* dummy_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1,
|
||||||
|
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN);
|
||||||
|
if (!dummy_window)
|
||||||
|
return 1.0f;
|
||||||
|
|
||||||
|
const float scale = GetDPIScaleFactor(dummy_window);
|
||||||
|
|
||||||
|
SDL_DestroyWindow(dummy_window);
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
int display_index = SDL_GetWindowDisplayIndex(window);
|
||||||
|
float display_dpi = DEFAULT_DPI;
|
||||||
|
if (SDL_GetDisplayDPI(display_index, &display_dpi, nullptr, nullptr) != 0)
|
||||||
|
return 1.0f;
|
||||||
|
|
||||||
|
return display_dpi / DEFAULT_DPI;
|
||||||
|
}
|
||||||
} // namespace SDLUtil
|
} // namespace SDLUtil
|
|
@ -7,4 +7,5 @@ struct SDL_Window;
|
||||||
|
|
||||||
namespace SDLUtil {
|
namespace SDLUtil {
|
||||||
std::optional<WindowInfo> GetWindowInfoForSDLWindow(SDL_Window* window);
|
std::optional<WindowInfo> GetWindowInfoForSDLWindow(SDL_Window* window);
|
||||||
|
float GetDPIScaleFactor(SDL_Window* window);
|
||||||
}
|
}
|
Loading…
Reference in a new issue