core/window: handle graphics context loss

This commit is contained in:
outfoxxed 2025-07-15 15:36:28 -07:00
parent a2146f6394
commit 3dfb7d8827
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 33 additions and 2 deletions

View file

@ -1,6 +1,7 @@
#include "proxywindow.hpp"
#include <private/qquickwindow_p.h>
#include <qcontainerfwd.h>
#include <qcoreevent.h>
#include <qevent.h>
#include <qguiapplication.h>
@ -112,6 +113,8 @@ void ProxyWindowBase::ensureQWindow() {
auto opaque = this->qsSurfaceFormat.opaqueModified ? this->qsSurfaceFormat.opaque
: this->mColor.alpha() >= 255;
format.setOption(QSurfaceFormat::ResetNotification);
if (opaque) format.setAlphaBufferSize(0);
else format.setAlphaBufferSize(8);
@ -195,6 +198,7 @@ void ProxyWindowBase::connectWindow() {
QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged);
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
QObject::connect(this->window, &QQuickWindow::sceneGraphError, this, &ProxyWindowBase::onSceneGraphError);
QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::onExposed);
QObject::connect(this->window, &ProxiedWindow::devicePixelRatioChanged, this, &ProxyWindowBase::devicePixelRatioChanged);
// clang-format on
@ -226,6 +230,22 @@ void ProxyWindowBase::completeWindow() {
emit this->screenChanged();
}
void ProxyWindowBase::onSceneGraphError(
QQuickWindow::SceneGraphError error,
const QString& message
) {
if (error == QQuickWindow::ContextNotAvailable) {
qCritical().nospace() << "Failed to create graphics context for " << this << ": " << message;
} else {
qCritical().nospace() << "Scene graph error " << error << " occurred for " << this << ": "
<< message;
}
emit this->resourcesLost();
this->mVisible = false;
this->setVisibleDirect(false);
}
void ProxyWindowBase::onVisibleChanged() {
if (this->mVisible && !this->window->isVisible()) {
this->mVisible = false;