From 23f43dd9fa774927a334c6d76f6df527b7bf2e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 14:10:50 -0600 Subject: [PATCH 1/8] DPI code cleanup --- Qt/QtMain.cpp | 6 ++++-- UI/NativeApp.cpp | 33 +++++++++++++++++---------------- UWP/PPSSPP_UWPMain.cpp | 7 +++++-- android/jni/app-android.cpp | 13 ++++++------- assets/compat.ini | 1 + 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 6d07e637cf9f..d9618824d5cd 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -839,12 +839,14 @@ int main(int argc, char *argv[]) if (res.width() < res.height()) res.transpose(); + g_display.pixel_xres = res.width(); g_display.pixel_yres = res.height(); - g_display.dpi_scale = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX(); // We assume physicalDotsPerInchY is the same as PerInchX. - g_display.dpi_scale_real = g_display.dpi_scale; + g_display.dpi_scale_real = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX(); + + g_display.dpi_scale = g_display.dpi_scale_real; g_display.dp_xres = (int)(g_display.pixel_xres * g_display.dpi_scale); g_display.dp_yres = (int)(g_display.pixel_yres * g_display.dpi_scale); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 79862da50010..59bb55c820d2 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1517,7 +1517,7 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) { return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80); } -bool Native_UpdateScreenScale(int width, int height) { +bool Native_UpdateScreenScale(int pixel_width, int pixel_height) { bool smallWindow; float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI); @@ -1530,29 +1530,30 @@ bool Native_UpdateScreenScale(int width, int height) { g_logical_dpi = 96.0f; } - g_display.dpi_scale = g_logical_dpi / g_display.dpi; - g_display.dpi_scale_real = g_display.dpi_scale; + g_display.dpi_scale_real = g_logical_dpi / g_display.dpi; + g_display.dpi_scale = g_display.dpi_scale_real; - smallWindow = IsWindowSmall(width, height); + smallWindow = IsWindowSmall(pixel_width, pixel_height); if (smallWindow) { g_display.dpi /= 2.0f; g_display.dpi_scale *= 2.0f; } g_display.pixel_in_dps = 1.0f / g_display.dpi_scale; - int new_dp_xres = (int)(width * g_display.dpi_scale); - int new_dp_yres = (int)(height * 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); bool dp_changed = new_dp_xres != g_display.dp_xres || new_dp_yres != g_display.dp_yres; - bool px_changed = g_display.pixel_xres != width || g_display.pixel_yres != height; - - if (dp_changed || px_changed) { - g_display.dp_xres = new_dp_xres; - g_display.dp_yres = new_dp_yres; - g_display.pixel_xres = width; - g_display.pixel_yres = height; - NativeResized(); - return true; + bool px_changed = g_display.pixel_xres != pixel_width || g_display.pixel_yres != pixel_height; + + if (!dp_changed && !px_changed) { + return false; } - 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/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 77c5fb51faed..324191eec5e5 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -143,16 +143,19 @@ void PPSSPP_UWPMain::UpdateScreenState() { if (g_display.rotation == DisplayRotation::ROTATE_90 || g_display.rotation == DisplayRotation::ROTATE_270) { // We need to swap our width/height. + // TODO: This is most likely dead code, since we no longer support Windows Phone. std::swap(g_display.pixel_xres, g_display.pixel_yres); } g_display.dpi = m_deviceResources->GetActualDpi(); - if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) { // Boost DPI a bit to look better. g_display.dpi *= 96.0f / 136.0f; } - g_display.dpi_scale = 96.0f / g_display.dpi; + + g_display.dpi_scale_real = 96.0f / g_display.dpi; + + g_display.dpi_scale = g_display.dpi_scale_real; g_display.pixel_in_dps = 1.0f / g_display.dpi_scale; g_display.dp_xres = g_display.pixel_xres * g_display.dpi_scale; diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 2bfb19d75a5d..4b4f86419458 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -152,8 +152,8 @@ static int deviceType; // Exposed so it can be displayed on the touchscreen test. static int display_xres; static int display_yres; -static int display_dpi_x; -static int display_dpi_y; +static int display_dpi; + static int backbuffer_format; // Android PixelFormat enum static int desiredBackbufferSizeX; @@ -999,8 +999,8 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * e } static void recalculateDpi() { - g_display.dpi = (float)display_dpi_x; - g_display.dpi_scale_real = 240.0f / (float)display_dpi_x; + g_display.dpi = (float)display_dpi; + g_display.dpi_scale_real = 240.0f / (float)display_dpi; g_display.dpi_scale = g_display.dpi_scale_real; g_display.dp_xres = display_xres * g_display.dpi_scale; @@ -1415,14 +1415,13 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setDisplayParameters(JN bool changed = false; changed = changed || display_xres != xres || display_yres != yres; - changed = changed || display_dpi_x != dpi || display_dpi_y != dpi; + changed = changed || display_dpi != dpi; changed = changed || g_display.display_hz != refreshRate; if (changed) { display_xres = xres; display_yres = yres; - display_dpi_x = dpi; - display_dpi_y = dpi; + display_dpi = dpi; g_display.display_hz = refreshRate; recalculateDpi(); diff --git a/assets/compat.ini b/assets/compat.ini index 1f4fe2db98ea..4c83c6bdc3b6 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1359,6 +1359,7 @@ ULES00808 = true ULUS10270 = true [DeswizzleDepth] +# Ratchet & Clank smoke effects (#15859) UCUS98633 = true UCAS40145 = true UCES00420 = true From 0acd2aa5171571be139c6f7a2c8387fc97736e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 14:27:22 -0600 Subject: [PATCH 2/8] DPI: Remove g_display.dpi --- Common/System/Display.cpp | 2 +- Common/System/Display.h | 12 ++++++------ UI/DevScreens.cpp | 21 ++++++++++++--------- UI/NativeApp.cpp | 22 ++++++++++++++-------- UWP/PPSSPP_UWPMain.cpp | 6 +++--- android/jni/app-android.cpp | 6 ++++-- ios/DisplayManager.mm | 9 +++++---- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/Common/System/Display.cpp b/Common/System/Display.cpp index 79038890b874..13a734087d8d 100644 --- a/Common/System/Display.cpp +++ b/Common/System/Display.cpp @@ -58,7 +58,7 @@ 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); - printf("dpi, dpi_scale: %f, %f\n", dpi, dpi_scale); + printf("dpi_scale: %f\n", dpi_scale); printf("pixel_in_dps: %f\n", pixel_in_dps); printf("dpi_real: %f\n", dpi_scale_real); diff --git a/Common/System/Display.h b/Common/System/Display.h index 98f350690f0e..a1afec1d7bf8 100644 --- a/Common/System/Display.h +++ b/Common/System/Display.h @@ -16,20 +16,20 @@ enum class DisplayRotation { }; struct DisplayProperties { - // Display resolution in virtual ("display") pixels - int dp_xres; - int dp_yres; // Display resolution in true pixels. int pixel_xres; int pixel_yres; - float dpi = 1.0f; float dpi_scale = 1.0f; - // pixel_xres/yres in dps + // Display resolution in virtual ("display") pixels + int dp_xres; + int dp_yres; + + // Size of a physical pixel in dps float pixel_in_dps = 1.0f; - // If DPI is overridden (like in small window mode), these are still the original DPI. + // If DPI is overridden (like in small window mode), this is still the original DPI scale factor. float dpi_scale_real = 1.0f; float display_hz = 60.0f; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index c280b156efdd..07fa45863eb4 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -646,11 +646,11 @@ void SystemInfoScreen::CreateTabs() { System_GetPropertyInt(SYSPROP_DISPLAY_XRES), System_GetPropertyInt(SYSPROP_DISPLAY_YRES)))); #endif - displayInfo->Add(new InfoItem(si->T("UI resolution"), StringFromFormat("%dx%d (%s: %0.2f)", + displayInfo->Add(new InfoItem(si->T("UI resolution"), StringFromFormat("%dx%d (%s: %d)", g_display.dp_xres, g_display.dp_yres, si->T_cstr("DPI"), - g_display.dpi))); + System_GetPropertyInt(SYSPROP_DISPLAY_DPI)))); displayInfo->Add(new InfoItem(si->T("Pixel resolution"), StringFromFormat("%dx%d", g_display.pixel_xres, g_display.pixel_yres))); @@ -1311,22 +1311,25 @@ void TouchTestScreen::DrawForeground(UIContext &dc) { truncate_cpy(extra_debug, Android_GetInputDeviceDebugString().c_str()); #endif - snprintf(buffer, sizeof(buffer), + // Hm, why don't we print all the info on Android? #if PPSSPP_PLATFORM(ANDROID) + snprintf(buffer, sizeof(buffer), + "display_res: %dx%d\n", + (int)System_GetPropertyInt(SYSPROP_DISPLAY_XRES), (int)System_GetPropertyInt(SYSPROP_DISPLAY_YRES)); +#else + snprintf(buffer, sizeof(buffer), "display_res: %dx%d\n" -#endif "dp_res: %dx%d pixel_res: %dx%d\n" - "g_dpi: %0.3f g_dpi_scale: %0.3f\n" - "g_dpi_scale_real: %0.3f\n" + "dpi_scale: %0.3f\n" + "dpi_scale_real: %0.3f\n" "delta: %0.2f ms fps: %0.3f\n%s", -#if PPSSPP_PLATFORM(ANDROID) (int)System_GetPropertyInt(SYSPROP_DISPLAY_XRES), (int)System_GetPropertyInt(SYSPROP_DISPLAY_YRES), -#endif g_display.dp_xres, g_display.dp_yres, g_display.pixel_xres, g_display.pixel_yres, - g_display.dpi, g_display.dpi_scale, + g_display.dpi_scale, g_display.dpi_scale_real, delta * 1000.0, 1.0 / delta, extra_debug); +#endif // On Android, also add joystick debug data. dc.DrawTextShadow(buffer, bounds.centerX(), bounds.y + 20.0f, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 59bb55c820d2..ed9cb7227e68 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1520,31 +1520,37 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) { 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; + float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI); - g_display.dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI); + float dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI); - if (g_display.dpi < 0.0f) { - g_display.dpi = 96.0f; + if (dpi < 0.0f) { + dpi = 96.0f; } if (g_logical_dpi < 0.0f) { g_logical_dpi = 96.0f; } - g_display.dpi_scale_real = g_logical_dpi / g_display.dpi; + 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); if (smallWindow) { - g_display.dpi /= 2.0f; - g_display.dpi_scale *= 2.0f; + scaleFactor = 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); - bool dp_changed = new_dp_xres != g_display.dp_xres || new_dp_yres != g_display.dp_yres; - bool px_changed = g_display.pixel_xres != pixel_width || g_display.pixel_yres != pixel_height; + const bool dp_changed = new_dp_xres != g_display.dp_xres || new_dp_yres != g_display.dp_yres; if (!dp_changed && !px_changed) { return false; diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 324191eec5e5..f6a841995418 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -147,13 +147,13 @@ void PPSSPP_UWPMain::UpdateScreenState() { std::swap(g_display.pixel_xres, g_display.pixel_yres); } - g_display.dpi = m_deviceResources->GetActualDpi(); + float dpi = m_deviceResources->GetActualDpi(); if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) { // Boost DPI a bit to look better. - g_display.dpi *= 96.0f / 136.0f; + dpi *= 96.0f / 136.0f; } - g_display.dpi_scale_real = 96.0f / g_display.dpi; + g_display.dpi_scale_real = 96.0f / dpi; g_display.dpi_scale = g_display.dpi_scale_real; g_display.pixel_in_dps = 1.0f / g_display.dpi_scale; diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 4b4f86419458..b273de135a0a 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -412,6 +412,8 @@ int64_t System_GetPropertyInt(SystemProperty prop) { return display_xres; case SYSPROP_DISPLAY_YRES: return display_yres; + case SYSPROP_DISPLAY_DPI: + return display_dpi; case SYSPROP_AUDIO_SAMPLE_RATE: return sampleRate; case SYSPROP_AUDIO_FRAMES_PER_BUFFER: @@ -999,8 +1001,8 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * e } static void recalculateDpi() { - g_display.dpi = (float)display_dpi; g_display.dpi_scale_real = 240.0f / (float)display_dpi; + g_display.dpi_scale = g_display.dpi_scale_real; g_display.dp_xres = display_xres * g_display.dpi_scale; @@ -1009,7 +1011,7 @@ static void recalculateDpi() { g_display.pixel_in_dps = (float)g_display.pixel_xres / g_display.dp_xres; INFO_LOG(Log::G3D, "RecalcDPI: display_xres=%d display_yres=%d pixel_xres=%d pixel_yres=%d", display_xres, display_yres, g_display.pixel_xres, g_display.pixel_yres); - INFO_LOG(Log::G3D, "RecalcDPI: g_dpi=%f g_dpi_scale=%f dp_xres=%d dp_yres=%d", g_display.dpi, g_display.dpi_scale, g_display.dp_xres, g_display.dp_yres); + INFO_LOG(Log::G3D, "RecalcDPI: g_dpi=%d g_dpi_scale=%f dp_xres=%d dp_yres=%d", display_dpi, g_display.dpi_scale, g_display.dp_xres, g_display.dp_yres); } extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) { diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index 62f53452f584..c2dae42cf135 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -142,13 +142,14 @@ - (void)updateResolution:(UIScreen *)screen { std::swap(size.height, size.width); } + float dpi; if (screen == [UIScreen mainScreen]) { - g_display.dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; + dpi = (IS_IPAD() ? 200.0f : 150.0f) * scale; } else { float diagonal = sqrt(size.height * size.height + size.width * size.width); - g_display.dpi = diagonal * scale * 0.1f; + dpi = diagonal * scale * 0.1f; } - g_display.dpi_scale_real = 240.0f / g_display.dpi; + g_display.dpi_scale_real = 240.0f / dpi; g_display.dpi_scale = g_display.dpi_scale_real; @@ -161,7 +162,7 @@ - (void)updateResolution:(UIScreen *)screen { g_display.pixel_in_dps = (float)g_display.pixel_xres / (float)g_display.dp_xres; [[sharedViewController getView] setContentScaleFactor:scale]; - + // PSP native resize PSP_CoreParameter().pixelWidth = g_display.pixel_xres; PSP_CoreParameter().pixelHeight = g_display.pixel_yres; From 91360fee9bde5f9147b925b6b9060b4da7438872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 14:52:50 -0600 Subject: [PATCH 3/8] Have Native_UpdateScreenScale use the new g_display.Recalculate() --- Common/System/Display.cpp | 27 ++++++++++++++++++++++++++ Common/System/Display.h | 3 +++ Common/System/NativeApp.h | 2 +- Qt/QtMain.cpp | 2 +- SDL/SDLMain.cpp | 4 ++-- UI/NativeApp.cpp | 41 +++++++++------------------------------ UWP/App.cpp | 2 +- Windows/MainWindow.cpp | 2 +- 8 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Common/System/Display.cpp b/Common/System/Display.cpp index 13a734087d8d..5cb0a4bee4f9 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 a1afec1d7bf8..3c1bb436a621 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 9308cf1bf2c1..8eef162c5b80 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 d9618824d5cd..f188e23a570a 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 7a553df63e28..8484fc81332c 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 ed9cb7227e68..8dca52188117 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 49eb8cd9762b..67bafebe0a4d 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 403a43d51c05..f0dc681c5c0f 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); } From 143e4a4ccfa752b3957349435518c139ede5a081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 14:57:15 -0600 Subject: [PATCH 4/8] Switch Android over to use g_display.Recalculate --- UWP/PPSSPP_UWPMain.cpp | 2 ++ android/jni/app-android.cpp | 9 +-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index f6a841995418..93712f5fad7d 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -147,6 +147,8 @@ void PPSSPP_UWPMain::UpdateScreenState() { std::swap(g_display.pixel_xres, g_display.pixel_yres); } + // TODO: The below stuff is probably completely redundant since the UWP app elsewhere calls Native_UpdateScreenScale. + float dpi = m_deviceResources->GetActualDpi(); if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) { // Boost DPI a bit to look better. diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index b273de135a0a..5a2b95633cf7 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1001,14 +1001,7 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * e } static void recalculateDpi() { - g_display.dpi_scale_real = 240.0f / (float)display_dpi; - - g_display.dpi_scale = g_display.dpi_scale_real; - - g_display.dp_xres = display_xres * g_display.dpi_scale; - g_display.dp_yres = display_yres * g_display.dpi_scale; - - g_display.pixel_in_dps = (float)g_display.pixel_xres / g_display.dp_xres; + g_display.Recalculate(display_xres, display_yres, 240.0f / (float)display_dpi, 1.0f); INFO_LOG(Log::G3D, "RecalcDPI: display_xres=%d display_yres=%d pixel_xres=%d pixel_yres=%d", display_xres, display_yres, g_display.pixel_xres, g_display.pixel_yres); INFO_LOG(Log::G3D, "RecalcDPI: g_dpi=%d g_dpi_scale=%f dp_xres=%d dp_yres=%d", display_dpi, g_display.dpi_scale, g_display.dp_xres, g_display.dp_yres); From 0a641e1b360a5c32e8e1ccb71537c2aa4984537d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 15:15:25 -0600 Subject: [PATCH 5/8] Assorted warning fixes, fix regression on Mac (save/load dialogs) --- Core/Core.cpp | 2 +- Core/HLE/sceMp4.cpp | 2 +- SDL/SDLMain.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 371019fbab3a..a37c59090745 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -427,7 +427,7 @@ void Core_Break(BreakReason reason, u32 relatedAddress) { // Allow overwriting the command. break; default: - ERROR_LOG(Log::CPU, "Core_Break called with a step-command already in progress: %s", g_cpuStepCommand.reason); + ERROR_LOG(Log::CPU, "Core_Break called with a step-command already in progress: %s", BreakReasonToString(g_cpuStepCommand.reason)); return; } } diff --git a/Core/HLE/sceMp4.cpp b/Core/HLE/sceMp4.cpp index 13cdb79f29e8..d9fb3e3b34e6 100644 --- a/Core/HLE/sceMp4.cpp +++ b/Core/HLE/sceMp4.cpp @@ -87,7 +87,7 @@ static u32 sceMp4AacDecode(u32 mp4, u32 auAddr, u32 bufferAddr, u32 init, u32 fr // Decode audio: // - init: 1 at first call, 0 afterwards // - frequency: 44100 - return hleLogError(Log::ME, 0, "mp4 % i, auAddr % 08x, bufferAddr % 08x, init % i, frequency % i ", mp4, auAddr, bufferAddr, init, frequency); + return hleLogError(Log::ME, 0, "mp4 %i, auAddr %08x, bufferAddr %08x, init %i, frequency %i ", mp4, auAddr, bufferAddr, init, frequency); //This is hack //return -1; } diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 8484fc81332c..2f585b7d0ee1 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -615,6 +615,7 @@ bool System_GetPropertyBool(SystemProperty prop) { #if PPSSPP_PLATFORM(MAC) case SYSPROP_HAS_FOLDER_BROWSER: case SYSPROP_HAS_FILE_BROWSER: + return true; #endif case SYSPROP_HAS_ACCELEROMETER: #if defined(MOBILE_DEVICE) From 7a78124a3bc27c4b7095ae85306b89f6b4bbb21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 15:23:58 -0600 Subject: [PATCH 6/8] Slightly more correct use in Android --- android/jni/app-android.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 5a2b95633cf7..5a00a86c9af3 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1000,30 +1000,28 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * e return true; } -static void recalculateDpi() { - g_display.Recalculate(display_xres, display_yres, 240.0f / (float)display_dpi, 1.0f); +static bool recalculateDpi(int pixel_xres, int pixel_yres) { + bool retval = g_display.Recalculate(pixel_xres, pixel_yres, 240.0f / (float)display_dpi, 1.0f); INFO_LOG(Log::G3D, "RecalcDPI: display_xres=%d display_yres=%d pixel_xres=%d pixel_yres=%d", display_xres, display_yres, g_display.pixel_xres, g_display.pixel_yres); INFO_LOG(Log::G3D, "RecalcDPI: g_dpi=%d g_dpi_scale=%f dp_xres=%d dp_yres=%d", display_dpi, g_display.dpi_scale, g_display.dp_xres, g_display.dp_yres); + + return retval; } -extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) { - INFO_LOG(Log::System, "NativeApp.backbufferResize(%d x %d)", bufw, bufh); +extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint pixel_xres, jint pixel_yres, jint format) { + INFO_LOG(Log::System, "NativeApp.backbufferResize(%d x %d)", pixel_xres, pixel_yres); - bool new_size = g_display.pixel_xres != bufw || g_display.pixel_yres != bufh; int old_w = g_display.pixel_xres; int old_h = g_display.pixel_yres; // pixel_*res is the backbuffer resolution. - g_display.pixel_xres = bufw; - g_display.pixel_yres = bufh; backbuffer_format = format; if (IsVREnabled()) { - GetVRResolutionPerEye(&g_display.pixel_xres, &g_display.pixel_yres); + GetVRResolutionPerEye(&pixel_xres, &pixel_yres); } - recalculateDpi(); - + bool new_size = recalculateDpi(pixel_xres, pixel_yres); if (new_size) { INFO_LOG(Log::G3D, "Size change detected (previously %d,%d) - calling NativeResized()", old_w, old_h); NativeResized(); @@ -1418,8 +1416,8 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setDisplayParameters(JN display_yres = yres; display_dpi = dpi; g_display.display_hz = refreshRate; - - recalculateDpi(); + // TODO: This is conflicting with the call in backbufferResize. + recalculateDpi(display_xres, display_yres); NativeResized(); } } From e791e31528ecc68d9f8ab882e26635f8f722806f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 15:26:58 -0600 Subject: [PATCH 7/8] Update the undermaintained Qt port to use the new DPI Recalculate --- Qt/QtMain.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index f188e23a570a..81d33c927ab4 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -840,15 +840,9 @@ int main(int argc, char *argv[]) if (res.width() < res.height()) res.transpose(); - g_display.pixel_xres = res.width(); - g_display.pixel_yres = res.height(); - // We assume physicalDotsPerInchY is the same as PerInchX. - g_display.dpi_scale_real = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX(); - - g_display.dpi_scale = g_display.dpi_scale_real; - g_display.dp_xres = (int)(g_display.pixel_xres * g_display.dpi_scale); - g_display.dp_yres = (int)(g_display.pixel_yres * g_display.dpi_scale); + float dpi_scale = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX(); + g_display.Recalculate(res.width(), res.height(), dpi_scale, 1.0f); refreshRate = screen->refreshRate(); From 361b14bc240794126e2f2f727363841bb31ff384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Feb 2025 15:28:33 -0600 Subject: [PATCH 8/8] Convert iOS to use the new DPI Recalculate --- ios/DisplayManager.mm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ios/DisplayManager.mm b/ios/DisplayManager.mm index c2dae42cf135..2319d5c944f4 100644 --- a/ios/DisplayManager.mm +++ b/ios/DisplayManager.mm @@ -149,18 +149,10 @@ - (void)updateResolution:(UIScreen *)screen { float diagonal = sqrt(size.height * size.height + size.width * size.width); dpi = diagonal * scale * 0.1f; } - g_display.dpi_scale_real = 240.0f / dpi; - g_display.dpi_scale = g_display.dpi_scale_real; + float dpi_scale = 240.0f / dpi; + g_display.Recalculate(size.width * scale, size.height * scale, dpi_scale, 1.0f); - g_display.pixel_xres = size.width * scale; - g_display.pixel_yres = size.height * scale; - - g_display.dp_xres = g_display.pixel_xres * g_display.dpi_scale; - g_display.dp_yres = g_display.pixel_yres * g_display.dpi_scale; - - g_display.pixel_in_dps = (float)g_display.pixel_xres / (float)g_display.dp_xres; - [[sharedViewController getView] setContentScaleFactor:scale]; // PSP native resize