Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | #include "qquickcontext2dcommandbuffer_p.h" | - | ||||||||||||||||||||||||||||||
41 | #include "qquickcanvasitem_p.h" | - | ||||||||||||||||||||||||||||||
42 | #include <qqml.h> | - | ||||||||||||||||||||||||||||||
43 | #include <QtCore/QMutex> | - | ||||||||||||||||||||||||||||||
44 | #include <QtQuick/qsgtexture.h> | - | ||||||||||||||||||||||||||||||
45 | #include <QtGui/QPaintEngine> | - | ||||||||||||||||||||||||||||||
46 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||||||||||||||
47 | # include <QtGui/QOpenGLContext> | - | ||||||||||||||||||||||||||||||
48 | # include <QtGui/private/qopenglpaintengine_p.h> | - | ||||||||||||||||||||||||||||||
49 | #endif | - | ||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||
51 | #define HAS_SHADOW(offsetX, offsetY, blur, color) (color.isValid() && color.alpha() && (blur || offsetX || offsetY)) | - | ||||||||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||||||||
53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||||||||
55 | void qt_image_boxblur(QImage& image, int radius, bool quality); | - | ||||||||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||||||||
57 | namespace { | - | ||||||||||||||||||||||||||||||
58 | class ShadowImageMaker | - | ||||||||||||||||||||||||||||||
59 | { | - | ||||||||||||||||||||||||||||||
60 | public: | - | ||||||||||||||||||||||||||||||
61 | virtual ~ShadowImageMaker() {} | - | ||||||||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||||||||
63 | void paintShapeAndShadow(QPainter *p, qreal offsetX, qreal offsetY, qreal blur, const QColor &color) | - | ||||||||||||||||||||||||||||||
64 | { | - | ||||||||||||||||||||||||||||||
65 | QRectF bounds = boundingRect().translated(offsetX, offsetY).adjusted(-2*blur, -2*blur, 2*blur, 2*blur); | - | ||||||||||||||||||||||||||||||
66 | QRect boundsAligned = bounds.toAlignedRect(); | - | ||||||||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||||||||
68 | QImage shadowImage(boundsAligned.size(), QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||||||||||||||
69 | shadowImage.fill(0); | - | ||||||||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||||||||
71 | QPainter shadowPainter(&shadowImage); | - | ||||||||||||||||||||||||||||||
72 | shadowPainter.setRenderHints(p->renderHints()); | - | ||||||||||||||||||||||||||||||
73 | shadowPainter.translate(offsetX - boundsAligned.left(), offsetY - boundsAligned.top()); | - | ||||||||||||||||||||||||||||||
74 | paint(&shadowPainter); | - | ||||||||||||||||||||||||||||||
75 | shadowPainter.end(); | - | ||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||
77 | if (blur > 0)
| 0 | ||||||||||||||||||||||||||||||
78 | qt_image_boxblur(shadowImage, qMax(1, qRound(blur / 2)), true); never executed: qt_image_boxblur(shadowImage, qMax(1, qRound(blur / 2)), true); | 0 | ||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||
80 | // blacken the image with shadow color... | - | ||||||||||||||||||||||||||||||
81 | shadowPainter.begin(&shadowImage); | - | ||||||||||||||||||||||||||||||
82 | shadowPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); | - | ||||||||||||||||||||||||||||||
83 | shadowPainter.fillRect(shadowImage.rect(), color); | - | ||||||||||||||||||||||||||||||
84 | shadowPainter.end(); | - | ||||||||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||||||||
86 | p->drawImage(boundsAligned.topLeft(), shadowImage); | - | ||||||||||||||||||||||||||||||
87 | paint(p); | - | ||||||||||||||||||||||||||||||
88 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||||||||
90 | virtual void paint(QPainter *p) const = 0; | - | ||||||||||||||||||||||||||||||
91 | virtual QRectF boundingRect() const = 0; | - | ||||||||||||||||||||||||||||||
92 | }; | - | ||||||||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||||||||
94 | class FillRectShadow : public ShadowImageMaker | - | ||||||||||||||||||||||||||||||
95 | { | - | ||||||||||||||||||||||||||||||
96 | public: | - | ||||||||||||||||||||||||||||||
97 | FillRectShadow(const QRectF &rect, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
98 | : m_rect(rect.normalized()) | - | ||||||||||||||||||||||||||||||
99 | , m_brush(brush) | - | ||||||||||||||||||||||||||||||
100 | { | - | ||||||||||||||||||||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||||||||
103 | void paint(QPainter *p) const override { p->fillRect(m_rect, m_brush); } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
104 | QRectF boundingRect() const override { return m_rect; } never executed: return m_rect; | 0 | ||||||||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||||||||
106 | private: | - | ||||||||||||||||||||||||||||||
107 | QRectF m_rect; | - | ||||||||||||||||||||||||||||||
108 | QBrush m_brush; | - | ||||||||||||||||||||||||||||||
109 | }; | - | ||||||||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||||||||
111 | class FillPathShadow : public ShadowImageMaker | - | ||||||||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||||||||
113 | public: | - | ||||||||||||||||||||||||||||||
114 | FillPathShadow(const QPainterPath &path, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
115 | : m_path(path) | - | ||||||||||||||||||||||||||||||
116 | , m_brush(brush) | - | ||||||||||||||||||||||||||||||
117 | { | - | ||||||||||||||||||||||||||||||
118 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||||||||
120 | void paint(QPainter *p) const override { p->fillPath(m_path, m_brush); } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
121 | QRectF boundingRect() const override { return m_path.boundingRect(); } never executed: return m_path.boundingRect(); | 0 | ||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||
123 | private: | - | ||||||||||||||||||||||||||||||
124 | QPainterPath m_path; | - | ||||||||||||||||||||||||||||||
125 | QBrush m_brush; | - | ||||||||||||||||||||||||||||||
126 | }; | - | ||||||||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||||||||
128 | class StrokePathShadow : public ShadowImageMaker | - | ||||||||||||||||||||||||||||||
129 | { | - | ||||||||||||||||||||||||||||||
130 | public: | - | ||||||||||||||||||||||||||||||
131 | StrokePathShadow(const QPainterPath &path, const QPen &pen) | - | ||||||||||||||||||||||||||||||
132 | : m_path(path) | - | ||||||||||||||||||||||||||||||
133 | , m_pen(pen) | - | ||||||||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||||||||
135 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||||||||
137 | void paint(QPainter *p) const override { p->strokePath(m_path, m_pen); } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||||||||
139 | QRectF boundingRect() const override | - | ||||||||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||||||||
141 | qreal d = qMax(qreal(1), m_pen.widthF()); | - | ||||||||||||||||||||||||||||||
142 | return m_path.boundingRect().adjusted(-d, -d, d, d); never executed: return m_path.boundingRect().adjusted(-d, -d, d, d); | 0 | ||||||||||||||||||||||||||||||
143 | } | - | ||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||
145 | private: | - | ||||||||||||||||||||||||||||||
146 | QPainterPath m_path; | - | ||||||||||||||||||||||||||||||
147 | QPen m_pen; | - | ||||||||||||||||||||||||||||||
148 | }; | - | ||||||||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||||||||
150 | class DrawImageShadow : public ShadowImageMaker | - | ||||||||||||||||||||||||||||||
151 | { | - | ||||||||||||||||||||||||||||||
152 | public: | - | ||||||||||||||||||||||||||||||
153 | DrawImageShadow(const QImage &image, const QPointF &offset) | - | ||||||||||||||||||||||||||||||
154 | : m_image(image) | - | ||||||||||||||||||||||||||||||
155 | , m_offset(offset) | - | ||||||||||||||||||||||||||||||
156 | { | - | ||||||||||||||||||||||||||||||
157 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||||||||
159 | void paint(QPainter *p) const override { p->drawImage(m_offset, m_image); } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||||||||
161 | QRectF boundingRect() const override { return QRectF(m_image.rect()).translated(m_offset); } never executed: return QRectF(m_image.rect()).translated(m_offset); | 0 | ||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||
163 | private: | - | ||||||||||||||||||||||||||||||
164 | QImage m_image; | - | ||||||||||||||||||||||||||||||
165 | QPointF m_offset; | - | ||||||||||||||||||||||||||||||
166 | }; | - | ||||||||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||||||||
169 | static void fillRectShadow(QPainter* p, QRectF shadowRect, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) | - | ||||||||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||||||||
171 | FillRectShadow shadowMaker(shadowRect, p->brush()); | - | ||||||||||||||||||||||||||||||
172 | shadowMaker.paintShapeAndShadow(p, offsetX, offsetY, blur, color); | - | ||||||||||||||||||||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||
175 | static void fillShadowPath(QPainter* p, const QPainterPath& path, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) | - | ||||||||||||||||||||||||||||||
176 | { | - | ||||||||||||||||||||||||||||||
177 | FillPathShadow shadowMaker(path, p->brush()); | - | ||||||||||||||||||||||||||||||
178 | shadowMaker.paintShapeAndShadow(p, offsetX, offsetY, blur, color); | - | ||||||||||||||||||||||||||||||
179 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||
181 | static void strokeShadowPath(QPainter* p, const QPainterPath& path, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) | - | ||||||||||||||||||||||||||||||
182 | { | - | ||||||||||||||||||||||||||||||
183 | StrokePathShadow shadowMaker(path, p->pen()); | - | ||||||||||||||||||||||||||||||
184 | shadowMaker.paintShapeAndShadow(p, offsetX, offsetY, blur, color); | - | ||||||||||||||||||||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||
187 | QPen QQuickContext2DCommandBuffer::makePen(const QQuickContext2D::State& state) | - | ||||||||||||||||||||||||||||||
188 | { | - | ||||||||||||||||||||||||||||||
189 | QPen pen; | - | ||||||||||||||||||||||||||||||
190 | pen.setWidthF(state.lineWidth); | - | ||||||||||||||||||||||||||||||
191 | pen.setCapStyle(state.lineCap); | - | ||||||||||||||||||||||||||||||
192 | pen.setJoinStyle(state.lineJoin); | - | ||||||||||||||||||||||||||||||
193 | pen.setMiterLimit(state.miterLimit); | - | ||||||||||||||||||||||||||||||
194 | pen.setBrush(state.strokeStyle); | - | ||||||||||||||||||||||||||||||
195 | return pen; never executed: return pen; | 0 | ||||||||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||||||||
198 | void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, const QQuickContext2D::State& state, const QPen& pen) | - | ||||||||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||||||||
200 | p->setTransform(state.matrix * p->transform()); | - | ||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||
202 | if (pen != p->pen())
| 0 | ||||||||||||||||||||||||||||||
203 | p->setPen(pen); never executed: p->setPen(pen); | 0 | ||||||||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||||||||
205 | if (state.fillStyle != p->brush())
| 0 | ||||||||||||||||||||||||||||||
206 | p->setBrush(state.fillStyle); never executed: p->setBrush(state.fillStyle); | 0 | ||||||||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||||||||
208 | if (state.font != p->font())
| 0 | ||||||||||||||||||||||||||||||
209 | p->setFont(state.font); never executed: p->setFont(state.font); | 0 | ||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||
211 | if (state.globalAlpha != p->opacity()) {
| 0 | ||||||||||||||||||||||||||||||
212 | p->setOpacity(state.globalAlpha); | - | ||||||||||||||||||||||||||||||
213 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||||||||
215 | if (state.globalCompositeOperation != p->compositionMode())
| 0 | ||||||||||||||||||||||||||||||
216 | p->setCompositionMode(state.globalCompositeOperation); never executed: p->setCompositionMode(state.globalCompositeOperation); | 0 | ||||||||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||||||||
218 | p->setClipping(state.clip); | - | ||||||||||||||||||||||||||||||
219 | if (state.clip)
| 0 | ||||||||||||||||||||||||||||||
220 | p->setClipPath(state.clipPath); never executed: p->setClipPath(state.clipPath); | 0 | ||||||||||||||||||||||||||||||
221 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||||||||
223 | static void qt_drawImage(QPainter *p, QQuickContext2D::State& state, QImage image, const QRectF& sr, const QRectF& dr, bool shadow = false) | - | ||||||||||||||||||||||||||||||
224 | { | - | ||||||||||||||||||||||||||||||
225 | Q_ASSERT(p); | - | ||||||||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||||||||
227 | if (image.isNull())
| 0 | ||||||||||||||||||||||||||||||
228 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||||||||
230 | qreal sx = sr.x(); | - | ||||||||||||||||||||||||||||||
231 | qreal sy = sr.y(); | - | ||||||||||||||||||||||||||||||
232 | qreal sw = sr.width(); | - | ||||||||||||||||||||||||||||||
233 | qreal sh = sr.height(); | - | ||||||||||||||||||||||||||||||
234 | qreal dx = dr.x(); | - | ||||||||||||||||||||||||||||||
235 | qreal dy = dr.y(); | - | ||||||||||||||||||||||||||||||
236 | qreal dw = dr.width(); | - | ||||||||||||||||||||||||||||||
237 | qreal dh = dr.height(); | - | ||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||
239 | if (sw == -1 || sh == -1) {
| 0 | ||||||||||||||||||||||||||||||
240 | sw = image.width(); | - | ||||||||||||||||||||||||||||||
241 | sh = image.height(); | - | ||||||||||||||||||||||||||||||
242 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
243 | if (sx != 0 || sy != 0 || sw != image.width() || sh != image.height())
| 0 | ||||||||||||||||||||||||||||||
244 | image = image.copy(sx, sy, sw, sh); never executed: image = image.copy(sx, sy, sw, sh); | 0 | ||||||||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||||||||
246 | if (sw != dw || sh != dh)
| 0 | ||||||||||||||||||||||||||||||
247 | image = image.scaled(dw, dh); never executed: image = image.scaled(dw, dh); | 0 | ||||||||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||||||||
249 | //Strange OpenGL painting behavior here, without beginNativePainting/endNativePainting, only the first image is painted. | - | ||||||||||||||||||||||||||||||
250 | p->beginNativePainting(); | - | ||||||||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||||||||
252 | if (shadow) {
| 0 | ||||||||||||||||||||||||||||||
253 | DrawImageShadow shadowMaker(image, QPointF(dx, dy)); | - | ||||||||||||||||||||||||||||||
254 | shadowMaker.paintShapeAndShadow(p, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); | - | ||||||||||||||||||||||||||||||
255 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
256 | p->drawImage(dx, dy, image); | - | ||||||||||||||||||||||||||||||
257 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||||||||
259 | p->endNativePainting(); | - | ||||||||||||||||||||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||||||||
262 | void QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State& state, const QVector2D &scaleFactor) | - | ||||||||||||||||||||||||||||||
263 | { | - | ||||||||||||||||||||||||||||||
264 | if (!p)
| 0 | ||||||||||||||||||||||||||||||
265 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||||||||
267 | reset(); | - | ||||||||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||||||||
269 | p->scale(scaleFactor.x(), scaleFactor.y()); | - | ||||||||||||||||||||||||||||||
270 | QTransform originMatrix = p->worldTransform(); | - | ||||||||||||||||||||||||||||||
271 | - | |||||||||||||||||||||||||||||||
272 | QPen pen = makePen(state); | - | ||||||||||||||||||||||||||||||
273 | setPainterState(p, state, pen); | - | ||||||||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||||||||
275 | while (hasNext()) {
| 0 | ||||||||||||||||||||||||||||||
276 | QQuickContext2D::PaintCommand cmd = takeNextCommand(); | - | ||||||||||||||||||||||||||||||
277 | switch (cmd) { | - | ||||||||||||||||||||||||||||||
278 | case QQuickContext2D::UpdateMatrix: never executed: case QQuickContext2D::UpdateMatrix: | 0 | ||||||||||||||||||||||||||||||
279 | { | - | ||||||||||||||||||||||||||||||
280 | state.matrix = takeMatrix(); | - | ||||||||||||||||||||||||||||||
281 | p->setWorldTransform(state.matrix * originMatrix); | - | ||||||||||||||||||||||||||||||
282 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
283 | } | - | ||||||||||||||||||||||||||||||
284 | case QQuickContext2D::ClearRect: never executed: case QQuickContext2D::ClearRect: | 0 | ||||||||||||||||||||||||||||||
285 | { | - | ||||||||||||||||||||||||||||||
286 | QPainter::CompositionMode cm = p->compositionMode(); | - | ||||||||||||||||||||||||||||||
287 | p->setCompositionMode(QPainter::CompositionMode_Clear); | - | ||||||||||||||||||||||||||||||
288 | p->fillRect(takeRect(), Qt::white); | - | ||||||||||||||||||||||||||||||
289 | p->setCompositionMode(cm); | - | ||||||||||||||||||||||||||||||
290 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
291 | } | - | ||||||||||||||||||||||||||||||
292 | case QQuickContext2D::FillRect: never executed: case QQuickContext2D::FillRect: | 0 | ||||||||||||||||||||||||||||||
293 | { | - | ||||||||||||||||||||||||||||||
294 | QRectF r = takeRect(); | - | ||||||||||||||||||||||||||||||
295 | if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor))
| 0 | ||||||||||||||||||||||||||||||
296 | fillRectShadow(p, r, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); never executed: fillRectShadow(p, r, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); | 0 | ||||||||||||||||||||||||||||||
297 | else | - | ||||||||||||||||||||||||||||||
298 | p->fillRect(r, p->brush()); never executed: p->fillRect(r, p->brush()); | 0 | ||||||||||||||||||||||||||||||
299 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
300 | } | - | ||||||||||||||||||||||||||||||
301 | case QQuickContext2D::ShadowColor: never executed: case QQuickContext2D::ShadowColor: | 0 | ||||||||||||||||||||||||||||||
302 | { | - | ||||||||||||||||||||||||||||||
303 | state.shadowColor = takeColor(); | - | ||||||||||||||||||||||||||||||
304 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
305 | } | - | ||||||||||||||||||||||||||||||
306 | case QQuickContext2D::ShadowBlur: never executed: case QQuickContext2D::ShadowBlur: | 0 | ||||||||||||||||||||||||||||||
307 | { | - | ||||||||||||||||||||||||||||||
308 | state.shadowBlur = takeShadowBlur(); | - | ||||||||||||||||||||||||||||||
309 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
310 | } | - | ||||||||||||||||||||||||||||||
311 | case QQuickContext2D::ShadowOffsetX: never executed: case QQuickContext2D::ShadowOffsetX: | 0 | ||||||||||||||||||||||||||||||
312 | { | - | ||||||||||||||||||||||||||||||
313 | state.shadowOffsetX = takeShadowOffsetX(); | - | ||||||||||||||||||||||||||||||
314 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
315 | } | - | ||||||||||||||||||||||||||||||
316 | case QQuickContext2D::ShadowOffsetY: never executed: case QQuickContext2D::ShadowOffsetY: | 0 | ||||||||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||||||||
318 | state.shadowOffsetY = takeShadowOffsetY(); | - | ||||||||||||||||||||||||||||||
319 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
320 | } | - | ||||||||||||||||||||||||||||||
321 | case QQuickContext2D::FillStyle: never executed: case QQuickContext2D::FillStyle: | 0 | ||||||||||||||||||||||||||||||
322 | { | - | ||||||||||||||||||||||||||||||
323 | state.fillStyle = takeFillStyle(); | - | ||||||||||||||||||||||||||||||
324 | state.fillPatternRepeatX = takeBool(); | - | ||||||||||||||||||||||||||||||
325 | state.fillPatternRepeatY = takeBool(); | - | ||||||||||||||||||||||||||||||
326 | p->setBrush(state.fillStyle); | - | ||||||||||||||||||||||||||||||
327 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||||||||
329 | case QQuickContext2D::StrokeStyle: never executed: case QQuickContext2D::StrokeStyle: | 0 | ||||||||||||||||||||||||||||||
330 | { | - | ||||||||||||||||||||||||||||||
331 | state.strokeStyle = takeStrokeStyle(); | - | ||||||||||||||||||||||||||||||
332 | state.strokePatternRepeatX = takeBool(); | - | ||||||||||||||||||||||||||||||
333 | state.strokePatternRepeatY = takeBool(); | - | ||||||||||||||||||||||||||||||
334 | QPen nPen = p->pen(); | - | ||||||||||||||||||||||||||||||
335 | nPen.setBrush(state.strokeStyle); | - | ||||||||||||||||||||||||||||||
336 | p->setPen(nPen); | - | ||||||||||||||||||||||||||||||
337 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||||||||
339 | case QQuickContext2D::LineWidth: never executed: case QQuickContext2D::LineWidth: | 0 | ||||||||||||||||||||||||||||||
340 | { | - | ||||||||||||||||||||||||||||||
341 | state.lineWidth = takeLineWidth(); | - | ||||||||||||||||||||||||||||||
342 | QPen nPen = p->pen(); | - | ||||||||||||||||||||||||||||||
343 | - | |||||||||||||||||||||||||||||||
344 | nPen.setWidthF(state.lineWidth); | - | ||||||||||||||||||||||||||||||
345 | p->setPen(nPen); | - | ||||||||||||||||||||||||||||||
346 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
347 | } | - | ||||||||||||||||||||||||||||||
348 | case QQuickContext2D::LineCap: never executed: case QQuickContext2D::LineCap: | 0 | ||||||||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||||||||
350 | state.lineCap = takeLineCap(); | - | ||||||||||||||||||||||||||||||
351 | QPen nPen = p->pen(); | - | ||||||||||||||||||||||||||||||
352 | nPen.setCapStyle(state.lineCap); | - | ||||||||||||||||||||||||||||||
353 | p->setPen(nPen); | - | ||||||||||||||||||||||||||||||
354 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
355 | } | - | ||||||||||||||||||||||||||||||
356 | case QQuickContext2D::LineJoin: never executed: case QQuickContext2D::LineJoin: | 0 | ||||||||||||||||||||||||||||||
357 | { | - | ||||||||||||||||||||||||||||||
358 | state.lineJoin = takeLineJoin(); | - | ||||||||||||||||||||||||||||||
359 | QPen nPen = p->pen(); | - | ||||||||||||||||||||||||||||||
360 | nPen.setJoinStyle(state.lineJoin); | - | ||||||||||||||||||||||||||||||
361 | p->setPen(nPen); | - | ||||||||||||||||||||||||||||||
362 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||||||||
364 | case QQuickContext2D::MiterLimit: never executed: case QQuickContext2D::MiterLimit: | 0 | ||||||||||||||||||||||||||||||
365 | { | - | ||||||||||||||||||||||||||||||
366 | state.miterLimit = takeMiterLimit(); | - | ||||||||||||||||||||||||||||||
367 | QPen nPen = p->pen(); | - | ||||||||||||||||||||||||||||||
368 | nPen.setMiterLimit(state.miterLimit); | - | ||||||||||||||||||||||||||||||
369 | p->setPen(nPen); | - | ||||||||||||||||||||||||||||||
370 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
371 | } | - | ||||||||||||||||||||||||||||||
372 | case QQuickContext2D::TextAlign: never executed: case QQuickContext2D::TextAlign: | 0 | ||||||||||||||||||||||||||||||
373 | case QQuickContext2D::TextBaseline: never executed: case QQuickContext2D::TextBaseline: | 0 | ||||||||||||||||||||||||||||||
374 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
375 | case QQuickContext2D::Fill: never executed: case QQuickContext2D::Fill: | 0 | ||||||||||||||||||||||||||||||
376 | { | - | ||||||||||||||||||||||||||||||
377 | QPainterPath path = takePath(); | - | ||||||||||||||||||||||||||||||
378 | path.closeSubpath(); | - | ||||||||||||||||||||||||||||||
379 | if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor))
| 0 | ||||||||||||||||||||||||||||||
380 | fillShadowPath(p,path, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); never executed: fillShadowPath(p,path, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); | 0 | ||||||||||||||||||||||||||||||
381 | else | - | ||||||||||||||||||||||||||||||
382 | p->fillPath(path, p->brush()); never executed: p->fillPath(path, p->brush()); | 0 | ||||||||||||||||||||||||||||||
383 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
384 | } | - | ||||||||||||||||||||||||||||||
385 | case QQuickContext2D::Stroke: never executed: case QQuickContext2D::Stroke: | 0 | ||||||||||||||||||||||||||||||
386 | { | - | ||||||||||||||||||||||||||||||
387 | if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor))
| 0 | ||||||||||||||||||||||||||||||
388 | strokeShadowPath(p,takePath(), state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); never executed: strokeShadowPath(p,takePath(), state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); | 0 | ||||||||||||||||||||||||||||||
389 | else | - | ||||||||||||||||||||||||||||||
390 | p->strokePath(takePath(), p->pen()); never executed: p->strokePath(takePath(), p->pen()); | 0 | ||||||||||||||||||||||||||||||
391 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
392 | } | - | ||||||||||||||||||||||||||||||
393 | case QQuickContext2D::Clip: never executed: case QQuickContext2D::Clip: | 0 | ||||||||||||||||||||||||||||||
394 | { | - | ||||||||||||||||||||||||||||||
395 | state.clip = takeBool(); | - | ||||||||||||||||||||||||||||||
396 | state.clipPath = takePath(); | - | ||||||||||||||||||||||||||||||
397 | p->setClipping(state.clip); | - | ||||||||||||||||||||||||||||||
398 | if (state.clip)
| 0 | ||||||||||||||||||||||||||||||
399 | p->setClipPath(state.clipPath); never executed: p->setClipPath(state.clipPath); | 0 | ||||||||||||||||||||||||||||||
400 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
401 | } | - | ||||||||||||||||||||||||||||||
402 | case QQuickContext2D::GlobalAlpha: never executed: case QQuickContext2D::GlobalAlpha: | 0 | ||||||||||||||||||||||||||||||
403 | { | - | ||||||||||||||||||||||||||||||
404 | state.globalAlpha = takeGlobalAlpha(); | - | ||||||||||||||||||||||||||||||
405 | p->setOpacity(state.globalAlpha); | - | ||||||||||||||||||||||||||||||
406 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
407 | } | - | ||||||||||||||||||||||||||||||
408 | case QQuickContext2D::GlobalCompositeOperation: never executed: case QQuickContext2D::GlobalCompositeOperation: | 0 | ||||||||||||||||||||||||||||||
409 | { | - | ||||||||||||||||||||||||||||||
410 | state.globalCompositeOperation = takeGlobalCompositeOperation(); | - | ||||||||||||||||||||||||||||||
411 | p->setCompositionMode(state.globalCompositeOperation); | - | ||||||||||||||||||||||||||||||
412 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||||||||
414 | case QQuickContext2D::DrawImage: never executed: case QQuickContext2D::DrawImage: | 0 | ||||||||||||||||||||||||||||||
415 | { | - | ||||||||||||||||||||||||||||||
416 | QRectF sr = takeRect(); | - | ||||||||||||||||||||||||||||||
417 | QRectF dr = takeRect(); | - | ||||||||||||||||||||||||||||||
418 | qt_drawImage(p, state, takeImage(), sr, dr, HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)); | - | ||||||||||||||||||||||||||||||
419 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
420 | } | - | ||||||||||||||||||||||||||||||
421 | case QQuickContext2D::DrawPixmap: never executed: case QQuickContext2D::DrawPixmap: | 0 | ||||||||||||||||||||||||||||||
422 | { | - | ||||||||||||||||||||||||||||||
423 | QRectF sr = takeRect(); | - | ||||||||||||||||||||||||||||||
424 | QRectF dr = takeRect(); | - | ||||||||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||||||||
426 | QQmlRefPointer<QQuickCanvasPixmap> pix = takePixmap(); | - | ||||||||||||||||||||||||||||||
427 | Q_ASSERT(!pix.isNull()); | - | ||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||
429 | const bool hasShadow = HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor);
| 0 | ||||||||||||||||||||||||||||||
430 | //TODO: generate shadow blur with shaders | - | ||||||||||||||||||||||||||||||
431 | qt_drawImage(p, state, pix->image(), sr, dr, hasShadow); | - | ||||||||||||||||||||||||||||||
432 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
433 | } | - | ||||||||||||||||||||||||||||||
434 | case QQuickContext2D::GetImageData: never executed: case QQuickContext2D::GetImageData: | 0 | ||||||||||||||||||||||||||||||
435 | { | - | ||||||||||||||||||||||||||||||
436 | //TODO: | - | ||||||||||||||||||||||||||||||
437 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||||||||
439 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
440 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
441 | } | - | ||||||||||||||||||||||||||||||
442 | } | - | ||||||||||||||||||||||||||||||
443 | - | |||||||||||||||||||||||||||||||
444 | p->end(); | - | ||||||||||||||||||||||||||||||
445 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||||||||
447 | QQuickContext2DCommandBuffer::QQuickContext2DCommandBuffer() | - | ||||||||||||||||||||||||||||||
448 | : cmdIdx(0) | - | ||||||||||||||||||||||||||||||
449 | , intIdx(0) | - | ||||||||||||||||||||||||||||||
450 | , boolIdx(0) | - | ||||||||||||||||||||||||||||||
451 | , realIdx(0) | - | ||||||||||||||||||||||||||||||
452 | , rectIdx(0) | - | ||||||||||||||||||||||||||||||
453 | , colorIdx(0) | - | ||||||||||||||||||||||||||||||
454 | , matrixIdx(0) | - | ||||||||||||||||||||||||||||||
455 | , brushIdx(0) | - | ||||||||||||||||||||||||||||||
456 | , pathIdx(0) | - | ||||||||||||||||||||||||||||||
457 | , imageIdx(0) | - | ||||||||||||||||||||||||||||||
458 | , pixmapIdx(0) | - | ||||||||||||||||||||||||||||||
459 | { | - | ||||||||||||||||||||||||||||||
460 | static bool registered = false; | - | ||||||||||||||||||||||||||||||
461 | if (!registered) {
| 0 | ||||||||||||||||||||||||||||||
462 | qRegisterMetaType<QQuickContext2DCommandBuffer*>("QQuickContext2DCommandBuffer*"); | - | ||||||||||||||||||||||||||||||
463 | registered = true; | - | ||||||||||||||||||||||||||||||
464 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
465 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||||||||
468 | QQuickContext2DCommandBuffer::~QQuickContext2DCommandBuffer() | - | ||||||||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||||||||
470 | } | - | ||||||||||||||||||||||||||||||
471 | - | |||||||||||||||||||||||||||||||
472 | void QQuickContext2DCommandBuffer::clear() | - | ||||||||||||||||||||||||||||||
473 | { | - | ||||||||||||||||||||||||||||||
474 | commands.clear(); | - | ||||||||||||||||||||||||||||||
475 | ints.clear(); | - | ||||||||||||||||||||||||||||||
476 | bools.clear(); | - | ||||||||||||||||||||||||||||||
477 | reals.clear(); | - | ||||||||||||||||||||||||||||||
478 | rects.clear(); | - | ||||||||||||||||||||||||||||||
479 | colors.clear(); | - | ||||||||||||||||||||||||||||||
480 | matrixes.clear(); | - | ||||||||||||||||||||||||||||||
481 | brushes.clear(); | - | ||||||||||||||||||||||||||||||
482 | pathes.clear(); | - | ||||||||||||||||||||||||||||||
483 | images.clear(); | - | ||||||||||||||||||||||||||||||
484 | pixmaps.clear(); | - | ||||||||||||||||||||||||||||||
485 | reset(); | - | ||||||||||||||||||||||||||||||
486 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||||||||
488 | void QQuickContext2DCommandBuffer::reset() | - | ||||||||||||||||||||||||||||||
489 | { | - | ||||||||||||||||||||||||||||||
490 | cmdIdx = 0; | - | ||||||||||||||||||||||||||||||
491 | intIdx = 0; | - | ||||||||||||||||||||||||||||||
492 | boolIdx = 0; | - | ||||||||||||||||||||||||||||||
493 | realIdx = 0; | - | ||||||||||||||||||||||||||||||
494 | rectIdx = 0; | - | ||||||||||||||||||||||||||||||
495 | colorIdx = 0; | - | ||||||||||||||||||||||||||||||
496 | matrixIdx = 0; | - | ||||||||||||||||||||||||||||||
497 | brushIdx = 0; | - | ||||||||||||||||||||||||||||||
498 | pathIdx = 0; | - | ||||||||||||||||||||||||||||||
499 | imageIdx = 0; | - | ||||||||||||||||||||||||||||||
500 | pixmapIdx = 0; | - | ||||||||||||||||||||||||||||||
501 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||||||||
503 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |