Android: Remove mSurface from EmulationState

This commit is contained in:
JosJuice 2021-08-08 12:10:03 +02:00
parent 6129290d31
commit 2c564a0b9d
3 changed files with 15 additions and 24 deletions

View File

@ -393,6 +393,8 @@ public final class NativeLibrary
public static native void SurfaceDestroyed();
public static native boolean HasSurface();
/**
* Unpauses emulation from a paused state.
*/

View File

@ -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())
{

View File

@ -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)
{