ScreenPanelNative: Don't try to render the framebuffer if the emulator is not actually active.

This fixes an issue where the window draws with a gray background in macOS, and is see-through on Wayland-based desktops.
This commit is contained in:
Nadia Holmquist Pedersen
2021-12-09 01:57:02 +01:00
parent 14c6bba21f
commit f1c9b42b45
2 changed files with 24 additions and 15 deletions

View File

@ -714,6 +714,11 @@ bool EmuThread::emuIsRunning()
return (EmuRunning == 1); return (EmuRunning == 1);
} }
bool EmuThread::emuIsActive()
{
return (RunningSomething == 1);
}
void ScreenHandler::screenSetupLayout(int w, int h) void ScreenHandler::screenSetupLayout(int w, int h)
{ {
@ -942,6 +947,8 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event)
// fill background // fill background
painter.fillRect(event->rect(), QColor::fromRgb(0, 0, 0)); painter.fillRect(event->rect(), QColor::fromRgb(0, 0, 0));
if (emuThread->emuIsActive())
{
emuThread->FrontBufferLock.lock(); emuThread->FrontBufferLock.lock();
int frontbuf = emuThread->FrontBuffer; int frontbuf = emuThread->FrontBuffer;
if (!GPU::Framebuffer[frontbuf][0] || !GPU::Framebuffer[frontbuf][1]) if (!GPU::Framebuffer[frontbuf][0] || !GPU::Framebuffer[frontbuf][1])
@ -950,11 +957,11 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event)
return; return;
} }
memcpy(screen[0].scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); memcpy(screen[0].scanLine(0), GPU::Framebuffer[frontbuf][0], 256 * 192 * 4);
memcpy(screen[1].scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); memcpy(screen[1].scanLine(0), GPU::Framebuffer[frontbuf][1], 256 * 192 * 4);
emuThread->FrontBufferLock.unlock(); emuThread->FrontBufferLock.unlock();
painter.setRenderHint(QPainter::SmoothPixmapTransform, Config::ScreenFilter!=0); painter.setRenderHint(QPainter::SmoothPixmapTransform, Config::ScreenFilter != 0);
QRect screenrc(0, 0, 256, 192); QRect screenrc(0, 0, 256, 192);
@ -963,6 +970,7 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event)
painter.setTransform(screenTrans[i]); painter.setTransform(screenTrans[i]);
painter.drawImage(screenrc, screen[screenKind[i]]); painter.drawImage(screenrc, screen[screenKind[i]]);
} }
}
OSD::Update(nullptr); OSD::Update(nullptr);
OSD::DrawNative(painter); OSD::DrawNative(painter);

View File

@ -59,6 +59,7 @@ public:
void emuFrameStep(); void emuFrameStep();
bool emuIsRunning(); bool emuIsRunning();
bool emuIsActive();
int FrontBuffer = 0; int FrontBuffer = 0;
QMutex FrontBufferLock; QMutex FrontBufferLock;