Have Native_UpdateScreenScale use the new g_display.Recalculate()

This commit is contained in:
Henrik Rydgård 2025-02-20 14:52:50 -06:00
parent 0acd2aa517
commit 91360fee9b
8 changed files with 45 additions and 38 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}