Refactor pause/resume functions to be strictly CPU thread pause/resume

This commit is contained in:
Aaron Culliney 2015-10-31 14:01:47 -07:00
parent e52f753bf3
commit acdc8da64f
3 changed files with 15 additions and 17 deletions

View File

@ -98,9 +98,9 @@ public class Apple2Activity extends Activity {
private native void nativeOnKeyUp(int keyCode, int metaState); private native void nativeOnKeyUp(int keyCode, int metaState);
private native void nativeOnResume(boolean isSystemResume); private native void nativeEmulationResume();
public native void nativeOnPause(boolean isSystemPause); public native void nativeEmulationPause();
public native void nativeOnQuit(); public native void nativeOnQuit();
@ -196,7 +196,6 @@ public class Apple2Activity extends Activity {
Log.d(TAG, "onResume()"); Log.d(TAG, "onResume()");
mView.onResume(); mView.onResume();
nativeOnResume(/*isSystemResume:*/true);
} }
@Override @Override
@ -218,7 +217,7 @@ public class Apple2Activity extends Activity {
// Dismiss these popups to avoid android.view.WindowLeaked issues // Dismiss these popups to avoid android.view.WindowLeaked issues
synchronized (this) { synchronized (this) {
dismissAllMenus(); dismissAllMenus();
nativeOnPause(true); nativeEmulationPause();
} }
mPausing.set(false); mPausing.set(false);
@ -356,6 +355,8 @@ public class Apple2Activity extends Activity {
} }
void graphicsInitialized(int w, int h) { void graphicsInitialized(int w, int h) {
Log.v(TAG, "graphicsInitialized(" + w + ", " + h + ")");
if (mMainMenu == null) { if (mMainMenu == null) {
mMainMenu = new Apple2MainMenu(this, mView); mMainMenu = new Apple2MainMenu(this, mView);
} }
@ -370,7 +371,6 @@ public class Apple2Activity extends Activity {
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
// tell native about this...
nativeGraphicsInitialized(w, h); nativeGraphicsInitialized(w, h);
showSplashScreen(); showSplashScreen();
@ -478,7 +478,7 @@ public class Apple2Activity extends Activity {
public synchronized void pushApple2View(Apple2MenuView apple2MenuView) { public synchronized void pushApple2View(Apple2MenuView apple2MenuView) {
mMenuStack.add(apple2MenuView); mMenuStack.add(apple2MenuView);
View menuView = apple2MenuView.getView(); View menuView = apple2MenuView.getView();
nativeOnPause(false); nativeEmulationPause();
addContentView(menuView, new FrameLayout.LayoutParams(getWidth(), getHeight())); addContentView(menuView, new FrameLayout.LayoutParams(getWidth(), getHeight()));
} }
@ -560,13 +560,13 @@ public class Apple2Activity extends Activity {
dismissAllMenus(); dismissAllMenus();
} }
if (mMenuStack.size() == 0 && !mPausing.get()) { if (mMenuStack.size() == 0 && !mPausing.get()) {
nativeOnResume(/*isSystemResume:*/false); nativeEmulationResume();
} }
} }
void _mainMenuDismissed() { void _mainMenuDismissed() {
if (mMenuStack.size() == 0 && !mPausing.get()) { if (mMenuStack.size() == 0 && !mPausing.get()) {
nativeOnResume(/*isSystemResume:*/false); nativeEmulationResume();
} }
} }
@ -583,7 +583,7 @@ public class Apple2Activity extends Activity {
} }
public void maybeQuitApp() { public void maybeQuitApp() {
nativeOnPause(false); nativeEmulationPause();
AlertDialog quitDialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.quit_really).setMessage(R.string.quit_warning).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { AlertDialog quitDialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.quit_really).setMessage(R.string.quit_warning).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -606,7 +606,7 @@ public class Apple2Activity extends Activity {
} }
public void maybeReboot() { public void maybeReboot() {
nativeOnPause(false); nativeEmulationPause();
AlertDialog rebootDialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.reboot_really).setMessage(R.string.reboot_warning).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { AlertDialog rebootDialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.reboot_really).setMessage(R.string.reboot_warning).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {

View File

@ -203,7 +203,7 @@ public class Apple2MainMenu {
return; return;
} }
mActivity.nativeOnPause(false); mActivity.nativeEmulationPause();
mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0); mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0);
} }

View File

@ -186,21 +186,19 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv
video_backend->init((void *)0); video_backend->init((void *)0);
} }
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobject obj, jboolean isSystemResume) { void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationResume(JNIEnv *env, jobject obj) {
if (!cpu_isPaused()) { if (!cpu_isPaused()) {
return; return;
} }
LOG("..."); LOG("...");
if (!isSystemResume) {
#if TESTING #if TESTING
// test driver thread is managing CPU // test driver thread is managing CPU
#else #else
cpu_resume(); cpu_resume();
#endif #endif
}
} }
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobject obj, jboolean isSystemPause) { void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationPause(JNIEnv *env, jobject obj) {
if (appState != APP_RUNNING) { if (appState != APP_RUNNING) {
return; return;
} }