#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)
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)
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)
{
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;
m_surface->sendOnScreenVisibilityChange(enabled);
}
- emit clientRenderingEnabledChanged();
+ emit clientRenderingEnabledChanged();
}
}
#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)
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; }
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