Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickshapecurverenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKSHAPECURVERENDERER_P_H
5#define QQUICKSHAPECURVERENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuickShapes/private/qquickshape_p_p.h>
20#include <QtQuick/private/qquadpath_p.h>
21#include <QtQuick/private/qsgcurveabstractnode_p.h>
22#include <QtQuick/private/qsggradientcache_p.h>
23#include <qsgnode.h>
24#include <qsggeometry.h>
25#include <qsgmaterial.h>
26#include <qsgrendererinterface.h>
27#include <qsgtexture.h>
28#include <QtCore/qrunnable.h>
29#include <QRunnable>
30
31#include <QtGui/private/qtriangulator_p.h>
32#include <QtQuick/private/qsgcurvefillnode_p.h>
33
35
37
38class Q_QUICKSHAPES_EXPORT QQuickShapeCurveRenderer : public QQuickAbstractPathRenderer
39{
40public:
41 QQuickShapeCurveRenderer(QQuickItem *item)
42 : m_item(item)
43 { }
44 ~QQuickShapeCurveRenderer() override;
45
46 void beginSync(int totalCount, bool *countChanged) override;
47 void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) override;
48 void setStrokeColor(int index, const QColor &color) override;
49 void setStrokeWidth(int index, qreal w) override;
50 void setCosmeticStroke(int index, bool c) override;
51 void setFillColor(int index, const QColor &color) override;
52 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
53 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
54 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
55 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
56 qreal dashOffset, const QVector<qreal> &dashPattern) override;
57 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
58 void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override;
59 void setFillTransform(int index, const QSGTransform &transform) override;
60 void endSync(bool async) override;
61 void setAsyncCallback(void (*)(void *), void *) override;
62 Flags flags() const override { return SupportsAsync; }
63 void handleSceneChange(QQuickWindow *window) override;
64
65 void updateNode() override;
66
67 void setRootNode(QSGNode *node);
68 void clearNodeReferences();
69
70 using NodeList = QVector<QSGCurveAbstractNode *>;
71
72 enum DirtyFlag
73 {
74 PathDirty = 0x01,
75 FillDirty = 0x02,
76 StrokeDirty = 0x04,
77 UniformsDirty = 0x08
78 };
79
80 enum DebugVisualizationOption {
81 NoDebug = 0,
82 DebugCurves = 0x01,
83 DebugWireframe = 0x02
84 };
85
86 static int debugVisualization();
87 static void setDebugVisualization(int options);
88
89private:
90 struct PathData {
91
92 bool isFillVisible() const
93 {
94 return gradientType != QGradient::NoGradient
95 || fillTextureProviderItem != nullptr
96 || fillColor.alpha() > 0;
97 }
98
99 bool isStrokeVisible() const
100 {
101 return validPenWidth && pen.color().alpha() > 0 && pen.style() != Qt::NoPen;
102 }
103
104 QGradient::Type gradientType = QGradient::NoGradient;
105 QSGGradientCache::GradientDesc gradient;
106 QSGTransform fillTransform;
107 QColor fillColor;
108 Qt::FillRule fillRule = Qt::OddEvenFill;
109 QPen pen;
110 bool validPenWidth = true;
111 int m_dirty = 0;
112 QQuickShapePath::PathHints pathHints;
113
114 QPainterPath originalPath;
115 QQuadPath path;
116 QQuadPath fillPath;
117
118 NodeList fillNodes;
119 NodeList strokeNodes;
120
121 QQuickShapeCurveRunnable *currentRunner = nullptr;
122 QQuickItem *fillTextureProviderItem = nullptr;
123 };
124
125 void setUpRunner(PathData *pathData);
126 void maybeUpdateAsyncItem();
127
128 static void processPath(PathData *pathData);
129 static NodeList addFillNodes(const QQuadPath &path);
130 static NodeList addTriangulatingStrokerNodes(const QQuadPath &path, const QPen &pen);
131 static NodeList addCurveStrokeNodes(const QQuadPath &path, const QPen &pen);
132
133 QQuickItem *m_item;
134 QSGNode *m_rootNode = nullptr;
135 QVector<PathData> m_paths;
136 QVector<PathData> m_removedPaths;
137 void (*m_asyncCallback)(void *) = nullptr;
138 void *m_asyncCallbackData = nullptr;
139 static int debugVisualizationFlags;
140
141 friend class QQuickShapeCurveRunnable;
142};
143
145{
147
148public:
150 void run() override;
151
152 bool isInitialized = false;
153 bool isAsync = false;
154 bool isDone = false;
155 bool orphaned = false;
156
157 // input / output
159
162};
163
164QT_END_NAMESPACE
165
166#endif // QQUICKSHAPECURVERENDERER_P_H
virtual void setTriangulationScale(qreal)
virtual void setFillTextureProvider(int index, QQuickItem *textureProviderItem)=0
virtual void beginSync(int totalCount, bool *countChanged)=0
virtual void setStrokeColor(int index, const QColor &color)=0
virtual void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={})=0
virtual void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern)=0
virtual void setAsyncCallback(void(*)(void *), void *)
virtual Flags flags() const
virtual void setCapStyle(int index, QQuickShapePath::CapStyle capStyle)=0
virtual void setFillGradient(int index, QQuickShapeGradient *gradient)=0
virtual void setFillColor(int index, const QColor &color)=0
virtual void setCosmeticStroke(int index, bool c)=0
virtual void setPath(int index, const QQuickPath *path)
virtual void setFillRule(int index, QQuickShapePath::FillRule fillRule)=0
virtual void setStrokeWidth(int index, qreal w)=0
virtual void setFillTransform(int index, const QSGTransform &transform)=0
virtual void endSync(bool async)=0
virtual void updateNode()=0
virtual void handleSceneChange(QQuickWindow *window)=0
virtual void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit)=0
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeConicalGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void run() override
Implement this pure virtual function in your subclass.
QQuickShapeGenericRenderer::Color4ub fillColor
QQuickShapeGenericRenderer::VertexContainerType fillVertices
QQuickShapeGenericRenderer::IndexContainerType fillIndices
static QSGMaterial * createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
static QSGMaterial * createTextureFill(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
static QSGMaterial * createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
static QSGMaterial * createVertexColor(QQuickWindow *window)
static QSGMaterial * createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
QQuickShapeGenericStrokeFillNode * m_fillNode
QQuickShapeGenericStrokeFillNode * m_strokeNode
void setAsyncCallback(void(*)(void *), void *) override
QVector< QSGGeometry::TexturedPoint2D > TexturedVertexContainerType
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setFillTransform(int index, const QSGTransform &transform) override
void setCosmeticStroke(int index, bool c) override
static void triangulateFill(const QPainterPath &path, const Color4ub &fillColor, VertexContainerType *fillVertices, IndexContainerType *fillIndices, QSGGeometry::Type *indexType, bool supportsElementIndexUint, qreal triangulationScale)
void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={}) override
void setStrokeColor(int index, const QColor &color) override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setFillColor(int index, const QColor &color) override
QVector< QSGGeometry::ColoredPoint2D > VertexContainerType
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
void setRootNode(QQuickShapeGenericNode *node)
void handleSceneChange(QQuickWindow *window) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
static void triangulateStroke(const QPainterPath &path, const QPen &pen, const Color4ub &strokeColor, VertexContainerType *strokeVertices, const QSize &clipSize, qreal triangulationScale)
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
QSGGradientCache::GradientDesc m_fillGradient
void preprocess() override
Override this function to do processing on the node before it is rendered.
void activateMaterial(QQuickWindow *window, Material m)
QQuickShapeLinearGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeGenericStrokeFillNode * node() const
QQuickShapeRadialGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
RenderingFlags flags() const override
void releaseResources() override
This function is called when all custom graphics resources allocated by this node have to be freed im...
void render(const RenderState *state) override
This function is called by the renderer and should paint this node with directly invoking commands vi...
StateFlags changedStates() const override
This function should return a mask where each bit represents graphics states changed by the \l render...
void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={}) override
void setStrokeColor(int index, const QColor &color) override
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setFillColor(int index, const QColor &color) override
void handleSceneChange(QQuickWindow *window) override
void setNode(QQuickShapeSoftwareRenderNode *node)
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void setCosmeticStroke(int index, bool c) override
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
void setStrokeWidth(int index, qreal w) override
void setFillTransform(int index, const QSGTransform &transform) override
QQuickShapeGenericRenderer::Color4ub strokeColor
QQuickShapeGenericRenderer::VertexContainerType strokeVertices
QQuickShapeTextureFillMaterial(QQuickShapeGenericStrokeFillNode *node)
void setDummyTexture(QSGPlainTexture *texture)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QQuickShapeGenericStrokeFillNode * node() const
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
static void initResources()
static void vpe_clear(QQmlListProperty< QObject > *property)
static void vpe_append(QQmlListProperty< QObject > *property, QObject *obj)
Q_GHS_KEEP_REFERENCE(QQuickShapes_initializeModule)
QQuickShapeGradient * fillGradient