summaryrefslogtreecommitdiff
path: root/Source/Android
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2016-01-11 01:18:37 -0500
committerRyan Houdek <Sonicadvance1@gmail.com>2016-01-11 01:18:37 -0500
commit78bb37b29f61a4293ac5ab24a146f6fbfb68f822 (patch)
treeced63a6faa2502475ca7d28949f2c311732c1499 /Source/Android
parent77cef0c7bf957bc3a87e4f532a5cdbc87f3934c4 (diff)
parent5a549ef6632a444f6943f662471357c751ef1198 (diff)
Merge pull request #3494 from Sonicadvance1/android_rotation
[Android] Add support for rotation and minimizing the application
Diffstat (limited to 'Source/Android')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java8
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java15
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java11
-rw-r--r--Source/Android/jni/MainAndroid.cpp56
4 files changed, 62 insertions, 28 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 71fbbd93e6..209d59919e 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
@@ -333,10 +333,12 @@ public final class NativeLibrary
/**
* Begins emulation.
- *
- * @param surf The surface to render to.
*/
- public static native void Run(Surface surf);
+ public static native void Run();
+
+ // Surface Handling
+ public static native void SurfaceChanged(Surface surf);
+ public static native void SurfaceDestroyed();
/** Unpauses emulation from a paused state. */
public static native void UnPauseEmulation();
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
index 04b5149a0e..5415b65b7d 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
@@ -177,13 +177,16 @@ public final class EmulationActivity extends AppCompatActivity
}
});
- // Instantiate an EmulationFragment.
- EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
+ if (savedInstanceState == null)
+ {
+ // Instantiate an EmulationFragment.
+ EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
- // Add fragment to the activity - this triggers all its lifecycle callbacks.
- getFragmentManager().beginTransaction()
- .add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
- .commit();
+ // Add fragment to the activity - this triggers all its lifecycle callbacks.
+ getFragmentManager().beginTransaction()
+ .add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
+ .commit();
+ }
if (mDeviceHasTouchScreen)
{
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 1eb1684531..ab79e62a68 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
@@ -115,7 +115,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
public void onStop()
{
super.onStop();
- pauseEmulation();
}
@Override
@@ -160,12 +159,14 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
{
Log.d("DolphinEmu", "Surface changed. Resolution: " + width + "x" + height);
mSurface = holder.getSurface();
+ NativeLibrary.SurfaceChanged(mSurface);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.d("DolphinEmu", "Surface destroyed.");
+ NativeLibrary.SurfaceDestroyed();
if (mEmulationRunning)
{
@@ -216,20 +217,14 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mEmulationRunning = true;
mEmulationStarted = true;
- // Loop until onSurfaceCreated succeeds
while (mSurface == null)
- {
if (!mEmulationRunning)
- {
- // So that if the user quits before this gets a surface, we don't loop infinitely.
return;
- }
- }
Log.i("DolphinEmu", "Starting emulation: " + mSurface);
// Start emulation using the provided Surface.
- NativeLibrary.Run(mSurface);
+ NativeLibrary.Run();
}
};
}
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp
index 2cff486721..ffa0eca40a 100644
--- a/Source/Android/jni/MainAndroid.cpp
+++ b/Source/Android/jni/MainAndroid.cpp
@@ -18,6 +18,7 @@
#include "Common/CPUDetect.h"
#include "Common/Event.h"
#include "Common/FileUtil.h"
+#include "Common/GL/GLInterfaceBase.h"
#include "Common/Logging/LogManager.h"
#include "Core/BootManager.h"
@@ -380,16 +381,17 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv *env, jobject obj, jboolean enable);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf);
-
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj);
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv *env, jobject obj, jobject _surf);
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv *env, jobject obj)
{
- PowerPC::Start();
+ Core::SetState(Core::CORE_RUN);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv *env, jobject obj)
{
- PowerPC::Pause();
+ Core::SetState(Core::CORE_PAUSE);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv *env, jobject obj)
@@ -596,17 +598,44 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClasses
g_jni_method_end = env->GetStaticMethodID(g_jni_class, "endEmulationActivity", "()V");
}
-JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf)
+// Surface Handling
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv *env, jobject obj, jobject _surf)
{
- __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", g_filename.c_str());
-
surf = ANativeWindow_fromSurface(env, _surf);
-
if (surf == nullptr)
- {
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
- return;
+
+ // If GLInterface isn't a thing yet then we don't need to let it know that the surface has changed
+ if (GLInterface)
+ {
+ GLInterface->UpdateHandle(surf);
+ Renderer::s_ChangedSurface.Reset();
+ Renderer::s_SurfaceNeedsChanged.Set();
+ Renderer::s_ChangedSurface.Wait();
+ }
+}
+
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv *env, jobject obj)
+{
+ if (surf)
+ {
+ ANativeWindow_release(surf);
+ surf = nullptr;
+ }
+
+ // If GLInterface isn't a thing yet then we don't need to let it know that the surface has changed
+ if (GLInterface)
+ {
+ GLInterface->UpdateHandle(nullptr);
+ Renderer::s_ChangedSurface.Reset();
+ Renderer::s_SurfaceNeedsChanged.Set();
+ Renderer::s_ChangedSurface.Wait();
}
+}
+
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj)
+{
+ __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", g_filename.c_str());
// Install our callbacks
OSD::AddCallback(OSD::CallbackType::Initialization, ButtonManager::Init);
@@ -627,7 +656,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *
Core::Shutdown();
UICommon::Shutdown();
- ANativeWindow_release(surf);
+
+ if (surf)
+ {
+ ANativeWindow_release(surf);
+ surf = nullptr;
+ }
// Execute the Java method.
env->CallStaticVoidMethod(g_jni_class, g_jni_method_end);