2017-10-17 17:29:02 +02:00
|
|
|
/******************************************************************************
|
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
|
2017-10-17 17:29:02 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskBoxClipNode.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskBoxBorderMetrics.h"
|
2017-10-17 17:29:02 +02:00
|
|
|
#include "QskBoxRenderer.h"
|
|
|
|
#include "QskBoxShapeMetrics.h"
|
|
|
|
#include "QskFunctions.h"
|
|
|
|
|
2024-11-07 11:21:45 +01:00
|
|
|
#include <qquickitem.h>
|
|
|
|
|
2022-03-25 10:28:06 +01:00
|
|
|
static inline QskHashValue qskMetricsHash(
|
2018-08-03 08:15:28 +02:00
|
|
|
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
2022-03-25 10:28:06 +01:00
|
|
|
QskHashValue hash = 13000;
|
2017-10-17 17:29:02 +02:00
|
|
|
|
|
|
|
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 )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
|
|
|
setGeometry( &m_geometry );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskBoxClipNode::~QskBoxClipNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-11-07 11:21:45 +01:00
|
|
|
void QskBoxClipNode::setBox( const QQuickWindow* window, const QRectF& rect,
|
2017-10-17 17:29:02 +02:00
|
|
|
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
|
|
|
|
{
|
2022-03-25 10:28:06 +01:00
|
|
|
const auto hash = qskMetricsHash( shape, border );
|
2017-10-17 17:29:02 +02:00
|
|
|
if ( hash == m_hash && rect == m_rect )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_rect = rect;
|
|
|
|
m_hash = hash;
|
|
|
|
|
2023-07-19 15:10:25 +02:00
|
|
|
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 ...
|
|
|
|
*/
|
|
|
|
|
2017-10-17 17:29:02 +02:00
|
|
|
if ( shape.isRectangle() )
|
2023-07-19 15:10:25 +02:00
|
|
|
isRectangular = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( isRectangular )
|
2017-10-17 17:29:02 +02:00
|
|
|
{
|
|
|
|
if ( m_geometry.vertexCount() > 0 )
|
|
|
|
m_geometry.allocate( 0 );
|
|
|
|
|
|
|
|
setIsRectangular( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setIsRectangular( false );
|
2024-11-07 11:21:45 +01:00
|
|
|
|
|
|
|
QskBoxRenderer renderer( window );
|
|
|
|
renderer.setFillLines( rect, shape, border, m_geometry );
|
2017-10-17 17:29:02 +02:00
|
|
|
}
|
|
|
|
|
2018-01-12 15:46:15 +01:00
|
|
|
/*
|
|
|
|
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();
|
2017-10-17 17:29:02 +02:00
|
|
|
markDirty( QSGNode::DirtyGeometry );
|
|
|
|
}
|