From cd21ae6cdffb3118ae0195a448f7b437886c4701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 10 Dec 2023 12:29:44 +0100 Subject: [PATCH] QRhiBackingStore: Support flushing child windows with same surface type As long as the surface type of the child window is the same as the one owning the backingstore we can flush it through the same code path as for the top level window. This code path was already exercised by QWidgetRepaintManager::flush(), by calling rhiFlush() directly, but we now support it in those (rare) cases of non-Widgets windows using a single QBackingStore for a full window hierarchy. A future improvement would be to decouple the RHI configuration from the backingstore, so that we can flush child windows with different surface types through the same backingstore. This is relevant for platforms that rely on QRhiBackingStore exclusively (iOS and Android), as in widgets we currently only switch the top level widget surface type when enabling RHI based flushing, leaving all child windows with QWindow::RasterSurface. This could potentially be solved by teaching widgets to re-configure all QWidgetWindows, including children. Task-number: QTBUG-119309 Change-Id: Ifa3fe6125493ac1becd2538ba84f3b4a5e3a5d71 Reviewed-by: Laszlo Agocs Reviewed-by: Timur Pocheptsov --- src/gui/painting/qrhibackingstore.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qrhibackingstore.cpp b/src/gui/painting/qrhibackingstore.cpp index cf13df3765..72ab28f1fc 100644 --- a/src/gui/painting/qrhibackingstore.cpp +++ b/src/gui/painting/qrhibackingstore.cpp @@ -15,17 +15,24 @@ QRhiBackingStore::~QRhiBackingStore() { } -void QRhiBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +void QRhiBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, const QPoint &offset) { Q_UNUSED(region); Q_UNUSED(offset); - if (window != this->window()) + if (flushedWindow->surfaceType() != window()->surfaceType()) { + qWarning() << "Cannot flush child window" << flushedWindow + << "with surface type" << flushedWindow->surfaceType() << ";" + << "Must match" << window()->surfaceType() << "of" << window(); + + // FIXME: Support different surface types by not tying the + // RHI config to the backing store itself (per window config). return; + } if (!rhi()) { QPlatformBackingStoreRhiConfig rhiConfig; - switch (window->surfaceType()) { + switch (window()->surfaceType()) { case QSurface::OpenGLSurface: rhiConfig.setApi(QPlatformBackingStoreRhiConfig::OpenGL); break; @@ -41,7 +48,8 @@ void QRhiBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoin static QPlatformTextureList emptyTextureList; bool translucentBackground = m_image.hasAlphaChannel(); - rhiFlush(window, window->devicePixelRatio(), region, offset, &emptyTextureList, translucentBackground); + rhiFlush(flushedWindow, flushedWindow->devicePixelRatio(), + region, offset, &emptyTextureList, translucentBackground); } QImage::Format QRhiBackingStore::format() const