diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-10-22 11:59:02 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-10-22 22:28:23 +0200 |
commit | 5a5db3681fe5f236cbfbddd45f48ae669c7742c5 (patch) | |
tree | f51ded8aec8d12f7388df38dd02fc02dad540252 | |
parent | 9a66bb751bb5f5830e5f30a3c1a22ddb5f34f1bb (diff) |
Add high dpi support to QQuickFramebufferObject
Change-Id: I58aa163bd17fae7190161641d94f51887d8f88a6
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r-- | src/quick/items/qquickframebufferobject.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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<int>(minFboSize.width(), width()), qMax<int>(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) { |