From b902f540cda4bb523297a7a5c59520be06f30a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Mon, 30 Mar 2015 14:14:00 +0200 Subject: Match the offscreen windows position to the QQuickWidget position. The position of the offscreen window would always be set to 0,0, making it impossible to get the actual position of the scene. With this change, it will be possible for child windows or items in the scene to correctly calculate their global position. Change-Id: Ibd3ff03880209047776e86ad889b40cbf79c3e6e Reviewed-by: Laszlo Agocs --- src/quickwidgets/qquickwidget.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/quickwidgets/qquickwidget.cpp') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index b472664068..8b7a42de57 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -623,6 +623,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); @@ -747,7 +763,11 @@ void QQuickWidget::createFramebufferObject() d->fbo = new QOpenGLFramebufferObject(fboSize, format); } - d->offscreenWindow->setGeometry(0, 0, width(), height()); + // 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) @@ -1100,6 +1120,10 @@ bool QQuickWidget::event(QEvent *e) } break; + case QEvent::Move: + d->updatePosition(); + break; + default: break; } -- cgit v1.2.3 From a7eeec59adba0e9a6f08e9ab1503d4ecfca349ba Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 15 Apr 2015 18:14:15 +0200 Subject: Support sRGB for text with QQuickWidget Otherwise we get visually different results with QQuickWindow and QQuickWidget on OS X. Task-number: QTBUG-42861 Change-Id: Icbf6f6e980129f5de73a88e7be7bef4f592e875e Reviewed-by: Gunnar Sletta --- src/quickwidgets/qquickwidget.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/quickwidgets/qquickwidget.cpp') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 8b7a42de57..38dde806ed 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -755,6 +755,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. @@ -763,6 +773,17 @@ void QQuickWidget::createFramebufferObject() d->fbo = new QOpenGLFramebufferObject(fboSize, format); } + // 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()). -- cgit v1.2.3