From 73046239e3af8541a1a84a095a4ccafbdf5392fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 5 Jul 2020 22:46:04 +0200 Subject: [PATCH] Android: Add option to ignore camera notches when sizing the display. This is generally what you want, at least on phones with small notches. Not sure about the most intuitive polarity and name of the setting.. bit of a shame to create another setting with a negation. But most people should probably ignore this. --- Core/Config.cpp | 1 + Core/Config.h | 1 + GPU/Common/FramebufferCommon.cpp | 2 +- GPU/Common/GPUStateUtils.cpp | 2 +- GPU/Common/PresentationCommon.cpp | 30 +++++++++++++++++------------- GPU/Common/PresentationCommon.h | 2 +- UI/GameSettingsScreen.cpp | 11 ++++++++++- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index df3bf415dc..9ff2635200 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -758,6 +758,7 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("SmallDisplayZoomLevel", &g_Config.fSmallDisplayZoomLevel, 1.0f, true, true), ConfigSetting("ImmersiveMode", &g_Config.bImmersiveMode, false, true, true), ConfigSetting("SustainedPerformanceMode", &g_Config.bSustainedPerformanceMode, false, true, true), + ConfigSetting("IgnoreScreenInsets", &g_Config.bIgnoreScreenInsets, true, true, false), ReportedConfigSetting("ReplaceTextures", &g_Config.bReplaceTextures, true, true, true), ReportedConfigSetting("SaveNewTextures", &g_Config.bSaveNewTextures, false, true, true), diff --git a/Core/Config.h b/Core/Config.h index 2e5cea51c9..c4ba00d2b1 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -156,6 +156,7 @@ public: float fSmallDisplayZoomLevel; //This is used for zoom values, both in and out. bool bImmersiveMode; // Mode on Android Kitkat 4.4 that hides the back button etc. bool bSustainedPerformanceMode; // Android: Slows clocks down to avoid overheating/speed fluctuations. + bool bIgnoreScreenInsets; // Android: Center screen disregarding insets if this is enabled. bool bVSync; int iFrameSkip; int iFrameSkipType; diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index b6578a4737..98a7bbd9e3 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -661,7 +661,7 @@ void FramebufferManagerCommon::DrawPixels(VirtualFramebuffer *vfb, int dstX, int std::swap(v0, v1); flags = g_Config.iBufFilter == SCALE_LINEAR ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; flags = flags | DRAWTEX_TO_BACKBUFFER; - FRect frame = GetInsetScreenFrame(pixelWidth_, pixelHeight_); + FRect frame = GetScreenFrame(pixelWidth_, pixelHeight_); FRect rc; CenterDisplayOutputRect(&rc, 480.0f, 272.0f, frame, ROTATION_LOCKED_HORIZONTAL); SetViewport2D(rc.x, rc.y, rc.w, rc.h); diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index dc29213429..5406f9d360 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -557,7 +557,7 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo } else { float pixelW = PSP_CoreParameter().pixelWidth; float pixelH = PSP_CoreParameter().pixelHeight; - FRect frame = GetInsetScreenFrame(pixelW, pixelH); + FRect frame = GetScreenFrame(pixelW, pixelH); FRect rc; CenterDisplayOutputRect(&rc, 480, 272, frame, ROTATION_LOCKED_HORIZONTAL); displayOffsetX = rc.x; diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index b88cc1affe..4432568b7d 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -41,7 +41,7 @@ struct Vertex { uint32_t rgba; }; -FRect GetInsetScreenFrame(float pixelWidth, float pixelHeight) { +FRect GetScreenFrame(float pixelWidth, float pixelHeight) { FRect rc = FRect{ 0.0f, 0.0f, @@ -49,17 +49,21 @@ FRect GetInsetScreenFrame(float pixelWidth, float pixelHeight) { pixelHeight, }; - // Remove the DPI scale to get back to pixels. - float left = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT) / g_dpi_scale_x; - float right = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT) / g_dpi_scale_x; - float top = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP) / g_dpi_scale_y; - float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM) / g_dpi_scale_y; + bool applyInset = !g_Config.bIgnoreScreenInsets; - // Adjust left edge to compensate for cutouts (notches) if any. - rc.x += left; - rc.w -= (left + right); - rc.y += top; - rc.h -= (top + bottom); + if (applyInset) { + // Remove the DPI scale to get back to pixels. + float left = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT) / g_dpi_scale_x; + float right = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT) / g_dpi_scale_x; + float top = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP) / g_dpi_scale_y; + float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM) / g_dpi_scale_y; + + // Adjust left edge to compensate for cutouts (notches) if any. + rc.x += left; + rc.w -= (left + right); + rc.y += top; + rc.h -= (top + bottom); + } return rc; } @@ -281,7 +285,7 @@ bool PresentationCommon::BuildPostShader(const ShaderInfo *shaderInfo, const Sha } else if (shaderInfo->outputResolution) { // If the current shader uses output res (not next), we will use output res for it. FRect rc; - FRect frame = GetInsetScreenFrame((float)pixelWidth_, (float)pixelHeight_); + FRect frame = GetScreenFrame((float)pixelWidth_, (float)pixelHeight_); CenterDisplayOutputRect(&rc, 480.0f, 272.0f, frame, g_Config.iInternalScreenRotation); nextWidth = (int)rc.w; nextHeight = (int)rc.h; @@ -528,7 +532,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u int lastHeight = srcHeight_; // These are the output coordinates. - FRect frame = GetInsetScreenFrame((float)pixelWidth_, (float)pixelHeight_); + FRect frame = GetScreenFrame((float)pixelWidth_, (float)pixelHeight_); FRect rc; CenterDisplayOutputRect(&rc, 480.0f, 272.0f, frame, uvRotation); diff --git a/GPU/Common/PresentationCommon.h b/GPU/Common/PresentationCommon.h index 502ef318e9..30395ab161 100644 --- a/GPU/Common/PresentationCommon.h +++ b/GPU/Common/PresentationCommon.h @@ -45,7 +45,7 @@ struct FRect { float h; }; -FRect GetInsetScreenFrame(float pixelWidth, float pixelHeight); +FRect GetScreenFrame(float pixelWidth, float pixelHeight); void CenterDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &frame, int rotation); namespace Draw { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 9d824e28b3..62a70b67a4 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -313,7 +313,16 @@ void GameSettingsScreen::CreateViews() { displayEditor_ = graphicsSettings->Add(new Choice(gr->T("Display layout editor"))); displayEditor_->OnClick.Handle(this, &GameSettingsScreen::OnDisplayLayoutEditor); -#ifdef __ANDROID__ +#if PPSSPP_PLATFORM(ANDROID) + // Hide insets option if no insets, or OS too old. + if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 29 && + (System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT) != 0.0f || + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP) != 0.0f || + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT) != 0.0f || + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM) != 0.0f)) { + graphicsSettings->Add(new CheckBox(&g_Config.bIgnoreScreenInsets, gr->T("Ignore camera inset when centering"))); + } + // Hide Immersive Mode on pre-kitkat Android if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 19) { // Let's reuse the Fullscreen translation string from desktop.