From 01635a5cd6da760b91ea97c713cc16e05c9dfa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 31 May 2017 11:12:11 +0200 Subject: [PATCH] Android: Just like on Windows, prompt to restart when changing graphics backend. --- UI/GameSettingsScreen.cpp | 8 ++------ UI/NativeApp.cpp | 10 ++++------ android/jni/app-android.cpp | 15 ++++++++++++++- android/src/org/ppsspp/ppsspp/NativeActivity.java | 5 +++++ ext/native/gfx/gl_lost_manager.cpp | 4 ++++ ext/native/gfx_es2/draw_buffer.cpp | 6 ++++++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index d364a94639..4e1d3cf4fb 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1071,7 +1071,6 @@ void GlobalSettingsScreen::CreateViews() { }*/ void GameSettingsScreen::CallbackRenderingBackend(bool yes) { -#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) // If the user ends up deciding not to restart, set the config back to the current backend // so it doesn't get switched by accident. if (yes) { @@ -1079,11 +1078,9 @@ void GameSettingsScreen::CallbackRenderingBackend(bool yes) { } else { g_Config.iGPUBackend = (int)GetGPUBackend(); } -#endif } UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) { -#if defined(_WIN32) I18NCategory *di = GetI18NCategory("Dialog"); // It only makes sense to show the restart prompt if the backend was actually changed. @@ -1091,12 +1088,11 @@ UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) { screenManager()->push(new PromptScreen(di->T("ChangingGPUBackends", "Changing GPU backends requires PPSSPP to restart. Restart now?"), di->T("Yes"), di->T("No"), std::bind(&GameSettingsScreen::CallbackRenderingBackend, this, std::placeholders::_1))); } -#endif return UI::EVENT_DONE; } UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) { -#if defined(_WIN32) || defined(USING_QT_UI) +#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) const size_t name_len = 256; char name[name_len]; @@ -1112,7 +1108,7 @@ UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) { } UI::EventReturn GameSettingsScreen::OnChangeproAdhocServerAddress(UI::EventParams &e) { -#if defined(_WIN32) || defined(USING_QT_UI) +#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) if (!g_Config.bFullScreen) { const size_t name_len = 256; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 429ee2cd3e..a002d63329 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -916,6 +916,7 @@ void NativeUpdate() { } void NativeDeviceLost() { + ILOG("NativeDeviceLost"); // We start by calling gl_lost - this lets objects zero their native GL objects // so they then don't try to delete them as well. if (GetGPUBackend() == GPUBackend::OPENGL) { @@ -927,6 +928,7 @@ void NativeDeviceLost() { } void NativeDeviceRestore() { + ILOG("NativeDeviceRestore"); if (GetGPUBackend() == GPUBackend::OPENGL) { gl_restore(); } @@ -1109,12 +1111,8 @@ void NativeShutdown() { net::Shutdown(); - // This means that the activity has been completely destroyed. PPSSPP does not - // boot up correctly with "dirty" global variables currently, so we hack around that - // by simply exiting. -#if PPSSPP_PLATFORM(ANDROID) - exit(0); -#endif + // Previously we did exit() here on Android but that makes it hard to do things like restart on backend change. + // I think we handle most globals correctly or correct-enough now. } void NativePermissionStatus(SystemPermission permission, PermissionStatus status) { diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 103872ff63..64f2892074 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -139,6 +139,7 @@ void AndroidEGLGraphicsContext::Shutdown() { gl->Shutdown(); delete gl; ANativeWindow_release(wnd_); + finalize_glslang(); } void AndroidEGLGraphicsContext::SwapBuffers() { @@ -155,7 +156,13 @@ public: ~AndroidJavaEGLGraphicsContext() { delete draw_; } - void Shutdown() override {} + void Shutdown() override { + ILOG("AndroidJavaEGLGraphicsContext::Shutdown"); + delete draw_; + draw_ = nullptr; + NativeShutdownGraphics(); + finalize_glslang(); + } void SwapBuffers() override {} void SwapInterval(int interval) override {} void Resize() override {} @@ -295,6 +302,7 @@ bool AndroidVulkanContext::Init(ANativeWindow *wnd, int desiredBackbufferSizeX, } void AndroidVulkanContext::Shutdown() { + ILOG("AndroidVulkanContext::Shutdown"); delete draw_; draw_ = nullptr; NativeShutdownGraphics(); @@ -627,14 +635,19 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_pause(JNIEnv *, jclass) { extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) { ILOG("NativeApp.shutdown() -- begin"); if (renderer_inited) { + ILOG("Shutting down renderer"); graphicsContext->Shutdown(); delete graphicsContext; graphicsContext = nullptr; renderer_inited = false; + } else { + ILOG("Not shutting down renderer - not initialized"); } NativeShutdown(); VFSShutdown(); + while (frameCommands.size()) + frameCommands.pop(); ILOG("NativeApp.shutdown() -- end"); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index cddb25f0fd..bb0513561a 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -601,6 +601,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { } if (shuttingDown || isFinishing()) { NativeApp.shutdown(); + initialized = false; } } @@ -1160,6 +1161,10 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { } } else if (command.equals("recreate")) { recreate(); + } else if (command.equals("graphics_restart")) { + Log.i(TAG, "graphics_restart"); + shuttingDown = true; + recreate(); } else if (command.equals("ask_permission") && params.equals("storage")) { askForStoragePermission(); } diff --git a/ext/native/gfx/gl_lost_manager.cpp b/ext/native/gfx/gl_lost_manager.cpp index e01352c3db..dd83c406e5 100644 --- a/ext/native/gfx/gl_lost_manager.cpp +++ b/ext/native/gfx/gl_lost_manager.cpp @@ -120,6 +120,10 @@ void gl_lost_manager_shutdown() { FLOG("Lost manager already shutdown"); } else if (holders->size() > 0) { ELOG("Lost manager shutdown with %i objects still registered", (int)holders->size()); + for (size_t i = 0; i < holders->size(); i++) { + ELOG(" (%d / %d, %s, prio %d)", (int)(i + 1), (int)holders->size(), + (*holders)[i].desc, (*holders)[i].priority); + } } delete holders; diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index 533f330667..b45f352949 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -65,8 +65,14 @@ Draw::InputLayout *DrawBuffer::CreateInputLayout(Draw::DrawContext *t3d) { void DrawBuffer::Shutdown() { if (vbuf_) { vbuf_->Release(); + vbuf_ = nullptr; } inited_ = false; + alphaStack_.clear(); + drawMatrixStack_.clear(); + pipeline_ = nullptr; + draw_ = nullptr; + count_ = 0; } void DrawBuffer::Begin(Draw::Pipeline *program) {