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

Support drawing around notches on Android displays. Fixes #12261 #12779

Merged
merged 1 commit into from
Mar 31, 2020
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
2 changes: 1 addition & 1 deletion UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ void EmuScreen::CreateViews() {
auto n = GetI18NCategory("Networking");
auto sc = GetI18NCategory("Screen");

const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
const Bounds &bounds = screenManager()->getUIContext()->GetLayoutBounds();
InitPadLayout(bounds.w, bounds.h);
root_ = CreatePadLayout(bounds.w, bounds.h, &pauseTrigger_);
if (g_Config.bShowDeveloperMenu) {
Expand Down
23 changes: 22 additions & 1 deletion android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ JavaVM* gJvm = nullptr;
static jobject gClassLoader;
static jmethodID gFindClassMethod;

static float g_safeInsetLeft = 0.0;
static float g_safeInsetRight = 0.0;
static float g_safeInsetTop = 0.0;
static float g_safeInsetBottom = 0.0;

static jmethodID postCommand;
static jobject nativeActivity;
Expand Down Expand Up @@ -314,6 +318,14 @@ float System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_REFRESH_RATE:
return display_hz;
case SYSPROP_DISPLAY_SAFE_INSET_LEFT:
return g_safeInsetLeft;
case SYSPROP_DISPLAY_SAFE_INSET_RIGHT:
return g_safeInsetRight;
case SYSPROP_DISPLAY_SAFE_INSET_TOP:
return g_safeInsetTop;
case SYSPROP_DISPLAY_SAFE_INSET_BOTTOM:
return g_safeInsetBottom;
default:
return -1;
}
Expand Down Expand Up @@ -883,6 +895,16 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessage(JNIEnv *env
permissions[SYSTEM_PERMISSION_STORAGE] = PERMISSION_STATUS_GRANTED;
} else if (msg == "sustained_perf_supported") {
sustainedPerfSupported = true;
} else if (msg == "safe_insets") {
ILOG("Got insets: %s", prm.c_str());
// We don't bother with supporting exact rectangular regions. Safe insets are good enough.
int left, right, top, bottom;
if (4 == sscanf(prm.c_str(), "%d:%d:%d:%d", &left, &right, &top, &bottom)) {
g_safeInsetLeft = (float)left * g_dpi_scale_x;
g_safeInsetRight = (float)right * g_dpi_scale_x;
g_safeInsetTop = (float)top * g_dpi_scale_y;
g_safeInsetBottom = (float)bottom * g_dpi_scale_y;
}
}

// Ensures that the receiver can handle it on a sensible thread.
Expand Down Expand Up @@ -968,7 +990,6 @@ extern "C" jint JNICALL Java_org_ppsspp_ppsspp_NativeApp_getDesiredBackbufferHei
return desiredBackbufferSizeY;
}


std::vector<std::string> __cameraGetDeviceList() {
jclass cameraClass = findClass("org/ppsspp/ppsspp/CameraHelper");
jmethodID deviceListMethod = getEnv()->GetStaticMethodID(cameraClass, "getDeviceList", "()Ljava/util/ArrayList;");
Expand Down
5 changes: 3 additions & 2 deletions android/res/values-v28/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:navigationBarColor">@color/black</item>
<!-- TODO: Our rendering is not ready for these yet.
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item> -->
<!-- TODO: Our rendering is not ready for these yet.
<item name="android:windowTranslucentNavigation">true</item>
-->
</style>
</resources>
3 changes: 3 additions & 0 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
Expand Down Expand Up @@ -861,6 +863,7 @@ public void onAttachedToWindow() {
safeInsetTop = 0;
safeInsetBottom = 0;
}
NativeApp.sendMessage("safe_insets", safeInsetLeft + ":" + safeInsetRight + ":" + safeInsetTop + ":" + safeInsetBottom);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Expand Down
6 changes: 6 additions & 0 deletions ext/native/base/NativeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ enum SystemProperty {
SYSPROP_DISPLAY_COUNT,
SYSPROP_MOGA_VERSION,

// Float only:
SYSPROP_DISPLAY_SAFE_INSET_LEFT,
SYSPROP_DISPLAY_SAFE_INSET_RIGHT,
SYSPROP_DISPLAY_SAFE_INSET_TOP,
SYSPROP_DISPLAY_SAFE_INSET_BOTTOM,

SYSPROP_DEVICE_TYPE,
SYSPROP_APP_GOLD, // To avoid having #ifdef GOLD other than in main.cpp and similar.

Expand Down
3 changes: 2 additions & 1 deletion ext/native/ui/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root) {
ELOG("Tried to layout a view hierarchy from a zero pointer root");
return;
}
const Bounds &rootBounds = dc.GetBounds();

Bounds rootBounds = dc.GetLayoutBounds();

MeasureSpec horiz(EXACTLY, rootBounds.w);
MeasureSpec vert(EXACTLY, rootBounds.h);
Expand Down
21 changes: 21 additions & 0 deletions ext/native/ui/ui_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <algorithm>

#include "base/display.h"
#include "base/NativeApp.h"
#include "base/logging.h"
#include "ui/ui.h"
#include "ui/view.h"
#include "ui/ui_context.h"
Expand Down Expand Up @@ -104,6 +106,25 @@ Bounds UIContext::GetScissorBounds() {
return bounds_;
}

Bounds UIContext::GetLayoutBounds() const {
Bounds bounds = GetBounds();

float left = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
float right = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT);
float top = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM);

// ILOG("Insets: %f %f %f %f", left, right, top, bottom);

// Adjust left edge to compensate for cutouts (notches) if any.
bounds.x += left;
bounds.w -= (left + right);
bounds.y += top;
bounds.h -= (top + bottom);

return bounds;
}

void UIContext::ActivateTopScissor() {
Bounds bounds;
if (scissorStack_.size()) {
Expand Down
1 change: 1 addition & 0 deletions ext/native/ui/ui_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class UIContext {
// in dps, like dp_xres and dp_yres
void SetBounds(const Bounds &b) { bounds_ = b; }
const Bounds &GetBounds() const { return bounds_; }
Bounds GetLayoutBounds() const;
Draw::DrawContext *GetDrawContext() { return draw_; }
void SetCurZ(float curZ);

Expand Down