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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKSHAPECURVERENDERER_P_H
6#define QQUICKSHAPECURVERENDERER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of a number of Qt sources files. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuickShapes/private/qquickshapesglobal_p.h>
20#include <QtQuickShapes/private/qquickshape_p_p.h>
21#include <QtQuick/private/qquadpath_p.h>
22#include <QtQuick/private/qsgcurveabstractnode_p.h>
23#include <QtQuick/private/qsggradientcache_p.h>
24#include <qsgnode.h>
25#include <qsggeometry.h>
26#include <qsgmaterial.h>
27#include <qsgrendererinterface.h>
28#include <qsgtexture.h>
29#include <QtCore/qrunnable.h>
30#include <QRunnable>
31
32#include <QtGui/private/qtriangulator_p.h>
33#include <QtQuick/private/qsgcurvefillnode_p.h>
34
36
38
39class Q_QUICKSHAPES_EXPORT QQuickShapeCurveRenderer : public QQuickAbstractPathRenderer
40{
41public:
42 QQuickShapeCurveRenderer(QQuickItem *item)
43 : m_item(item)
44 { }
45 ~QQuickShapeCurveRenderer() override;
46
47 void beginSync(int totalCount, bool *countChanged) override;
48 void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) override;
49 void setStrokeColor(int index, const QColor &color) override;
50 void setStrokeWidth(int index, qreal w) override;
51 void setCosmeticStroke(int index, bool c) override;
52 void setFillColor(int index, const QColor &color) override;
53 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
54 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
55 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
56 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
57 qreal dashOffset, const QList<qreal> &dashPattern) override;
58 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
59 void setStrokeGradient(int index, QQuickShapeGradient *gradient) override;
60 void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override;
61 void setFillTransform(int index, const QSGTransform &transform) override;
62 void setVisible(int index, bool visible) override;
63 void endSync(bool async) override;
64 void setAsyncCallback(void (*)(void *), void *) override;
65 Flags flags() const override { return SupportsAsync; }
66 void handleSceneChange(QQuickWindow *window) override;
67
68 void updateNode() override;
69
70 void setRootNode(QSGNode *node);
71 void clearNodeReferences();
72
73 using NodeList = QList<QSGCurveAbstractNode *>;
74
75 enum DirtyFlag
76 {
77 PathDirty = 0x01,
78 FillDirty = 0x02,
79 StrokeDirty = 0x04,
80 UniformsDirty = 0x08
81 };
82
83 enum DebugVisualizationOption {
84 NoDebug = 0,
85 DebugCurves = 0x01,
86 DebugWireframe = 0x02
87 };
88
89 static int debugVisualization();
90 static void setDebugVisualization(int options);
91
92private:
93 struct PathData {
94
95 bool isFillVisible() const
96 {
97 return visible
98 && (gradientType != QGradient::NoGradient
99 || fillTextureProviderItem != nullptr
100 || fillColor.alpha() > 0);
101 }
102
103 bool isStrokeVisible() const
104 {
105 return visible && validPenWidth && pen.style() != Qt::NoPen
106 && (pen.color().alpha() > 0 || strokeGradientType != QGradient::NoGradient);
107 }
108
109 QGradient::Type gradientType = QGradient::NoGradient;
110 QSGGradientCache::GradientDesc gradient;
111
112 QGradient::Type strokeGradientType = QGradient::NoGradient;
113 QSGGradientCache::GradientDesc strokeGradient;
114
115 QSGTransform fillTransform;
116 QColor fillColor;
117 Qt::FillRule fillRule = Qt::OddEvenFill;
118 QPen pen;
119 bool validPenWidth = true;
120 bool visible = true;
121 int m_dirty = 0;
122 QQuickShapePath::PathHints pathHints;
123
124 QPainterPath originalPath;
125 QQuadPath path;
126 QQuadPath fillPath;
127
128 NodeList fillNodes;
129 NodeList strokeNodes;
130
131 QQuickShapeCurveRunnable *currentRunner = nullptr;
132 QQuickItem *fillTextureProviderItem = nullptr;
133 };
134
135 void setUpRunner(PathData *pathData);
136 void maybeUpdateAsyncItem();
137
138 static void processPath(PathData *pathData);
139 static NodeList addFillNodes(const QQuadPath &path);
140 static NodeList addTriangulatingStrokerNodes(const QQuadPath &path, const QPen &pen);
141 static NodeList addCurveStrokeNodes(const QQuadPath &path, const QPen &pen);
142
143 QQuickItem *m_item;
144 QSGNode *m_rootNode = nullptr;
145 QList<PathData> m_paths;
146 QList<PathData> m_removedPaths;
147 void (*m_asyncCallback)(void *) = nullptr;
148 void *m_asyncCallbackData = nullptr;
149 static int debugVisualizationFlags;
150
151 friend class QQuickShapeCurveRunnable;
152};
153
155{
157
158public:
160 void run() override;
161
162 bool isInitialized = false;
163 bool isAsync = false;
164 bool isDone = false;
165 bool orphaned = false;
166
167 // input / output
169
172};
173
174QT_END_NAMESPACE
175
176#endif // QQUICKSHAPECURVERENDERER_P_H
virtual void setVisible(int index, bool visible)=0
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 setAsyncCallback(void(*)(void *), void *)
virtual Flags flags() const
virtual void setCapStyle(int index, QQuickShapePath::CapStyle capStyle)=0
virtual void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern)=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 setTriangulationScale(int, qreal)
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 setStrokeGradient(int index, QQuickShapeGradient *gradient)=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
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern) override
void setFillTransform(int index, const QSGTransform &transform) override
void setCosmeticStroke(int index, bool c) override
void setStrokeGradient(int index, QQuickShapeGradient *gradient) override
static void triangulateFill(const QPainterPath &path, const Color4ub &fillColor, VertexContainerType *fillVertices, IndexContainerType *fillIndices, QSGGeometry::Type *indexType, bool supportsElementIndexUint, qreal triangulationScale)
QList< QSGGeometry::ColoredPoint2D > VertexContainerType
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
void setTriangulationScale(int index, qreal scale) override
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
void setRootNode(QQuickShapeGenericNode *node)
QList< QSGGeometry::TexturedPoint2D > TexturedVertexContainerType
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 setVisible(int index, bool visible) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
QSGGradientCache::GradientDesc m_gradient
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 setStrokeGradient(int index, QQuickShapeGradient *gradient) override
void setFillColor(int index, const QColor &color) override
void setTriangulationScale(int index, qreal scale) override
void setVisible(int index, bool visible) override
void handleSceneChange(QQuickWindow *window) override
void setNode(QQuickShapeSoftwareRenderNode *node)
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern) override
void setCosmeticStroke(int index, bool c) 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)
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,...
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
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 * strokeGradient
QQuickShapeGradient * fillGradient