OpenCoverage

qquickshapegenericrenderer_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quickshapes/qquickshapegenericrenderer_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#ifndef QQUICKSHAPEGENERICRENDERER_P_H-
41#define QQUICKSHAPEGENERICRENDERER_P_H-
42-
43//-
44// W A R N I N G-
45// --------------
46//-
47// This file is not part of the Qt API. It exists for the convenience-
48// of a number of Qt sources files. This header file may change from-
49// version to version without notice, or even be removed.-
50//-
51// We mean it.-
52//-
53-
54#include <QtQuickShapes/private/qquickshapesglobal_p.h>-
55#include <QtQuickShapes/private/qquickshape_p_p.h>-
56#include <qsgnode.h>-
57#include <qsggeometry.h>-
58#include <qsgmaterial.h>-
59#include <qsgrendererinterface.h>-
60#include <QtCore/qrunnable.h>-
61-
62QT_BEGIN_NAMESPACE-
63-
64class QQuickShapeGenericNode;-
65class QQuickShapeGenericStrokeFillNode;-
66class QQuickShapeFillRunnable;-
67class QQuickShapeStrokeRunnable;-
68-
69class QQuickShapeGenericRenderer : public QQuickAbstractPathRenderer-
70{-
71public:-
72 enum Dirty {-
73 DirtyFillGeom = 0x01,-
74 DirtyStrokeGeom = 0x02,-
75 DirtyColor = 0x04,-
76 DirtyFillGradient = 0x08,-
77 DirtyList = 0x10 // only for accDirty-
78 };-
79-
80 QQuickShapeGenericRenderer(QQuickItem *item)-
81 : m_item(item),-
82 m_api(QSGRendererInterface::Unknown),-
83 m_rootNode(nullptr),-
84 m_accDirty(0),-
85 m_asyncCallback(nullptr),-
86 m_asyncCallbackData(nullptr)-
87 { }
executed 83 times by 1 test: end of block
Executed by:
  • tst_examples
83
88 ~QQuickShapeGenericRenderer();-
89-
90 void beginSync(int totalCount) override;-
91 void setPath(int index, const QQuickPath *path) override;-
92 void setStrokeColor(int index, const QColor &color) override;-
93 void setStrokeWidth(int index, qreal w) override;-
94 void setFillColor(int index, const QColor &color) override;-
95 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;-
96 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;-
97 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;-
98 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,-
99 qreal dashOffset, const QVector<qreal> &dashPattern) override;-
100 void setFillGradient(int index, QQuickShapeGradient *gradient) override;-
101 void endSync(bool async) override;-
102 void setAsyncCallback(void (*)(void *), void *) override;-
103 Flags flags() const override { return SupportsAsync; }
executed 4 times by 1 test: return SupportsAsync;
Executed by:
  • tst_examples
4
104-
105 void updateNode() override;-
106-
107 void setRootNode(QQuickShapeGenericNode *node);-
108-
109 struct Color4ub { unsigned char r, g, b, a; };-
110 typedef QVector<QSGGeometry::ColoredPoint2D> VertexContainerType;-
111 typedef QVector<quint32> IndexContainerType;-
112-
113 static void triangulateFill(const QPainterPath &path,-
114 const Color4ub &fillColor,-
115 VertexContainerType *fillVertices,-
116 IndexContainerType *fillIndices,-
117 QSGGeometry::Type *indexType,-
118 bool supportsElementIndexUint);-
119 static void triangulateStroke(const QPainterPath &path,-
120 const QPen &pen,-
121 const Color4ub &strokeColor,-
122 VertexContainerType *strokeVertices,-
123 const QSize &clipSize);-
124-
125private:-
126 void maybeUpdateAsyncItem();-
127-
128 struct ShapePathData {-
129 float strokeWidth;-
130 QPen pen;-
131 Color4ub strokeColor;-
132 Color4ub fillColor;-
133 Qt::FillRule fillRule;-
134 QPainterPath path;-
135 FillGradientType fillGradientActive;-
136 GradientDesc fillGradient;-
137 VertexContainerType fillVertices;-
138 IndexContainerType fillIndices;-
139 QSGGeometry::Type indexType;-
140 VertexContainerType strokeVertices;-
141 int syncDirty;-
142 int effectiveDirty = 0;-
143 QQuickShapeFillRunnable *pendingFill = nullptr;-
144 QQuickShapeStrokeRunnable *pendingStroke = nullptr;-
145 };-
146-
147 void updateShadowDataInNode(ShapePathData *d, QQuickShapeGenericStrokeFillNode *n);-
148 void updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node);-
149 void updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node);-
150-
151 QQuickItem *m_item;-
152 QSGRendererInterface::GraphicsApi m_api;-
153 QQuickShapeGenericNode *m_rootNode;-
154 QVector<ShapePathData> m_sp;-
155 int m_accDirty;-
156 void (*m_asyncCallback)(void *);-
157 void *m_asyncCallbackData;-
158};-
159-
160class QQuickShapeFillRunnable : public QObject, public QRunnable-
161{-
162 Q_OBJECT-
163-
164public:-
165 void run() override;-
166-
167 bool orphaned = false;-
168-
169 // input-
170 QPainterPath path;-
171 QQuickShapeGenericRenderer::Color4ub fillColor;-
172 bool supportsElementIndexUint;-
173-
174 // output-
175 QQuickShapeGenericRenderer::VertexContainerType fillVertices;-
176 QQuickShapeGenericRenderer::IndexContainerType fillIndices;-
177 QSGGeometry::Type indexType;-
178-
179Q_SIGNALS:-
180 void done(QQuickShapeFillRunnable *self);-
181};-
182-
183class QQuickShapeStrokeRunnable : public QObject, public QRunnable-
184{-
185 Q_OBJECT-
186-
187public:-
188 void run() override;-
189-
190 bool orphaned = false;-
191-
192 // input-
193 QPainterPath path;-
194 QPen pen;-
195 QQuickShapeGenericRenderer::Color4ub strokeColor;-
196 QSize clipSize;-
197-
198 // output-
199 QQuickShapeGenericRenderer::VertexContainerType strokeVertices;-
200-
201Q_SIGNALS:-
202 void done(QQuickShapeStrokeRunnable *self);-
203};-
204-
205class QQuickShapeGenericStrokeFillNode : public QSGGeometryNode-
206{-
207public:-
208 QQuickShapeGenericStrokeFillNode(QQuickWindow *window);-
209-
210 enum Material {-
211 MatSolidColor,-
212 MatLinearGradient,-
213 MatRadialGradient,-
214 MatConicalGradient-
215 };-
216-
217 void activateMaterial(QQuickWindow *window, Material m);-
218-
219 // shadow data for custom materials-
220 QQuickAbstractPathRenderer::GradientDesc m_fillGradient;-
221-
222private:-
223 QScopedPointer<QSGMaterial> m_material;-
224-
225 friend class QQuickShapeGenericRenderer;-
226};-
227-
228class QQuickShapeGenericNode : public QSGNode-
229{-
230public:-
231 QQuickShapeGenericStrokeFillNode *m_fillNode = nullptr;-
232 QQuickShapeGenericStrokeFillNode *m_strokeNode = nullptr;-
233 QQuickShapeGenericNode *m_next = nullptr;-
234};-
235-
236class QQuickShapeGenericMaterialFactory-
237{-
238public:-
239 static QSGMaterial *createVertexColor(QQuickWindow *window);-
240 static QSGMaterial *createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);-
241 static QSGMaterial *createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);-
242 static QSGMaterial *createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node);-
243};-
244-
245#if QT_CONFIG(opengl)-
246-
247class QQuickShapeLinearGradientShader : public QSGMaterialShader-
248{-
249public:-
250 QQuickShapeLinearGradientShader();-
251-
252 void initialize() override;-
253 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;-
254 char const *const *attributeNames() const override;-
255-
256 static QSGMaterialType type;-
257-
258private:-
259 int m_opacityLoc = -1;-
260 int m_matrixLoc = -1;-
261 int m_gradStartLoc = -1;-
262 int m_gradEndLoc = -1;-
263};-
264-
265class QQuickShapeLinearGradientMaterial : public QSGMaterial-
266{-
267public:-
268 QQuickShapeLinearGradientMaterial(QQuickShapeGenericStrokeFillNode *node)-
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 }
executed 12 times by 1 test: end of block
Executed by:
  • tst_examples
12
278-
279 QSGMaterialType *type() const override-
280 {-
281 return &QQuickShapeLinearGradientShader::type;
executed 14 times by 1 test: return &QQuickShapeLinearGradientShader::type;
Executed by:
  • tst_examples
14
282 }-
283-
284 int compare(const QSGMaterial *other) const override;-
285-
286 QSGMaterialShader *createShader() const override-
287 {-
288 return new QQuickShapeLinearGradientShader;
executed 8 times by 1 test: return new QQuickShapeLinearGradientShader;
Executed by:
  • tst_examples
8
289 }-
290-
291 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
executed 8 times by 1 test: return m_node;
Executed by:
  • tst_examples
8
292-
293private:-
294 QQuickShapeGenericStrokeFillNode *m_node;-
295};-
296-
297class QQuickShapeRadialGradientShader : public QSGMaterialShader-
298{-
299public:-
300 QQuickShapeRadialGradientShader();-
301-
302 void initialize() override;-
303 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;-
304 char const *const *attributeNames() const override;-
305-
306 static QSGMaterialType type;-
307-
308private:-
309 int m_opacityLoc = -1;-
310 int m_matrixLoc = -1;-
311 int m_translationPointLoc = -1;-
312 int m_focalToCenterLoc = -1;-
313 int m_centerRadiusLoc = -1;-
314 int m_focalRadiusLoc = -1;-
315};-
316-
317class QQuickShapeRadialGradientMaterial : public QSGMaterial-
318{-
319public:-
320 QQuickShapeRadialGradientMaterial(QQuickShapeGenericStrokeFillNode *node)-
321 : m_node(node)-
322 {-
323 setFlag(Blending | RequiresFullMatrix);-
324 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_examples
4
325-
326 QSGMaterialType *type() const override-
327 {-
328 return &QQuickShapeRadialGradientShader::type;
executed 10 times by 1 test: return &QQuickShapeRadialGradientShader::type;
Executed by:
  • tst_examples
10
329 }-
330-
331 int compare(const QSGMaterial *other) const override;-
332-
333 QSGMaterialShader *createShader() const override-
334 {-
335 return new QQuickShapeRadialGradientShader;
executed 4 times by 1 test: return new QQuickShapeRadialGradientShader;
Executed by:
  • tst_examples
4
336 }-
337-
338 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
executed 4 times by 1 test: return m_node;
Executed by:
  • tst_examples
4
339-
340private:-
341 QQuickShapeGenericStrokeFillNode *m_node;-
342};-
343-
344class QQuickShapeConicalGradientShader : public QSGMaterialShader-
345{-
346public:-
347 QQuickShapeConicalGradientShader();-
348-
349 void initialize() override;-
350 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;-
351 char const *const *attributeNames() const override;-
352-
353 static QSGMaterialType type;-
354-
355private:-
356 int m_opacityLoc = -1;-
357 int m_matrixLoc = -1;-
358 int m_angleLoc = -1;-
359 int m_translationPointLoc = -1;-
360};-
361-
362class QQuickShapeConicalGradientMaterial : public QSGMaterial-
363{-
364public:-
365 QQuickShapeConicalGradientMaterial(QQuickShapeGenericStrokeFillNode *node)-
366 : m_node(node)-
367 {-
368 setFlag(Blending | RequiresFullMatrix);-
369 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_examples
3
370-
371 QSGMaterialType *type() const override-
372 {-
373 return &QQuickShapeConicalGradientShader::type;
executed 9 times by 1 test: return &QQuickShapeConicalGradientShader::type;
Executed by:
  • tst_examples
9
374 }-
375-
376 int compare(const QSGMaterial *other) const override;-
377-
378 QSGMaterialShader *createShader() const override-
379 {-
380 return new QQuickShapeConicalGradientShader;
executed 3 times by 1 test: return new QQuickShapeConicalGradientShader;
Executed by:
  • tst_examples
3
381 }-
382-
383 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
executed 3 times by 1 test: return m_node;
Executed by:
  • tst_examples
3
384-
385private:-
386 QQuickShapeGenericStrokeFillNode *m_node;-
387};-
388-
389#endif // QT_CONFIG(opengl)-
390-
391QT_END_NAMESPACE-
392-
393#endif // QQUICKSHAPEGENERICRENDERER_P_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0