~ubuntu-branches/ubuntu/vivid/qtdeclarative-opensource-src-gles/vivid

« back to all changes in this revision

Viewing changes to src/quick/items/context2d/qquickcontext2d.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2015-03-11 16:51:45 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20150311165145-7653iqap3mau92gy
Tags: 5.4.1-0ubuntu1
Sync package with qtdeclarative-opensource-src - 5.4.1-1ubuntu3

Show diffs side-by-side

added added

removed removed

Lines of Context:
4171
4171
 
4172
4172
QImage QQuickContext2D::toImage(const QRectF& bounds)
4173
4173
{
4174
 
    flush();
4175
 
    if (m_texture->thread() == QThread::currentThread())
4176
 
        m_texture->grabImage(bounds);
4177
 
    else if (m_renderStrategy == QQuickCanvasItem::Cooperative) {
 
4174
    if (m_texture->thread() == QThread::currentThread()) {
 
4175
        // if we're either not rendering to an fbo or we have a separate opengl context we can just
 
4176
        // flush. Otherwise we have to make sure the shared opengl context is current before we do
 
4177
        // so. It may or may not be current already, depending on how this method is called.
 
4178
        if (m_renderTarget != QQuickCanvasItem::FramebufferObject || m_glContext) {
 
4179
            flush();
 
4180
            m_texture->grabImage(bounds);
 
4181
        } else {
 
4182
            QQuickWindow *window = m_canvas->window();
 
4183
            QOpenGLContext *ctx =  window ? window->openglContext() : 0;
 
4184
            if (ctx && ctx->isValid()) {
 
4185
                if (ctx == QOpenGLContext::currentContext()) {
 
4186
                    flush();
 
4187
                } else {
 
4188
                    ctx->makeCurrent(window);
 
4189
                    flush();
 
4190
                    ctx->doneCurrent();
 
4191
                }
 
4192
                m_texture->grabImage(bounds);
 
4193
            } else {
 
4194
                qWarning() << "Cannot read pixels from canvas before opengl context is valid";
 
4195
                return QImage();
 
4196
            }
 
4197
        }
 
4198
    } else if (m_renderStrategy == QQuickCanvasItem::Cooperative) {
4178
4199
        qWarning() << "Pixel readback is not supported in Cooperative mode, please try Threaded or Immediate mode";
4179
4200
        return QImage();
4180
4201
    } else {
 
4202
        flush();
4181
4203
        QCoreApplication::postEvent(m_texture, new QEvent(QEvent::Type(QEvent::User + 10)));
4182
4204
        QMetaObject::invokeMethod(m_texture,
4183
4205
                                  "grabImage",