From 9b13b5e49213f3189c85530f314318e8cfa0acfc Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 14 Jun 2024 19:30:10 +0200 Subject: [PATCH] use the message queue for GL context init/deinit --- src/frontend/qt_sdl/EmuThread.cpp | 34 +++++++++++++------------------ src/frontend/qt_sdl/EmuThread.h | 11 +++------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index c95a1ad8..ffe4974b 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -443,22 +443,6 @@ void EmuThread::run() { emuInstance->drawScreenGL(); } - - ContextRequestKind contextRequest = ContextRequest; - if (contextRequest == contextRequest_InitGL) - { - emuInstance->initOpenGL(); - - useOpenGL = true; - ContextRequest = contextRequest_None; - } - else if (contextRequest == contextRequest_DeInitGL) - { - emuInstance->deinitOpenGL(); - - useOpenGL = false; - ContextRequest = contextRequest_None; - } } handleMessages(); @@ -510,6 +494,16 @@ void EmuThread::handleMessages() emuInstance->audioDisable(); emit windowEmuStop(); break; + + case msg_InitGL: + emuInstance->initOpenGL(); + useOpenGL = true; + break; + + case msg_DeInitGL: + emuInstance->deinitOpenGL(); + useOpenGL = false; + break; } msgSemaphore.release(); @@ -535,14 +529,14 @@ void EmuThread::emuRun() void EmuThread::initContext() { - ContextRequest = contextRequest_InitGL; - while (ContextRequest != contextRequest_None); + sendMessage(msg_InitGL); + waitMessage(); } void EmuThread::deinitContext() { - ContextRequest = contextRequest_DeInitGL; - while (ContextRequest != contextRequest_None); + sendMessage(msg_DeInitGL); + waitMessage(); } void EmuThread::emuPause() diff --git a/src/frontend/qt_sdl/EmuThread.h b/src/frontend/qt_sdl/EmuThread.h index c4bd8f77..a5daaa0e 100644 --- a/src/frontend/qt_sdl/EmuThread.h +++ b/src/frontend/qt_sdl/EmuThread.h @@ -58,6 +58,9 @@ public: enum MessageType { msg_EmuStop, + + msg_InitGL, + msg_DeInitGL, }; struct Message @@ -146,14 +149,6 @@ private: QSemaphore msgSemaphore; QQueue msgQueue; - enum ContextRequestKind - { - contextRequest_None = 0, - contextRequest_InitGL, - contextRequest_DeInitGL - }; - std::atomic ContextRequest = contextRequest_None; - EmuInstance* emuInstance; int autoScreenSizing;