Merge pull request #2529 from Cacodemon345/qt-renderer-fix

qt: Fix black screen when switching between renderers
This commit is contained in:
Miran Grča
2022-07-29 16:30:42 +02:00
committed by GitHub
3 changed files with 38 additions and 23 deletions

View File

@@ -237,28 +237,40 @@ RendererStack::switchRenderer(Renderer renderer)
{
startblit();
if (current) {
rendererWindow->finalize();
if (rendererWindow->hasBlitFunc()) {
while (directBlitting) {}
connect(this, &RendererStack::blit, this, &RendererStack::blitDummy, Qt::DirectConnection);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitRenderer);
if ((current_vid_api == Renderer::Direct3D9 && renderer != Renderer::Direct3D9)
|| (current_vid_api != Renderer::Direct3D9 && renderer == Renderer::Direct3D9)) {
rendererWindow->finalize();
if (rendererWindow->hasBlitFunc()) {
while (directBlitting) {}
connect(this, &RendererStack::blit, this, &RendererStack::blitDummy, Qt::DirectConnection);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitRenderer);
} else {
connect(this, &RendererStack::blit, this, &RendererStack::blitDummy, Qt::DirectConnection);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitCommon);
}
removeWidget(current.get());
disconnect(this, &RendererStack::blitToRenderer, nullptr, nullptr);
/* Create new renderer only after previous is destroyed! */
connect(current.get(), &QObject::destroyed, [this, renderer](QObject *) {
createRenderer(renderer);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitDummy);
blitDummied = false;
QTimer::singleShot(1000, this, [this]() { this->blitDummied = false; } );
});
rendererWindow->hasBlitFunc() ? current.reset() : current.release()->deleteLater();
} else {
connect(this, &RendererStack::blit, this, &RendererStack::blitDummy, Qt::DirectConnection);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitCommon);
rendererWindow->finalize();
removeWidget(current.get());
disconnect(this, &RendererStack::blitToRenderer, nullptr, nullptr);
/* Create new renderer only after previous is destroyed! */
connect(current.get(), &QObject::destroyed, [this, renderer](QObject *) { createRenderer(renderer); });
current.release()->deleteLater();
}
removeWidget(current.get());
disconnect(this, &RendererStack::blitToRenderer, nullptr, nullptr);
/* Create new renderer only after previous is destroyed! */
connect(current.get(), &QObject::destroyed, [this, renderer](QObject *) {
createRenderer(renderer);
disconnect(this, &RendererStack::blit, this, &RendererStack::blitDummy);
blitDummied = false;
QTimer::singleShot(1000, this, [this]() { this->blitDummied = false; } );
});
rendererWindow->hasBlitFunc() ? current.reset() : current.release()->deleteLater();
} else {
createRenderer(renderer);
}
@@ -267,6 +279,7 @@ RendererStack::switchRenderer(Renderer renderer)
void
RendererStack::createRenderer(Renderer renderer)
{
current_vid_api = renderer;
switch (renderer) {
default:
case Renderer::Software:

View File

@@ -47,7 +47,8 @@ public:
OpenGLES,
OpenGL3,
Vulkan,
Direct3D9
Direct3D9,
None = -1
};
void switchRenderer(Renderer renderer);
@@ -96,6 +97,8 @@ private:
int isMouseDown = 0;
int m_monitor_index = 0;
Renderer current_vid_api = Renderer::None;
std::vector<std::tuple<uint8_t *, std::atomic_flag *>> imagebufs;
RendererCommon *rendererWindow { nullptr };

View File

@@ -36,6 +36,7 @@
#include <86box/unix_sdl.h>
#include <86box/timer.h>
#include <86box/nvr.h>
#include <86box/video.h>
#include <86box/ui.h>
#include <86box/gdbstub.h>
@@ -602,7 +603,6 @@ do_stop(void)
if (blitreq)
{
blitreq = 0;
extern void video_blit_complete();
video_blit_complete();
}
@@ -611,7 +611,6 @@ do_stop(void)
if (blitreq)
{
blitreq = 0;
extern void video_blit_complete();
video_blit_complete();
}
}