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