Permalink
Browse files

Android: Fix C++ EGL code path with threaded GLES.

Still has the same problems as before.
  • Loading branch information...
unknownbrackets committed Jun 18, 2018
1 parent 03edd61 commit 767886c4a3d18ba5419e4de71d28e56b2fccef76
Showing with 67 additions and 14 deletions.
  1. +8 −2 android/jni/AndroidEGLContext.cpp
  2. +20 −0 android/jni/AndroidEGLContext.h
  3. +39 −12 android/jni/app-android.cpp
@@ -47,15 +47,21 @@ bool AndroidEGLGraphicsContext::InitFromRenderThread(ANativeWindow *wnd, int des
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext();
SetGPUBackend(GPUBackend::OPENGL);
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
bool success = draw_->CreatePresets(); // There will always be a GLSL compiler capable of compiling these.
assert(success);
return true;
}
void AndroidEGLGraphicsContext::Shutdown() {
void AndroidEGLGraphicsContext::ShutdownFromRenderThread() {
ILOG("AndroidEGLGraphicsContext::Shutdown");
renderManager_->WaitUntilQueueIdle();
renderManager_ = nullptr; // owned by draw_.
delete draw_;
draw_ = nullptr;
NativeShutdownGraphics();
}
void AndroidEGLGraphicsContext::Shutdown() {
gl->ClearCurrent();
gl->Shutdown();
delete gl;
@@ -1,12 +1,14 @@
#pragma once
#include "thin3d/GLRenderManager.h"
#include "AndroidGraphicsContext.h"
#include "Common/GL/GLInterfaceBase.h"
class AndroidEGLGraphicsContext : public AndroidGraphicsContext {
public:
AndroidEGLGraphicsContext() : draw_(nullptr), wnd_(nullptr), gl(nullptr) {}
bool InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
void ShutdownFromRenderThread() override;
void Shutdown() override;
void SwapBuffers() override;
void SwapInterval(int interval) override {}
@@ -18,8 +20,26 @@ class AndroidEGLGraphicsContext : public AndroidGraphicsContext {
return draw_ != nullptr;
}
void ThreadStart() override {
renderManager_->ThreadStart();
}
bool ThreadFrame() override {
return renderManager_->ThreadFrame();
}
void ThreadEnd() override {
renderManager_->ThreadEnd();
}
void StopThread() override {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}
private:
Draw::DrawContext *draw_;
ANativeWindow *wnd_;
cInterfaceBase *gl;
GLRenderManager *renderManager_ = nullptr;
};
@@ -442,9 +442,12 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
switch (g_Config.iGPUBackend) {
case (int)GPUBackend::OPENGL:
useCPUThread = true;
_assert_(javaGL);
ILOG("NativeApp.init() -- creating OpenGL context (JavaGL)");
graphicsContext = new AndroidJavaEGLGraphicsContext();
if (javaGL) {
ILOG("NativeApp.init() -- creating OpenGL context (JavaGL)");
graphicsContext = new AndroidJavaEGLGraphicsContext();
} else {
graphicsContext = new AndroidEGLGraphicsContext();
}
break;
case (int)GPUBackend::VULKAN:
{
@@ -521,7 +524,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_pause(JNIEnv *, jclass) {
}
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {
if (useCPUThread && graphicsContext) {
if (renderer_inited && useCPUThread && graphicsContext) {
// Only used in Java EGL path.
EmuThreadStop();
while (graphicsContext->ThreadFrame()) {
continue;
@@ -963,31 +967,54 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
}
if (!exitRenderLoop) {
NativeInitGraphics(graphicsContext);
if (!useCPUThread) {
NativeInitGraphics(graphicsContext);
}
graphicsContext->ThreadStart();
renderer_inited = true;
}
while (!exitRenderLoop) {
if (!exitRenderLoop) {
static bool hasSetThreadName = false;
if (!hasSetThreadName) {
hasSetThreadName = true;
setCurrentThreadName("AndroidRender");
}
}
NativeUpdate();
if (useCPUThread) {
ELOG("Running graphics loop");
while (!exitRenderLoop) {
// This is the "GPU thread".
graphicsContext->ThreadFrame();
graphicsContext->SwapBuffers();
}
} else {
while (!exitRenderLoop) {
NativeUpdate();
NativeRender(graphicsContext);
time_update();
NativeRender(graphicsContext);
time_update();
graphicsContext->SwapBuffers();
graphicsContext->SwapBuffers();
ProcessFrameCommands(env);
ProcessFrameCommands(env);
}
}
ILOG("Leaving EGL/Vulkan render loop.");
NativeShutdownGraphics();
if (useCPUThread) {
EmuThreadStop();
while (graphicsContext->ThreadFrame()) {
continue;
}
EmuThreadJoin();
} else {
NativeShutdownGraphics();
}
renderer_inited = false;
graphicsContext->ThreadEnd();
// Shut the graphics context down to the same state it was in when we entered the render thread.
ILOG("Shutting down graphics context from render thread...");

0 comments on commit 767886c

Please sign in to comment.