Skip to content

Commit

Permalink
More simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 22, 2022
1 parent fe0f19f commit db98ed9
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) {
return JNI_VERSION_1_6;
}

// Only used in OpenGL mode.
static void EmuThreadFunc() {
JNIEnv *env;
gJvm->AttachCurrentThread(&env, nullptr);
Expand Down Expand Up @@ -723,12 +724,15 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
useCPUThread = true;
INFO_LOG(SYSTEM, "NativeApp.init() -- creating OpenGL context (JavaGL)");
graphicsContext = new AndroidJavaEGLGraphicsContext();
INFO_LOG(SYSTEM, "NativeApp.init() - launching emu thread");
EmuThreadStart();
break;
case (int)GPUBackend::VULKAN:
{
INFO_LOG(SYSTEM, "NativeApp.init() -- creating Vulkan context");
useCPUThread = false; // The Vulkan render manager manages its own thread.
// We create and destroy the Vulkan graphics context in the "EGL" thread.
useCPUThread = false;
// The Vulkan render manager manages its own thread.
// We create and destroy the Vulkan graphics context in the app main thread though.
AndroidVulkanContext *ctx = new AndroidVulkanContext();
if (!ctx->InitAPI()) {
INFO_LOG(SYSTEM, "Failed to initialize Vulkan, switching to OpenGL");
Expand All @@ -746,11 +750,6 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
goto retry;
}

if (useCPUThread) {
INFO_LOG(SYSTEM, "NativeApp.init() - launching emu thread");
EmuThreadStart();
}

if (IsVREnabled()) {
Version gitVer(PPSSPP_GIT_VERSION);
InitVROnAndroid(gJvm, nativeActivity, systemName.c_str(), gitVer.ToInteger(), "PPSSPP");
Expand Down Expand Up @@ -873,6 +872,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {

// JavaEGL. This doesn't get called on the Vulkan path.
extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env, jobject obj) {
_assert_(useCPUThread);

INFO_LOG(G3D, "NativeApp.displayInit()");
bool firstStart = !renderer_inited;

Expand All @@ -881,19 +882,16 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
if (renderer_inited) {
// Would be really nice if we could get something on the GL thread immediately when shutting down.
INFO_LOG(G3D, "NativeApp.displayInit() restoring");
if (useCPUThread) {
EmuThreadStop("displayInit");
graphicsContext->BeginAndroidShutdown();
INFO_LOG(G3D, "BeginAndroidShutdown. Looping until emu thread done...");
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
INFO_LOG(G3D, "Joining emu thread");
EmuThreadJoin();
} else {
NativeShutdownGraphics();
EmuThreadStop("displayInit");
graphicsContext->BeginAndroidShutdown();
INFO_LOG(G3D, "BeginAndroidShutdown. Looping until emu thread done...");
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
INFO_LOG(G3D, "Joining emu thread");
EmuThreadJoin();

graphicsContext->ThreadEnd();
graphicsContext->ShutdownFromRenderThread();

Expand All @@ -908,17 +906,10 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
host->NotifyUserMessage(details, 5.0, 0xFFFFFFFF, "error_callback");
}, nullptr);

if (useCPUThread) {
EmuThreadStart();
} else {
if (!NativeInitGraphics(graphicsContext)) {
// Gonna be in a weird state here, not good.
System_Toast("Failed to initialize graphics.");
return false;
}
}
EmuThreadStart();

graphicsContext->ThreadStart();

INFO_LOG(G3D, "Restored.");
} else {
INFO_LOG(G3D, "NativeApp.displayInit() first time");
Expand All @@ -940,7 +931,6 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
if (IsVREnabled()) {
EnterVR(firstStart, graphicsContext->GetAPIContext());
}

return true;
}

Expand Down Expand Up @@ -1034,6 +1024,7 @@ void UpdateRunLoopAndroid(JNIEnv *env) {

std::lock_guard<std::mutex> guard(frameCommandLock);
if (!nativeActivity) {
ERROR_LOG(SYSTEM, "No activity, clearing commands");
while (!frameCommands.empty())
frameCommands.pop();
return;
Expand Down

0 comments on commit db98ed9

Please sign in to comment.