Make use of OnSystemUiVisibilityChangeListener to check whether navbar is hidden. Affects DPI calculations.

Also recalculate all dp parameters after either display or buffer size changed.
This commit is contained in:
Henrik Rydgård 2019-10-05 23:29:15 +02:00
parent 349e64fe31
commit c023cd7e20
4 changed files with 49 additions and 34 deletions

View File

@ -611,6 +611,30 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
NativeMessageReceived("recreateviews", ""); NativeMessageReceived("recreateviews", "");
} }
static void recalculateDpi() {
g_dpi = display_dpi_x;
g_dpi_scale_x = 240.0f / display_dpi_x;
g_dpi_scale_y = 240.0f / display_dpi_y;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = display_xres * g_dpi_scale_x;
dp_yres = display_yres * g_dpi_scale_y;
// Touch scaling is from display pixels to dp pixels.
// Wait, doesn't even make sense... this is equal to g_dpi_scale_x. TODO: Figure out what's going on!
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
ILOG("RecalcDPI: g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
ILOG("RecalcDPI: dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
ILOG("RecalcDPI: dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
ILOG("RecalcDPI: pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
}
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) { extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv *, jclass, jint bufw, jint bufh, jint format) {
ILOG("NativeApp.backbufferResize(%d x %d)", bufw, bufh); ILOG("NativeApp.backbufferResize(%d x %d)", bufw, bufh);
@ -622,32 +646,13 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv
pixel_yres = bufh; pixel_yres = bufh;
backbuffer_format = format; backbuffer_format = format;
g_dpi = display_dpi_x; recalculateDpi();
g_dpi_scale_x = 240.0f / g_dpi;
g_dpi_scale_y = 240.0f / g_dpi;
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = display_xres * g_dpi_scale_x;
dp_yres = display_yres * g_dpi_scale_y;
// Touch scaling is from display pixels to dp pixels.
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
ILOG("g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
ILOG("dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
ILOG("dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
ILOG("pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
if (new_size) { if (new_size) {
ILOG("Size change detected (previously %d,%d) - calling NativeResized()", old_w, old_h); ILOG("Size change detected (previously %d,%d) - calling NativeResized()", old_w, old_h);
NativeResized(); NativeResized();
} else { } else {
ILOG("NativeApp::backbufferReisze: Size didn't change."); ILOG("NativeApp::backbufferResize: Size didn't change.");
} }
} }
@ -897,6 +902,8 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setDisplayParameters(JN
display_dpi_x = dpi; display_dpi_x = dpi;
display_dpi_y = dpi; display_dpi_y = dpi;
display_hz = refreshRate; display_hz = refreshRate;
recalculateDpi();
} }
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_computeDesiredBackbufferDimensions() { extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_computeDesiredBackbufferDimensions() {

View File

@ -53,6 +53,8 @@ import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
public abstract class NativeActivity extends Activity implements SurfaceHolder.Callback { public abstract class NativeActivity extends Activity implements SurfaceHolder.Callback {
// Remember to loadLibrary your JNI .so in a static {} block // Remember to loadLibrary your JNI .so in a static {} block
@ -85,6 +87,8 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
private boolean sustainedPerfSupported; private boolean sustainedPerfSupported;
private boolean navigationHidden;
// audioFocusChangeListener to listen to changes in audio state // audioFocusChangeListener to listen to changes in audio state
private AudioFocusChangeListener audioFocusChangeListener; private AudioFocusChangeListener audioFocusChangeListener;
private AudioManager audioManager; private AudioManager audioManager;
@ -404,18 +408,20 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateSystemUiVisibility() { private void updateSystemUiVisibility() {
// Compute our _desired_ systemUiVisibility
int flags = 0; int flags = 0;
if (useLowProfileButtons()) { if (useLowProfileButtons()) {
flags |= View.SYSTEM_UI_FLAG_LOW_PROFILE; flags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
} }
if (useImmersive()) { if (useImmersive()) {
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
} }
if (getWindow().getDecorView() != null) { if (getWindow().getDecorView() != null) {
getWindow().getDecorView().setSystemUiVisibility(flags); getWindow().getDecorView().setSystemUiVisibility(flags);
} else { } else {
Log.e(TAG, "updateSystemUiVisibility: decor view not yet created, ignoring"); Log.e(TAG, "updateSystemUiVisibility: decor view not yet created, ignoring");
} }
updateDisplayMeasurements(); updateDisplayMeasurements();
} }
@ -457,16 +463,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
Display display = getWindowManager().getDefaultDisplay(); Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
if (useImmersive() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (navigationHidden) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInMultiWindowMode()) { display.getRealMetrics(metrics);
display.getRealMetrics(metrics);
} else {
// multi-window mode
display.getMetrics(metrics);
}
} else { } else {
display.getMetrics(metrics); display.getMetrics(metrics);
} }
densityDpi = metrics.densityDpi; densityDpi = metrics.densityDpi;
refreshRate = display.getRefreshRate(); refreshRate = display.getRefreshRate();
@ -602,6 +604,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
return; return;
} }
Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format); Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format);
// The window size might have changed (immersive mode, native fullscreen on some devices)
NativeApp.backbufferResize(width, height, format); NativeApp.backbufferResize(width, height, format);
mSurface = holder.getSurface(); mSurface = holder.getSurface();
if (!javaGL) { if (!javaGL) {
@ -671,9 +674,14 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() { getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
@Override @Override
public void onSystemUiVisibilityChange(int visibility) { public void onSystemUiVisibilityChange(int visibility) {
if (visibility == 0) { // Called when the system UI's visibility changes, regardless of
updateSystemUiVisibility(); // whether it's because of our or system actions.
} // We will try to force it to follow our preference but will not stupidly
// act as if it's visible if it's not.
navigationHidden = ((visibility & SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0);
// TODO: Check here if it's the state we want.
Log.i(TAG, "SystemUiVisibilityChange! visibility=" + visibility + " navigationHidden: " + navigationHidden);
updateDisplayMeasurements();
} }
}); });
} }

View File

@ -116,7 +116,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
@Override @Override
public void onPause() { public void onPause() {
Log.i(TAG, "onPause");
super.onPause(); super.onPause();
mSensorManager.unregisterListener(this); mSensorManager.unregisterListener(this);
if (mController != null) { if (mController != null) {
@ -131,7 +130,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
if (mController != null) { if (mController != null) {
mController.onResume(); mController.onResume();
// According to the docs, the Moga's state can be inconsistent here. // According to the docs, the Moga's state can be inconsistent here.
// We should do a one time poll. TODO // We should do a one time poll. TODO
} }

View File

@ -3,6 +3,7 @@ package org.ppsspp.ppsspp;
// Touch- and sensor-enabled SurfaceView. // Touch- and sensor-enabled SurfaceView.
// Supports simple multitouch and pressure. // Supports simple multitouch and pressure.
// DPI scaling is handled by the native code. // DPI scaling is handled by the native code.
// Used by the Vulkan backend (and EGL, but that path is no longer active)
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
@ -115,6 +116,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
} }
public void onPause() { public void onPause() {
Log.i(TAG, "onPause");
mSensorManager.unregisterListener(this); mSensorManager.unregisterListener(this);
if (mController != null) { if (mController != null) {
mController.onPause(); mController.onPause();