From e268da823a4cc11196ea53495451e66b4d1ac042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 11:31:13 +0200 Subject: [PATCH 1/8] Android: Add some missing codepaths when using Vulkan, might fix audio/controller issues on task switching --- android/src/org/ppsspp/ppsspp/NativeActivity.java | 12 +++++++++--- android/src/org/ppsspp/ppsspp/NativeSurfaceView.java | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 98d3c46553..286d398ef9 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -549,14 +549,17 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { if (javaGL) { Log.i(TAG, "onDestroy"); mGLSurfaceView.onDestroy(); - NativeApp.audioShutdown(); // Probably vain attempt to help the garbage collector... mGLSurfaceView = null; audioFocusChangeListener = null; audioManager = null; - unregisterCallbacks(); + } else { + mSurfaceView.onDestroy(); + mSurfaceView = null; } if (shuttingDown || isFinishing()) { + unregisterCallbacks(); + NativeApp.audioShutdown(); NativeApp.shutdown(); initialized = false; } @@ -595,7 +598,6 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { return info.reqGlEsVersion >= 0x30000; } - @Override protected void onResume() { super.onResume(); @@ -614,6 +616,10 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { } else { Log.e(TAG, "mGLSurfaceView really shouldn't be null in onResume"); } + } else { + if (mSurfaceView != null) { + mSurfaceView.onResume(); + } } gainAudioFocus(this.audioManager, this.audioFocusChangeListener); diff --git a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java index c645907902..fc621b5e12 100644 --- a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java +++ b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java @@ -133,6 +133,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene } public void onDestroy() { + Log.i(TAG, "onDestroy"); if (mController != null) { mController.exit(); } From 5627d8289147dde52efc7941ad98ce3663078b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 11:40:56 +0200 Subject: [PATCH 2/8] Format string fixes in DPI logging --- android/jni/app-android.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 4e7ad514bd..becc982512 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -725,7 +725,7 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv 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); - ILOG("g_dpi=%d g_dpi_scale_x=%f g_dpi_scale_y", g_dpi, g_dpi_scale_x, g_dpi_scale_y); + ILOG("g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y); NativeResized(); } From cefb57d778dfe4794b9f4abef2c570cbe2e528d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 13:00:46 +0200 Subject: [PATCH 3/8] Misc cleanup --- android/gradle.properties | 1 + .../org/ppsspp/ppsspp/InputDeviceState.java | 17 ----------------- .../src/org/ppsspp/ppsspp/NativeActivity.java | 4 +--- .../src/org/ppsspp/ppsspp/NativeGLView.java | 18 ------------------ .../org/ppsspp/ppsspp/NativeSurfaceView.java | 3 +-- .../org/ppsspp/ppsspp/SimpleFileChooser.java | 1 - 6 files changed, 3 insertions(+), 41 deletions(-) create mode 100644 android/gradle.properties diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 0000000000..8bd86f6805 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx1536M diff --git a/android/src/org/ppsspp/ppsspp/InputDeviceState.java b/android/src/org/ppsspp/ppsspp/InputDeviceState.java index 23bcaeaf24..09381dbd71 100644 --- a/android/src/org/ppsspp/ppsspp/InputDeviceState.java +++ b/android/src/org/ppsspp/ppsspp/InputDeviceState.java @@ -48,23 +48,7 @@ public class InputDeviceState { } NativeApp.sendMessage("inputDeviceConnected", device.getName()); } - - public static float ProcessAxis(InputDevice.MotionRange range, float axisvalue) { - float absaxisvalue = Math.abs(axisvalue); - float deadzone = range.getFlat(); - if (absaxisvalue <= deadzone) { - return 0.0f; - } - float normalizedvalue; - if (axisvalue < 0.0f) { - normalizedvalue = absaxisvalue / range.getMin(); - } else { - normalizedvalue = absaxisvalue / range.getMax(); - } - return normalizedvalue; - } - public boolean onKeyDown(KeyEvent event) { int keyCode = event.getKeyCode(); boolean repeat = event.getRepeatCount() > 0; @@ -84,7 +68,6 @@ public class InputDeviceState { for (int i = 0; i < mAxes.length; i++) { int axisId = mAxes[i]; float value = event.getAxisValue(axisId); - // TODO: Use processAxis or move that to the C++ code NativeApp.joystickAxis(deviceId, axisId, value); } NativeApp.endJoystickEvent(); diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 286d398ef9..4f88c62828 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -348,7 +348,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { Log.i(TAG, "Starting the render loop: " + mSurface); // Start emulation using the provided Surface. if (!runEGLRenderLoop(mSurface)) { - // TODO: Add an alert dialog or something + // Shouldn't happen. Log.e(TAG, "Failed to start up OpenGL"); } Log.i(TAG, "Left the render loop: " + mSurface); @@ -507,7 +507,6 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { Log.w(TAG, "Joined render loop thread."); mRenderLoopThread = null; } catch (InterruptedException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -866,7 +865,6 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { // Fall through default: // send the rest of the keys through. - // TODO: get rid of the three special cases above by adjusting the native side of the code. // Log.d(TAG, "Key down: " + keyCode + ", KeyEvent: " + event); return NativeApp.keyUp(0, keyCode); } diff --git a/android/src/org/ppsspp/ppsspp/NativeGLView.java b/android/src/org/ppsspp/ppsspp/NativeGLView.java index 9e430bc34a..68c8a5082c 100644 --- a/android/src/org/ppsspp/ppsspp/NativeGLView.java +++ b/android/src/org/ppsspp/ppsspp/NativeGLView.java @@ -37,24 +37,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, super(activity); mActivity = activity; - /*// TODO: This would be nice. - if (Build.VERSION.SDK_INT >= 11) { - try { - Method method_setPreserveEGLContextOnPause = GLSurfaceView.class.getMethod( - "setPreserveEGLContextOnPause", new Class[] { Boolean.class }); - Log.i(TAG, "Invoking setPreserveEGLContextOnPause"); - method_setPreserveEGLContextOnPause.invoke(this, true); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - }*/ - mSensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); diff --git a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java index fc621b5e12..2d53328573 100644 --- a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java +++ b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java @@ -126,9 +126,8 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene 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 + // Should we do a one time poll? } } diff --git a/android/src/org/ppsspp/ppsspp/SimpleFileChooser.java b/android/src/org/ppsspp/ppsspp/SimpleFileChooser.java index 7c814670dc..9e73fbb119 100644 --- a/android/src/org/ppsspp/ppsspp/SimpleFileChooser.java +++ b/android/src/org/ppsspp/ppsspp/SimpleFileChooser.java @@ -13,7 +13,6 @@ import android.os.Environment; /** * Simple dialog to pick file. - * TODO: Use GameBrowser from MainScreen.cpp instead. Then remove this class. */ public class SimpleFileChooser { From 7a3a620ff2bc38e0a34120d9ef4b9b650fd2d96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 13:03:23 +0200 Subject: [PATCH 4/8] Always shut down audio, regardless of why the task is being destroyed. Might help #9771 --- android/src/org/ppsspp/ppsspp/NativeActivity.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 4f88c62828..d34ff48c5a 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -91,6 +91,9 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { private Vibrator vibrator; private boolean isXperiaPlay; + + // This is to avoid losing the game/menu state etc when we are just + // switched-away from or rotated etc. private boolean shuttingDown; private static int RESULT_LOAD_IMAGE = 1; @@ -556,9 +559,9 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { mSurfaceView.onDestroy(); mSurfaceView = null; } + NativeApp.audioShutdown(); if (shuttingDown || isFinishing()) { unregisterCallbacks(); - NativeApp.audioShutdown(); NativeApp.shutdown(); initialized = false; } From 3be568224721ed77b079f45146d46e35c9da94a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 13:22:36 +0200 Subject: [PATCH 5/8] Disable codepath that requires vibration permission which we don't have --- android/src/org/ppsspp/ppsspp/NativeActivity.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index d34ff48c5a..80dc6bc98f 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -54,7 +54,7 @@ import android.widget.EditText; import android.widget.FrameLayout; import android.widget.Toast; -public 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 // Adjust these as necessary @@ -1091,9 +1091,8 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { surfView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); break; default: - if (vibrator != null) { - vibrator.vibrate(milliseconds); - } + // Requires the vibrate permission, which we don't have, so disabled. + // vibrator.vibrate(milliseconds); break; } return true; From 7b4cf8516bf59080746ccf785f9358da3fd3371a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 13:30:34 +0200 Subject: [PATCH 6/8] Make some decls private --- .../src/org/ppsspp/ppsspp/NativeActivity.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 80dc6bc98f..d9c193a5a2 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -99,15 +99,15 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C // Allow for multiple connected gamepads but just consider them the same for now. // Actually this is not entirely true, see the code. - InputDeviceState inputPlayerA; - InputDeviceState inputPlayerB; - InputDeviceState inputPlayerC; - String inputPlayerADesc; + private InputDeviceState inputPlayerA; + private InputDeviceState inputPlayerB; + private InputDeviceState inputPlayerC; + private String inputPlayerADesc; - float densityDpi; - float refreshRate; - int pixelWidth; - int pixelHeight; + private float densityDpi; + private float refreshRate; + private int pixelWidth; + private int pixelHeight; // Functions for the app activity to override to change behaviour. From 2de5e2b5c02334eba14d26a407b94fe5fa696dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 13:40:58 +0200 Subject: [PATCH 7/8] Android: Fix bug where the surface size could be wrong after task switching and automatic recreation --- android/jni/app-android.cpp | 6 ++--- .../src/org/ppsspp/ppsspp/NativeActivity.java | 25 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index becc982512..d4930f8f39 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -362,10 +362,10 @@ static int deviceType; // Should only be used for display detection during startup (for config defaults etc) // This is the ACTUAL display size, not the hardware scaled display size. -static int display_dpi_x; -static int display_dpi_y; static int display_xres; static int display_yres; +static int display_dpi_x; +static int display_dpi_y; static int backbuffer_format; // Android PixelFormat enum static int desiredBackbufferSizeX; @@ -722,10 +722,10 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv 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); - ILOG("g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y); NativeResized(); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index d9c193a5a2..76c83124a5 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -458,13 +458,11 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C } } - // @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format); NativeApp.backbufferResize(width, height, format); mSurface = holder.getSurface(); - if (!javaGL) { // If we got a surface, this starts the thread. If not, it doesn't. if (mSurface == null) { @@ -475,6 +473,17 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C } } + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + mSurface = null; + Log.w(TAG, "Surface destroyed."); + if (!javaGL) { + joinRenderLoopThread(); + } + // Autosize the next created surface. + holder.setSizeFromLayout(); + } + // Invariants: After this, mRenderLoopThread will be set, and the thread will be running. protected synchronized void ensureRenderLoop() { if (javaGL) { @@ -515,18 +524,6 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C } } - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - if (javaGL) { - Log.e(TAG, "JavaGL - should not get into surfaceDestroyed."); - return; - } - - mSurface = null; - Log.w(TAG, "Surface destroyed."); - joinRenderLoopThread(); - } - @TargetApi(19) void setupSystemUiCallback() { getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() { From 4b35e9e2785511299155631cd69f8d3eb61899ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 8 Aug 2017 15:58:25 +0200 Subject: [PATCH 8/8] Reset the UI state properly in NativeInit. Fixes #9771 --- UI/NativeApp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 0f293b8831..4f91c7a8cd 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -252,7 +252,7 @@ int NativeMix(short *audio, int num_samples) { num_samples = __AudioMix(audio, num_samples, sample_rate > 0 ? sample_rate : 44100); #ifdef _WIN32 - winAudioBackend->Update(); + winAudioBackend->Update*(); #endif return num_samples; @@ -307,6 +307,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch InitFastMath(cpu_info.bNEON); SetupAudioFormats(); + // Make sure UI state is MENU. + ResetUIState(); + bool skipLogo = false; setlocale( LC_ALL, "C" ); std::string user_data_path = savegame_dir;