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 gradientHash = 0;
|
||||
QRectF rect;
|
||||
|
||||
QSGGeometry geometry;
|
||||
@ -83,60 +82,57 @@ void QskBoxFillNode::updateNode(
|
||||
{
|
||||
Q_D( QskBoxFillNode );
|
||||
|
||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
||||
|
||||
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() )
|
||||
if ( rect.isEmpty() || !gradient.isVisible() )
|
||||
{
|
||||
d->rect = QRectF();
|
||||
d->metricsHash = 0;
|
||||
qskResetGeometry( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const auto metricsHash = qskMetricsHash( shapeMetrics, borderMetrics );
|
||||
const bool dirtyGeometry = ( metricsHash != d->metricsHash ) || ( rect == d->rect );
|
||||
|
||||
d->metricsHash = metricsHash;
|
||||
d->rect = rect;
|
||||
|
||||
if ( dirtyGeometry )
|
||||
{
|
||||
QskBoxRenderer().renderFill( rect, shapeMetrics, borderMetrics, d->geometry );
|
||||
markDirty( QSGNode::DirtyGeometry );
|
||||
}
|
||||
|
||||
if ( dirtyMaterial )
|
||||
if ( gradient.isMonochrome() )
|
||||
{
|
||||
if ( effectiveGradient.isMonochrome() )
|
||||
if ( material() == nullptr || d->gradientType >= 0 )
|
||||
{
|
||||
if ( material() == nullptr || d->gradientType >= 0 )
|
||||
{
|
||||
setMaterial( new QSGFlatColorMaterial() );
|
||||
d->gradientType = -1;
|
||||
}
|
||||
|
||||
auto colorMaterial = static_cast< QSGFlatColorMaterial* >( material() );
|
||||
colorMaterial->setColor( effectiveGradient.startColor().toRgb() );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto gradientType = effectiveGradient.type();
|
||||
|
||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||
{
|
||||
setMaterial( QskGradientMaterial::createMaterial( gradientType ) );
|
||||
d->gradientType = gradientType;
|
||||
}
|
||||
|
||||
auto gradientMaterial = static_cast< QskGradientMaterial* >( material() );
|
||||
gradientMaterial->updateGradient( rect, effectiveGradient );
|
||||
setMaterial( new QSGFlatColorMaterial() );
|
||||
d->gradientType = -1;
|
||||
}
|
||||
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
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();
|
||||
|
||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||
{
|
||||
setMaterial( QskGradientMaterial::createMaterial( gradientType ) );
|
||||
d->gradientType = gradientType;
|
||||
}
|
||||
|
||||
auto mat = static_cast< QskGradientMaterial* >( material() );
|
||||
if ( mat->updateGradient( rect, effectiveGradient ) )
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,6 @@ class QSK_EXPORT QskBoxFillNode : public QSGGeometryNode
|
||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
||||
const QskGradient& );
|
||||
|
||||
void updateNode( const QRectF&,
|
||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
||||
const QColor& );
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( QskBoxFillNode )
|
||||
};
|
||||
|
@ -18,8 +18,9 @@ QSK_QT_PRIVATE_END
|
||||
|
||||
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;
|
||||
g.setLinearDirection( Qt::Vertical );
|
||||
g.setStops( gradient.stops() );
|
||||
@ -112,44 +113,6 @@ QskShapeNode::QskShapeNode()
|
||||
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,
|
||||
const QTransform& transform, const QRectF& rect, const QskGradient& gradient )
|
||||
{
|
||||
@ -158,17 +121,12 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||
if ( path.isEmpty() || !gradient.isVisible() )
|
||||
{
|
||||
d->path = QPainterPath();
|
||||
d->transform = QTransform();
|
||||
qskResetGeometry( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( gradient.isMonochrome() )
|
||||
{
|
||||
updateNode( path, transform, gradient.startColor() );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( transform != d->transform ) || ( path != d->path ) )
|
||||
{
|
||||
d->path = path;
|
||||
@ -178,18 +136,36 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||
markDirty( QSGNode::DirtyGeometry );
|
||||
}
|
||||
|
||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
||||
|
||||
const auto gradientType = effectiveGradient.type();
|
||||
|
||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||
if ( gradient.isMonochrome() )
|
||||
{
|
||||
setMaterial( QskGradientMaterial::createMaterial( gradientType ) );
|
||||
d->gradientType = gradientType;
|
||||
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();
|
||||
|
||||
auto gradientMaterial = static_cast< QskGradientMaterial* >( material() );
|
||||
if ( gradientMaterial->updateGradient( rect, effectiveGradient ) )
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||
{
|
||||
setMaterial( QskGradientMaterial::createMaterial( gradientType ) );
|
||||
d->gradientType = gradientType;
|
||||
}
|
||||
|
||||
auto mat = static_cast< QskGradientMaterial* >( material() );
|
||||
if ( mat->updateGradient( rect, effectiveGradient ) )
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,6 @@ class QSK_EXPORT QskShapeNode : public QSGGeometryNode
|
||||
void updateNode( const QPainterPath&, const QTransform&,
|
||||
const QRectF&, const QskGradient& );
|
||||
|
||||
void updateNode( const QPainterPath&,
|
||||
const QTransform&, const QColor& );
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( QskShapeNode )
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user