updated to latest API
authorGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 22 Aug 2011 14:07:56 +0000 (16:07 +0200)
committerGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 22 Aug 2011 14:07:56 +0000 (16:07 +0200)
src/qt-compositor/compositor_api/waylandsurfaceitem.cpp
src/qt-compositor/compositor_api/waylandsurfaceitem.h

index e503a03..7184f1c 100644 (file)
 #include <QtDeclarative/QSGSimpleRectNode>
 #include <QtDeclarative/QSGCanvas>
 
-void WaylandSurfaceItem::surfaceDamaged(const QRect &)
+class WaylandSurfaceTextureProvider : public QSGTextureProvider
 {
-    QSGTexture *oldTexture = m_texture;
-
-    if (m_surface->type() == WaylandSurface::Texture) {
-        QSGEngine::TextureOption opt = useTextureAlpha() ? QSGEngine::TextureHasAlphaChannel : QSGEngine::TextureOption(0);
-
-        m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(),
-                                                                      m_surface->geometry().size(),
-                                                                      opt);
-    } else {
-        m_texture = canvas()->sceneGraphEngine()->createTextureFromImage(m_surface->image());
+public:
+    QSGTexture *texture() const {
+        t->setFiltering(smooth ? QSGTexture::Linear : QSGTexture::Nearest);
+        return t;
     }
 
-    delete oldTexture;
+    QSGTexture *t;
+    bool smooth;
+};
 
-    emit textureChanged();
+void WaylandSurfaceItem::surfaceDamaged(const QRect &)
+{
+    m_damaged = true;
 }
 
 WaylandSurfaceItem::WaylandSurfaceItem(QSGItem *parent)
@@ -105,11 +103,13 @@ void WaylandSurfaceItem::init(WaylandSurface *surface)
     connect(this, SIGNAL(textureChanged()), this, SLOT(update()));
     connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &)));
 
+    m_damaged = false;
+
 }
 
 WaylandSurfaceItem::~WaylandSurfaceItem()
 {
-    delete m_texture;
+    m_texture->deleteLater();
 }
 
 void WaylandSurfaceItem::setSurface(WaylandSurface *surface)
@@ -122,11 +122,11 @@ bool WaylandSurfaceItem::isYInverted() const
     return m_surface->isYInverted();
 }
 
-QSGTexture *WaylandSurfaceItem::texture() const
+QSGTextureProvider *WaylandSurfaceItem::textureProvider() const
 {
-    if (m_texture)
-        m_texture->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
-    return m_texture;
+    if (!m_provider)
+        m_provider = new WaylandSurfaceTextureProvider();
+    return m_provider;
 }
 
 void WaylandSurfaceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -216,6 +216,26 @@ QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa
 {
     QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode);
 
+    if (m_damaged) {
+        QSGTexture *oldTexture = m_texture;
+        if (m_surface->type() == WaylandSurface::Texture) {
+            QSGEngine::TextureOption opt = useTextureAlpha() ? QSGEngine::TextureHasAlphaChannel : QSGEngine::TextureOption(0);
+            m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(),
+                                                                          m_surface->geometry().size(),
+                                                                          opt);
+        } else {
+            m_texture = canvas()->sceneGraphEngine()->createTextureFromImage(m_surface->image());
+        }
+        delete oldTexture;
+        emit textureChanged();
+        m_damaged = false;
+    }
+
+    if (m_provider) {
+        m_provider->t = m_texture;
+        m_provider->smooth = smooth();
+    }
+
     if (!m_texture || !m_paintEnabled) {
         delete oldNode;
         return 0;
@@ -255,7 +275,7 @@ void WaylandSurfaceItem::setClientRenderingEnabled(bool enabled)
             m_surface->sendOnScreenVisibilityChange(enabled);
         }
 
-        emit clientRenderingEnabledChanged();       
+        emit clientRenderingEnabledChanged();
     }
 }
 
index bc296b5..81f4a58 100644 (file)
 #include <private/qsgtextureprovider_p.h>
 
 class WaylandSurface;
+class WaylandSurfaceTextureProvider;
+
 Q_DECLARE_METATYPE(WaylandSurface*)
 
-class WaylandSurfaceItem : public QSGItem, public QSGTextureProvider
+class WaylandSurfaceItem : public QSGItem
 {
     Q_OBJECT
-    Q_INTERFACES(QSGTextureProvider)
     Q_PROPERTY(WaylandSurface* surface READ surface WRITE setSurface)
     Q_PROPERTY(bool paintEnabled READ paintEnabled WRITE setPaintEnabled)
     Q_PROPERTY(bool useTextureAlpha READ useTextureAlpha WRITE setUseTextureAlpha NOTIFY useTextureAlphaChanged)
@@ -69,8 +70,8 @@ public:
 
     Q_INVOKABLE bool isYInverted() const;
 
-    QSGTexture *texture() const;
-    const char *textureChangedSignal() const { return SIGNAL(textureChanged()); }
+    bool isTextureProvider() const { return true; }
+    QSGTextureProvider *textureProvider() const;
 
     bool paintEnabled() const;
     bool useTextureAlpha() const  { return m_useTextureAlpha; }
@@ -115,10 +116,12 @@ private:
 
     WaylandSurface *m_surface;
     QSGTexture *m_texture;
+    mutable WaylandSurfaceTextureProvider *m_provider;
     bool m_paintEnabled;
     bool m_useTextureAlpha;
     bool m_clientRenderingEnabled;
     bool m_touchEventsEnabled;
+    bool m_damaged;
 };
 
 #endif