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