From 5a5db3681fe5f236cbfbddd45f48ae669c7742c5 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 22 Oct 2014 11:59:02 +0200 Subject: Add high dpi support to QQuickFramebufferObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I58aa163bd17fae7190161641d94f51887d8f88a6 Reviewed-by: Morten Johan Sørvig Reviewed-by: Gunnar Sletta --- src/quick/items/qquickframebufferobject.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp index dc4668be3f..09a25f4efa 100644 --- a/src/quick/items/qquickframebufferobject.cpp +++ b/src/quick/items/qquickframebufferobject.cpp @@ -161,6 +161,7 @@ public: , renderer(0) , renderPending(true) , invalidatePending(false) + , devicePixelRatio(1) { qsgnode_set_description(this, QStringLiteral("fbonode")); } @@ -202,14 +203,25 @@ public Q_SLOTS: } } + void handleScreenChange() + { + if (window->effectiveDevicePixelRatio() != devicePixelRatio) { + renderer->invalidateFramebufferObject(); + quickFbo->update(); + } + } + public: QQuickWindow *window; QOpenGLFramebufferObject *fbo; QOpenGLFramebufferObject *msDisplayFbo; QQuickFramebufferObject::Renderer *renderer; + QQuickFramebufferObject *quickFbo; bool renderPending; bool invalidatePending; + + int devicePixelRatio; }; /*! @@ -239,7 +251,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode n->window = window(); n->renderer = createRenderer(); n->renderer->data = n; + n->quickFbo = this; connect(window(), SIGNAL(beforeRendering()), n, SLOT(render())); + connect(window(), SIGNAL(screenChanged(QScreen*)), n, SLOT(handleScreenChange())); } n->renderer->synchronize(this); @@ -248,6 +262,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode QSize desiredFboSize(qMax(minFboSize.width(), width()), qMax(minFboSize.height(), height())); + n->devicePixelRatio = window()->effectiveDevicePixelRatio(); + desiredFboSize *= n->devicePixelRatio; + if (n->fbo && (d->followsItemSize || n->invalidatePending)) { if (n->fbo->size() != desiredFboSize) { delete n->fbo; @@ -414,6 +431,12 @@ void QQuickFramebufferObject::Renderer::invalidateFramebufferObject() * \note Some hardware has issues with small FBO sizes. \a size takes that into account, so * be cautious when overriding the size with a fixed size. A minimal size of 64x64 should * always work. + * + * \note \a size takes the device pixel ratio into account, meaning that it is + * already multiplied by the correct scale factor. When moving the window + * containing the QQuickFramebufferObject item to a screen with different + * settings, the FBO is automatically recreated and this function is invoked + * with the correct size. */ QOpenGLFramebufferObject *QQuickFramebufferObject::Renderer::createFramebufferObject(const QSize &size) { -- cgit v1.2.3