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
qquickshapegenericrenderer_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 QQUICKSHAPEGENERICRENDERER_P_H
6#define QQUICKSHAPEGENERICRENDERER_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/qsggradientcache_p.h>
22#include <qsgnode.h>
23#include <qsggeometry.h>
24#include <qsgmaterial.h>
25#include <qsgrendererinterface.h>
26#include <qsgtexture.h>
27#include <QtCore/qrunnable.h>
28
30
35
37{
38public:
39 enum Dirty {
42 DirtyColor = 0x04,
46 DirtyList = 0x40, // only for accDirty
48 DirtyVisible = 0x100,
49 };
50
52 : m_item(item),
54 m_rootNode(nullptr),
55 m_accDirty(0),
56 m_asyncCallback(nullptr),
57 m_asyncCallbackData(nullptr),
58 m_rhiBackendInitialized(false),
59 m_supportsElementIndexUint(true)
60 { }
62
63 void beginSync(int totalCount, bool *countChanged) override;
64 void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) override;
65 void setStrokeColor(int index, const QColor &color) override;
66 void setStrokeWidth(int index, qreal w) override;
67 void setCosmeticStroke(int index, bool c) override;
68 void setFillColor(int index, const QColor &color) override;
69 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
70 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
71 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
72 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
73 qreal dashOffset, const QList<qreal> &dashPattern) override;
74 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
75 void setStrokeGradient(int index, QQuickShapeGradient *gradient) override;
76 void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override;
77 void setFillTransform(int index, const QSGTransform &transform) override;
78 void setTriangulationScale(int index, qreal scale) override;
79 void setVisible(int index, bool visible) override;
80 void endSync(bool async) override;
81 void setAsyncCallback(void (*)(void *), void *) override;
82 Flags flags() const override { return SupportsAsync; }
83 void handleSceneChange(QQuickWindow *window) override;
84
85 void updateNode() override;
86
88
89 struct Color4ub { unsigned char r, g, b, a; };
93
94 static void triangulateFill(const QPainterPath &path,
95 const Color4ub &fillColor,
96 VertexContainerType *fillVertices,
97 IndexContainerType *fillIndices,
98 QSGGeometry::Type *indexType,
99 bool supportsElementIndexUint,
100 qreal triangulationScale);
101 static void triangulateStroke(const QPainterPath &path,
102 const QPen &pen,
103 const Color4ub &strokeColor,
104 VertexContainerType *strokeVertices,
105 const QSize &clipSize,
106 qreal triangulationScale);
107
108private:
109 void maybeUpdateAsyncItem();
110
111 struct ShapePathData {
112 float strokeWidth;
113 float triangulationScale;
114 QPen pen;
115 Color4ub strokeColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
116 Color4ub fillColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
117 Qt::FillRule fillRule;
118 QPainterPath path;
119 FillGradientType fillGradientActive;
120 FillGradientType strokeGradientActive;
121 QSGGradientCache::GradientDesc fillGradient;
122 QSGGradientCache::GradientDesc strokeGradient;
123 QQuickItem *fillTextureProviderItem = nullptr;
124 QSGTransform fillTransform;
125 VertexContainerType fillVertices;
126 IndexContainerType fillIndices;
127 QSGGeometry::Type indexType;
128 VertexContainerType strokeVertices;
129 int syncDirty;
130 int effectiveDirty = 0;
131 int hiddenGeomDirty = 0;
132 QQuickShapeFillRunnable *pendingFill = nullptr;
133 QQuickShapeStrokeRunnable *pendingStroke = nullptr;
134 bool visible = true;
135 };
136
137 void updateShadowDataInNode(ShapePathData *d, QQuickShapeGenericStrokeFillNode *n);
138 void updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node);
139 void updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node);
140
141 QQuickItem *m_item;
143 QQuickShapeGenericNode *m_rootNode;
144 QList<ShapePathData> m_sp;
145 int m_accDirty;
146 void (*m_asyncCallback)(void *);
147 void *m_asyncCallbackData;
148 bool m_rhiBackendInitialized;
149 bool m_supportsElementIndexUint;
150};
151
175
198
200{
202public:
204
212
213 void activateMaterial(QQuickWindow *window, Material m);
214
215 // shadow data for custom materials
219 void preprocess() override;
220
221private Q_SLOTS:
223 void handleTextureProviderDestroyed();
224
225private:
226 QScopedPointer<QSGMaterial> m_material;
227
229};
230
238
240{
241public:
242 static QSGMaterial *createVertexColor(QQuickWindow *window);
243 static QSGMaterial *createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
244 static QSGMaterial *createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
245 static QSGMaterial *createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
246 static QSGMaterial *createTextureFill(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
247};
248
250{
251public:
253
254 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
255 QSGMaterial *oldMaterial) override;
256 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
257 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
258
259private:
260 QSGTransform m_fillTransform;
261 QVector2D m_gradA;
262 QVector2D m_gradB;
263};
264
266{
267public:
269 : m_node(node)
270 {
271 // Passing RequiresFullMatrix is essential in order to prevent the
272 // batch renderer from baking in simple, translate-only transforms into
273 // the vertex data. The shader will rely on the fact that
274 // vertexCoord.xy is the Shape-space coordinate and so no modifications
275 // are welcome.
276 setFlag(Blending | RequiresFullMatrix);
277 }
278
279 QSGMaterialType *type() const override;
280 int compare(const QSGMaterial *other) const override;
281 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
282
283 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
284
285private:
287};
288
290{
291public:
293
294 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
295 QSGMaterial *oldMaterial) override;
296 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
297 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
298
299private:
300 QSGTransform m_fillTransform;
301 QVector2D m_focalPoint;
302 QVector2D m_focalToCenter;
303 float m_centerRadius;
304 float m_focalRadius;
305};
306
308{
309public:
311 : m_node(node)
312 {
313 setFlag(Blending | RequiresFullMatrix);
314 }
315
316 QSGMaterialType *type() const override;
317 int compare(const QSGMaterial *other) const override;
318 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
319
320 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
321
322private:
324};
325
327{
328public:
330
331 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
332 QSGMaterial *oldMaterial) override;
333 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
334 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
335
336private:
337 QSGTransform m_fillTransform;
338 QVector2D m_centerPoint;
339 float m_angle;
340};
341
343{
344public:
346 : m_node(node)
347 {
348 setFlag(Blending | RequiresFullMatrix);
349 }
350
351 QSGMaterialType *type() const override;
352 int compare(const QSGMaterial *other) const override;
353 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
354
355 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
356
357private:
359};
360
362{
363public:
364 QQuickShapeTextureFillRhiShader(int viewCount);
365
366 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
367 QSGMaterial *oldMaterial) override;
368 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
369 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
370
371private:
372 QSGTransform m_fillTransform;
373 QVector2D m_boundsOffset;
374 QVector2D m_boundsSize;
375};
376
378{
379public:
381 : m_node(node)
382 {
383 setFlag(Blending | RequiresFullMatrix);
384 }
386
387 QSGMaterialType *type() const override;
388 int compare(const QSGMaterial *other) const override;
389 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
390
391 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
392
393 QSGPlainTexture *dummyTexture() const
394 {
395 return m_dummyTexture;
396 }
397
398 void setDummyTexture(QSGPlainTexture *texture)
399 {
400 m_dummyTexture = texture;
401 }
402
403private:
405 QSGPlainTexture *m_dummyTexture = nullptr;
406};
407
408QT_END_NAMESPACE
409
410#endif // QQUICKSHAPEGENERICRENDERER_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...
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,...
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