1 #include "waylandsurfacenode.h"
2 #include "waylandsurfaceitem.h"
4 #include <QtCore/QMutexLocker>
5 #include <QtQuick/QSGTexture>
6 #include <QtQuick/QSGSimpleTextureNode>
7 #include <QtQuick/QSGFlatColorMaterial>
9 WaylandSurfaceNode::WaylandSurfaceNode(WaylandSurfaceItem *item)
11 , m_textureUpdated(false)
12 , m_useTextureAlpha(false)
13 , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
15 m_textureMaterial = WaylandSurfaceTextureMaterial::createMaterial();
16 m_opaqueTextureMaterial = WaylandSurfaceTextureOpaqueMaterial::createMaterial();
18 m_currentMaterial = m_opaqueTextureMaterial;
20 setGeometry(&m_geometry);
21 setMaterial(m_currentMaterial);
24 m_item->m_node = this;
25 setFlag(UsePreprocess,true);
29 WaylandSurfaceNode::~WaylandSurfaceNode()
31 QMutexLocker locker(WaylandSurfaceItem::mutex);
34 delete m_textureMaterial;
35 delete m_opaqueTextureMaterial;
38 void WaylandSurfaceNode::preprocess()
40 QMutexLocker locker(WaylandSurfaceItem::mutex);
42 //Update if the item is dirty and we haven't done an updateTexture for this frame
43 if (m_item && m_item->m_damaged && !m_textureUpdated) {
44 m_item->updateTexture();
47 //Reset value for next frame: we have not done updatePaintNode yet
48 m_textureUpdated = false;
51 void WaylandSurfaceNode::updateTexture()
53 Q_ASSERT(m_item && m_item->textureProvider());
55 //If m_item->useTextureAlpha has changed to true use m_texureMaterial
56 //otherwise use m_opaqueTextureMaterial.
57 if (m_item->useTextureAlpha() != m_useTextureAlpha) {
58 m_useTextureAlpha = m_item->useTextureAlpha();
59 if (m_useTextureAlpha) {
60 m_currentMaterial = m_textureMaterial;
62 m_currentMaterial = m_opaqueTextureMaterial;
64 setMaterial(m_currentMaterial);
67 QSGTexture *texture = m_item->textureProvider()->texture();
71 void WaylandSurfaceNode::setRect(const QRectF &rect)
78 QSize ts = texture()->textureSize();
79 QRectF sourceRect(0, 0, ts.width(), ts.height());
80 QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_rect, texture()->convertToNormalizedSourceRect(sourceRect));
84 void WaylandSurfaceNode::setTexture(QSGTexture *texture)
86 if (m_currentMaterial->state()->texture() == texture)
88 m_currentMaterial->state()->setTexture(texture);
90 QSize ts = texture->textureSize();
91 QRectF sourceRect(0, 0, ts.width(), ts.height());
92 QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_rect, texture->convertToNormalizedSourceRect(sourceRect));
93 markDirty(DirtyMaterial);
96 QSGTexture *WaylandSurfaceNode::texture() const
98 return m_currentMaterial->state()->texture();
101 void WaylandSurfaceNode::setItem(WaylandSurfaceItem *item)