aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/context2d/qquickcontext2d.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-01-14 12:00:56 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-01-16 12:46:52 +0100
commit291aea14636a0e779d874a01630524facb1397dd (patch)
tree044ff4131a9b3f5a3edb00e6a807d0609c04a182 /src/quick/items/context2d/qquickcontext2d.cpp
parent39f1e0d66dc434e764731fbfed29c8fd98d217aa (diff)
parent88e87647c3b7d651dba2c8e61f945d47ecdd02c4 (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts: .qmake.conf src/qml/jsruntime/qv4context_p.h src/qml/jsruntime/qv4debugging.cpp src/qml/jsruntime/qv4engine.cpp src/qml/jsruntime/qv4functionobject_p.h src/qml/jsruntime/qv4qobjectwrapper.cpp src/quick/scenegraph/shaders/visualization.frag tests/auto/qml/qjsengine/tst_qjsengine.cpp Change-Id: I492e8546c278f80a300a2129e9a29d861e144a30
Diffstat (limited to 'src/quick/items/context2d/qquickcontext2d.cpp')
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index da4212e5b1..bc5fd8504f 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -4170,13 +4170,35 @@ QQuickContext2DTexture *QQuickContext2D::texture() const
QImage QQuickContext2D::toImage(const QRectF& bounds)
{
- flush();
- if (m_texture->thread() == QThread::currentThread())
- m_texture->grabImage(bounds);
- else if (m_renderStrategy == QQuickCanvasItem::Cooperative) {
+ if (m_texture->thread() == QThread::currentThread()) {
+ // if we're either not rendering to an fbo or we have a separate opengl context we can just
+ // flush. Otherwise we have to make sure the shared opengl context is current before we do
+ // so. It may or may not be current already, depending on how this method is called.
+ if (m_renderTarget != QQuickCanvasItem::FramebufferObject || m_glContext) {
+ flush();
+ m_texture->grabImage(bounds);
+ } else {
+ QQuickWindow *window = m_canvas->window();
+ QOpenGLContext *ctx = window ? window->openglContext() : 0;
+ if (ctx && ctx->isValid()) {
+ if (ctx == QOpenGLContext::currentContext()) {
+ flush();
+ } else {
+ ctx->makeCurrent(window);
+ flush();
+ ctx->doneCurrent();
+ }
+ m_texture->grabImage(bounds);
+ } else {
+ qWarning() << "Cannot read pixels from canvas before opengl context is valid";
+ return QImage();
+ }
+ }
+ } else if (m_renderStrategy == QQuickCanvasItem::Cooperative) {
qWarning() << "Pixel readback is not supported in Cooperative mode, please try Threaded or Immediate mode";
return QImage();
} else {
+ flush();
QCoreApplication::postEvent(m_texture, new QEvent(QEvent::Type(QEvent::User + 10)));
QMetaObject::invokeMethod(m_texture,
"grabImage",