1 | // Copyright (C) 2016 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 QQUICKSHAPE_P_P_H |
5 | #define QQUICKSHAPE_P_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 purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // 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.h> |
20 | #include <private/qquickitem_p.h> |
21 | #include <private/qsgtransform_p.h> |
22 | #include <QPainterPath> |
23 | #include <QColor> |
24 | #include <QBrush> |
25 | #include <QElapsedTimer> |
26 | #if QT_CONFIG(opengl) |
27 | # include <private/qopenglcontext_p.h> |
28 | #endif |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QSGPlainTexture; |
32 | class QRhi; |
33 | |
34 | class QQuickAbstractPathRenderer |
35 | { |
36 | public: |
37 | enum Flag { |
38 | SupportsAsync = 0x01 |
39 | }; |
40 | Q_DECLARE_FLAGS(Flags, Flag) |
41 | enum FillGradientType { NoGradient = 0, LinearGradient, RadialGradient, ConicalGradient }; |
42 | |
43 | virtual ~QQuickAbstractPathRenderer() { } |
44 | |
45 | // Gui thread |
46 | virtual void beginSync(int totalCount, bool *countChanged) = 0; |
47 | virtual void endSync(bool async) = 0; |
48 | virtual void setAsyncCallback(void (*)(void *), void *) { } |
49 | virtual Flags flags() const { return {}; } |
50 | virtual void setPath(int index, const QQuickPath *path) = 0; |
51 | virtual void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints = {}) = 0; |
52 | virtual void setStrokeColor(int index, const QColor &color) = 0; |
53 | virtual void setStrokeWidth(int index, qreal w) = 0; |
54 | virtual void setFillColor(int index, const QColor &color) = 0; |
55 | virtual void setFillRule(int index, QQuickShapePath::FillRule fillRule) = 0; |
56 | virtual void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) = 0; |
57 | virtual void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) = 0; |
58 | virtual void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, |
59 | qreal dashOffset, const QVector<qreal> &dashPattern) = 0; |
60 | virtual void setFillGradient(int index, QQuickShapeGradient *gradient) = 0; |
61 | virtual void setFillTextureProvider(int index, QQuickItem *textureProviderItem) = 0; |
62 | virtual void setFillTransform(int index, const QSGTransform &transform) = 0; |
63 | virtual void setTriangulationScale(qreal) { } |
64 | virtual void handleSceneChange(QQuickWindow *window) = 0; |
65 | |
66 | // Render thread, with gui blocked |
67 | virtual void updateNode() = 0; |
68 | }; |
69 | |
70 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractPathRenderer::Flags) |
71 | |
72 | struct QQuickShapeStrokeFillParams |
73 | { |
74 | QQuickShapeStrokeFillParams(); |
75 | |
76 | QColor strokeColor; |
77 | qreal strokeWidth; |
78 | QColor fillColor; |
79 | QQuickShapePath::FillRule fillRule; |
80 | QQuickShapePath::JoinStyle joinStyle; |
81 | int miterLimit; |
82 | QQuickShapePath::CapStyle capStyle; |
83 | QQuickShapePath::StrokeStyle strokeStyle; |
84 | qreal dashOffset; |
85 | QVector<qreal> dashPattern; |
86 | QQuickShapeGradient *fillGradient; |
87 | QSGTransform fillTransform; |
88 | QQuickItem *fillItem; |
89 | }; |
90 | |
91 | class Q_QUICKSHAPES_EXPORT QQuickShapePathPrivate : public QQuickPathPrivate |
92 | { |
93 | Q_DECLARE_PUBLIC(QQuickShapePath) |
94 | |
95 | public: |
96 | enum Dirty { |
97 | DirtyPath = 0x01, |
98 | DirtyStrokeColor = 0x02, |
99 | DirtyStrokeWidth = 0x04, |
100 | DirtyFillColor = 0x08, |
101 | DirtyFillRule = 0x10, |
102 | DirtyStyle = 0x20, |
103 | DirtyDash = 0x40, |
104 | DirtyFillGradient = 0x80, |
105 | DirtyFillTransform = 0x100, |
106 | DirtyFillItem = 0x200, |
107 | |
108 | DirtyAll = 0x3FF |
109 | }; |
110 | |
111 | QQuickShapePathPrivate(); |
112 | |
113 | void _q_pathChanged(); |
114 | void _q_fillGradientChanged(); |
115 | void _q_fillItemDestroyed(); |
116 | |
117 | void handleSceneChange(); |
118 | |
119 | static QQuickShapePathPrivate *get(QQuickShapePath *p) { return p->d_func(); } |
120 | |
121 | int dirty; |
122 | QQuickShapeStrokeFillParams sfp; |
123 | QQuickShapePath::PathHints pathHints; |
124 | }; |
125 | |
126 | class QQuickShapePrivate : public QQuickItemPrivate |
127 | { |
128 | Q_DECLARE_PUBLIC(QQuickShape) |
129 | |
130 | public: |
131 | QQuickShapePrivate(); |
132 | ~QQuickShapePrivate(); |
133 | |
134 | QQuickShape::RendererType selectRendererType(); |
135 | void createRenderer(); |
136 | QSGNode *createNode(); |
137 | void sync(); |
138 | |
139 | void _q_shapePathChanged(); |
140 | void setStatus(QQuickShape::Status newStatus); |
141 | void handleSceneChange(QQuickWindow *w); |
142 | |
143 | static QQuickShapePrivate *get(QQuickShape *item) { return item->d_func(); } |
144 | |
145 | static void asyncShapeReady(void *data); |
146 | |
147 | qreal getImplicitWidth() const override; |
148 | qreal getImplicitHeight() const override; |
149 | |
150 | int effectRefCount; |
151 | QVector<QQuickShapePath *> sp; |
152 | QElapsedTimer syncTimer; |
153 | QQuickAbstractPathRenderer *renderer = nullptr; |
154 | int syncTimingTotalDirty = 0; |
155 | int syncTimeCounter = 0; |
156 | QQuickShape::Status status = QQuickShape::Null; |
157 | QQuickShape::RendererType rendererType = QQuickShape::UnknownRenderer; |
158 | QQuickShape::RendererType preferredType = QQuickShape::UnknownRenderer; |
159 | QQuickShape::ContainsMode containsMode = QQuickShape::BoundingRectContains; |
160 | QQuickShape::FillMode fillMode = QQuickShape::NoResize; |
161 | QQuickShape::HAlignment horizontalAlignment = QQuickShape::AlignLeft; |
162 | QQuickShape::VAlignment verticalAlignment = QQuickShape::AlignTop; |
163 | |
164 | bool spChanged = false; |
165 | bool rendererChanged = false; |
166 | bool async = false; |
167 | bool enableVendorExts = false; |
168 | bool syncTimingActive = false; |
169 | qreal triangulationScale = 1.0; |
170 | }; |
171 | |
172 | QT_END_NAMESPACE |
173 | |
174 | #endif |
175 | |