Skip to content

Commit

Permalink
passing QQuickWindow to the box renderer, so it knows about detals of
Browse files Browse the repository at this point in the history
the render target ( f.e devivePixelratio )
  • Loading branch information
uwerat committed Nov 7, 2024
1 parent a2719b4 commit fe17069
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 215 deletions.
2 changes: 1 addition & 1 deletion examples/frames/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void Frame::updateFrameNode( const QRectF& rect, QskBoxRectangleNode* node )
const QskBoxBorderColors borderColors( c1, c1, c2, c2 );
const qreal radius = effectiveRadius( rect, m_radius );

node->updateBox( rect, radius, m_frameWidth, borderColors, m_color );
node->updateBox( window(), rect, radius, m_frameWidth, borderColors, m_color );
}

#include "moc_Frame.cpp"
2 changes: 1 addition & 1 deletion examples/iotdashboard/DiagramSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ QSGNode* DiagramSkinlet::updateChartNode( const Diagram* diagram, QSGNode* node
color = diagram->color( barSubcontrol );

const auto shape = diagram->boxShapeHint( barSubcontrol );
barNode->updateFilling( barRect, shape, color );
barNode->updateFilling( diagram->window(), barRect, shape, color );
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions playground/gradients/GradientView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ QSGNode* GradientView::updatePaintNode(
{
auto node = gradientNode< QskBoxRectangleNode >( oldNode );
node->setHint( QskFillNode::PreferColoredGeometry, false );
node->updateFilling( rect, shape, m_gradient );
node->updateFilling( window(), rect, shape, m_gradient );

return node;
}
case BoxRectangle:
{
auto node = gradientNode< QskBoxRectangleNode >( oldNode );
node->setHint( QskFillNode::PreferColoredGeometry, true );
node->updateFilling( rect, shape, m_gradient );
node->updateFilling( window(), rect, shape, m_gradient );

return node;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ list(APPEND HEADERS
nodes/QskBoxMetrics.h
nodes/QskBoxBasicStroker.h
nodes/QskBoxGradientStroker.h
nodes/QskBoxColorMap.h
nodes/QskBoxShadowNode.h
nodes/QskColorRamp.h
nodes/QskFillNode.h
Expand All @@ -133,6 +132,7 @@ list(APPEND HEADERS
nodes/QskTextRenderer.h
nodes/QskTextureRenderer.h
nodes/QskVertex.h
nodes/QskVertexHelper.h
)

list(APPEND PRIVATE_HEADERS
Expand Down
40 changes: 26 additions & 14 deletions src/controls/QskSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,37 @@ static inline QskTextColors qskTextColors(
return c;
}

static inline QQuickWindow* qskWindowOfSkinnable( const QskSkinnable* skinnable )
{
if ( auto item = skinnable->owningItem() )
return item->window();

return nullptr;
}

static inline QSGNode* qskUpdateBoxNode(
const QskSkinnable*, QSGNode* node, const QRectF& rect,
const QskSkinnable* skinnable, QSGNode* node, const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics,
const QskBoxBorderColors& borderColors, const QskGradient& gradient,
const QskShadowMetrics& shadowMetrics, const QColor& shadowColor )
{
if ( rect.isEmpty() )
return nullptr;

if ( !qskIsBoxVisible( borderMetrics, borderColors, gradient )
&& !qskIsShadowVisible( shadowMetrics, shadowColor ) )
if ( !rect.isEmpty() )
{
return nullptr;
}
if ( qskIsBoxVisible( borderMetrics, borderColors, gradient )
|| qskIsShadowVisible( shadowMetrics, shadowColor ) )
{
if ( auto window = qskWindowOfSkinnable( skinnable ) )
{
auto boxNode = QskSGNode::ensureNode< QskBoxNode >( node );
boxNode->updateNode( window, rect, shape, borderMetrics,
borderColors, gradient, shadowMetrics, shadowColor );

auto boxNode = QskSGNode::ensureNode< QskBoxNode >( node );
boxNode->updateNode( rect, shape, borderMetrics,
borderColors, gradient, shadowMetrics, shadowColor );
return boxNode;
}
}
}

return boxNode;
return nullptr;
}

static inline QSGNode* qskUpdateArcNode(
Expand Down Expand Up @@ -373,7 +384,7 @@ QSGNode* QskSkinlet::updateBackgroundNode(
return nullptr;

auto rectNode = QskSGNode::ensureNode< QskBoxRectangleNode >( node );
rectNode->updateFilling( rect, gradient );
rectNode->updateFilling( control->window(), rect, gradient );

return rectNode;
}
Expand Down Expand Up @@ -648,7 +659,8 @@ QSGNode* QskSkinlet::updateBoxClipNode( const QskSkinnable* skinnable,
auto shape = skinnable->boxShapeHint( subControl );
shape = shape.toAbsolute( clipRect.size() );

clipNode->setBox( clipRect, shape, borderMetrics );
const auto window = qskWindowOfSkinnable( skinnable );
clipNode->setBox( window, clipRect, shape, borderMetrics );
}

return clipNode;
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/QskArcRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "QskArcMetrics.h"
#include "QskGradient.h"
#include "QskVertex.h"
#include "QskBoxColorMap.h"
#include "QskVertexHelper.h"
#include "QskRgbValue.h"

#include <qsggeometry.h>
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace
void Renderer::renderLines( const LineStroker& lineStroker,
Line* fillLines, Line* borderLines ) const
{
QskBoxRenderer::GradientIterator it;
QskVertex::GradientIterator it;

if ( fillLines )
{
Expand Down
9 changes: 4 additions & 5 deletions src/nodes/QskBoxBasicStroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*****************************************************************************/

#include "QskBoxBasicStroker.h"
#include "QskBoxColorMap.h"

namespace
{
Expand Down Expand Up @@ -144,7 +143,7 @@ namespace
{
public:
inline FillMap( const QskBoxMetrics& metrics,
const QskBoxRenderer::ColorMap& colorMap )
const QskVertex::ColorMap& colorMap )
: m_colorMap( colorMap )
, m_corners( metrics.corners )
{
Expand Down Expand Up @@ -184,7 +183,7 @@ namespace
m_colorMap.setLine( x1, y1, x2, y2, line );
}

const QskBoxRenderer::ColorMap& m_colorMap;
const QskVertex::ColorMap& m_colorMap;
const QskBoxMetrics::Corner* m_corners;
};
}
Expand Down Expand Up @@ -379,12 +378,12 @@ QskBoxBasicStroker::QskBoxBasicStroker( const QskBoxMetrics& metrics )

QskBoxBasicStroker::QskBoxBasicStroker( const QskBoxMetrics& metrics,
const QskBoxBorderColors& borderColors )
: QskBoxBasicStroker( metrics, borderColors, QskBoxRenderer::ColorMap() )
: QskBoxBasicStroker( metrics, borderColors, QskVertex::ColorMap() )
{
}

QskBoxBasicStroker::QskBoxBasicStroker( const QskBoxMetrics& metrics,
const QskBoxBorderColors& borderColors, const QskBoxRenderer::ColorMap& colorMap )
const QskBoxBorderColors& borderColors, const QskVertex::ColorMap& colorMap )
: m_metrics( metrics )
, m_borderColors( borderColors )
, m_colorMap( colorMap )
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/QskBoxBasicStroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "QskBoxMetrics.h"
#include "QskBoxBorderColors.h"
#include "QskBoxColorMap.h"
#include "QskVertexHelper.h"

class QskBoxShapeMetrics;
class QskBoxBorderMetrics;
Expand All @@ -25,7 +25,7 @@ class QskBoxBasicStroker
QskBoxBasicStroker( const QskBoxMetrics& );
QskBoxBasicStroker( const QskBoxMetrics&, const QskBoxBorderColors& );
QskBoxBasicStroker( const QskBoxMetrics&,
const QskBoxBorderColors&, const QskBoxRenderer::ColorMap& );
const QskBoxBorderColors&, const QskVertex::ColorMap& );

int fillCount() const;
int borderCount() const;
Expand Down Expand Up @@ -78,7 +78,7 @@ class QskBoxBasicStroker

const QskBoxMetrics& m_metrics;
const QskBoxBorderColors m_borderColors;
const QskBoxRenderer::ColorMap m_colorMap;
const QskVertex::ColorMap m_colorMap;
const GeometryLayout m_geometryLayout;

const bool m_isColored;
Expand Down
8 changes: 6 additions & 2 deletions src/nodes/QskBoxClipNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "QskBoxShapeMetrics.h"
#include "QskFunctions.h"

#include <qquickitem.h>

static inline QskHashValue qskMetricsHash(
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{
Expand All @@ -29,7 +31,7 @@ QskBoxClipNode::~QskBoxClipNode()
{
}

void QskBoxClipNode::setBox( const QRectF& rect,
void QskBoxClipNode::setBox( const QQuickWindow* window, const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border )
{
const auto hash = qskMetricsHash( shape, border );
Expand Down Expand Up @@ -67,7 +69,9 @@ void QskBoxClipNode::setBox( const QRectF& rect,
else
{
setIsRectangular( false );
QskBoxRenderer::setFillLines( rect, shape, border, m_geometry );

QskBoxRenderer renderer( window );
renderer.setFillLines( rect, shape, border, m_geometry );
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/nodes/QskBoxClipNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
class QskBoxShapeMetrics;
class QskBoxBorderMetrics;

class QQuickWindow;

class QSK_EXPORT QskBoxClipNode : public QSGClipNode
{
public:
QskBoxClipNode();
~QskBoxClipNode() override;

void setBox( const QRectF&,
void setBox( const QQuickWindow*, const QRectF&,
const QskBoxShapeMetrics&, const QskBoxBorderMetrics& );

private:
Expand Down
9 changes: 4 additions & 5 deletions src/nodes/QskBoxGradientStroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

#include "QskBoxGradientStroker.h"
#include "QskBoxBasicStroker.h"
#include "QskVertex.h"
#include "QskBoxColorMap.h"
#include "QskVertexHelper.h"
#include "QskBoxMetrics.h"

static inline bool qskCanUseHVFiller(
Expand Down Expand Up @@ -172,7 +171,7 @@ namespace
qreal m_t0, m_dt;

const QskBoxMetrics::Corner* m_c1, * m_c2, * m_c3;
QskBoxRenderer::GradientIterator m_gradientIterator;
QskVertex::GradientIterator m_gradientIterator;
};
}

Expand Down Expand Up @@ -528,7 +527,7 @@ namespace
int setLines( const QskGradient& gradient, ColoredLine* lines )
{
ContourIterator it( m_metrics, gradient.linearDirection() );
QskBoxRenderer::GradientIterator gradientIt( gradient.stops() );
QskVertex::GradientIterator gradientIt( gradient.stops() );

ColoredLine* l = lines;

Expand Down Expand Up @@ -584,7 +583,7 @@ namespace
const qreal y1 = m_metrics.innerRect.top();
const qreal y2 = m_metrics.innerRect.bottom();

QskBoxRenderer::GradientIterator it( gradient.stops() );
QskVertex::GradientIterator it( gradient.stops() );
ColoredLine* l = lines;

const auto dir = gradient.linearDirection();
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/QskBoxMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "QskBoxMetrics.h"
#include "QskBoxShapeMetrics.h"
#include "QskBoxBorderMetrics.h"
#include "QskVertex.h"
#include "QskVertexHelper.h"
#include "QskFunctions.h"

QskBoxMetrics::QskBoxMetrics( const QRectF& rect,
Expand Down
16 changes: 10 additions & 6 deletions src/nodes/QskBoxNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ QskBoxNode::~QskBoxNode()
{
}

void QskBoxNode::updateNode( const QRectF& rect,
void QskBoxNode::updateNode( const QQuickWindow* window, const QRectF& rect,
const QskBoxShapeMetrics& shapeMetrics, const QskBoxBorderMetrics& borderMetrics,
const QskBoxBorderColors& borderColors, const QskGradient& gradient,
const QskShadowMetrics& shadowMetrics, const QColor& shadowColor )
Expand Down Expand Up @@ -100,7 +100,8 @@ void QskBoxNode::updateNode( const QRectF& rect,
{
// QskBoxRectangleNode allows scene graph batching
shadowFillNode = qskNode< QskBoxRectangleNode >( this, ShadowFillRole );
shadowFillNode->updateFilling( shadowRect, shadowShape, shadowColor );
shadowFillNode->updateFilling( window,
shadowRect, shadowShape, shadowColor );
}
else
{
Expand All @@ -125,13 +126,16 @@ void QskBoxNode::updateNode( const QRectF& rect,

if ( fillNode )
{
rectNode->updateBorder( rect, shapeMetrics, borderMetrics, borderColors );
fillNode->updateFilling( rect, shapeMetrics, borderMetrics, gradient );
rectNode->updateBorder( window, rect,
shapeMetrics, borderMetrics, borderColors );

fillNode->updateFilling( window, rect,
shapeMetrics, borderMetrics, gradient );
}
else
{
rectNode->updateBox( rect, shapeMetrics,
borderMetrics, borderColors, gradient );
rectNode->updateBox( window, rect,
shapeMetrics, borderMetrics, borderColors, gradient );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/QskBoxNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QskBoxBorderMetrics;
class QskBoxBorderColors;
class QskGradient;
class QskShadowMetrics;
class QQuickWindow;
class QColor;

class QSK_EXPORT QskBoxNode : public QSGNode
Expand All @@ -23,7 +24,7 @@ class QSK_EXPORT QskBoxNode : public QSGNode
QskBoxNode();
~QskBoxNode() override;

void updateNode( const QRectF&,
void updateNode( const QQuickWindow*, const QRectF&,
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
const QskBoxBorderColors&, const QskGradient&,
const QskShadowMetrics&, const QColor& shadowColor );
Expand Down
Loading

0 comments on commit fe17069

Please sign in to comment.