Commit 5a5db368 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Add high dpi support to QQuickFramebufferObject


Change-Id: I58aa163bd17fae7190161641d94f51887d8f88a6
Reviewed-by: default avatarMorten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: default avatarGunnar Sletta <gunnar@sletta.org>
parent 9a66bb75
No related merge requests found
Showing with 23 additions and 0 deletions
...@@ -161,6 +161,7 @@ public: ...@@ -161,6 +161,7 @@ public:
, renderer(0) , renderer(0)
, renderPending(true) , renderPending(true)
, invalidatePending(false) , invalidatePending(false)
, devicePixelRatio(1)
{ {
qsgnode_set_description(this, QStringLiteral("fbonode")); qsgnode_set_description(this, QStringLiteral("fbonode"));
} }
...@@ -202,14 +203,25 @@ public Q_SLOTS: ...@@ -202,14 +203,25 @@ public Q_SLOTS:
} }
} }
void handleScreenChange()
{
if (window->effectiveDevicePixelRatio() != devicePixelRatio) {
renderer->invalidateFramebufferObject();
quickFbo->update();
}
}
public: public:
QQuickWindow *window; QQuickWindow *window;
QOpenGLFramebufferObject *fbo; QOpenGLFramebufferObject *fbo;
QOpenGLFramebufferObject *msDisplayFbo; QOpenGLFramebufferObject *msDisplayFbo;
QQuickFramebufferObject::Renderer *renderer; QQuickFramebufferObject::Renderer *renderer;
QQuickFramebufferObject *quickFbo;
bool renderPending; bool renderPending;
bool invalidatePending; bool invalidatePending;
int devicePixelRatio;
}; };
/*! /*!
...@@ -239,7 +251,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode ...@@ -239,7 +251,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
n->window = window(); n->window = window();
n->renderer = createRenderer(); n->renderer = createRenderer();
n->renderer->data = n; n->renderer->data = n;
n->quickFbo = this;
connect(window(), SIGNAL(beforeRendering()), n, SLOT(render())); connect(window(), SIGNAL(beforeRendering()), n, SLOT(render()));
connect(window(), SIGNAL(screenChanged(QScreen*)), n, SLOT(handleScreenChange()));
} }
n->renderer->synchronize(this); n->renderer->synchronize(this);
...@@ -248,6 +262,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode ...@@ -248,6 +262,9 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
QSize desiredFboSize(qMax<int>(minFboSize.width(), width()), QSize desiredFboSize(qMax<int>(minFboSize.width(), width()),
qMax<int>(minFboSize.height(), height())); qMax<int>(minFboSize.height(), height()));
n->devicePixelRatio = window()->effectiveDevicePixelRatio();
desiredFboSize *= n->devicePixelRatio;
if (n->fbo && (d->followsItemSize || n->invalidatePending)) { if (n->fbo && (d->followsItemSize || n->invalidatePending)) {
if (n->fbo->size() != desiredFboSize) { if (n->fbo->size() != desiredFboSize) {
delete n->fbo; delete n->fbo;
...@@ -414,6 +431,12 @@ void QQuickFramebufferObject::Renderer::invalidateFramebufferObject() ...@@ -414,6 +431,12 @@ void QQuickFramebufferObject::Renderer::invalidateFramebufferObject()
* \note Some hardware has issues with small FBO sizes. \a size takes that into account, so * \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 * be cautious when overriding the size with a fixed size. A minimal size of 64x64 should
* always work. * 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) QOpenGLFramebufferObject *QQuickFramebufferObject::Renderer::createFramebufferObject(const QSize &size)
{ {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment