diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-07-14 12:43:46 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-07-15 09:30:31 +0000 |
commit | c2414e16aba2ad499a49d3661a2961795c9a9dc9 (patch) | |
tree | 08c8d0a06bc4c9bb218f45739daf3b48540cd2d0 /src/quick/items/qquickrendercontrol.cpp | |
parent | 12de7bbc1ee2959f4e31a345b4573242d34474cf (diff) |
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 <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/items/qquickrendercontrol.cpp')
-rw-r--r-- | src/quick/items/qquickrendercontrol.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
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 <QtQuick/QQuickWindow> #include <QtQuick/private/qquickwindow_p.h> +#include <QtQuick/private/qsgsoftwarerenderer_p.h> #include <QtCore/private/qobject_p.h> - 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<QSGSoftwareRenderer *>(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; } |