Qt: Fix black screen when starting with a game (fixes #2781)

This commit is contained in:
Vicki Pfau 2023-03-05 23:55:54 -08:00
parent 89f8873df3
commit a7c232b284
3 changed files with 20 additions and 1 deletions

View File

@ -24,6 +24,7 @@ Other fixes:
- Qt: Fix a handful of edge cases with graphics viewers (fixes mgba.io/i/2827) - Qt: Fix a handful of edge cases with graphics viewers (fixes mgba.io/i/2827)
- Qt: Fix full-buffer rewind - Qt: Fix full-buffer rewind
- Qt: Fix crash if loading a shader fails - Qt: Fix crash if loading a shader fails
- Qt: Fix black screen when starting with a game (fixes mgba.io/i/2781)
- Scripting: Fix receiving packets for client sockets - Scripting: Fix receiving packets for client sockets
- Scripting: Fix empty receive calls returning unknown error on Windows - Scripting: Fix empty receive calls returning unknown error on Windows
Misc: Misc:

View File

@ -48,6 +48,11 @@ using QOpenGLFunctions_Baseline = QOpenGLFunctions_3_2_Core;
using namespace QGBA; using namespace QGBA;
enum ThreadStartFrom {
START = 1,
PROXY = 2,
};
QHash<QSurfaceFormat, bool> DisplayGL::s_supports; QHash<QSurfaceFormat, bool> DisplayGL::s_supports;
uint qHash(const QSurfaceFormat& format, uint seed) { uint qHash(const QSurfaceFormat& format, uint seed) {
@ -235,7 +240,16 @@ void DisplayGL::startDrawing(std::shared_ptr<CoreController> controller) {
messagePainter()->resize(size(), devicePixelRatio()); messagePainter()->resize(size(), devicePixelRatio());
#endif #endif
CoreController::Interrupter interrupter(controller); startThread(ThreadStartFrom::START);
}
void DisplayGL::startThread(int from) {
m_threadStartPending |= from;
if (m_threadStartPending < 3) {
return;
}
CoreController::Interrupter interrupter(m_context);
QMetaObject::invokeMethod(m_painter.get(), "start"); QMetaObject::invokeMethod(m_painter.get(), "start");
if (!m_gl) { if (!m_gl) {
if (shouldDisableUpdates()) { if (shouldDisableUpdates()) {
@ -310,6 +324,7 @@ void DisplayGL::stopDrawing() {
hide(); hide();
} }
setUpdatesEnabled(true); setUpdatesEnabled(true);
m_threadStartPending &= ~1;
} }
m_context.reset(); m_context.reset();
} }
@ -435,6 +450,7 @@ void DisplayGL::setupProxyThread() {
#if defined(_WIN32) && defined(USE_EPOXY) #if defined(_WIN32) && defined(USE_EPOXY)
epoxy_handle_external_wglMakeCurrent(); epoxy_handle_external_wglMakeCurrent();
#endif #endif
QMetaObject::invokeMethod(this, "startThread", Q_ARG(int, ThreadStartFrom::PROXY));
}); });
connect(m_painter.get(), &PainterGL::texSwapped, m_proxyContext.get(), [this]() { connect(m_painter.get(), &PainterGL::texSwapped, m_proxyContext.get(), [this]() {
if (!m_context->hardwareAccelerated()) { if (!m_context->hardwareAccelerated()) {

View File

@ -113,6 +113,7 @@ protected:
virtual void resizeEvent(QResizeEvent*) override; virtual void resizeEvent(QResizeEvent*) override;
private slots: private slots:
void startThread(int);
void setupProxyThread(); void setupProxyThread();
private: private:
@ -123,6 +124,7 @@ private:
bool m_isDrawing = false; bool m_isDrawing = false;
bool m_hasStarted = false; bool m_hasStarted = false;
int m_threadStartPending = 0;
std::unique_ptr<PainterGL> m_painter; std::unique_ptr<PainterGL> m_painter;
QThread m_drawThread; QThread m_drawThread;
QThread m_proxyThread; QThread m_proxyThread;