Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More DPI work #20012

Merged
merged 8 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Common/System/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,38 @@ 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);

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);
Expand Down
15 changes: 9 additions & 6 deletions Common/System/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Common/System/NativeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

2 changes: 1 addition & 1 deletion Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceMp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 3 additions & 7 deletions Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -839,14 +839,10 @@ 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.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();

Expand Down
5 changes: 3 additions & 2 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -779,7 +780,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) {
Expand Down Expand Up @@ -1436,7 +1437,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;

Expand Down
21 changes: 12 additions & 9 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 11 additions & 27 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,47 +1512,31 @@ 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 width, int height) {
bool smallWindow;

bool Native_UpdateScreenScale(int pixel_width, int pixel_height, float customScale) {
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 = g_logical_dpi / g_display.dpi;
g_display.dpi_scale_real = g_display.dpi_scale;

smallWindow = IsWindowSmall(width, height);
bool smallWindow = IsWindowSmall(pixel_width, pixel_height);
if (smallWindow) {
g_display.dpi /= 2.0f;
g_display.dpi_scale *= 2.0f;
customScale *= 0.5f;
}
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);

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;
if (g_display.Recalculate(pixel_width, pixel_height, g_logical_dpi / dpi, customScale)) {
NativeResized();
return true;
} else {
return false;
}
return false;
}
2 changes: 1 addition & 1 deletion UWP/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 8 additions & 3 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,21 @@ 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();
// 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.
g_display.dpi *= 96.0f / 136.0f;
dpi *= 96.0f / 136.0f;
}
g_display.dpi_scale = 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;

g_display.dp_xres = g_display.pixel_xres * g_display.dpi_scale;
Expand Down
2 changes: 1 addition & 1 deletion Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
42 changes: 17 additions & 25 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -998,37 +1000,28 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * e
return true;
}

static void recalculateDpi() {
g_display.dpi = (float)display_dpi_x;
g_display.dpi_scale_real = 240.0f / (float)display_dpi_x;
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;
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=%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);

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();
Expand Down Expand Up @@ -1415,17 +1408,16 @@ 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();
// TODO: This is conflicting with the call in backbufferResize.
recalculateDpi(display_xres, display_yres);
NativeResized();
}
}
Expand Down
1 change: 1 addition & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ ULES00808 = true
ULUS10270 = true

[DeswizzleDepth]
# Ratchet & Clank smoke effects (#15859)
UCUS98633 = true
UCAS40145 = true
UCES00420 = true
Expand Down
Loading
Loading