qskinny/src/nodes/QskBoxClipNode.cpp

86 lines
2.2 KiB
C++
Raw Normal View History

/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "QskBoxClipNode.h"
2018-08-03 08:15:28 +02:00
#include "QskBoxBorderMetrics.h"
#include "QskBoxRenderer.h"
#include "QskBoxShapeMetrics.h"
#include "QskFunctions.h"
#include <qquickitem.h>
static inline QskHashValue qskMetricsHash(
2018-08-03 08:15:28 +02:00
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{
QskHashValue hash = 13000;
hash = shape.hash( hash );
return border.hash( hash );
}
2018-08-03 08:15:28 +02:00
QskBoxClipNode::QskBoxClipNode()
: m_hash( 0 )
, m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
setGeometry( &m_geometry );
}
QskBoxClipNode::~QskBoxClipNode()
{
}
void QskBoxClipNode::setBox( const QQuickWindow* window, const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{
const auto hash = qskMetricsHash( shape, border );
if ( hash == m_hash && rect == m_rect )
return;
m_rect = rect;
m_hash = hash;
bool isRectangular = false;
#if 0
/*
Depending on isRectangular the "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. TODO ...
*/
if ( shape.isRectangle() )
isRectangular = true;
#endif
if ( isRectangular )
{
if ( m_geometry.vertexCount() > 0 )
m_geometry.allocate( 0 );
setIsRectangular( true );
}
else
{
setIsRectangular( false );
QskBoxRenderer renderer( window );
renderer.setFillLines( rect, shape, border, m_geometry );
}
/*
Even in situations, where the clipping is not rectangular, it is
useful to know its bounding rectangle
*/
setClipRect( qskValidOrEmptyInnerRect( rect, border.widths() ) );
2023-11-15 11:47:56 +01:00
m_geometry.markVertexDataDirty();
markDirty( QSGNode::DirtyGeometry );
}