From 2c564a0b9d654d860dcc2832b2492f8e1b94813b Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 8 Aug 2021 12:10:03 +0200 Subject: [PATCH] Android: Remove mSurface from EmulationState --- .../dolphinemu/dolphinemu/NativeLibrary.java | 2 ++ .../fragments/EmulationFragment.java | 30 ++++--------------- Source/Android/jni/MainAndroid.cpp | 7 +++++ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 0ac2463217..5ab4e15993 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -393,6 +393,8 @@ public final class NativeLibrary public static native void SurfaceDestroyed(); + public static native boolean HasSurface(); + /** * Unpauses emulation from a paused state. */ diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index 7d18c47936..2ea106cb4a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -173,13 +173,15 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height); - mEmulationState.newSurface(holder.getSurface()); + NativeLibrary.SurfaceChanged(holder.getSurface()); + mEmulationState.newSurface(); } @Override public void surfaceDestroyed(@NonNull SurfaceHolder holder) { - mEmulationState.clearSurface(); + Log.debug("[EmulationFragment] Surface destroyed."); + NativeLibrary.SurfaceDestroyed(); } public void stopEmulation() @@ -219,7 +221,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C private final String[] mGamePaths; private State state; - private Surface mSurface; private boolean mRunWhenSurfaceIsValid; private boolean loadPreviousTemporaryState; private final String temporaryStatePath; @@ -304,7 +305,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C } // If the surface is set, run now. Otherwise, wait for it to get set. - if (mSurface != null) + if (NativeLibrary.HasSurface()) { runWithValidSurface(); } @@ -314,31 +315,14 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C } } - // Surface callbacks - public synchronized void newSurface(Surface surface) + public synchronized void newSurface() { - mSurface = surface; if (mRunWhenSurfaceIsValid) { runWithValidSurface(); } } - public synchronized void clearSurface() - { - if (mSurface == null) - { - Log.warning("[EmulationFragment] clearSurface called, but surface already null."); - } - else - { - mSurface = null; - Log.debug("[EmulationFragment] Surface destroyed."); - - NativeLibrary.SurfaceDestroyed(); - } - } - private void runWithValidSurface() { mRunWhenSurfaceIsValid = false; @@ -346,7 +330,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C { Thread emulationThread = new Thread(() -> { - NativeLibrary.SurfaceChanged(mSurface); if (loadPreviousTemporaryState) { Log.debug("[EmulationFragment] Starting emulation thread from previous state."); @@ -363,7 +346,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C } else if (state == State.PAUSED) { - NativeLibrary.SurfaceChanged(mSurface); if (!EmulationActivity.getHasUserPausedEmulation() && !NativeLibrary.IsShowingAlertMessage()) { diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 765bab1bcb..eedc728ad9 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -442,6 +442,13 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr } } +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_HasSurface(JNIEnv*, jclass) +{ + std::lock_guard guard(s_surface_lock); + + return s_surf ? JNI_TRUE : JNI_FALSE; +} + JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAspectRatio(JNIEnv*, jclass) {