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
4#ifndef QQUICKSHAPEGENERICRENDERER_P_H
5#define QQUICKSHAPEGENERICRENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuickShapes/private/qquickshape_p_p.h>
20#include <QtQuick/private/qsggradientcache_p.h>
21#include <qsgnode.h>
22#include <qsggeometry.h>
23#include <qsgmaterial.h>
24#include <qsgrendererinterface.h>
25#include <qsgtexture.h>
26#include <QtCore/qrunnable.h>
27
29
34
36{
37public:
38 enum Dirty {
41 DirtyColor = 0x04,
45 DirtyList = 0x40 // only for accDirty
46 };
47
49 : m_item(item),
51 m_rootNode(nullptr),
52 m_accDirty(0),
53 m_asyncCallback(nullptr),
54 m_asyncCallbackData(nullptr)
55 { }
57
58 void beginSync(int totalCount, bool *countChanged) override;
59 void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) override;
60 void setStrokeColor(int index, const QColor &color) override;
61 void setStrokeWidth(int index, qreal w) override;
62 void setCosmeticStroke(int index, bool c) override;
63 void setFillColor(int index, const QColor &color) override;
64 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
65 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
66 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
67 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
68 qreal dashOffset, const QVector<qreal> &dashPattern) override;
69 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
70 void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override;
71 void setFillTransform(int index, const QSGTransform &transform) override;
72 void setTriangulationScale(qreal scale) override;
73 void endSync(bool async) override;
74 void setAsyncCallback(void (*)(void *), void *) override;
75 Flags flags() const override { return SupportsAsync; }
76 void handleSceneChange(QQuickWindow *window) override;
77
78 void updateNode() override;
79
81
82 struct Color4ub { unsigned char r, g, b, a; };
86
87 static void triangulateFill(const QPainterPath &path,
88 const Color4ub &fillColor,
89 VertexContainerType *fillVertices,
90 IndexContainerType *fillIndices,
91 QSGGeometry::Type *indexType,
92 bool supportsElementIndexUint,
93 qreal triangulationScale);
94 static void triangulateStroke(const QPainterPath &path,
95 const QPen &pen,
96 const Color4ub &strokeColor,
97 VertexContainerType *strokeVertices,
98 const QSize &clipSize,
99 qreal triangulationScale);
100
101private:
102 void maybeUpdateAsyncItem();
103
104 struct ShapePathData {
105 float strokeWidth;
106 QPen pen;
107 Color4ub strokeColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
108 Color4ub fillColor = { uchar(0), uchar(0), uchar(0), uchar(0) };
109 Qt::FillRule fillRule;
110 QPainterPath path;
111 FillGradientType fillGradientActive;
112 QSGGradientCache::GradientDesc fillGradient;
113 QQuickItem *fillTextureProviderItem = nullptr;
114 QSGTransform fillTransform;
115 VertexContainerType fillVertices;
116 IndexContainerType fillIndices;
117 QSGGeometry::Type indexType;
118 VertexContainerType strokeVertices;
119 int syncDirty;
120 int effectiveDirty = 0;
121 QQuickShapeFillRunnable *pendingFill = nullptr;
122 QQuickShapeStrokeRunnable *pendingStroke = nullptr;
123 };
124
125 void updateShadowDataInNode(ShapePathData *d, QQuickShapeGenericStrokeFillNode *n);
126 void updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node);
127 void updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node);
128
129 QQuickItem *m_item;
131 QQuickShapeGenericNode *m_rootNode;
132 QVector<ShapePathData> m_sp;
133 int m_accDirty;
134 void (*m_asyncCallback)(void *);
135 void *m_asyncCallbackData;
136 float m_triangulationScale = 1.0;
137};
138
162
185
187{
189public:
191
199
200 void activateMaterial(QQuickWindow *window, Material m);
201
202 // shadow data for custom materials
206 void preprocess() override;
207
208private Q_SLOTS:
210 void handleTextureProviderDestroyed();
211
212private:
213 QScopedPointer<QSGMaterial> m_material;
214
216};
217
225
227{
228public:
229 static QSGMaterial *createVertexColor(QQuickWindow *window);
230 static QSGMaterial *createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
231 static QSGMaterial *createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
232 static QSGMaterial *createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
233 static QSGMaterial *createTextureFill(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);
234};
235
237{
238public:
240
241 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
242 QSGMaterial *oldMaterial) override;
243 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
244 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
245
246private:
247 QSGTransform m_fillTransform;
248 QVector2D m_gradA;
249 QVector2D m_gradB;
250};
251
253{
254public:
256 : m_node(node)
257 {
258 // Passing RequiresFullMatrix is essential in order to prevent the
259 // batch renderer from baking in simple, translate-only transforms into
260 // the vertex data. The shader will rely on the fact that
261 // vertexCoord.xy is the Shape-space coordinate and so no modifications
262 // are welcome.
263 setFlag(Blending | RequiresFullMatrix);
264 }
265
266 QSGMaterialType *type() const override;
267 int compare(const QSGMaterial *other) const override;
268 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
269
270 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
271
272private:
274};
275
277{
278public:
280
281 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
282 QSGMaterial *oldMaterial) override;
283 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
284 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
285
286private:
287 QSGTransform m_fillTransform;
288 QVector2D m_focalPoint;
289 QVector2D m_focalToCenter;
290 float m_centerRadius;
291 float m_focalRadius;
292};
293
295{
296public:
298 : m_node(node)
299 {
300 setFlag(Blending | RequiresFullMatrix);
301 }
302
303 QSGMaterialType *type() const override;
304 int compare(const QSGMaterial *other) const override;
305 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
306
307 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
308
309private:
311};
312
314{
315public:
317
318 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
319 QSGMaterial *oldMaterial) override;
320 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
321 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
322
323private:
324 QSGTransform m_fillTransform;
325 QVector2D m_centerPoint;
326 float m_angle;
327};
328
330{
331public:
333 : m_node(node)
334 {
335 setFlag(Blending | RequiresFullMatrix);
336 }
337
338 QSGMaterialType *type() const override;
339 int compare(const QSGMaterial *other) const override;
340 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
341
342 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
343
344private:
346};
347
349{
350public:
351 QQuickShapeTextureFillRhiShader(int viewCount);
352
353 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
354 QSGMaterial *oldMaterial) override;
355 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
356 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
357
358private:
359 QSGTransform m_fillTransform;
360 QVector2D m_boundsOffset;
361 QVector2D m_boundsSize;
362};
363
365{
366public:
368 : m_node(node)
369 {
370 setFlag(Blending | RequiresFullMatrix);
371 }
373
374 QSGMaterialType *type() const override;
375 int compare(const QSGMaterial *other) const override;
376 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
377
378 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
379
380 QSGPlainTexture *dummyTexture() const
381 {
382 return m_dummyTexture;
383 }
384
385 void setDummyTexture(QSGPlainTexture *texture)
386 {
387 m_dummyTexture = texture;
388 }
389
390private:
392 QSGPlainTexture *m_dummyTexture = nullptr;
393};
394
395QT_END_NAMESPACE
396
397#endif // QQUICKSHAPEGENERICRENDERER_P_H
virtual void setTriangulationScale(qreal)
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 setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern)=0
virtual void setAsyncCallback(void(*)(void *), void *)
virtual Flags flags() const
virtual void setCapStyle(int index, QQuickShapePath::CapStyle capStyle)=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 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
QVector< QSGGeometry::TexturedPoint2D > TexturedVertexContainerType
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) 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)
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
QVector< QSGGeometry::ColoredPoint2D > VertexContainerType
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
void setRootNode(QQuickShapeGenericNode *node)
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 setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
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,...
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
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