diff --git a/Common/System/Display.cpp b/Common/System/Display.cpp index 13a734087d..5cb0a4bee4 100644 --- a/Common/System/Display.cpp +++ b/Common/System/Display.cpp @@ -54,6 +54,33 @@ DisplayProperties::DisplayProperties() { rot_matrix.setIdentity(); } +bool DisplayProperties::Recalculate(int new_pixel_xres, int new_pixel_yres, float new_scale, float customScale) { + bool px_changed = false; + if (pixel_xres != new_pixel_xres) { + pixel_xres = new_pixel_xres; + px_changed = true; + } + if (pixel_yres != new_pixel_yres) { + pixel_yres = new_pixel_yres; + px_changed = true; + } + + dpi_scale_real = new_scale; + dpi_scale = new_scale / customScale; + pixel_in_dps = 1.0f / dpi_scale; + + int new_dp_xres = (int)(new_pixel_xres * dpi_scale); + int new_dp_yres = (int)(new_pixel_yres * dpi_scale); + + if (new_dp_xres != dp_xres || new_dp_yres != dp_yres || px_changed) { + dp_xres = new_dp_xres; + dp_yres = new_dp_yres; + return true; + } else { + return false; + } +} + void DisplayProperties::Print() { printf("dp_xres/yres: %d, %d\n", dp_xres, dp_yres); printf("pixel_xres/yres: %d, %d\n", pixel_xres, pixel_yres); diff --git a/Common/System/Display.h b/Common/System/Display.h index a1afec1d7b..3c1bb436a6 100644 --- a/Common/System/Display.h +++ b/Common/System/Display.h @@ -39,6 +39,9 @@ struct DisplayProperties { DisplayProperties(); void Print(); + + // Returns true if the dimensions changed. + bool Recalculate(int new_pixel_xres, int new_pixel_yres, float new_scale, float customScale); }; extern DisplayProperties g_display; diff --git a/Common/System/NativeApp.h b/Common/System/NativeApp.h index 9308cf1bf2..8eef162c5b 100644 --- a/Common/System/NativeApp.h +++ b/Common/System/NativeApp.h @@ -90,5 +90,5 @@ void Native_NotifyWindowHidden(bool hidden); bool Native_IsWindowHidden(); // TODO: Feels like this belongs elsewhere. -bool Native_UpdateScreenScale(int width, int height); +bool Native_UpdateScreenScale(int width, int height, float customScale); diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index d9618824d5..f188e23a57 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -549,7 +549,7 @@ QString MainUI::InputBoxGetQString(QString title, QString defaultValue) { } void MainUI::resizeGL(int w, int h) { - if (Native_UpdateScreenScale(w, h)) { + if (Native_UpdateScreenScale(w, h, 1.0f)) { System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED); } xscale = w / this->width(); diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 7a553df63e..8484fc8133 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -779,7 +779,7 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta bool fullscreen = (window_flags & SDL_WINDOW_FULLSCREEN); // This one calls NativeResized if the size changed. - Native_UpdateScreenScale(new_width_px, new_height_px); + Native_UpdateScreenScale(new_width_px, new_height_px, 1.0f); // Set variable here in case fullscreen was toggled by hotkey if (g_Config.UseFullScreen() != fullscreen) { @@ -1436,7 +1436,7 @@ int main(int argc, char *argv[]) { float dpi_scale = 1.0f / (g_ForcedDPI == 0.0f ? g_DesktopDPI : g_ForcedDPI); - Native_UpdateScreenScale(w * g_DesktopDPI, h * g_DesktopDPI); + Native_UpdateScreenScale(w * g_DesktopDPI, h * g_DesktopDPI, 1.0f); bool mainThreadIsRender = g_Config.iGPUBackend == (int)GPUBackend::OPENGL; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index ed9cb7227e..8dca521881 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1512,16 +1512,12 @@ bool Native_IsWindowHidden() { static bool IsWindowSmall(int pixelWidth, int pixelHeight) { // Can't take this from config as it will not be set if windows is maximized. - int w = (int)(pixelWidth * g_display.dpi_scale); - int h = (int)(pixelHeight * g_display.dpi_scale); + int w = (int)(pixelWidth * g_display.dpi_scale_real); + int h = (int)(pixelHeight * g_display.dpi_scale_real); return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80); } -bool Native_UpdateScreenScale(int pixel_width, int pixel_height) { - bool smallWindow; - - const bool px_changed = g_display.pixel_xres != pixel_width || g_display.pixel_yres != pixel_height; - +bool Native_UpdateScreenScale(int pixel_width, int pixel_height, float customScale) { float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI); float dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI); @@ -1532,34 +1528,15 @@ bool Native_UpdateScreenScale(int pixel_width, int pixel_height) { g_logical_dpi = 96.0f; } - g_display.dpi_scale_real = g_logical_dpi / dpi; - g_display.dpi_scale = g_display.dpi_scale_real; - - float scaleFactor = 1.0f; - - smallWindow = IsWindowSmall(pixel_width, pixel_height); + bool smallWindow = IsWindowSmall(pixel_width, pixel_height); if (smallWindow) { - scaleFactor = 0.5f; + customScale *= 0.5f; } - // No need to change ".dpi" here. - g_display.dpi_scale /= scaleFactor; - - g_display.pixel_in_dps = 1.0f / g_display.dpi_scale; - - int new_dp_xres = (int)(pixel_width * g_display.dpi_scale); - int new_dp_yres = (int)(pixel_height * g_display.dpi_scale); - - const bool dp_changed = new_dp_xres != g_display.dp_xres || new_dp_yres != g_display.dp_yres; - - if (!dp_changed && !px_changed) { + if (g_display.Recalculate(pixel_width, pixel_height, g_logical_dpi / dpi, customScale)) { + NativeResized(); + return true; + } else { return false; } - - g_display.dp_xres = new_dp_xres; - g_display.dp_yres = new_dp_yres; - g_display.pixel_xres = pixel_width; - g_display.pixel_yres = pixel_height; - NativeResized(); - return true; } diff --git a/UWP/App.cpp b/UWP/App.cpp index 49eb8cd976..67bafebe0a 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -330,7 +330,7 @@ void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ ar PSP_CoreParameter().pixelWidth = (int)(width * scale); PSP_CoreParameter().pixelHeight = (int)(height * scale); - if (Native_UpdateScreenScale((int)width, (int)height)) { + if (Native_UpdateScreenScale((int)width, (int)height, 1.0f)) { System_PostUIMessage(UIMessage::GPU_DISPLAY_RESIZED); } } diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 403a43d51c..f0dc681c5c 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -298,7 +298,7 @@ namespace MainWindow DEBUG_LOG(Log::System, "Pixel width/height: %dx%d", PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); - if (Native_UpdateScreenScale(width, height)) { + if (Native_UpdateScreenScale(width, height, 1.0f)) { System_PostUIMessage(UIMessage::GPU_DISPLAY_RESIZED); System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED); }