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 };
49
51 : m_item(item),
53 m_rootNode(nullptr),
54 m_accDirty(0),
55 m_asyncCallback(nullptr),
56 m_asyncCallbackData(nullptr),
57 m_rhiBackendInitialized(false),
58 m_supportsElementIndexUint(true)
59 { }
61
62 void beginSync(int totalCount, bool *countChanged) override;
63 void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) override;
64 void setStrokeColor(int index, const QColor &color) override;
65 void setStrokeWidth(int index, qreal w) override;
66 void setCosmeticStroke(int index, bool c) override;
67 void setFillColor(int index, const QColor &color) override;
68 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
69 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
70 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
71 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
72 qreal dashOffset, const QList<qreal> &dashPattern) override;
73 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
74 void setStrokeGradient(int index, QQuickShapeGradient *gradient) override;
75 void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override;
76 void setFillTransform(int index, const QSGTransform &transform) override;
77 void setTriangulationScale(int index, qreal scale) override;
78 void endSync(bool async) override;
79 void setAsyncCallback(void (*)(void *), void *) override;
80 Flags flags() const override { return SupportsAsync; }
81 void handleSceneChange(QQuickWindow *window) override;
82
83 void updateNode() override;
84
86
87 struct Color4ub { unsigned char r, g, b, a; };
91
92 static void triangulateFill(const QPainterPath &path,
93 const Color4ub &fillColor,
94 VertexContainerType *fillVertices,
95 IndexContainerType *fillIndices,
96 QSGGeometry::Type *indexType,
97 bool supportsElementIndexUint,
98 qreal triangulationScale);
99 static void triangulateStroke(const QPainterPath &path,
100 const QPen &pen,
101 const Color4ub &strokeColor,
102 VertexContainerType *strokeVertices,
103 const QSize &clipSize,
104 qreal triangulationScale);
105
106private:
107 void maybeUpdateAsyncItem();
108
109 struct ShapePathData {
110 float strokeWidth;
111 float triangulationScale;
112 QPen pen;
113 Color4ub strokeColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
114 Color4ub fillColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
115 Qt::FillRule fillRule;
116 QPainterPath path;
117 FillGradientType fillGradientActive;
118 FillGradientType strokeGradientActive;
119 QSGGradientCache::GradientDesc fillGradient;
120 QSGGradientCache::GradientDesc strokeGradient;
121 QQuickItem *fillTextureProviderItem = nullptr;
122 QSGTransform fillTransform;
123 VertexContainerType fillVertices;
124 IndexContainerType fillIndices;
125 QSGGeometry::Type indexType;
126 VertexContainerType strokeVertices;
127 int syncDirty;
128 int effectiveDirty = 0;
129 QQuickShapeFillRunnable *pendingFill = nullptr;
130 QQuickShapeStrokeRunnable *pendingStroke = nullptr;
131 };
132
133 void updateShadowDataInNode(ShapePathData *d, QQuickShapeGenericStrokeFillNode *n);
134 void updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node);
135 void updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node);
136
137 QQuickItem *m_item;
139 QQuickShapeGenericNode *m_rootNode;
140 QList<ShapePathData> m_sp;
141 int m_accDirty;
142 void (*m_asyncCallback)(void *);
143 void *m_asyncCallbackData;
144 bool m_rhiBackendInitialized;
145 bool m_supportsElementIndexUint;
146};
147
171
194
196{
198public:
200
208
209 void activateMaterial(QQuickWindow *window, Material m);
210
211 // shadow data for custom materials
215 void preprocess() override;
216
217private Q_SLOTS:
219 void handleTextureProviderDestroyed();
220
221private:
222 QScopedPointer<QSGMaterial> m_material;
223
225};
226
234
236{
237public:
238 static QSGMaterial *createVertexColor(QQuickWindow *window);
239 static QSGMaterial *createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
240 static QSGMaterial *createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
241 static QSGMaterial *createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
242 static QSGMaterial *createTextureFill(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
243};
244
246{
247public:
249
250 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
251 QSGMaterial *oldMaterial) override;
252 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
253 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
254
255private:
256 QSGTransform m_fillTransform;
257 QVector2D m_gradA;
258 QVector2D m_gradB;
259};
260
262{
263public:
265 : m_node(node)
266 {
267 // Passing RequiresFullMatrix is essential in order to prevent the
268 // batch renderer from baking in simple, translate-only transforms into
269 // the vertex data. The shader will rely on the fact that
270 // vertexCoord.xy is the Shape-space coordinate and so no modifications
271 // are welcome.
272 setFlag(Blending | RequiresFullMatrix);
273 }
274
275 QSGMaterialType *type() const override;
276 int compare(const QSGMaterial *other) const override;
277 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
278
279 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
280
281private:
283};
284
286{
287public:
289
290 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
291 QSGMaterial *oldMaterial) override;
292 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
293 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
294
295private:
296 QSGTransform m_fillTransform;
297 QVector2D m_focalPoint;
298 QVector2D m_focalToCenter;
299 float m_centerRadius;
300 float m_focalRadius;
301};
302
304{
305public:
307 : m_node(node)
308 {
309 setFlag(Blending | RequiresFullMatrix);
310 }
311
312 QSGMaterialType *type() const override;
313 int compare(const QSGMaterial *other) const override;
314 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
315
316 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
317
318private:
320};
321
323{
324public:
326
327 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
328 QSGMaterial *oldMaterial) override;
329 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
330 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
331
332private:
333 QSGTransform m_fillTransform;
334 QVector2D m_centerPoint;
335 float m_angle;
336};
337
339{
340public:
342 : m_node(node)
343 {
344 setFlag(Blending | RequiresFullMatrix);
345 }
346
347 QSGMaterialType *type() const override;
348 int compare(const QSGMaterial *other) const override;
349 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
350
351 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
352
353private:
355};
356
358{
359public:
360 QQuickShapeTextureFillRhiShader(int viewCount);
361
362 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
363 QSGMaterial *oldMaterial) override;
364 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
365 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
366
367private:
368 QSGTransform m_fillTransform;
369 QVector2D m_boundsOffset;
370 QVector2D m_boundsSize;
371};
372
374{
375public:
377 : m_node(node)
378 {
379 setFlag(Blending | RequiresFullMatrix);
380 }
382
383 QSGMaterialType *type() const override;
384 int compare(const QSGMaterial *other) const override;
385 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
386
387 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
388
389 QSGPlainTexture *dummyTexture() const
390 {
391 return m_dummyTexture;
392 }
393
394 void setDummyTexture(QSGPlainTexture *texture)
395 {
396 m_dummyTexture = texture;
397 }
398
399private:
401 QSGPlainTexture *m_dummyTexture = nullptr;
402};
403
404QT_END_NAMESPACE
405
406#endif // QQUICKSHAPEGENERICRENDERER_P_H
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 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)
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,...
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