-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QskBoxClipNode renamed to QskClipNode + more clip options added
- Loading branch information
Showing
7 changed files
with
185 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/****************************************************************************** | ||
* QSkinny - Copyright (C) The authors | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*****************************************************************************/ | ||
|
||
#include "QskClipNode.h" | ||
#include "QskBoxBorderMetrics.h" | ||
#include "QskBoxRenderer.h" | ||
#include "QskBoxShapeMetrics.h" | ||
#include "QskFunctions.h" | ||
#include "QskVertex.h" | ||
|
||
#include <qquickwindow.h> | ||
|
||
static inline QskHashValue qskMetricsHash( | ||
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border ) | ||
{ | ||
QskHashValue hash = 13000; | ||
|
||
hash = shape.hash( hash ); | ||
return border.hash( hash ); | ||
} | ||
|
||
static inline void qskSetBoundingRect( QSGClipNode* node, const QRectF& rect ) | ||
{ | ||
/* | ||
Depending on isRectangular: the "scene graph renderer can use | ||
scissoring instead of stencil, which is significantly faster." | ||
However the batch renderer ( qsgbatchrenderer.cpp ) is rounding | ||
the clip rectangle to integers and the clip might become too small/large. | ||
So we always have to use stencil clipping - even if it might have a negative | ||
impact on the performance. | ||
When isRectangular is set to false the clipRect is not used from the | ||
renderer and we use the memory for the storing the bounding rectangle. | ||
*/ | ||
|
||
node->setIsRectangular( false ); | ||
node->setClipRect( rect ); | ||
} | ||
|
||
static inline QskVertex::Line* qskAllocateLines( | ||
QSGGeometry& geometry, int lineCount ) | ||
{ | ||
geometry.allocate( 2 * lineCount ); // 2 points per line | ||
return reinterpret_cast< QskVertex::Line* >( geometry.vertexData() ); | ||
} | ||
|
||
QskClipNode::QskClipNode() | ||
: m_hash( 0 ) | ||
, m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 ) | ||
{ | ||
setGeometry( &m_geometry ); | ||
} | ||
|
||
QskClipNode::~QskClipNode() | ||
{ | ||
} | ||
|
||
void QskClipNode::setRect( const QRectF& rect ) | ||
{ | ||
setRegion( rect, QRectF() ); | ||
} | ||
|
||
void QskClipNode::setRegion( const QRectF& rect, const QRectF& excludedRect ) | ||
{ | ||
if ( rect.isEmpty() ) | ||
{ | ||
/* | ||
what about rectangles having a width/height | ||
of 0 ( f.e lines ) TODO ... | ||
*/ | ||
reset(); | ||
return; | ||
} | ||
|
||
const auto innerRect = excludedRect.isEmpty() | ||
? QRectF() : excludedRect.intersected( rect ); | ||
|
||
const auto hash = qHashBits( &innerRect, sizeof( innerRect ), 1450 ); | ||
if ( ( hash == m_hash ) && ( rect == Inherited::clipRect() ) ) | ||
return; | ||
|
||
qskSetBoundingRect( this, rect ); | ||
m_hash = hash; | ||
|
||
m_geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip ); | ||
|
||
if ( innerRect.isEmpty() ) | ||
{ | ||
const auto l = qskAllocateLines( m_geometry, 2 ); | ||
|
||
l[0].setLine( rect.topLeft(), rect.topRight() ); | ||
l[1].setLine( rect.bottomLeft(), rect.bottomRight() ); | ||
} | ||
else | ||
{ | ||
const auto l = qskAllocateLines( m_geometry, 5 ); | ||
|
||
l[0].setLine( rect.topLeft(), innerRect.topLeft() ); | ||
l[1].setLine( rect.topRight(), innerRect.topRight() ); | ||
l[2].setLine( rect.bottomRight(), innerRect.bottomRight() ); | ||
l[3].setLine( rect.bottomLeft(), innerRect.bottomLeft() ); | ||
l[4] = l[0]; | ||
} | ||
|
||
m_geometry.markVertexDataDirty(); | ||
markDirty( QSGNode::DirtyGeometry ); | ||
} | ||
|
||
void QskClipNode::setBox( const QQuickWindow* window, const QRectF& rect, | ||
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border ) | ||
{ | ||
if ( rect.isEmpty() ) | ||
{ | ||
reset(); | ||
return; | ||
} | ||
|
||
const auto hash = qskMetricsHash( shape, border ); | ||
if ( hash == m_hash && rect == boundingRectangle() ) | ||
return; | ||
|
||
qskSetBoundingRect( this, rect ); | ||
m_hash = hash; | ||
|
||
QskBoxRenderer renderer( window ); | ||
renderer.setFillLines( rect, shape, border, m_geometry ); | ||
|
||
m_geometry.markVertexDataDirty(); | ||
markDirty( QSGNode::DirtyGeometry ); | ||
} | ||
|
||
void QskClipNode::reset() | ||
{ | ||
Inherited::setIsRectangular( true ); | ||
Inherited::setClipRect( QRectF() ); | ||
|
||
if ( m_geometry.vertexData() ) | ||
{ | ||
m_geometry.allocate( 0 ); | ||
m_geometry.markVertexDataDirty(); | ||
} | ||
|
||
if ( m_hash != 0 ) | ||
{ | ||
m_hash = 0; | ||
markDirty( QSGNode::DirtyGeometry ); | ||
} | ||
} |
Oops, something went wrong.