6#include "QskClipNode.h"
7#include "QskBoxBorderMetrics.h"
8#include "QskBoxRenderer.h"
9#include "QskBoxShapeMetrics.h"
10#include "QskFunctions.h"
13#include <qquickwindow.h>
15static inline QskHashValue qskMetricsHash(
18 QskHashValue hash = 13000;
20 hash = shape.hash( hash );
21 return border.hash( hash );
24static inline void qskSetBoundingRect( QSGClipNode* node,
const QRectF& rect )
39 node->setIsRectangular(
false );
40 node->setClipRect( rect );
44 QSGGeometry& geometry,
int lineCount )
46 geometry.allocate( 2 * lineCount );
50QskClipNode::QskClipNode()
52 , m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
54 setGeometry( &m_geometry );
57QskClipNode::~QskClipNode()
61void QskClipNode::setRect(
const QRectF& rect )
63 setRegion( rect, QRectF() );
66void QskClipNode::setRegion(
const QRectF& rect,
const QRectF& excludedRect )
78 const auto innerRect = excludedRect.isEmpty()
79 ? QRectF() : excludedRect.intersected( rect );
81 const auto hash = qHashBits( &innerRect,
sizeof( innerRect ), 1450 );
82 if ( ( hash == m_hash ) && ( rect == Inherited::clipRect() ) )
85 qskSetBoundingRect(
this, rect );
88 m_geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
90 if ( innerRect.isEmpty() )
92 const auto l = qskAllocateLines( m_geometry, 2 );
94 l[0].setLine( rect.topLeft(), rect.topRight() );
95 l[1].setLine( rect.bottomLeft(), rect.bottomRight() );
99 const auto l = qskAllocateLines( m_geometry, 5 );
101 l[0].setLine( rect.topLeft(), innerRect.topLeft() );
102 l[1].setLine( rect.topRight(), innerRect.topRight() );
103 l[2].setLine( rect.bottomRight(), innerRect.bottomRight() );
104 l[3].setLine( rect.bottomLeft(), innerRect.bottomLeft() );
108 m_geometry.markVertexDataDirty();
109 markDirty( QSGNode::DirtyGeometry );
112void QskClipNode::setBox(
const QQuickWindow* window,
const QRectF& rect,
115 if ( rect.isEmpty() )
121 const auto hash = qskMetricsHash( shape, border );
122 if ( hash == m_hash && rect == boundingRectangle() )
125 qskSetBoundingRect(
this, rect );
129 renderer.setFillLines( rect, shape, border, m_geometry );
131 m_geometry.markVertexDataDirty();
132 markDirty( QSGNode::DirtyGeometry );
135void QskClipNode::reset()
137 Inherited::setIsRectangular(
true );
138 Inherited::setClipRect( QRectF() );
140 if ( m_geometry.vertexData() )
142 m_geometry.allocate( 0 );
143 m_geometry.markVertexDataDirty();
149 markDirty( QSGNode::DirtyGeometry );