mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 02:10:34 +00:00
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:
parent
349e64fe31
commit
c023cd7e20
@ -611,6 +611,30 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
|
||||
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) {
|
||||
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;
|
||||
backbuffer_format = format;
|
||||
|
||||
g_dpi = display_dpi_x;
|
||||
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);
|
||||
recalculateDpi();
|
||||
|
||||
if (new_size) {
|
||||
ILOG("Size change detected (previously %d,%d) - calling NativeResized()", old_w, old_h);
|
||||
NativeResized();
|
||||
} 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_y = dpi;
|
||||
display_hz = refreshRate;
|
||||
|
||||
recalculateDpi();
|
||||
}
|
||||
|
||||
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_computeDesiredBackbufferDimensions() {
|
||||
|
@ -53,6 +53,8 @@ import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
|
||||
public abstract class NativeActivity extends Activity implements SurfaceHolder.Callback {
|
||||
// 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 navigationHidden;
|
||||
|
||||
// audioFocusChangeListener to listen to changes in audio state
|
||||
private AudioFocusChangeListener audioFocusChangeListener;
|
||||
private AudioManager audioManager;
|
||||
@ -404,18 +408,20 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
@SuppressLint("InlinedApi")
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
private void updateSystemUiVisibility() {
|
||||
// Compute our _desired_ systemUiVisibility
|
||||
int flags = 0;
|
||||
if (useLowProfileButtons()) {
|
||||
flags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
|
||||
}
|
||||
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) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||
} else {
|
||||
Log.e(TAG, "updateSystemUiVisibility: decor view not yet created, ignoring");
|
||||
}
|
||||
|
||||
updateDisplayMeasurements();
|
||||
}
|
||||
|
||||
@ -457,16 +463,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
if (useImmersive() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInMultiWindowMode()) {
|
||||
display.getRealMetrics(metrics);
|
||||
} else {
|
||||
// multi-window mode
|
||||
display.getMetrics(metrics);
|
||||
}
|
||||
if (navigationHidden) {
|
||||
display.getRealMetrics(metrics);
|
||||
} else {
|
||||
display.getMetrics(metrics);
|
||||
}
|
||||
|
||||
densityDpi = metrics.densityDpi;
|
||||
refreshRate = display.getRefreshRate();
|
||||
|
||||
@ -602,6 +604,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
return;
|
||||
}
|
||||
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);
|
||||
mSurface = holder.getSurface();
|
||||
if (!javaGL) {
|
||||
@ -671,9 +674,14 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
if (visibility == 0) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
// Called when the system UI's visibility changes, regardless of
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -116,7 +116,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Log.i(TAG, "onPause");
|
||||
super.onPause();
|
||||
mSensorManager.unregisterListener(this);
|
||||
if (mController != null) {
|
||||
@ -131,7 +130,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
if (mController != null) {
|
||||
mController.onResume();
|
||||
|
||||
// According to the docs, the Moga's state can be inconsistent here.
|
||||
// We should do a one time poll. TODO
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.ppsspp.ppsspp;
|
||||
// Touch- and sensor-enabled SurfaceView.
|
||||
// Supports simple multitouch and pressure.
|
||||
// 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.TargetApi;
|
||||
@ -115,6 +116,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Log.i(TAG, "onPause");
|
||||
mSensorManager.unregisterListener(this);
|
||||
if (mController != null) {
|
||||
mController.onPause();
|
||||
|
Loading…
Reference in New Issue
Block a user