aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@sletta.org>2014-08-23 15:27:51 +0200
committerGunnar Sletta <gunnar@sletta.org>2014-08-26 06:13:40 +0200
commit916ced089f37d96ca8ef1cdb938791247bd44b72 (patch)
tree61f9225945298a8ae893a04acf72c99f00708abc /src
parent695a9605c6575eafe535c2dbfe94ad3e7697a5a8 (diff)
Make QQuickPaintedItem a texture provider.
Change-Id: I605dc35fcc2284a890851c41946cf95537e92d2e Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickpainteditem.cpp70
-rw-r--r--src/quick/items/qquickpainteditem.h7
-rw-r--r--src/quick/items/qquickpainteditem_p.h6
-rw-r--r--src/quick/scenegraph/util/qsgpainternode_p.h2
4 files changed, 84 insertions, 1 deletions
diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp
index 508ec1cb98..08145d89aa 100644
--- a/src/quick/items/qquickpainteditem.cpp
+++ b/src/quick/items/qquickpainteditem.cpp
@@ -42,6 +42,14 @@
QT_BEGIN_NAMESPACE
+class QQuickPaintedItemTextureProvider : public QSGTextureProvider
+{
+public:
+ QSGPainterNode *node;
+ QSGTexture *texture() const { return node ? node->texture() : 0; }
+ void fireTextureChanged() { emit textureChanged(); }
+};
+
/*!
\class QQuickPaintedItem
\brief The QQuickPaintedItem class provides a way to use the QPainter API in the
@@ -63,6 +71,11 @@ QT_BEGIN_NAMESPACE
start by implementing its only pure virtual public function: paint(), which implements
the actual painting. To get the size of the area painted by the item, use
contentsBoundingRect().
+
+ Starting Qt 5.4, the QQuickPaintedItem is a
+ \l{QSGTextureProvider}{texture provider}
+ and can be used directly in \l {ShaderEffect}{ShaderEffects} and other
+ classes that consume texture providers.
*/
/*!
@@ -115,6 +128,8 @@ QQuickPaintedItemPrivate::QQuickPaintedItemPrivate()
, opaquePainting(false)
, antialiasing(false)
, mipmap(false)
+ , textureProvider(0)
+ , node(0)
{
}
@@ -125,6 +140,7 @@ QQuickPaintedItem::QQuickPaintedItem(QQuickItem *parent)
: QQuickItem(*(new QQuickPaintedItemPrivate), parent)
{
setFlag(ItemHasContents);
+ connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
@@ -134,6 +150,7 @@ QQuickPaintedItem::QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *p
: QQuickItem(dd, parent)
{
setFlag(ItemHasContents);
+ connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
@@ -141,6 +158,9 @@ QQuickPaintedItem::QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *p
*/
QQuickPaintedItem::~QQuickPaintedItem()
{
+ Q_D(QQuickPaintedItem);
+ if (d->textureProvider)
+ QQuickWindowQObjectCleanupJob::schedule(window(), d->textureProvider);
}
/*!
@@ -494,12 +514,18 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat
if (width() <= 0 || height() <= 0) {
delete oldNode;
+ if (d->textureProvider) {
+ d->textureProvider->node = 0;
+ d->textureProvider->fireTextureChanged();
+ }
return 0;
}
QSGPainterNode *node = static_cast<QSGPainterNode *>(oldNode);
- if (!node)
+ if (!node) {
node = new QSGPainterNode(this);
+ d->node = node;
+ }
QRectF br = contentsBoundingRect();
@@ -517,7 +543,49 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat
d->dirtyRect = QRect();
+ if (d->textureProvider) {
+ d->textureProvider->node = node;
+ d->textureProvider->fireTextureChanged();
+ }
+
return node;
}
+void QQuickPaintedItem::releaseResources()
+{
+ Q_D(QQuickPaintedItem);
+ if (d->textureProvider) {
+ QQuickWindowQObjectCleanupJob::schedule(window(), d->textureProvider);
+ d->textureProvider = 0;
+ }
+ d->node = 0; // Managed by the scene graph, just clear the pointer.
+}
+
+void QQuickPaintedItem::invalidateSG()
+{
+ Q_D(QQuickPaintedItem);
+ delete d->textureProvider;
+ d->textureProvider = 0;
+ d->node = 0; // Managed by the scene graph, just clear the pointer
+}
+
+bool QQuickPaintedItem::isTextureProvider() const
+{
+ return true;
+}
+
+QSGTextureProvider *QQuickPaintedItem::textureProvider() const
+{
+ Q_D(const QQuickPaintedItem);
+ QQuickWindow *w = window();
+ if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) {
+ qWarning("QQuickPaintedItem::textureProvider: can only be queried on the rendering thread of an exposed window");
+ return 0;
+ }
+ if (!d->textureProvider)
+ d->textureProvider = new QQuickPaintedItemTextureProvider();
+ d->textureProvider->node = d->node;
+ return d->textureProvider;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickpainteditem.h b/src/quick/items/qquickpainteditem.h
index c5f5357dda..0a387e6b26 100644
--- a/src/quick/items/qquickpainteditem.h
+++ b/src/quick/items/qquickpainteditem.h
@@ -96,6 +96,9 @@ public:
virtual void paint(QPainter *painter) = 0;
+ bool isTextureProvider() const Q_DECL_OVERRIDE;
+ QSGTextureProvider *textureProvider() const Q_DECL_OVERRIDE;
+
Q_SIGNALS:
void fillColorChanged();
void contentsSizeChanged();
@@ -105,6 +108,10 @@ Q_SIGNALS:
protected:
QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = 0);
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ void releaseResources() Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void invalidateSG();
private:
Q_DISABLE_COPY(QQuickPaintedItem)
diff --git a/src/quick/items/qquickpainteditem_p.h b/src/quick/items/qquickpainteditem_p.h
index 34d043cdb3..f7da2f49b0 100644
--- a/src/quick/items/qquickpainteditem_p.h
+++ b/src/quick/items/qquickpainteditem_p.h
@@ -39,6 +39,9 @@
QT_BEGIN_NAMESPACE
+class QQuickPaintedItemTextureProvider;
+class QSGPainterNode;
+
class QQuickPaintedItemPrivate : public QQuickItemPrivate
{
public:
@@ -55,6 +58,9 @@ public:
bool opaquePainting: 1;
bool antialiasing: 1;
bool mipmap: 1;
+
+ mutable QQuickPaintedItemTextureProvider *textureProvider;
+ QSGPainterNode *node;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgpainternode_p.h b/src/quick/scenegraph/util/qsgpainternode_p.h
index 230527a10f..15ba2625f0 100644
--- a/src/quick/scenegraph/util/qsgpainternode_p.h
+++ b/src/quick/scenegraph/util/qsgpainternode_p.h
@@ -99,6 +99,8 @@ public:
void paint();
+ QSGTexture *texture() const { return m_texture; }
+
private:
void updateTexture();
void updateGeometry();