extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) { ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf); WLOG("runEGLRenderLoop. display_xres=%d display_yres=%d", display_xres, display_yres); if (wnd == nullptr) { ELOG("Error: Surface is null."); return false; } bool vulkan = g_Config.iGPUBackend == GPU_BACKEND_VULKAN; AndroidGraphicsContext *graphicsContext; if (vulkan) { graphicsContext = new AndroidVulkanContext(); } else { graphicsContext = new AndroidEGLGraphicsContext(); } if (!graphicsContext->Init(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) { ELOG("Failed to initialize graphics context."); delete graphicsContext; return false; } if (!renderer_inited) { NativeInitGraphics(graphicsContext); if (renderer_ever_inited) { NativeDeviceRestore(); } renderer_inited = true; renderer_ever_inited = true; } exitRenderLoop = false; renderLoopRunning = true; while (!exitRenderLoop) { static bool hasSetThreadName = false; if (!hasSetThreadName) { hasSetThreadName = true; setCurrentThreadName("AndroidRender"); } // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; input_state.pad_rstick_x = right_joystick_x_async; input_state.pad_rstick_y = right_joystick_y_async; UpdateInputState(&input_state); } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(graphicsContext); time_update(); graphicsContext->SwapBuffers(); ProcessFrameCommands(env); } ILOG("After render loop."); g_gameInfoCache->WorkQueue()->Flush(); NativeDeviceLost(); NativeShutdownGraphics(); renderer_inited = false; graphicsContext->Shutdown(); delete graphicsContext; renderLoopRunning = false; WLOG("Render loop function exited."); return true; }
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) { ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf); // Need to get the local JNI env for the graphics thread. Used later in draw_text_android. int res = javaVM->GetEnv((void **)&jniEnvGraphics, JNI_VERSION_1_6); if (res != JNI_OK) { ELOG("GetEnv failed: %d", res); } WLOG("runEGLRenderLoop. display_xres=%d display_yres=%d", display_xres, display_yres); if (wnd == nullptr) { ELOG("Error: Surface is null."); return false; } retry: bool vulkan = g_Config.iGPUBackend == GPU_BACKEND_VULKAN; int tries = 0; AndroidGraphicsContext *graphicsContext; if (vulkan) { graphicsContext = new AndroidVulkanContext(); } else { graphicsContext = new AndroidEGLGraphicsContext(); } if (!graphicsContext->Init(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) { ELOG("Failed to initialize graphics context."); if (vulkan && tries < 2) { ILOG("Trying again, this time with OpenGL."); g_Config.iGPUBackend = GPU_BACKEND_OPENGL; SetGPUBackend((GPUBackend)g_Config.iGPUBackend); // Wait, why do we need a separate enum here? tries++; goto retry; } delete graphicsContext; return false; } if (!renderer_inited) { NativeInitGraphics(graphicsContext); if (renderer_ever_inited) { NativeDeviceRestore(); } renderer_inited = true; renderer_ever_inited = true; } exitRenderLoop = false; renderLoopRunning = true; while (!exitRenderLoop) { static bool hasSetThreadName = false; if (!hasSetThreadName) { hasSetThreadName = true; setCurrentThreadName("AndroidRender"); } NativeUpdate(); NativeRender(graphicsContext); time_update(); graphicsContext->SwapBuffers(); ProcessFrameCommands(env); } ILOG("After render loop."); g_gameInfoCache->WorkQueue()->Flush(); NativeDeviceLost(); renderer_inited = false; ILOG("Shutting down graphics context."); graphicsContext->Shutdown(); delete graphicsContext; graphicsContext = nullptr; renderLoopRunning = false; WLOG("Render loop function exited."); jniEnvGraphics = nullptr; return true; }