mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Add NeedsRenderThread property to GraphicsContext
This commit is contained in:
1 parent
86c98c2d23
commit
af7977267e
9 files changed
+26
-11
No files matched your search
@@ -29,6 +29,9 @@ public:
|
||||
// Needs casting to the appropriate type, unfortunately. Should find a better solution..
|
||||
virtual void *GetAPIContext() { return nullptr; }
|
||||
|
||||
// OpenGL returns true here.
|
||||
virtual bool NeedsRenderThread() const { return false; }
|
||||
|
||||
// Called from the render thread from threaded backends.
|
||||
virtual void ThreadStart() {}
|
||||
virtual bool ThreadFrame(bool waitIfEmpty) { return true; } // waitIfEmpty should normally be true, except in exit scenarios.
|
||||
@@ -41,6 +44,8 @@ public:
|
||||
virtual Draw::DrawContext *GetDrawContext() = 0;
|
||||
|
||||
void ThreadFrameUntilCondition(std::function<bool()> conditionStopped) {
|
||||
_dbg_assert_(NeedsRenderThread());
|
||||
|
||||
bool exitOnEmpty = false;
|
||||
|
||||
INFO_LOG(Log::System, "Executing graphicsContext->ThreadFrame to clear buffers");
|
||||
|
||||
+8
-9
@@ -74,23 +74,24 @@ std::thread EmuThread_Start(GraphicsContext *graphicsContext, std::function<void
|
||||
}
|
||||
|
||||
void EmuThread_Join(GraphicsContext *graphicsContext, std::thread &emuThread) {
|
||||
_dbg_assert_(emuThread.joinable());
|
||||
const EmuThreadState state = g_emuThreadState;
|
||||
if (state != EmuThreadState::QUIT_REQUESTED &&
|
||||
state != EmuThreadState::STOPPED) {
|
||||
g_emuThreadState = EmuThreadState::QUIT_REQUESTED;
|
||||
}
|
||||
graphicsContext->ThreadFrameUntilCondition([] {
|
||||
// Need to keep eating frames to allow the EmuThread to exit correctly.
|
||||
return g_emuThreadState == EmuThreadState::STOPPED;
|
||||
});
|
||||
_dbg_assert_(emuThread.joinable());
|
||||
if (graphicsContext->NeedsRenderThread()) {
|
||||
graphicsContext->ThreadFrameUntilCondition([] {
|
||||
// Need to keep eating frames to allow the EmuThread to exit correctly.
|
||||
return g_emuThreadState == EmuThreadState::STOPPED;
|
||||
});
|
||||
}
|
||||
emuThread.join();
|
||||
emuThread = std::thread();
|
||||
}
|
||||
|
||||
void MainThreadFunc(GraphicsContext *graphicsContext, std::function<void()> postFrame) {
|
||||
const bool useEmuThread = g_Config.iGPUBackend == (int)GPUBackend::OPENGL;
|
||||
if (useEmuThread) {
|
||||
if (graphicsContext->NeedsRenderThread()) {
|
||||
SetCurrentThreadName("RenderThread");
|
||||
// This is now the render thread, and will spawn the emu thread below.
|
||||
|
||||
@@ -139,7 +140,6 @@ void MainThreadFunc(GraphicsContext *graphicsContext, std::function<void()> post
|
||||
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.
|
||||
@@ -158,7 +158,6 @@ void MainThreadFunc(GraphicsContext *graphicsContext, std::function<void()> post
|
||||
|
||||
graphicsContext->ThreadEnd();
|
||||
graphicsContext->ShutdownFromRenderThread();
|
||||
|
||||
}
|
||||
|
||||
graphicsContext->Shutdown();
|
||||
|
||||
@@ -65,6 +65,8 @@ public:
|
||||
renderManager_ = nullptr;
|
||||
}
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
void Shutdown() override {}
|
||||
void Resize() override {}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ public:
|
||||
// Returns 0 on success.
|
||||
int Init(SDL_Window *&window, int x, int y, int w, int h, int mode, std::string *error_message, int force_gl_version);
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
bool InitFromRenderThread(std::string *errorMessage) override;
|
||||
|
||||
void Shutdown() override {}
|
||||
|
||||
@@ -13,6 +13,8 @@ class WindowsGLContext : public WindowsGraphicsContext {
|
||||
public:
|
||||
bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override;
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
bool InitFromRenderThread(std::string *errorMessage) override;
|
||||
void ShutdownFromRenderThread() override;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ public:
|
||||
AndroidJavaEGLGraphicsContext();
|
||||
~AndroidJavaEGLGraphicsContext() override { delete draw_; }
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
// This performs the actual initialization,
|
||||
bool InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
~IOSGLESContext() {
|
||||
delete draw_;
|
||||
}
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
hw_render_.bottom_left_origin = true;
|
||||
}
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
bool Init() override;
|
||||
void CreateDrawContext() override;
|
||||
void DestroyDrawContext() override;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
class LibretroGLCoreContext : public LibretroHWRenderContext {
|
||||
public:
|
||||
LibretroGLCoreContext()
|
||||
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL_CORE, 3, 1)
|
||||
{
|
||||
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL_CORE, 3, 1) {
|
||||
hw_render_.bottom_left_origin = true;
|
||||
}
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
|
||||
bool Init() override;
|
||||
void CreateDrawContext() override;
|
||||
|
||||
Reference in new issue
Block a user