From c2414e16aba2ad499a49d3661a2961795c9a9dc9 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 14 Jul 2016 12:43:46 +0200 Subject: Fix rendercontrol grabs with the software backend Calling grabWindow recurses (since that is implemented via QQuickRenderControl::grab...) so it's not an option. Instead, call directly in the software renderer implementation. Fix also the size of the offscreen QQuickWindow when using QQuickWidget in combination with the software backend. Change-Id: I857a2cc0aebbbaa5d52d809aeaec37c15b0787b9 Reviewed-by: Andy Nichols --- src/quick/items/qquickrendercontrol.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/quick/items/qquickrendercontrol.cpp') diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index dbe1add345..8c18c58224 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -56,9 +56,9 @@ #include #include +#include #include - QT_BEGIN_NAMESPACE #ifndef QT_NO_OPENGL extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha); @@ -369,12 +369,31 @@ QImage QQuickRenderControl::grab() if (!d->window) return QImage(); - render(); + QImage grabContent; + + if (d->window->rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL) { #ifndef QT_NO_OPENGL - QImage grabContent = qt_gl_read_framebuffer(d->window->size() * d->window->effectiveDevicePixelRatio(), false, false); -#else - QImage grabContent = d->window->grabWindow(); + render(); + grabContent = qt_gl_read_framebuffer(d->window->size() * d->window->effectiveDevicePixelRatio(), false, false); #endif + } else if (d->window->rendererInterface()->graphicsApi() == QSGRendererInterface::Software) { + QQuickWindowPrivate *cd = QQuickWindowPrivate::get(d->window); + QSGSoftwareRenderer *softwareRenderer = static_cast(cd->renderer); + if (softwareRenderer) { + const qreal dpr = d->window->effectiveDevicePixelRatio(); + const QSize imageSize = d->window->size() * dpr; + grabContent = QImage(imageSize, QImage::Format_ARGB32_Premultiplied); + grabContent.setDevicePixelRatio(dpr); + QPaintDevice *prevDev = softwareRenderer->currentPaintDevice(); + softwareRenderer->setCurrentPaintDevice(&grabContent); + softwareRenderer->markDirty(); + render(); + softwareRenderer->setCurrentPaintDevice(prevDev); + } + } else { + qWarning("QQuickRenderControl: grabs are not supported with the current Qt Quick backend"); + } + return grabContent; } -- cgit v1.2.3