code simplified/harmonized
This commit is contained in:
parent
71321578a6
commit
296b2f368a
|
@ -60,7 +60,6 @@ class QskBoxFillNodePrivate final : public QSGGeometryNodePrivate
|
||||||
}
|
}
|
||||||
|
|
||||||
QskHashValue metricsHash = 0;
|
QskHashValue metricsHash = 0;
|
||||||
QskHashValue gradientHash = 0;
|
|
||||||
QRectF rect;
|
QRectF rect;
|
||||||
|
|
||||||
QSGGeometry geometry;
|
QSGGeometry geometry;
|
||||||
|
@ -83,36 +82,28 @@ void QskBoxFillNode::updateNode(
|
||||||
{
|
{
|
||||||
Q_D( QskBoxFillNode );
|
Q_D( QskBoxFillNode );
|
||||||
|
|
||||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
if ( rect.isEmpty() || !gradient.isVisible() )
|
||||||
|
|
||||||
const auto metricsHash = qskMetricsHash( shapeMetrics, borderMetrics );
|
|
||||||
const auto gradientHash = effectiveGradient.hash( 17321 );
|
|
||||||
|
|
||||||
const bool dirtyGeometry = ( metricsHash != d->metricsHash ) || ( rect == d->rect );
|
|
||||||
const bool dirtyMaterial = gradientHash != d->gradientHash;
|
|
||||||
|
|
||||||
if ( !( dirtyGeometry || dirtyMaterial ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->metricsHash = metricsHash;
|
|
||||||
d->gradientHash = gradientHash;
|
|
||||||
d->rect = rect;
|
|
||||||
|
|
||||||
if ( rect.isEmpty() || !effectiveGradient.isVisible() )
|
|
||||||
{
|
{
|
||||||
|
d->rect = QRectF();
|
||||||
|
d->metricsHash = 0;
|
||||||
qskResetGeometry( this );
|
qskResetGeometry( this );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto metricsHash = qskMetricsHash( shapeMetrics, borderMetrics );
|
||||||
|
const bool dirtyGeometry = ( metricsHash != d->metricsHash ) || ( rect == d->rect );
|
||||||
|
|
||||||
|
d->metricsHash = metricsHash;
|
||||||
|
d->rect = rect;
|
||||||
|
|
||||||
if ( dirtyGeometry )
|
if ( dirtyGeometry )
|
||||||
{
|
{
|
||||||
QskBoxRenderer().renderFill( rect, shapeMetrics, borderMetrics, d->geometry );
|
QskBoxRenderer().renderFill( rect, shapeMetrics, borderMetrics, d->geometry );
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
markDirty( QSGNode::DirtyGeometry );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dirtyMaterial )
|
if ( gradient.isMonochrome() )
|
||||||
{
|
|
||||||
if ( effectiveGradient.isMonochrome() )
|
|
||||||
{
|
{
|
||||||
if ( material() == nullptr || d->gradientType >= 0 )
|
if ( material() == nullptr || d->gradientType >= 0 )
|
||||||
{
|
{
|
||||||
|
@ -120,11 +111,18 @@ void QskBoxFillNode::updateNode(
|
||||||
d->gradientType = -1;
|
d->gradientType = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto colorMaterial = static_cast< QSGFlatColorMaterial* >( material() );
|
const auto color = gradient.startColor().toRgb();
|
||||||
colorMaterial->setColor( effectiveGradient.startColor().toRgb() );
|
|
||||||
|
auto mat = static_cast< QSGFlatColorMaterial* >( material() );
|
||||||
|
if ( mat->color() != color )
|
||||||
|
{
|
||||||
|
mat->setColor( color );
|
||||||
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
||||||
const auto gradientType = effectiveGradient.type();
|
const auto gradientType = effectiveGradient.type();
|
||||||
|
|
||||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||||
|
@ -133,10 +131,8 @@ void QskBoxFillNode::updateNode(
|
||||||
d->gradientType = gradientType;
|
d->gradientType = gradientType;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto gradientMaterial = static_cast< QskGradientMaterial* >( material() );
|
auto mat = static_cast< QskGradientMaterial* >( material() );
|
||||||
gradientMaterial->updateGradient( rect, effectiveGradient );
|
if ( mat->updateGradient( rect, effectiveGradient ) )
|
||||||
}
|
|
||||||
|
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@ class QSK_EXPORT QskBoxFillNode : public QSGGeometryNode
|
||||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
||||||
const QskGradient& );
|
const QskGradient& );
|
||||||
|
|
||||||
void updateNode( const QRectF&,
|
|
||||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
|
||||||
const QColor& );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE( QskBoxFillNode )
|
Q_DECLARE_PRIVATE( QskBoxFillNode )
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,8 +18,9 @@ QSK_QT_PRIVATE_END
|
||||||
|
|
||||||
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
||||||
{
|
{
|
||||||
if ( gradient.type() == QskGradient::Stops )
|
if ( gradient.type() == QskGradient::Stops || gradient.isMonochrome() )
|
||||||
{
|
{
|
||||||
|
// the shader for linear gradients is the fastest
|
||||||
QskGradient g;
|
QskGradient g;
|
||||||
g.setLinearDirection( Qt::Vertical );
|
g.setLinearDirection( Qt::Vertical );
|
||||||
g.setStops( gradient.stops() );
|
g.setStops( gradient.stops() );
|
||||||
|
@ -112,44 +113,6 @@ QskShapeNode::QskShapeNode()
|
||||||
setFlag( QSGNode::OwnsMaterial, true );
|
setFlag( QSGNode::OwnsMaterial, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskShapeNode::updateNode( const QPainterPath& path,
|
|
||||||
const QTransform& transform, const QColor& color )
|
|
||||||
{
|
|
||||||
Q_D( QskShapeNode );
|
|
||||||
|
|
||||||
if ( path.isEmpty() || !color.isValid() || color.alpha() == 0 )
|
|
||||||
{
|
|
||||||
d->path = QPainterPath();
|
|
||||||
qskResetGeometry( this );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( transform != d->transform ) || ( path != d->path ) )
|
|
||||||
{
|
|
||||||
d->path = path;
|
|
||||||
d->transform = transform;
|
|
||||||
|
|
||||||
qskUpdateGeometry( path, transform, d->geometry );
|
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( material() == nullptr || d->gradientType >= 0 )
|
|
||||||
{
|
|
||||||
setMaterial( new QSGFlatColorMaterial() );
|
|
||||||
d->gradientType = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto c = color.toRgb();
|
|
||||||
|
|
||||||
auto colorMaterial = static_cast< QSGFlatColorMaterial* >( material() );
|
|
||||||
if ( colorMaterial->color() != c )
|
|
||||||
{
|
|
||||||
colorMaterial->setColor( c );
|
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskShapeNode::updateNode( const QPainterPath& path,
|
void QskShapeNode::updateNode( const QPainterPath& path,
|
||||||
const QTransform& transform, const QRectF& rect, const QskGradient& gradient )
|
const QTransform& transform, const QRectF& rect, const QskGradient& gradient )
|
||||||
{
|
{
|
||||||
|
@ -158,17 +121,12 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||||
if ( path.isEmpty() || !gradient.isVisible() )
|
if ( path.isEmpty() || !gradient.isVisible() )
|
||||||
{
|
{
|
||||||
d->path = QPainterPath();
|
d->path = QPainterPath();
|
||||||
|
d->transform = QTransform();
|
||||||
qskResetGeometry( this );
|
qskResetGeometry( this );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gradient.isMonochrome() )
|
|
||||||
{
|
|
||||||
updateNode( path, transform, gradient.startColor() );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( transform != d->transform ) || ( path != d->path ) )
|
if ( ( transform != d->transform ) || ( path != d->path ) )
|
||||||
{
|
{
|
||||||
d->path = path;
|
d->path = path;
|
||||||
|
@ -178,8 +136,26 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
markDirty( QSGNode::DirtyGeometry );
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
if ( gradient.isMonochrome() )
|
||||||
|
{
|
||||||
|
if ( material() == nullptr || d->gradientType >= 0 )
|
||||||
|
{
|
||||||
|
setMaterial( new QSGFlatColorMaterial() );
|
||||||
|
d->gradientType = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto color = gradient.startColor().toRgb();
|
||||||
|
|
||||||
|
auto mat = static_cast< QSGFlatColorMaterial* >( material() );
|
||||||
|
if ( mat->color() != color )
|
||||||
|
{
|
||||||
|
mat->setColor( color );
|
||||||
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
||||||
const auto gradientType = effectiveGradient.type();
|
const auto gradientType = effectiveGradient.type();
|
||||||
|
|
||||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||||
|
@ -188,8 +164,8 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||||
d->gradientType = gradientType;
|
d->gradientType = gradientType;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto gradientMaterial = static_cast< QskGradientMaterial* >( material() );
|
auto mat = static_cast< QskGradientMaterial* >( material() );
|
||||||
if ( gradientMaterial->updateGradient( rect, effectiveGradient ) )
|
if ( mat->updateGradient( rect, effectiveGradient ) )
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
markDirty( QSGNode::DirtyMaterial );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,9 +23,6 @@ class QSK_EXPORT QskShapeNode : public QSGGeometryNode
|
||||||
void updateNode( const QPainterPath&, const QTransform&,
|
void updateNode( const QPainterPath&, const QTransform&,
|
||||||
const QRectF&, const QskGradient& );
|
const QRectF&, const QskGradient& );
|
||||||
|
|
||||||
void updateNode( const QPainterPath&,
|
|
||||||
const QTransform&, const QColor& );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE( QskShapeNode )
|
Q_DECLARE_PRIVATE( QskShapeNode )
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue