From: Gunnar Sletta Date: Sat, 23 Aug 2014 07:00:51 +0000 (+0200) Subject: Make QQuickFramebufferObject a texture provider. X-Git-Tag: v5.3.99+beta1~116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d324db8839c5a06980384d0b2d4e06125bb5a83d;p=platform%2Fupstream%2Fqtdeclarative.git Make QQuickFramebufferObject a texture provider. Change-Id: Ib9cf0f99dc07e4125c4ccd2d45da2839d8af88b6 Reviewed-by: Laszlo Agocs --- diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp index 99db5b8..7c70f27 100644 --- a/src/quick/items/qquickframebufferobject.cpp +++ b/src/quick/items/qquickframebufferobject.cpp @@ -47,10 +47,12 @@ class QQuickFramebufferObjectPrivate : public QQuickItemPrivate public: QQuickFramebufferObjectPrivate() : followsItemSize(true) + , node(0) { } bool followsItemSize; + mutable QSGFramebufferObjectNode *node; }; /*! @@ -91,6 +93,11 @@ public: * to \c false and return a texture of your choosing from * QQuickFramebufferObject::Renderer::createFramebufferObject(). * + * Starting Qt 5.4, the QQuickFramebufferObject class is a + * \l{QSGTextureProvider}{texture provider} + * and can be used directly in \l {ShaderEffect}{ShaderEffects} and other + * classes that consume texture providers. + * * \sa {Scene Graph - Rendering FBOs}, {Scene Graph and Rendering} */ @@ -101,6 +108,7 @@ QQuickFramebufferObject::QQuickFramebufferObject(QQuickItem *parent) : QQuickItem(*new QQuickFramebufferObjectPrivate, parent) { setFlag(ItemHasContents); + connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG())); } /*! @@ -142,7 +150,7 @@ void QQuickFramebufferObject::geometryChanged(const QRectF &newGeometry, const Q update(); } -class QSGFramebufferObjectNode : public QObject, public QSGSimpleTextureNode +class QSGFramebufferObjectNode : public QSGTextureProvider, public QSGSimpleTextureNode { Q_OBJECT @@ -155,7 +163,7 @@ public: , renderPending(true) , invalidatePending(false) { - + qsgnode_set_description(this, QStringLiteral("fbonode")); } ~QSGFramebufferObjectNode() @@ -172,6 +180,11 @@ public: window->update(); } + QSGTexture *texture() const Q_DECL_OVERRIDE + { + return QSGSimpleTextureNode::texture(); + } + public Q_SLOTS: void render() { @@ -186,6 +199,7 @@ public Q_SLOTS: QOpenGLFramebufferObject::blitFramebuffer(msDisplayFbo, fbo); markDirty(QSGNode::DirtyMaterial); + emit textureChanged(); } } @@ -217,11 +231,13 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode Q_D(QQuickFramebufferObject); if (!n) { - n = new QSGFramebufferObjectNode; - n->window = window(); + if (!d->node) + d->node = new QSGFramebufferObjectNode; + n = d->node; } if (!n->renderer) { + n->window = window(); n->renderer = createRenderer(); n->renderer->data = n; connect(window(), SIGNAL(beforeRendering()), n, SLOT(render())); @@ -265,6 +281,39 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode return n; } +bool QQuickFramebufferObject::isTextureProvider() const +{ + return true; +} + +QSGTextureProvider *QQuickFramebufferObject::textureProvider() const +{ + Q_D(const QQuickFramebufferObject); + QQuickWindow *w = window(); + if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) { + qWarning("QQuickFramebufferObject::textureProvider: can only be queried on the rendering thread of an exposed window"); + return 0; + } + if (!d->node) + d->node = new QSGFramebufferObjectNode; + return d->node; +} + +void QQuickFramebufferObject::releaseResources() +{ + // When release resources is called on the GUI thread, we only need to + // forget about the node. Since it is the node we returned from updatePaintNode + // it will be managed by the scene graph. + Q_D(QQuickFramebufferObject); + d->node = 0; +} + +void QQuickFramebufferObject::invalidateSG() +{ + Q_D(QQuickFramebufferObject); + d->node = 0; +} + /*! * \class QQuickFramebufferObject::Renderer * \inmodule QtQuick diff --git a/src/quick/items/qquickframebufferobject.h b/src/quick/items/qquickframebufferobject.h index 22f8c92..99e68b9 100644 --- a/src/quick/items/qquickframebufferobject.h +++ b/src/quick/items/qquickframebufferobject.h @@ -75,6 +75,10 @@ public: virtual Renderer *createRenderer() const = 0; + bool isTextureProvider() const Q_DECL_OVERRIDE; + QSGTextureProvider *textureProvider() const Q_DECL_OVERRIDE; + void releaseResources() Q_DECL_OVERRIDE; + protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -83,6 +87,9 @@ protected: Q_SIGNALS: void textureFollowsItemSizeChanged(bool); + +private Q_SLOTS: + void invalidateSG(); }; QT_END_NAMESPACE