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

Still has the same problems as before.
This commit is contained in:
Unknown W. Brackets committed 2018-06-17 21:56:18 -07:00
1 parent 03edd6129a
commit 767886c4a3
3 files changed
+67 -14

No files matched your search

+8 -2
View File
@@ -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;
+20
View File
@@ -1,5 +1,6 @@
#pragma once
#include "thin3d/GLRenderManager.h"
#include "AndroidGraphicsContext.h"
#include "Common/GL/GLInterfaceBase.h"
@@ -7,6 +8,7 @@ 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 @@ public:
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;
};
+39 -12
View File
@@ -442,9 +442,12 @@ retry:
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 @@ retry:
}
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...");