diff options
Diffstat (limited to 'src/quickwidgets')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 47 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget_p.h | 3 |
2 files changed, 48 insertions, 2 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 29577b856d..5dd439fdd0 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -630,6 +630,22 @@ void QQuickWidgetPrivate::updateSize() } } +/*! + \internal + + Update the position of the offscreen window, so it matches the position of the QQuickWidget. + */ +void QQuickWidgetPrivate::updatePosition() +{ + Q_Q(QQuickWidget); + if (offscreenWindow == 0) + return; + + const QPoint &pos = q->mapToGlobal(QPoint(0, 0)); + if (offscreenWindow->position() != pos) + offscreenWindow->setPosition(pos); +} + QSize QQuickWidgetPrivate::rootObjectSize() const { QSize rootObjectSize(0,0); @@ -746,6 +762,16 @@ void QQuickWidget::createFramebufferObject() format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(samples); + // The default framebuffer for normal windows have sRGB support on OS X which leads to the Qt Quick text item + // utilizing sRGB blending. To get identical results with QQuickWidget we have to have our framebuffer backed + // by an sRGB texture. +#ifdef Q_OS_OSX + if (context->hasExtension("GL_ARB_framebuffer_sRGB") + && context->hasExtension("GL_EXT_texture_sRGB") + && context->hasExtension("GL_EXT_texture_sRGB_decode")) + format.setInternalTextureFormat(GL_SRGB8_ALPHA8_EXT); +#endif + const QSize fboSize = size() * devicePixelRatio(); // Could be a simple hide - show, in which case the previous fbo is just fine. @@ -754,7 +780,22 @@ void QQuickWidget::createFramebufferObject() d->fbo = new QOpenGLFramebufferObject(fboSize, format); } - d->offscreenWindow->setGeometry(0, 0, width(), height()); + // When compositing in the backingstore, sampling the sRGB texture would perform an + // sRGB-linear conversion which is not what we want when the final framebuffer (the window's) + // is sRGB too. Disable the conversion. +#ifdef Q_OS_OSX + if (format.internalTextureFormat() == GL_SRGB8_ALPHA8_EXT) { + QOpenGLFunctions *funcs = context->functions(); + funcs->glBindTexture(GL_TEXTURE_2D, d->fbo->texture()); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } +#endif + + // Even though this is just an offscreen window we should set the position on it, as it might be + // useful for an item to know the actual position of the scene. + // Note: The position will be update when we get a move event (see: updatePosition()). + const QPoint &globalPos = mapToGlobal(QPoint(0, 0)); + d->offscreenWindow->setGeometry(globalPos.x(), globalPos.y(), width(), height()); d->offscreenWindow->setRenderTarget(d->fbo); if (samples > 0) @@ -1108,6 +1149,10 @@ bool QQuickWidget::event(QEvent *e) } break; + case QEvent::Move: + d->updatePosition(); + break; + default: break; } diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index c16ce2fece..dd0da96c3d 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -73,6 +73,7 @@ public: void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); void initResize(); void updateSize(); + void updatePosition(); void updateFrambufferObjectSize(); void setRootObject(QObject *); void render(bool needsSync); @@ -81,7 +82,7 @@ public: void destroyContext(); void handleContextCreationFailure(const QSurfaceFormat &format, bool isEs); - QObject *focusObject() Q_DECL_OVERRIDE; + QObject *focusObject(); GLuint textureId() const Q_DECL_OVERRIDE; QImage grabFramebuffer() Q_DECL_OVERRIDE; |