QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskBoxClipNode.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskBoxClipNode.h"
7#include "QskBoxBorderMetrics.h"
8#include "QskBoxRenderer.h"
9#include "QskBoxShapeMetrics.h"
10#include "QskFunctions.h"
11
12#include <qquickitem.h>
13
14static inline QskHashValue qskMetricsHash(
15 const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
16{
17 QskHashValue hash = 13000;
18
19 hash = shape.hash( hash );
20 return border.hash( hash );
21}
22
23QskBoxClipNode::QskBoxClipNode()
24 : m_hash( 0 )
25 , m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
26{
27 setGeometry( &m_geometry );
28}
29
30QskBoxClipNode::~QskBoxClipNode()
31{
32}
33
34void QskBoxClipNode::setBox( const QQuickWindow* window, const QRectF& rect,
35 const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
36{
37 const auto hash = qskMetricsHash( shape, border );
38 if ( hash == m_hash && rect == m_rect )
39 return;
40
41 m_rect = rect;
42 m_hash = hash;
43
44 bool isRectangular = false;
45
46#if 0
47 /*
48 Depending on isRectangular the "renderer can use scissoring instead of stencil,
49 which is significantly faster."
50
51 However the batch renderer ( qsgbatchrenderer.cpp ) is rounding the clip rectangle
52 to integers and the clip might become too small/large.
53
54 So we always have to use stencil clipping - even if it might have a negative
55 impact on the performance. TODO ...
56 */
57
58 if ( shape.isRectangle() )
59 isRectangular = true;
60#endif
61
62 if ( isRectangular )
63 {
64 if ( m_geometry.vertexCount() > 0 )
65 m_geometry.allocate( 0 );
66
67 setIsRectangular( true );
68 }
69 else
70 {
71 setIsRectangular( false );
72
73 QskBoxRenderer renderer( window );
74 renderer.setFillLines( rect, shape, border, m_geometry );
75 }
76
77 /*
78 Even in situations, where the clipping is not rectangular, it is
79 useful to know its bounding rectangle
80 */
81 setClipRect( qskValidOrEmptyInnerRect( rect, border.widths() ) );
82
83 m_geometry.markVertexDataDirty();
84 markDirty( QSGNode::DirtyGeometry );
85}