Use the new common RunMainLoop on Android

This commit is contained in:
Henrik Rydgård committed 2026-07-26 13:42:16 +02:00
1 parent 4a95d8eeaa
commit 8020b60dda
3 files changed
+41 -54

No files matched your search

+31 -31
View File
@@ -70,7 +70,6 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext, Application *applica
// This normally calls NativeShutdownGraphics()
application->ShutdownGraphics(graphicsContext);
delete application;
INFO_LOG(Log::System, "Leaving separate emu thread");
@@ -102,6 +101,36 @@ void EmuThread_Join(GraphicsContext *graphicsContext, std::thread &emuThread) {
emuThread = std::thread();
}
bool RunMainLoop(GraphicsContext *graphicsContext, Application *application, std::function<bool()> runCondition, std::function<void()> postFrame) {
// This is the main thread. the graphics contexts will spawn and handle its own threads if needed.
// InitFromRenderThread/ShutdownFromRenderThread are not used.
application->InitGraphics(graphicsContext);
// NativeResized();
DEBUG_LOG(Log::Boot, "Done.");
g_inLoop = true;
while (runCondition()) {
// We're here again, so the game quit. Restart Run() which controls the UI.
// This way they can load a new game.
application->Frame(graphicsContext);
postFrame();
}
Core_Stop();
// Process the shutdown. Without this, non-GL delays 800ms on shutdown.
Core_StateProcessed();
application->Frame(graphicsContext);
g_inLoop = false;
application->ShutdownGraphics(graphicsContext);
delete application;
return true;
}
// Call InitAPI and ShutdownAPI outside this!
bool MainThreadFunc(GraphicsContext *graphicsContext, Application *application, WindowSystem windowSystem, void *windowData1, void *windowData2, std::function<void()> postFrame) {
// This is now the render thread, and will spawn the emu thread below.
@@ -143,36 +172,7 @@ bool MainThreadFunc(GraphicsContext *graphicsContext, Application *application,
} else {
SetCurrentThreadName("MainThread");
// This is the main thread. the graphics contexts will spawn and handle its own threads if needed.
// InitFromRenderThread/ShutdownFromRenderThread are not used.
std::string error_string;
application->InitGraphics(graphicsContext);
// NativeResized();
DEBUG_LOG(Log::Boot, "Done.");
g_inLoop = true;
graphicsContext->ThreadStart();
while (GetUIState() != UISTATE_EXIT) {
// We're here again, so the game quit. Restart Run() which controls the UI.
// This way they can load a new game.
application->Frame(graphicsContext);
postFrame();
}
Core_Stop();
// Process the shutdown. Without this, non-GL delays 800ms on shutdown.
Core_StateProcessed();
application->Frame(graphicsContext);
g_inLoop = false;
application->ShutdownGraphics(graphicsContext);
graphicsContext->ThreadEnd();
RunMainLoop(graphicsContext, application, []() { return GetUIState() != UISTATE_EXIT; }, postFrame);
}
graphicsContext->ShutdownSurface();
+6 -1
View File
@@ -34,7 +34,12 @@ class GraphicsContext;
bool MainThreadFunc(GraphicsContext * graphicsContext, Application *application, WindowSystem windowSystem, void *windowData1, void *windowData2, std::function<void()> postFrame);
// If you're not using MainThreadFunc, you can at least use these to manage a spinning EmuThread (that calls NativeFrame),
// whether your graphics context requires multithreading or not.
// whether your graphics context requires multithreading or not. Then use RunMainLoop to implement your main loop for
// the case where a separate EmuThread is not needed.
// NOTE: Does take ownership over Application (which is just a wrapper for NativeInitGraphics/NativeShutdownGraphics/NativeFrame).
std::thread EmuThread_Start(GraphicsContext *graphicsContext, Application *application, std::function<void()> postFrame);
void EmuThread_Join(GraphicsContext *graphicsContext, std::thread &emuThread);
// Call from the main thread.
// NOTE: Does take ownership over Application (which is just a wrapper for NativeInitGraphics/NativeShutdownGraphics/NativeFrame).
bool RunMainLoop(GraphicsContext *graphicsContext, Application *application, std::function<bool()> runCondition, std::function<void()> postFrame);
+4 -22
View File
@@ -182,7 +182,8 @@ static jobject ppssppActivity;
static std::atomic<bool> exitRenderLoop;
static std::atomic<bool> renderLoopRunning;
static bool renderer_inited = false;
static bool renderer_inited = false; // only used with OpenGL.
static bool sustainedPerfSupported = false;
static std::string g_installerName;
@@ -1701,27 +1702,8 @@ static void VulkanEmuThread(ANativeWindow *wnd, GraphicsContext *graphicsContext
return;
}
if (!exitRenderLoop) {
INFO_LOG(Log::G3D, "Calling NativeInitGraphics");
if (!NativeInitGraphics(graphicsContext)) {
ERROR_LOG(Log::G3D, "Failed to initialize graphics.");
// Gonna be in a weird state here..
}
renderer_inited = true;
// The main loop.
while (!exitRenderLoop) {
NativeFrame(graphicsContext);
ProcessFrameCommands();
}
INFO_LOG(Log::G3D, "Leaving Vulkan main loop.");
} else {
INFO_LOG(Log::G3D, "Not entering main loop.");
}
NativeShutdownGraphics(graphicsContext);
renderer_inited = true;
RunMainLoop(graphicsContext, new NativeApplication(), []() { return !exitRenderLoop; }, []() { ProcessFrameCommands(); });
renderer_inited = false;
// Shut the graphics context down to the same state it was in when we entered the render thread.