author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenVG module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qpaintengine_vg_p.h" |
|
43 |
#include "qpixmapdata_vg_p.h" |
|
44 |
#include "qpixmapfilter_vg_p.h" |
|
45 |
#include "qvgcompositionhelper_p.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
#include "qvgimagepool_p.h" |
0 | 47 |
#if !defined(QT_NO_EGL) |
48 |
#include <QtGui/private/qegl_p.h> |
|
49 |
#include "qwindowsurface_vgegl_p.h" |
|
50 |
#endif |
|
51 |
#include <QtCore/qvarlengtharray.h> |
|
52 |
#include <QtGui/private/qdrawhelper_p.h> |
|
53 |
#include <QtGui/private/qtextureglyphcache_p.h> |
|
54 |
#include <QtGui/private/qtextengine_p.h> |
|
55 |
#include <QtGui/private/qfontengine_p.h> |
|
56 |
#include <QtGui/private/qpainterpath_p.h> |
|
57 |
#include <QDebug> |
|
58 |
#include <QSet> |
|
59 |
||
60 |
QT_BEGIN_NAMESPACE |
|
61 |
||
62 |
// vgDrawGlyphs() only exists in OpenVG 1.1 and higher. |
|
63 |
#if !defined(OPENVG_VERSION_1_1) && !defined(QVG_NO_DRAW_GLYPHS) |
|
64 |
#define QVG_NO_DRAW_GLYPHS 1 |
|
65 |
#endif |
|
66 |
||
67 |
// vgRenderToMask() only exists in OpenVG 1.1 and higher. |
|
68 |
// Also, disable masking completely if we are using the scissor to clip. |
|
69 |
#if !defined(OPENVG_VERSION_1_1) && !defined(QVG_NO_RENDER_TO_MASK) |
|
70 |
#define QVG_NO_RENDER_TO_MASK 1 |
|
71 |
#endif |
|
72 |
#if defined(QVG_SCISSOR_CLIP) && !defined(QVG_NO_RENDER_TO_MASK) |
|
73 |
#define QVG_NO_RENDER_TO_MASK 1 |
|
74 |
#endif |
|
75 |
||
76 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
77 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
78 |
Q_DECL_IMPORT extern int qt_defaultDpiX(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
79 |
Q_DECL_IMPORT extern int qt_defaultDpiY(); |
0 | 80 |
|
81 |
class QVGPaintEnginePrivate; |
|
82 |
||
83 |
class QVGFontGlyphCache |
|
84 |
{ |
|
85 |
public: |
|
86 |
QVGFontGlyphCache(); |
|
87 |
~QVGFontGlyphCache(); |
|
88 |
||
89 |
void cacheGlyphs(QVGPaintEnginePrivate *d, |
|
90 |
const QTextItemInt &ti, |
|
91 |
const QVarLengthArray<glyph_t> &glyphs); |
|
92 |
void setScaleFromText(const QTextItemInt &ti); |
|
93 |
||
94 |
VGFont font; |
|
95 |
VGfloat scaleX; |
|
96 |
VGfloat scaleY; |
|
97 |
||
98 |
uint cachedGlyphsMask[256 / 32]; |
|
99 |
QSet<glyph_t> cachedGlyphs; |
|
100 |
}; |
|
101 |
||
102 |
typedef QHash<QFontEngine*, QVGFontGlyphCache*> QVGFontCache; |
|
103 |
||
104 |
#endif |
|
105 |
||
106 |
class QVGFontEngineCleaner : public QObject |
|
107 |
{ |
|
108 |
Q_OBJECT |
|
109 |
public: |
|
110 |
QVGFontEngineCleaner(QVGPaintEnginePrivate *d); |
|
111 |
~QVGFontEngineCleaner(); |
|
112 |
||
113 |
public slots: |
|
114 |
void fontEngineDestroyed(); |
|
115 |
||
116 |
private: |
|
117 |
QVGPaintEnginePrivate *d_ptr; |
|
118 |
}; |
|
119 |
||
120 |
class QVGPaintEnginePrivate : public QPaintEngineExPrivate |
|
121 |
{ |
|
122 |
public: |
|
123 |
QVGPaintEnginePrivate(); |
|
124 |
~QVGPaintEnginePrivate(); |
|
125 |
||
126 |
void init(); |
|
127 |
void initObjects(); |
|
128 |
void destroy(); |
|
129 |
void setTransform(VGMatrixMode mode, const QTransform& transform); |
|
130 |
void updateTransform(QPaintDevice *pdev); |
|
131 |
void draw(VGPath path, const QPen& pen, const QBrush& brush, VGint rule = VG_EVEN_ODD); |
|
132 |
void stroke(VGPath path, const QPen& pen); |
|
133 |
void fill(VGPath path, const QBrush& brush, VGint rule = VG_EVEN_ODD); |
|
134 |
VGPath vectorPathToVGPath(const QVectorPath& path); |
|
135 |
VGPath painterPathToVGPath(const QPainterPath& path); |
|
136 |
VGPath roundedRectPath(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode); |
|
137 |
VGPaintType setBrush |
|
138 |
(VGPaint paint, const QBrush& brush, VGMatrixMode mode, |
|
139 |
VGPaintType prevPaintType); |
|
140 |
void setPenParams(const QPen& pen); |
|
141 |
void setBrushTransform(const QBrush& brush, VGMatrixMode mode); |
|
142 |
void setupColorRamp(const QGradient *grad, VGPaint paint); |
|
143 |
void setImageOptions(); |
|
144 |
#if !defined(QVG_SCISSOR_CLIP) |
|
145 |
void ensureMask(QVGPaintEngine *engine, int width, int height); |
|
146 |
void modifyMask |
|
147 |
(QVGPaintEngine *engine, VGMaskOperation op, const QRegion& region); |
|
148 |
void modifyMask |
|
149 |
(QVGPaintEngine *engine, VGMaskOperation op, const QRect& rect); |
|
150 |
#endif |
|
151 |
||
152 |
VGint maxScissorRects; // Maximum scissor rectangles for clipping. |
|
153 |
||
154 |
VGPaint penPaint; // Paint for currently active pen. |
|
155 |
VGPaint brushPaint; // Paint for currently active brush. |
|
156 |
VGPaint opacityPaint; // Paint for drawing images with opacity. |
|
157 |
VGPaint fillPaint; // Current fill paint that is active. |
|
158 |
||
159 |
QPen currentPen; // Current pen set in "penPaint". |
|
160 |
QBrush currentBrush; // Current brush set in "brushPaint". |
|
161 |
||
162 |
bool forcePenChange; // Force a pen change, even if the same. |
|
163 |
bool forceBrushChange; // Force a brush change, even if the same. |
|
164 |
||
165 |
VGPaintType penType; // Type of the last pen that was set. |
|
166 |
VGPaintType brushType; // Type of the last brush that was set. |
|
167 |
||
168 |
QPointF brushOrigin; // Current brush origin. |
|
169 |
||
170 |
VGint fillRule; // Last fill rule that was set. |
|
171 |
||
172 |
qreal opacity; // Current drawing opacity. |
|
173 |
qreal paintOpacity; // Opacity in opacityPaint. |
|
174 |
||
175 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
176 |
VGPath rectPath; // Cached path for quick drawing of rectangles. |
|
177 |
VGPath linePath; // Cached path for quick drawing of lines. |
|
178 |
VGPath roundRectPath; // Cached path for quick drawing of rounded rects. |
|
179 |
#endif |
|
180 |
||
181 |
QTransform transform; // Currently active transform. |
|
182 |
bool simpleTransform; // True if the transform is simple (non-projective). |
|
183 |
qreal penScale; // Pen scaling factor from "transform". |
|
184 |
||
185 |
QTransform pathTransform; // Calculated VG path transformation. |
|
186 |
QTransform imageTransform; // Calculated VG image transformation. |
|
187 |
bool pathTransformSet; // True if path transform set in the VG context. |
|
188 |
||
189 |
bool maskValid; // True if vgMask() contains valid data. |
|
190 |
bool maskIsSet; // True if mask would be fully set if it was valid. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
191 |
bool scissorMask; // True if scissor is used in place of the mask. |
0 | 192 |
bool rawVG; // True if processing a raw VG escape. |
193 |
||
194 |
QRect maskRect; // Rectangle version of mask if it is simple. |
|
195 |
||
196 |
QTransform penTransform; // Transform for the pen. |
|
197 |
QTransform brushTransform; // Transform for the brush. |
|
198 |
||
199 |
VGMatrixMode matrixMode; // Last matrix mode that was set. |
|
200 |
VGImageMode imageMode; // Last image mode that was set. |
|
201 |
||
202 |
QRegion scissorRegion; // Currently active scissor region. |
|
203 |
bool scissorActive; // True if scissor region is active. |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
204 |
bool scissorDirty; // True if scissor is dirty after native painting. |
0 | 205 |
|
206 |
QPaintEngine::DirtyFlags dirty; |
|
207 |
||
208 |
QColor clearColor; // Last clear color that was set. |
|
209 |
VGfloat clearOpacity; // Opacity during the last clear. |
|
210 |
||
211 |
VGBlendMode blendMode; // Active blend mode. |
|
212 |
VGRenderingQuality renderingQuality; // Active rendering quality. |
|
213 |
VGImageQuality imageQuality; // Active image quality. |
|
214 |
||
215 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
216 |
QVGFontCache fontCache; |
|
217 |
QVGFontEngineCleaner *fontEngineCleaner; |
|
218 |
#endif |
|
219 |
||
220 |
QScopedPointer<QPixmapFilter> convolutionFilter; |
|
221 |
QScopedPointer<QPixmapFilter> colorizeFilter; |
|
222 |
QScopedPointer<QPixmapFilter> dropShadowFilter; |
|
223 |
QScopedPointer<QPixmapFilter> blurFilter; |
|
224 |
||
225 |
// Ensure that the path transform is properly set in the VG context |
|
226 |
// before we perform a vgDrawPath() operation. |
|
227 |
inline void ensurePathTransform() |
|
228 |
{ |
|
229 |
if (!pathTransformSet) { |
|
230 |
setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, pathTransform); |
|
231 |
pathTransformSet = true; |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
// Ensure that a specific pen has been set into penPaint. |
|
236 |
inline void ensurePen(const QPen& pen) { |
|
237 |
if (forcePenChange || pen != currentPen) { |
|
238 |
currentPen = pen; |
|
239 |
forcePenChange = false; |
|
240 |
penType = setBrush |
|
241 |
(penPaint, pen.brush(), |
|
242 |
VG_MATRIX_STROKE_PAINT_TO_USER, penType); |
|
243 |
setPenParams(pen); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
// Ensure that a specific brush has been set into brushPaint. |
|
248 |
inline void ensureBrush(const QBrush& brush) { |
|
249 |
if (forceBrushChange || brush != currentBrush) { |
|
250 |
currentBrush = brush; |
|
251 |
forceBrushChange = false; |
|
252 |
brushType = setBrush |
|
253 |
(brushPaint, brush, VG_MATRIX_FILL_PAINT_TO_USER, brushType); |
|
254 |
} |
|
255 |
if (fillPaint != brushPaint) { |
|
256 |
vgSetPaint(brushPaint, VG_FILL_PATH); |
|
257 |
fillPaint = brushPaint; |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
// Set various modes, but only if different. |
|
262 |
inline void setImageMode(VGImageMode mode); |
|
263 |
inline void setRenderingQuality(VGRenderingQuality mode); |
|
264 |
inline void setImageQuality(VGImageQuality mode); |
|
265 |
inline void setBlendMode(VGBlendMode mode); |
|
266 |
inline void setFillRule(VGint mode); |
|
267 |
||
268 |
// Clear all lazily-set modes. |
|
269 |
void clearModes(); |
|
270 |
}; |
|
271 |
||
272 |
inline void QVGPaintEnginePrivate::setImageMode(VGImageMode mode) |
|
273 |
{ |
|
274 |
if (imageMode != mode) { |
|
275 |
imageMode = mode; |
|
276 |
vgSeti(VG_IMAGE_MODE, mode); |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
inline void QVGPaintEnginePrivate::setRenderingQuality(VGRenderingQuality mode) |
|
281 |
{ |
|
282 |
if (renderingQuality != mode) { |
|
283 |
vgSeti(VG_RENDERING_QUALITY, mode); |
|
284 |
renderingQuality = mode; |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
inline void QVGPaintEnginePrivate::setImageQuality(VGImageQuality mode) |
|
289 |
{ |
|
290 |
if (imageQuality != mode) { |
|
291 |
vgSeti(VG_IMAGE_QUALITY, mode); |
|
292 |
imageQuality = mode; |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
inline void QVGPaintEnginePrivate::setBlendMode(VGBlendMode mode) |
|
297 |
{ |
|
298 |
if (blendMode != mode) { |
|
299 |
vgSeti(VG_BLEND_MODE, mode); |
|
300 |
blendMode = mode; |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
inline void QVGPaintEnginePrivate::setFillRule(VGint mode) |
|
305 |
{ |
|
306 |
if (fillRule != mode) { |
|
307 |
fillRule = mode; |
|
308 |
vgSeti(VG_FILL_RULE, mode); |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
void QVGPaintEnginePrivate::clearModes() |
|
313 |
{ |
|
314 |
matrixMode = (VGMatrixMode)0; |
|
315 |
imageMode = (VGImageMode)0; |
|
316 |
blendMode = (VGBlendMode)0; |
|
317 |
renderingQuality = (VGRenderingQuality)0; |
|
318 |
imageQuality = (VGImageQuality)0; |
|
319 |
} |
|
320 |
||
321 |
QVGPaintEnginePrivate::QVGPaintEnginePrivate() |
|
322 |
{ |
|
323 |
init(); |
|
324 |
} |
|
325 |
||
326 |
void QVGPaintEnginePrivate::init() |
|
327 |
{ |
|
328 |
maxScissorRects = 0; |
|
329 |
||
330 |
penPaint = 0; |
|
331 |
brushPaint = 0; |
|
332 |
opacityPaint = 0; |
|
333 |
fillPaint = 0; |
|
334 |
||
335 |
forcePenChange = true; |
|
336 |
forceBrushChange = true; |
|
337 |
penType = (VGPaintType)0; |
|
338 |
brushType = (VGPaintType)0; |
|
339 |
||
340 |
brushOrigin = QPointF(0.0f, 0.0f); |
|
341 |
||
342 |
fillRule = 0; |
|
343 |
||
344 |
opacity = 1.0; |
|
345 |
paintOpacity = 1.0f; |
|
346 |
||
347 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
348 |
rectPath = 0; |
|
349 |
linePath = 0; |
|
350 |
roundRectPath = 0; |
|
351 |
#endif |
|
352 |
||
353 |
simpleTransform = true; |
|
354 |
pathTransformSet = false; |
|
355 |
penScale = 1.0; |
|
356 |
||
357 |
maskValid = false; |
|
358 |
maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
359 |
scissorMask = false; |
0 | 360 |
rawVG = false; |
361 |
||
362 |
scissorActive = false; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
363 |
scissorDirty = false; |
0 | 364 |
|
365 |
dirty = 0; |
|
366 |
||
367 |
clearOpacity = 1.0f; |
|
368 |
||
369 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
370 |
fontEngineCleaner = 0; |
|
371 |
#endif |
|
372 |
||
373 |
clearModes(); |
|
374 |
} |
|
375 |
||
376 |
QVGPaintEnginePrivate::~QVGPaintEnginePrivate() |
|
377 |
{ |
|
378 |
destroy(); |
|
379 |
} |
|
380 |
||
381 |
void QVGPaintEnginePrivate::initObjects() |
|
382 |
{ |
|
383 |
maxScissorRects = vgGeti(VG_MAX_SCISSOR_RECTS); |
|
384 |
||
385 |
penPaint = vgCreatePaint(); |
|
386 |
vgSetParameteri(penPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
387 |
vgSetPaint(penPaint, VG_STROKE_PATH); |
|
388 |
||
389 |
vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER); |
|
390 |
vgLoadIdentity(); |
|
391 |
||
392 |
brushPaint = vgCreatePaint(); |
|
393 |
vgSetParameteri(brushPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
394 |
vgSetPaint(brushPaint, VG_FILL_PATH); |
|
395 |
fillPaint = brushPaint; |
|
396 |
||
397 |
vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); |
|
398 |
vgLoadIdentity(); |
|
399 |
matrixMode = VG_MATRIX_FILL_PAINT_TO_USER; |
|
400 |
||
401 |
opacityPaint = vgCreatePaint(); |
|
402 |
vgSetParameteri(opacityPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
403 |
VGfloat values[4]; |
|
404 |
values[0] = 1.0f; |
|
405 |
values[1] = 1.0f; |
|
406 |
values[2] = 1.0f; |
|
407 |
values[3] = paintOpacity; |
|
408 |
vgSetParameterfv(opacityPaint, VG_PAINT_COLOR, 4, values); |
|
409 |
||
410 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
411 |
// Create a dummy path for rectangle drawing, which we can |
|
412 |
// modify later with vgModifyPathCoords(). This should be |
|
413 |
// faster than constantly creating and destroying paths. |
|
414 |
rectPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
415 |
VG_PATH_DATATYPE_F, |
|
416 |
1.0f, // scale |
|
417 |
0.0f, // bias |
|
418 |
5, // segmentCapacityHint |
|
419 |
8, // coordCapacityHint |
|
420 |
VG_PATH_CAPABILITY_ALL); |
|
421 |
static VGubyte const segments[5] = { |
|
422 |
VG_MOVE_TO_ABS, |
|
423 |
VG_LINE_TO_ABS, |
|
424 |
VG_LINE_TO_ABS, |
|
425 |
VG_LINE_TO_ABS, |
|
426 |
VG_CLOSE_PATH |
|
427 |
}; |
|
428 |
VGfloat coords[8]; |
|
429 |
coords[0] = 0.0f; |
|
430 |
coords[1] = 0.0f; |
|
431 |
coords[2] = 100.0f; |
|
432 |
coords[3] = coords[1]; |
|
433 |
coords[4] = coords[2]; |
|
434 |
coords[5] = 100.0f; |
|
435 |
coords[6] = coords[0]; |
|
436 |
coords[7] = coords[5]; |
|
437 |
vgAppendPathData(rectPath, 5, segments, coords); |
|
438 |
||
439 |
// Create a dummy line drawing path as well. |
|
440 |
linePath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
441 |
VG_PATH_DATATYPE_F, |
|
442 |
1.0f, // scale |
|
443 |
0.0f, // bias |
|
444 |
2, // segmentCapacityHint |
|
445 |
4, // coordCapacityHint |
|
446 |
VG_PATH_CAPABILITY_ALL); |
|
447 |
vgAppendPathData(linePath, 2, segments, coords); |
|
448 |
#endif |
|
449 |
} |
|
450 |
||
451 |
void QVGPaintEnginePrivate::destroy() |
|
452 |
{ |
|
453 |
if (penPaint) |
|
454 |
vgDestroyPaint(penPaint); |
|
455 |
if (brushPaint) |
|
456 |
vgDestroyPaint(brushPaint); |
|
457 |
if (opacityPaint) |
|
458 |
vgDestroyPaint(opacityPaint); |
|
459 |
||
460 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
461 |
if (rectPath) |
|
462 |
vgDestroyPath(rectPath); |
|
463 |
if (linePath) |
|
464 |
vgDestroyPath(linePath); |
|
465 |
if (roundRectPath) |
|
466 |
vgDestroyPath(roundRectPath); |
|
467 |
#endif |
|
468 |
||
469 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
470 |
QVGFontCache::Iterator it; |
|
471 |
for (it = fontCache.begin(); it != fontCache.end(); ++it) |
|
472 |
delete it.value(); |
|
473 |
fontCache.clear(); |
|
474 |
delete fontEngineCleaner; |
|
475 |
#endif |
|
476 |
} |
|
477 |
||
478 |
// Set a specific VG transformation matrix in the current VG context. |
|
479 |
void QVGPaintEnginePrivate::setTransform |
|
480 |
(VGMatrixMode mode, const QTransform& transform) |
|
481 |
{ |
|
482 |
VGfloat mat[9]; |
|
483 |
if (mode != matrixMode) { |
|
484 |
vgSeti(VG_MATRIX_MODE, mode); |
|
485 |
matrixMode = mode; |
|
486 |
} |
|
487 |
mat[0] = transform.m11(); |
|
488 |
mat[1] = transform.m12(); |
|
489 |
mat[2] = transform.m13(); |
|
490 |
mat[3] = transform.m21(); |
|
491 |
mat[4] = transform.m22(); |
|
492 |
mat[5] = transform.m23(); |
|
493 |
mat[6] = transform.m31(); |
|
494 |
mat[7] = transform.m32(); |
|
495 |
mat[8] = transform.m33(); |
|
496 |
vgLoadMatrix(mat); |
|
497 |
} |
|
498 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
499 |
Q_DECL_IMPORT extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); |
0 | 500 |
|
501 |
void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) |
|
502 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
503 |
VGfloat devh = pdev->height(); |
0 | 504 |
|
505 |
// Construct the VG transform by combining the Qt transform with |
|
506 |
// the following viewport transformation: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
507 |
// | 1 0 0 | |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
508 |
// | 0 -1 devh | |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
509 |
// | 0 0 1 | |
0 | 510 |
// The full VG transform is effectively: |
511 |
// 1. Apply the user's transformation matrix. |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
512 |
// 2. Flip the co-ordinate system upside down. |
0 | 513 |
QTransform viewport(1.0f, 0.0f, 0.0f, |
514 |
0.0f, -1.0f, 0.0f, |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
515 |
0.0f, devh, 1.0f); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
516 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
517 |
// Compute the path transform and determine if it is projective. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
518 |
pathTransform = transform * viewport; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
519 |
bool projective = (pathTransform.m13() != 0.0f || |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
520 |
pathTransform.m23() != 0.0f || |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
521 |
pathTransform.m33() != 1.0f); |
0 | 522 |
if (projective) { |
523 |
// The engine cannot do projective path transforms for us, |
|
524 |
// so we will have to convert the co-ordinates ourselves. |
|
525 |
// Change the matrix to just the viewport transformation. |
|
526 |
pathTransform = viewport; |
|
527 |
simpleTransform = false; |
|
528 |
} else { |
|
529 |
simpleTransform = true; |
|
530 |
} |
|
531 |
pathTransformSet = false; |
|
532 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
533 |
// The image transform is always the full transformation, |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
534 |
imageTransform = transform * viewport; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
535 |
|
0 | 536 |
// Calculate the scaling factor to use for turning cosmetic pens |
537 |
// into ordinary non-cosmetic pens. |
|
538 |
qt_scaleForTransform(transform, &penScale); |
|
539 |
} |
|
540 |
||
541 |
VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path) |
|
542 |
{ |
|
543 |
int count = path.elementCount(); |
|
544 |
const qreal *points = path.points(); |
|
545 |
const QPainterPath::ElementType *elements = path.elements(); |
|
546 |
||
547 |
VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
548 |
VG_PATH_DATATYPE_F, |
|
549 |
1.0f, // scale |
|
550 |
0.0f, // bias |
|
551 |
count + 1, // segmentCapacityHint |
|
552 |
count * 2, // coordCapacityHint |
|
553 |
VG_PATH_CAPABILITY_ALL); |
|
554 |
||
555 |
// Size is sufficient segments for drawRoundedRect() paths. |
|
556 |
QVarLengthArray<VGubyte, 20> segments; |
|
557 |
||
558 |
if (sizeof(qreal) == sizeof(VGfloat) && elements && simpleTransform) { |
|
559 |
// If Qt was compiled with qreal the same size as VGfloat, |
|
560 |
// then convert the segment types and use the incoming |
|
561 |
// points array directly. |
|
562 |
for (int i = 0; i < count; ++i) { |
|
563 |
switch (elements[i]) { |
|
564 |
||
565 |
case QPainterPath::MoveToElement: |
|
566 |
segments.append(VG_MOVE_TO_ABS); break; |
|
567 |
||
568 |
case QPainterPath::LineToElement: |
|
569 |
segments.append(VG_LINE_TO_ABS); break; |
|
570 |
||
571 |
case QPainterPath::CurveToElement: |
|
572 |
segments.append(VG_CUBIC_TO_ABS); break; |
|
573 |
||
574 |
case QPainterPath::CurveToDataElement: break; |
|
575 |
||
576 |
} |
|
577 |
} |
|
578 |
if (path.hasImplicitClose()) |
|
579 |
segments.append(VG_CLOSE_PATH); |
|
580 |
||
581 |
vgAppendPathData(vgpath, segments.count(), segments.constData(), |
|
582 |
reinterpret_cast<const VGfloat *>(points)); |
|
583 |
||
584 |
return vgpath; |
|
585 |
} |
|
586 |
||
587 |
// Sizes chosen so that drawRoundedRect() paths fit in these arrays. |
|
588 |
QVarLengthArray<VGfloat, 48> coords; |
|
589 |
||
590 |
int curvePos = 0; |
|
591 |
QPointF temp; |
|
592 |
||
593 |
if (elements && simpleTransform) { |
|
594 |
// Convert the members of the element array. |
|
595 |
for (int i = 0; i < count; ++i) { |
|
596 |
switch (elements[i]) { |
|
597 |
||
598 |
case QPainterPath::MoveToElement: |
|
599 |
{ |
|
600 |
coords.append(points[0]); |
|
601 |
coords.append(points[1]); |
|
602 |
segments.append(VG_MOVE_TO_ABS); |
|
603 |
} |
|
604 |
break; |
|
605 |
||
606 |
case QPainterPath::LineToElement: |
|
607 |
{ |
|
608 |
coords.append(points[0]); |
|
609 |
coords.append(points[1]); |
|
610 |
segments.append(VG_LINE_TO_ABS); |
|
611 |
} |
|
612 |
break; |
|
613 |
||
614 |
case QPainterPath::CurveToElement: |
|
615 |
{ |
|
616 |
coords.append(points[0]); |
|
617 |
coords.append(points[1]); |
|
618 |
curvePos = 2; |
|
619 |
} |
|
620 |
break; |
|
621 |
||
622 |
case QPainterPath::CurveToDataElement: |
|
623 |
{ |
|
624 |
coords.append(points[0]); |
|
625 |
coords.append(points[1]); |
|
626 |
curvePos += 2; |
|
627 |
if (curvePos == 6) { |
|
628 |
curvePos = 0; |
|
629 |
segments.append(VG_CUBIC_TO_ABS); |
|
630 |
} |
|
631 |
} |
|
632 |
break; |
|
633 |
||
634 |
} |
|
635 |
points += 2; |
|
636 |
} |
|
637 |
} else if (elements && !simpleTransform) { |
|
638 |
// Convert the members of the element array after applying the |
|
639 |
// current transform to the path locally. |
|
640 |
for (int i = 0; i < count; ++i) { |
|
641 |
switch (elements[i]) { |
|
642 |
||
643 |
case QPainterPath::MoveToElement: |
|
644 |
{ |
|
645 |
temp = transform.map(QPointF(points[0], points[1])); |
|
646 |
coords.append(temp.x()); |
|
647 |
coords.append(temp.y()); |
|
648 |
segments.append(VG_MOVE_TO_ABS); |
|
649 |
} |
|
650 |
break; |
|
651 |
||
652 |
case QPainterPath::LineToElement: |
|
653 |
{ |
|
654 |
temp = transform.map(QPointF(points[0], points[1])); |
|
655 |
coords.append(temp.x()); |
|
656 |
coords.append(temp.y()); |
|
657 |
segments.append(VG_LINE_TO_ABS); |
|
658 |
} |
|
659 |
break; |
|
660 |
||
661 |
case QPainterPath::CurveToElement: |
|
662 |
{ |
|
663 |
temp = transform.map(QPointF(points[0], points[1])); |
|
664 |
coords.append(temp.x()); |
|
665 |
coords.append(temp.y()); |
|
666 |
curvePos = 2; |
|
667 |
} |
|
668 |
break; |
|
669 |
||
670 |
case QPainterPath::CurveToDataElement: |
|
671 |
{ |
|
672 |
temp = transform.map(QPointF(points[0], points[1])); |
|
673 |
coords.append(temp.x()); |
|
674 |
coords.append(temp.y()); |
|
675 |
curvePos += 2; |
|
676 |
if (curvePos == 6) { |
|
677 |
curvePos = 0; |
|
678 |
segments.append(VG_CUBIC_TO_ABS); |
|
679 |
} |
|
680 |
} |
|
681 |
break; |
|
682 |
||
683 |
} |
|
684 |
points += 2; |
|
685 |
} |
|
686 |
} else if (count > 0 && simpleTransform) { |
|
687 |
// If there is no element array, then the path is assumed |
|
688 |
// to be a MoveTo followed by several LineTo's. |
|
689 |
coords.append(points[0]); |
|
690 |
coords.append(points[1]); |
|
691 |
segments.append(VG_MOVE_TO_ABS); |
|
692 |
while (count > 1) { |
|
693 |
points += 2; |
|
694 |
coords.append(points[0]); |
|
695 |
coords.append(points[1]); |
|
696 |
segments.append(VG_LINE_TO_ABS); |
|
697 |
--count; |
|
698 |
} |
|
699 |
} else if (count > 0 && !simpleTransform) { |
|
700 |
// Convert a simple path, and apply the transform locally. |
|
701 |
temp = transform.map(QPointF(points[0], points[1])); |
|
702 |
coords.append(temp.x()); |
|
703 |
coords.append(temp.y()); |
|
704 |
segments.append(VG_MOVE_TO_ABS); |
|
705 |
while (count > 1) { |
|
706 |
points += 2; |
|
707 |
temp = transform.map(QPointF(points[0], points[1])); |
|
708 |
coords.append(temp.x()); |
|
709 |
coords.append(temp.y()); |
|
710 |
segments.append(VG_LINE_TO_ABS); |
|
711 |
--count; |
|
712 |
} |
|
713 |
} |
|
714 |
||
715 |
// Close the path if specified. |
|
716 |
if (path.hasImplicitClose()) |
|
717 |
segments.append(VG_CLOSE_PATH); |
|
718 |
||
719 |
vgAppendPathData(vgpath, segments.count(), |
|
720 |
segments.constData(), coords.constData()); |
|
721 |
||
722 |
return vgpath; |
|
723 |
} |
|
724 |
||
725 |
VGPath QVGPaintEnginePrivate::painterPathToVGPath(const QPainterPath& path) |
|
726 |
{ |
|
727 |
int count = path.elementCount(); |
|
728 |
||
729 |
VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
730 |
VG_PATH_DATATYPE_F, |
|
731 |
1.0f, // scale |
|
732 |
0.0f, // bias |
|
733 |
count + 1, // segmentCapacityHint |
|
734 |
count * 2, // coordCapacityHint |
|
735 |
VG_PATH_CAPABILITY_ALL); |
|
736 |
||
737 |
if (count == 0) |
|
738 |
return vgpath; |
|
739 |
||
740 |
const QPainterPath::Element *elements = &(path.elementAt(0)); |
|
741 |
||
742 |
// Sizes chosen so that drawRoundedRect() paths fit in these arrays. |
|
743 |
QVarLengthArray<VGfloat, 48> coords; |
|
744 |
QVarLengthArray<VGubyte, 20> segments; |
|
745 |
||
746 |
int curvePos = 0; |
|
747 |
QPointF temp; |
|
748 |
||
749 |
// Keep track of the start and end of each sub-path. QPainterPath |
|
750 |
// does not have an "implicit close" flag like QVectorPath does. |
|
751 |
// We therefore have to detect closed paths by looking for a LineTo |
|
752 |
// element that connects back to the initial MoveTo element. |
|
753 |
qreal startx = 0.0; |
|
754 |
qreal starty = 0.0; |
|
755 |
qreal endx = 0.0; |
|
756 |
qreal endy = 0.0; |
|
757 |
bool haveStart = false; |
|
758 |
bool haveEnd = false; |
|
759 |
||
760 |
if (simpleTransform) { |
|
761 |
// Convert the members of the element array. |
|
762 |
for (int i = 0; i < count; ++i) { |
|
763 |
switch (elements[i].type) { |
|
764 |
||
765 |
case QPainterPath::MoveToElement: |
|
766 |
{ |
|
767 |
if (haveStart && haveEnd && startx == endx && starty == endy) { |
|
768 |
// Implicitly close the previous sub-path. |
|
769 |
segments.append(VG_CLOSE_PATH); |
|
770 |
} |
|
771 |
startx = elements[i].x; |
|
772 |
starty = elements[i].y; |
|
773 |
coords.append(startx); |
|
774 |
coords.append(starty); |
|
775 |
haveStart = true; |
|
776 |
haveEnd = false; |
|
777 |
segments.append(VG_MOVE_TO_ABS); |
|
778 |
} |
|
779 |
break; |
|
780 |
||
781 |
case QPainterPath::LineToElement: |
|
782 |
{ |
|
783 |
endx = elements[i].x; |
|
784 |
endy = elements[i].y; |
|
785 |
coords.append(endx); |
|
786 |
coords.append(endy); |
|
787 |
haveEnd = true; |
|
788 |
segments.append(VG_LINE_TO_ABS); |
|
789 |
} |
|
790 |
break; |
|
791 |
||
792 |
case QPainterPath::CurveToElement: |
|
793 |
{ |
|
794 |
coords.append(elements[i].x); |
|
795 |
coords.append(elements[i].y); |
|
796 |
haveEnd = false; |
|
797 |
curvePos = 2; |
|
798 |
} |
|
799 |
break; |
|
800 |
||
801 |
case QPainterPath::CurveToDataElement: |
|
802 |
{ |
|
803 |
coords.append(elements[i].x); |
|
804 |
coords.append(elements[i].y); |
|
805 |
haveEnd = false; |
|
806 |
curvePos += 2; |
|
807 |
if (curvePos == 6) { |
|
808 |
curvePos = 0; |
|
809 |
segments.append(VG_CUBIC_TO_ABS); |
|
810 |
} |
|
811 |
} |
|
812 |
break; |
|
813 |
||
814 |
} |
|
815 |
} |
|
816 |
} else { |
|
817 |
// Convert the members of the element array after applying the |
|
818 |
// current transform to the path locally. |
|
819 |
for (int i = 0; i < count; ++i) { |
|
820 |
switch (elements[i].type) { |
|
821 |
||
822 |
case QPainterPath::MoveToElement: |
|
823 |
{ |
|
824 |
if (haveStart && haveEnd && startx == endx && starty == endy) { |
|
825 |
// Implicitly close the previous sub-path. |
|
826 |
segments.append(VG_CLOSE_PATH); |
|
827 |
} |
|
828 |
temp = transform.map(QPointF(elements[i].x, elements[i].y)); |
|
829 |
startx = temp.x(); |
|
830 |
starty = temp.y(); |
|
831 |
coords.append(startx); |
|
832 |
coords.append(starty); |
|
833 |
haveStart = true; |
|
834 |
haveEnd = false; |
|
835 |
segments.append(VG_MOVE_TO_ABS); |
|
836 |
} |
|
837 |
break; |
|
838 |
||
839 |
case QPainterPath::LineToElement: |
|
840 |
{ |
|
841 |
temp = transform.map(QPointF(elements[i].x, elements[i].y)); |
|
842 |
endx = temp.x(); |
|
843 |
endy = temp.y(); |
|
844 |
coords.append(endx); |
|
845 |
coords.append(endy); |
|
846 |
haveEnd = true; |
|
847 |
segments.append(VG_LINE_TO_ABS); |
|
848 |
} |
|
849 |
break; |
|
850 |
||
851 |
case QPainterPath::CurveToElement: |
|
852 |
{ |
|
853 |
temp = transform.map(QPointF(elements[i].x, elements[i].y)); |
|
854 |
coords.append(temp.x()); |
|
855 |
coords.append(temp.y()); |
|
856 |
haveEnd = false; |
|
857 |
curvePos = 2; |
|
858 |
} |
|
859 |
break; |
|
860 |
||
861 |
case QPainterPath::CurveToDataElement: |
|
862 |
{ |
|
863 |
temp = transform.map(QPointF(elements[i].x, elements[i].y)); |
|
864 |
coords.append(temp.x()); |
|
865 |
coords.append(temp.y()); |
|
866 |
haveEnd = false; |
|
867 |
curvePos += 2; |
|
868 |
if (curvePos == 6) { |
|
869 |
curvePos = 0; |
|
870 |
segments.append(VG_CUBIC_TO_ABS); |
|
871 |
} |
|
872 |
} |
|
873 |
break; |
|
874 |
||
875 |
} |
|
876 |
} |
|
877 |
} |
|
878 |
||
879 |
if (haveStart && haveEnd && startx == endx && starty == endy) { |
|
880 |
// Implicitly close the last sub-path. |
|
881 |
segments.append(VG_CLOSE_PATH); |
|
882 |
} |
|
883 |
||
884 |
vgAppendPathData(vgpath, segments.count(), |
|
885 |
segments.constData(), coords.constData()); |
|
886 |
||
887 |
return vgpath; |
|
888 |
} |
|
889 |
||
890 |
VGPath QVGPaintEnginePrivate::roundedRectPath(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode) |
|
891 |
{ |
|
892 |
static VGubyte roundedrect_types[] = { |
|
893 |
VG_MOVE_TO_ABS, |
|
894 |
VG_LINE_TO_ABS, |
|
895 |
VG_CUBIC_TO_ABS, |
|
896 |
VG_LINE_TO_ABS, |
|
897 |
VG_CUBIC_TO_ABS, |
|
898 |
VG_LINE_TO_ABS, |
|
899 |
VG_CUBIC_TO_ABS, |
|
900 |
VG_LINE_TO_ABS, |
|
901 |
VG_CUBIC_TO_ABS, |
|
902 |
VG_CLOSE_PATH |
|
903 |
}; |
|
904 |
||
905 |
qreal x1 = rect.left(); |
|
906 |
qreal x2 = rect.right(); |
|
907 |
qreal y1 = rect.top(); |
|
908 |
qreal y2 = rect.bottom(); |
|
909 |
||
910 |
if (mode == Qt::RelativeSize) { |
|
911 |
xRadius = xRadius * rect.width() / 200.; |
|
912 |
yRadius = yRadius * rect.height() / 200.; |
|
913 |
} |
|
914 |
||
915 |
xRadius = qMin(xRadius, rect.width() / 2); |
|
916 |
yRadius = qMin(yRadius, rect.height() / 2); |
|
917 |
||
918 |
VGfloat pts[] = { |
|
919 |
x1 + xRadius, y1, // MoveTo |
|
920 |
x2 - xRadius, y1, // LineTo |
|
921 |
x2 - (1 - KAPPA) * xRadius, y1, // CurveTo |
|
922 |
x2, y1 + (1 - KAPPA) * yRadius, |
|
923 |
x2, y1 + yRadius, |
|
924 |
x2, y2 - yRadius, // LineTo |
|
925 |
x2, y2 - (1 - KAPPA) * yRadius, // CurveTo |
|
926 |
x2 - (1 - KAPPA) * xRadius, y2, |
|
927 |
x2 - xRadius, y2, |
|
928 |
x1 + xRadius, y2, // LineTo |
|
929 |
x1 + (1 - KAPPA) * xRadius, y2, // CurveTo |
|
930 |
x1, y2 - (1 - KAPPA) * yRadius, |
|
931 |
x1, y2 - yRadius, |
|
932 |
x1, y1 + yRadius, // LineTo |
|
933 |
x1, y1 + KAPPA * yRadius, // CurveTo |
|
934 |
x1 + (1 - KAPPA) * xRadius, y1, |
|
935 |
x1 + xRadius, y1 |
|
936 |
}; |
|
937 |
||
938 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
939 |
VGPath vgpath = roundRectPath; |
|
940 |
if (!vgpath) { |
|
941 |
vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
942 |
VG_PATH_DATATYPE_F, |
|
943 |
1.0f, // scale |
|
944 |
0.0f, // bias |
|
945 |
10, // segmentCapacityHint |
|
946 |
17 * 2, // coordCapacityHint |
|
947 |
VG_PATH_CAPABILITY_ALL); |
|
948 |
vgAppendPathData(vgpath, 10, roundedrect_types, pts); |
|
949 |
roundRectPath = vgpath; |
|
950 |
} else { |
|
951 |
vgModifyPathCoords(vgpath, 0, 9, pts); |
|
952 |
} |
|
953 |
#else |
|
954 |
VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
955 |
VG_PATH_DATATYPE_F, |
|
956 |
1.0f, // scale |
|
957 |
0.0f, // bias |
|
958 |
10, // segmentCapacityHint |
|
959 |
17 * 2, // coordCapacityHint |
|
960 |
VG_PATH_CAPABILITY_ALL); |
|
961 |
vgAppendPathData(vgpath, 10, roundedrect_types, pts); |
|
962 |
#endif |
|
963 |
||
964 |
return vgpath; |
|
965 |
} |
|
966 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
967 |
Q_DECL_IMPORT extern QImage qt_imageForBrush(int style, bool invert); |
0 | 968 |
|
969 |
static QImage colorizeBitmap(const QImage &image, const QColor &color) |
|
970 |
{ |
|
971 |
QImage sourceImage = image.convertToFormat(QImage::Format_MonoLSB); |
|
972 |
QImage dest = QImage(sourceImage.size(), QImage::Format_ARGB32_Premultiplied); |
|
973 |
||
974 |
QRgb fg = PREMUL(color.rgba()); |
|
975 |
QRgb bg = 0; |
|
976 |
||
977 |
int height = sourceImage.height(); |
|
978 |
int width = sourceImage.width(); |
|
979 |
for (int y=0; y<height; ++y) { |
|
980 |
uchar *source = sourceImage.scanLine(y); |
|
981 |
QRgb *target = reinterpret_cast<QRgb *>(dest.scanLine(y)); |
|
982 |
for (int x=0; x < width; ++x) |
|
983 |
target[x] = (source[x>>3] >> (x&7)) & 1 ? fg : bg; |
|
984 |
} |
|
985 |
return dest; |
|
986 |
} |
|
987 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
988 |
// defined in qpixmapdata_vg.cpp. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
989 |
const uchar *qt_vg_imageBits(const QImage& image); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
990 |
|
0 | 991 |
static VGImage toVGImage |
992 |
(const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor) |
|
993 |
{ |
|
994 |
QImage img(image); |
|
995 |
||
996 |
VGImageFormat format; |
|
997 |
switch (img.format()) { |
|
998 |
case QImage::Format_Mono: |
|
999 |
img = image.convertToFormat(QImage::Format_MonoLSB, flags); |
|
1000 |
format = VG_BW_1; |
|
1001 |
break; |
|
1002 |
case QImage::Format_MonoLSB: |
|
1003 |
format = VG_BW_1; |
|
1004 |
break; |
|
1005 |
case QImage::Format_RGB32: |
|
1006 |
format = VG_sXRGB_8888; |
|
1007 |
break; |
|
1008 |
case QImage::Format_ARGB32: |
|
1009 |
format = VG_sARGB_8888; |
|
1010 |
break; |
|
1011 |
case QImage::Format_ARGB32_Premultiplied: |
|
1012 |
format = VG_sARGB_8888_PRE; |
|
1013 |
break; |
|
1014 |
case QImage::Format_RGB16: |
|
1015 |
format = VG_sRGB_565; |
|
1016 |
break; |
|
1017 |
default: |
|
1018 |
// Convert everything else into ARGB32_Premultiplied. |
|
1019 |
img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied, flags); |
|
1020 |
format = VG_sARGB_8888_PRE; |
|
1021 |
break; |
|
1022 |
} |
|
1023 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1024 |
const uchar *pixels = qt_vg_imageBits(img); |
0 | 1025 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1026 |
VGImage vgImg = QVGImagePool::instance()->createPermanentImage |
0 | 1027 |
(format, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER); |
1028 |
vgImageSubData |
|
1029 |
(vgImg, pixels, img.bytesPerLine(), format, 0, 0, |
|
1030 |
img.width(), img.height()); |
|
1031 |
||
1032 |
return vgImg; |
|
1033 |
} |
|
1034 |
||
1035 |
static VGImage toVGImageSubRect |
|
1036 |
(const QImage & image, const QRect& sr, |
|
1037 |
Qt::ImageConversionFlags flags = Qt::AutoColor) |
|
1038 |
{ |
|
1039 |
QImage img(image); |
|
1040 |
||
1041 |
VGImageFormat format; |
|
1042 |
int bpp = 4; |
|
1043 |
||
1044 |
switch (img.format()) { |
|
1045 |
case QImage::Format_Mono: |
|
1046 |
case QImage::Format_MonoLSB: |
|
1047 |
return VG_INVALID_HANDLE; |
|
1048 |
case QImage::Format_RGB32: |
|
1049 |
format = VG_sXRGB_8888; |
|
1050 |
break; |
|
1051 |
case QImage::Format_ARGB32: |
|
1052 |
format = VG_sARGB_8888; |
|
1053 |
break; |
|
1054 |
case QImage::Format_ARGB32_Premultiplied: |
|
1055 |
format = VG_sARGB_8888_PRE; |
|
1056 |
break; |
|
1057 |
case QImage::Format_RGB16: |
|
1058 |
format = VG_sRGB_565; |
|
1059 |
bpp = 2; |
|
1060 |
break; |
|
1061 |
default: |
|
1062 |
// Convert everything else into ARGB32_Premultiplied. |
|
1063 |
img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied, flags); |
|
1064 |
format = VG_sARGB_8888_PRE; |
|
1065 |
break; |
|
1066 |
} |
|
1067 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1068 |
const uchar *pixels = qt_vg_imageBits(img) + bpp * sr.x() + |
0 | 1069 |
img.bytesPerLine() * sr.y(); |
1070 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1071 |
VGImage vgImg = QVGImagePool::instance()->createPermanentImage |
0 | 1072 |
(format, sr.width(), sr.height(), VG_IMAGE_QUALITY_FASTER); |
1073 |
vgImageSubData |
|
1074 |
(vgImg, pixels, img.bytesPerLine(), format, 0, 0, |
|
1075 |
sr.width(), sr.height()); |
|
1076 |
||
1077 |
return vgImg; |
|
1078 |
} |
|
1079 |
||
1080 |
static VGImage toVGImageWithOpacity(const QImage & image, qreal opacity) |
|
1081 |
{ |
|
1082 |
QImage img(image.size(), QImage::Format_ARGB32_Premultiplied); |
|
1083 |
img.fill(0); |
|
1084 |
QPainter painter; |
|
1085 |
painter.begin(&img); |
|
1086 |
painter.setOpacity(opacity); |
|
1087 |
painter.drawImage(0, 0, image); |
|
1088 |
painter.end(); |
|
1089 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1090 |
const uchar *pixels = qt_vg_imageBits(img); |
0 | 1091 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1092 |
VGImage vgImg = QVGImagePool::instance()->createPermanentImage |
0 | 1093 |
(VG_sARGB_8888_PRE, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER); |
1094 |
vgImageSubData |
|
1095 |
(vgImg, pixels, img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, |
|
1096 |
img.width(), img.height()); |
|
1097 |
||
1098 |
return vgImg; |
|
1099 |
} |
|
1100 |
||
1101 |
static VGImage toVGImageWithOpacitySubRect |
|
1102 |
(const QImage & image, qreal opacity, const QRect& sr) |
|
1103 |
{ |
|
1104 |
QImage img(sr.size(), QImage::Format_ARGB32_Premultiplied); |
|
1105 |
img.fill(0); |
|
1106 |
QPainter painter; |
|
1107 |
painter.begin(&img); |
|
1108 |
painter.setOpacity(opacity); |
|
1109 |
painter.drawImage(QPoint(0, 0), image, sr); |
|
1110 |
painter.end(); |
|
1111 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1112 |
const uchar *pixels = qt_vg_imageBits(img); |
0 | 1113 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1114 |
VGImage vgImg = QVGImagePool::instance()->createPermanentImage |
0 | 1115 |
(VG_sARGB_8888_PRE, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER); |
1116 |
vgImageSubData |
|
1117 |
(vgImg, pixels, img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, |
|
1118 |
img.width(), img.height()); |
|
1119 |
||
1120 |
return vgImg; |
|
1121 |
} |
|
1122 |
||
1123 |
VGPaintType QVGPaintEnginePrivate::setBrush |
|
1124 |
(VGPaint paint, const QBrush& brush, VGMatrixMode mode, |
|
1125 |
VGPaintType prevType) |
|
1126 |
{ |
|
1127 |
VGfloat values[5]; |
|
1128 |
setBrushTransform(brush, mode); |
|
1129 |
||
1130 |
// Reset the paint pattern on the brush, which will discard |
|
1131 |
// the previous VGImage if one was set. |
|
1132 |
if (prevType == VG_PAINT_TYPE_PATTERN || prevType == (VGPaintType)0) |
|
1133 |
vgPaintPattern(paint, VG_INVALID_HANDLE); |
|
1134 |
||
1135 |
switch (brush.style()) { |
|
1136 |
||
1137 |
case Qt::SolidPattern: { |
|
1138 |
// The brush is a solid color. |
|
1139 |
QColor color(brush.color()); |
|
1140 |
values[0] = color.redF(); |
|
1141 |
values[1] = color.greenF(); |
|
1142 |
values[2] = color.blueF(); |
|
1143 |
values[3] = color.alphaF() * opacity; |
|
1144 |
if (prevType != VG_PAINT_TYPE_COLOR) |
|
1145 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
1146 |
vgSetParameterfv(paint, VG_PAINT_COLOR, 4, values); |
|
1147 |
return VG_PAINT_TYPE_COLOR; |
|
1148 |
} |
|
1149 |
||
1150 |
case Qt::LinearGradientPattern: { |
|
1151 |
// The brush is a linear gradient. |
|
1152 |
Q_ASSERT(brush.gradient()->type() == QGradient::LinearGradient); |
|
1153 |
const QLinearGradient *grad = |
|
1154 |
static_cast<const QLinearGradient*>(brush.gradient()); |
|
1155 |
values[0] = grad->start().x(); |
|
1156 |
values[1] = grad->start().y(); |
|
1157 |
values[2] = grad->finalStop().x(); |
|
1158 |
values[3] = grad->finalStop().y(); |
|
1159 |
if (prevType != VG_PAINT_TYPE_LINEAR_GRADIENT) |
|
1160 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); |
|
1161 |
vgSetParameterfv(paint, VG_PAINT_LINEAR_GRADIENT, 4, values); |
|
1162 |
setupColorRamp(grad, paint); |
|
1163 |
return VG_PAINT_TYPE_LINEAR_GRADIENT; |
|
1164 |
} |
|
1165 |
||
1166 |
case Qt::RadialGradientPattern: { |
|
1167 |
// The brush is a radial gradient. |
|
1168 |
Q_ASSERT(brush.gradient()->type() == QGradient::RadialGradient); |
|
1169 |
const QRadialGradient *grad = |
|
1170 |
static_cast<const QRadialGradient*>(brush.gradient()); |
|
1171 |
values[0] = grad->center().x(); |
|
1172 |
values[1] = grad->center().y(); |
|
1173 |
values[2] = grad->focalPoint().x(); |
|
1174 |
values[3] = grad->focalPoint().y(); |
|
1175 |
values[4] = grad->radius(); |
|
1176 |
if (prevType != VG_PAINT_TYPE_RADIAL_GRADIENT) |
|
1177 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT); |
|
1178 |
vgSetParameterfv(paint, VG_PAINT_RADIAL_GRADIENT, 5, values); |
|
1179 |
setupColorRamp(grad, paint); |
|
1180 |
return VG_PAINT_TYPE_RADIAL_GRADIENT; |
|
1181 |
} |
|
1182 |
||
1183 |
case Qt::TexturePattern: { |
|
1184 |
// The brush is a texture specified by a QPixmap/QImage. |
|
1185 |
QPixmapData *pd = brush.texture().pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1187 |
break; // null QPixmap |
0 | 1188 |
VGImage vgImg; |
1189 |
bool deref = false; |
|
1190 |
if (pd->pixelType() == QPixmapData::BitmapType) { |
|
1191 |
// Colorize bitmaps using the brush color and opacity. |
|
1192 |
QColor color = brush.color(); |
|
1193 |
if (opacity != 1.0) |
|
1194 |
color.setAlphaF(color.alphaF() * opacity); |
|
1195 |
QImage image = colorizeBitmap(*(pd->buffer()), color); |
|
1196 |
vgImg = toVGImage(image); |
|
1197 |
deref = true; |
|
1198 |
} else if (opacity == 1.0) { |
|
1199 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
|
1200 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
1201 |
vgImg = vgpd->toVGImage(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
// We don't want the pool to reclaim this image |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
// because we cannot predict when the paint object |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
// will stop using it. Replacing the image with |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
// new data will make the paint object invalid. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1207 |
vgpd->detachImageFromPool(); |
0 | 1208 |
} else { |
1209 |
vgImg = toVGImage(*(pd->buffer())); |
|
1210 |
deref = true; |
|
1211 |
} |
|
1212 |
} else if (pd->classId() == QPixmapData::OpenVGClass) { |
|
1213 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
1214 |
vgImg = vgpd->toVGImage(opacity); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
vgpd->detachImageFromPool(); |
0 | 1216 |
} else { |
1217 |
vgImg = toVGImageWithOpacity(*(pd->buffer()), opacity); |
|
1218 |
deref = true; |
|
1219 |
} |
|
1220 |
if (vgImg == VG_INVALID_HANDLE) |
|
1221 |
break; |
|
1222 |
if (prevType != VG_PAINT_TYPE_PATTERN) |
|
1223 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN); |
|
1224 |
vgSetParameteri(paint, VG_PAINT_PATTERN_TILING_MODE, VG_TILE_REPEAT); |
|
1225 |
vgPaintPattern(paint, vgImg); |
|
1226 |
if (deref) |
|
1227 |
vgDestroyImage(vgImg); // Will be valid until pattern is destroyed. |
|
1228 |
return VG_PAINT_TYPE_PATTERN; |
|
1229 |
} |
|
1230 |
||
1231 |
case Qt::ConicalGradientPattern: { |
|
1232 |
// Convert conical gradients into the first stop color. |
|
1233 |
qWarning() << "QVGPaintEnginePrivate::setBrush: conical gradients are not supported by OpenVG"; |
|
1234 |
Q_ASSERT(brush.gradient()->type() == QGradient::ConicalGradient); |
|
1235 |
const QConicalGradient *grad = |
|
1236 |
static_cast<const QConicalGradient*>(brush.gradient()); |
|
1237 |
const QGradientStops stops = grad->stops(); |
|
1238 |
QColor color; |
|
1239 |
if (stops.size() > 0) |
|
1240 |
color = stops[0].second; |
|
1241 |
values[0] = color.redF(); |
|
1242 |
values[1] = color.greenF(); |
|
1243 |
values[2] = color.blueF(); |
|
1244 |
values[3] = color.alphaF() * opacity; |
|
1245 |
if (prevType != VG_PAINT_TYPE_COLOR) |
|
1246 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
1247 |
vgSetParameterfv(paint, VG_PAINT_COLOR, 4, values); |
|
1248 |
return VG_PAINT_TYPE_COLOR; |
|
1249 |
} |
|
1250 |
||
1251 |
case Qt::Dense1Pattern: |
|
1252 |
case Qt::Dense2Pattern: |
|
1253 |
case Qt::Dense3Pattern: |
|
1254 |
case Qt::Dense4Pattern: |
|
1255 |
case Qt::Dense5Pattern: |
|
1256 |
case Qt::Dense6Pattern: |
|
1257 |
case Qt::Dense7Pattern: |
|
1258 |
case Qt::HorPattern: |
|
1259 |
case Qt::VerPattern: |
|
1260 |
case Qt::CrossPattern: |
|
1261 |
case Qt::BDiagPattern: |
|
1262 |
case Qt::FDiagPattern: |
|
1263 |
case Qt::DiagCrossPattern: { |
|
1264 |
// The brush is a traditional dotted or cross-hatched pattern brush. |
|
1265 |
QColor color = brush.color(); |
|
1266 |
if (opacity != 1.0) |
|
1267 |
color.setAlphaF(color.alphaF() * opacity); |
|
1268 |
QImage image = colorizeBitmap |
|
1269 |
(qt_imageForBrush(brush.style(), true), color); |
|
1270 |
VGImage vgImg = toVGImage(image); |
|
1271 |
if (prevType != VG_PAINT_TYPE_PATTERN) |
|
1272 |
vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN); |
|
1273 |
vgSetParameteri(paint, VG_PAINT_PATTERN_TILING_MODE, VG_TILE_REPEAT); |
|
1274 |
vgPaintPattern(paint, vgImg); |
|
1275 |
vgDestroyImage(vgImg); // Will stay valid until pattern is destroyed. |
|
1276 |
return VG_PAINT_TYPE_PATTERN; |
|
1277 |
} |
|
1278 |
||
1279 |
default: break; |
|
1280 |
} |
|
1281 |
return (VGPaintType)0; |
|
1282 |
} |
|
1283 |
||
1284 |
void QVGPaintEnginePrivate::setPenParams(const QPen& pen) |
|
1285 |
{ |
|
1286 |
// Note: OpenVG does not support zero-width or cosmetic pens, |
|
1287 |
// so we have to simulate cosmetic pens by reversing the scale. |
|
1288 |
VGfloat width = pen.widthF(); |
|
1289 |
if (width <= 0.0f) |
|
1290 |
width = 1.0f; |
|
1291 |
if (pen.isCosmetic()) { |
|
1292 |
if (penScale != 1.0 && penScale != 0.0) |
|
1293 |
width /= penScale; |
|
1294 |
} |
|
1295 |
vgSetf(VG_STROKE_LINE_WIDTH, width); |
|
1296 |
||
1297 |
if (pen.capStyle() == Qt::FlatCap) |
|
1298 |
vgSetf(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); |
|
1299 |
else if (pen.capStyle() == Qt::SquareCap) |
|
1300 |
vgSetf(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); |
|
1301 |
else |
|
1302 |
vgSetf(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); |
|
1303 |
||
1304 |
if (pen.joinStyle() == Qt::MiterJoin) { |
|
1305 |
vgSetf(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER); |
|
1306 |
vgSetf(VG_STROKE_MITER_LIMIT, pen.miterLimit()); |
|
1307 |
} else if (pen.joinStyle() == Qt::BevelJoin) { |
|
1308 |
vgSetf(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); |
|
1309 |
} else { |
|
1310 |
vgSetf(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); |
|
1311 |
} |
|
1312 |
||
1313 |
if (pen.style() == Qt::SolidLine) { |
|
1314 |
vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL); |
|
1315 |
} else { |
|
1316 |
const QVector<qreal> dashPattern = pen.dashPattern(); |
|
1317 |
QVector<VGfloat> currentDashPattern(dashPattern.count()); |
|
1318 |
for (int i = 0; i < dashPattern.count(); ++i) |
|
1319 |
currentDashPattern[i] = dashPattern[i] * width; |
|
1320 |
vgSetfv(VG_STROKE_DASH_PATTERN, currentDashPattern.count(), currentDashPattern.data()); |
|
1321 |
vgSetf(VG_STROKE_DASH_PHASE, pen.dashOffset()); |
|
1322 |
vgSetf(VG_STROKE_DASH_PHASE_RESET, VG_FALSE); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
void QVGPaintEnginePrivate::setBrushTransform |
|
1327 |
(const QBrush& brush, VGMatrixMode mode) |
|
1328 |
{ |
|
1329 |
// Compute the new brush transformation matrix. |
|
1330 |
QTransform transform(brush.transform()); |
|
1331 |
if (brushOrigin.x() != 0.0f || brushOrigin.y() != 0.0f) |
|
1332 |
transform.translate(brushOrigin.x(), brushOrigin.y()); |
|
1333 |
||
1334 |
// Bail out if the matrix is the same as last time, to avoid |
|
1335 |
// updating the VG context state unless absolutely necessary. |
|
1336 |
// Most applications won't have a brush transformation set, |
|
1337 |
// which will leave the VG setting at its default of identity. |
|
1338 |
// Always change the transform if coming out of raw VG mode. |
|
1339 |
if (mode == VG_MATRIX_FILL_PAINT_TO_USER) { |
|
1340 |
if (!rawVG && transform == brushTransform) |
|
1341 |
return; |
|
1342 |
brushTransform = transform; |
|
1343 |
} else { |
|
1344 |
if (!rawVG && transform == penTransform) |
|
1345 |
return; |
|
1346 |
penTransform = transform; |
|
1347 |
} |
|
1348 |
||
1349 |
// Set the brush transformation matrix. |
|
1350 |
if (mode != matrixMode) { |
|
1351 |
vgSeti(VG_MATRIX_MODE, mode); |
|
1352 |
matrixMode = mode; |
|
1353 |
} |
|
1354 |
if (transform.isIdentity()) { |
|
1355 |
vgLoadIdentity(); |
|
1356 |
} else { |
|
1357 |
VGfloat mat[9]; |
|
1358 |
mat[0] = transform.m11(); |
|
1359 |
mat[1] = transform.m12(); |
|
1360 |
mat[2] = transform.m13(); |
|
1361 |
mat[3] = transform.m21(); |
|
1362 |
mat[4] = transform.m22(); |
|
1363 |
mat[5] = transform.m23(); |
|
1364 |
mat[6] = transform.m31(); |
|
1365 |
mat[7] = transform.m32(); |
|
1366 |
mat[8] = transform.m33(); |
|
1367 |
vgLoadMatrix(mat); |
|
1368 |
} |
|
1369 |
} |
|
1370 |
||
1371 |
void QVGPaintEnginePrivate::setupColorRamp(const QGradient *grad, VGPaint paint) |
|
1372 |
{ |
|
1373 |
QGradient::Spread spread = grad->spread(); |
|
1374 |
VGColorRampSpreadMode spreadMode; |
|
1375 |
if (spread == QGradient::ReflectSpread) |
|
1376 |
spreadMode = VG_COLOR_RAMP_SPREAD_REFLECT; |
|
1377 |
else if (spread == QGradient::RepeatSpread) |
|
1378 |
spreadMode = VG_COLOR_RAMP_SPREAD_REPEAT; |
|
1379 |
else |
|
1380 |
spreadMode = VG_COLOR_RAMP_SPREAD_PAD; |
|
1381 |
||
1382 |
const QGradientStops stops = grad->stops(); |
|
1383 |
int n = 5*stops.size(); |
|
1384 |
QVector<VGfloat> fill_stops(n); |
|
1385 |
||
1386 |
for (int i = 0; i < stops.size(); ++i ) { |
|
1387 |
QColor col = stops[i].second; |
|
1388 |
fill_stops[i*5] = stops[i].first; |
|
1389 |
fill_stops[i*5 + 1] = col.redF(); |
|
1390 |
fill_stops[i*5 + 2] = col.greenF(); |
|
1391 |
fill_stops[i*5 + 3] = col.blueF(); |
|
1392 |
fill_stops[i*5 + 4] = col.alphaF() * opacity; |
|
1393 |
} |
|
1394 |
||
1395 |
vgSetParameteri(paint, VG_PAINT_COLOR_RAMP_SPREAD_MODE, spreadMode); |
|
1396 |
vgSetParameteri(paint, VG_PAINT_COLOR_RAMP_PREMULTIPLIED, VG_FALSE); |
|
1397 |
vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, n, fill_stops.data()); |
|
1398 |
} |
|
1399 |
||
1400 |
QVGPainterState::QVGPainterState(QVGPainterState& other) |
|
1401 |
: QPainterState(other), |
|
1402 |
isNew(true), clipRegion(other.clipRegion), |
|
1403 |
savedDirty(0) |
|
1404 |
{ |
|
1405 |
} |
|
1406 |
||
1407 |
QVGPainterState::QVGPainterState() |
|
1408 |
: isNew(true), savedDirty(0) |
|
1409 |
{ |
|
1410 |
} |
|
1411 |
||
1412 |
QVGPainterState::~QVGPainterState() |
|
1413 |
{ |
|
1414 |
} |
|
1415 |
||
1416 |
QVGPaintEngine::QVGPaintEngine() |
|
1417 |
: QPaintEngineEx(*new QVGPaintEnginePrivate) |
|
1418 |
{ |
|
1419 |
} |
|
1420 |
||
1421 |
QVGPaintEngine::QVGPaintEngine(QVGPaintEnginePrivate &data) |
|
1422 |
: QPaintEngineEx(data) |
|
1423 |
{ |
|
1424 |
} |
|
1425 |
||
1426 |
QVGPaintEngine::~QVGPaintEngine() |
|
1427 |
{ |
|
1428 |
} |
|
1429 |
||
1430 |
QPainterState *QVGPaintEngine::createState(QPainterState *orig) const |
|
1431 |
{ |
|
1432 |
if (!orig) { |
|
1433 |
return new QVGPainterState(); |
|
1434 |
} else { |
|
1435 |
Q_D(const QVGPaintEngine); |
|
1436 |
QVGPaintEnginePrivate *d2 = const_cast<QVGPaintEnginePrivate*>(d); |
|
1437 |
QVGPainterState *origState = static_cast<QVGPainterState *>(orig); |
|
1438 |
origState->savedDirty = d2->dirty; |
|
1439 |
d2->dirty = 0; |
|
1440 |
return new QVGPainterState(*origState); |
|
1441 |
} |
|
1442 |
} |
|
1443 |
||
1444 |
void QVGPaintEnginePrivate::draw |
|
1445 |
(VGPath path, const QPen& pen, const QBrush& brush, VGint rule) |
|
1446 |
{ |
|
1447 |
VGbitfield mode = 0; |
|
1448 |
if (pen.style() != Qt::NoPen) { |
|
1449 |
ensurePen(pen); |
|
1450 |
mode |= VG_STROKE_PATH; |
|
1451 |
} |
|
1452 |
if (brush.style() != Qt::NoBrush) { |
|
1453 |
ensureBrush(brush); |
|
1454 |
setFillRule(rule); |
|
1455 |
mode |= VG_FILL_PATH; |
|
1456 |
} |
|
1457 |
if (mode != 0) { |
|
1458 |
ensurePathTransform(); |
|
1459 |
vgDrawPath(path, mode); |
|
1460 |
} |
|
1461 |
} |
|
1462 |
||
1463 |
void QVGPaintEnginePrivate::stroke(VGPath path, const QPen& pen) |
|
1464 |
{ |
|
1465 |
if (pen.style() == Qt::NoPen) |
|
1466 |
return; |
|
1467 |
ensurePen(pen); |
|
1468 |
ensurePathTransform(); |
|
1469 |
vgDrawPath(path, VG_STROKE_PATH); |
|
1470 |
} |
|
1471 |
||
1472 |
void QVGPaintEnginePrivate::fill(VGPath path, const QBrush& brush, VGint rule) |
|
1473 |
{ |
|
1474 |
if (brush.style() == Qt::NoBrush) |
|
1475 |
return; |
|
1476 |
ensureBrush(brush); |
|
1477 |
setFillRule(rule); |
|
1478 |
ensurePathTransform(); |
|
1479 |
vgDrawPath(path, VG_FILL_PATH); |
|
1480 |
} |
|
1481 |
||
1482 |
bool QVGPaintEngine::begin(QPaintDevice *pdev) |
|
1483 |
{ |
|
1484 |
Q_UNUSED(pdev); |
|
1485 |
Q_D(QVGPaintEngine); |
|
1486 |
||
1487 |
// Initialize the VG painting objects if we haven't done it yet. |
|
1488 |
if (!d->penPaint) |
|
1489 |
d->initObjects(); |
|
1490 |
||
1491 |
// The initial clip region is the entire device area. |
|
1492 |
QVGPainterState *s = state(); |
|
1493 |
s->clipRegion = defaultClipRegion(); |
|
1494 |
||
1495 |
// Initialize the VG state for this paint operation. |
|
1496 |
restoreState(QPaintEngine::AllDirty); |
|
1497 |
d->dirty = 0; |
|
1498 |
d->rawVG = false; |
|
1499 |
return true; |
|
1500 |
} |
|
1501 |
||
1502 |
bool QVGPaintEngine::end() |
|
1503 |
{ |
|
1504 |
return true; |
|
1505 |
} |
|
1506 |
||
1507 |
void QVGPaintEngine::draw(const QVectorPath &path) |
|
1508 |
{ |
|
1509 |
Q_D(QVGPaintEngine); |
|
1510 |
QVGPainterState *s = state(); |
|
1511 |
VGPath vgpath = d->vectorPathToVGPath(path); |
|
1512 |
if (!path.hasWindingFill()) |
|
1513 |
d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); |
|
1514 |
else |
|
1515 |
d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); |
|
1516 |
vgDestroyPath(vgpath); |
|
1517 |
} |
|
1518 |
||
1519 |
void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) |
|
1520 |
{ |
|
1521 |
Q_D(QVGPaintEngine); |
|
1522 |
VGPath vgpath = d->vectorPathToVGPath(path); |
|
1523 |
if (!path.hasWindingFill()) |
|
1524 |
d->fill(vgpath, brush, VG_EVEN_ODD); |
|
1525 |
else |
|
1526 |
d->fill(vgpath, brush, VG_NON_ZERO); |
|
1527 |
vgDestroyPath(vgpath); |
|
1528 |
} |
|
1529 |
||
1530 |
void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) |
|
1531 |
{ |
|
1532 |
Q_D(QVGPaintEngine); |
|
1533 |
VGPath vgpath = d->vectorPathToVGPath(path); |
|
1534 |
d->stroke(vgpath, pen); |
|
1535 |
vgDestroyPath(vgpath); |
|
1536 |
} |
|
1537 |
||
1538 |
// Determine if a co-ordinate transform is simple enough to allow |
|
1539 |
// rectangle-based clipping with vgMask(). Simple transforms most |
|
1540 |
// often result from origin translations. |
|
1541 |
static inline bool clipTransformIsSimple(const QTransform& transform) |
|
1542 |
{ |
|
1543 |
QTransform::TransformationType type = transform.type(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1544 |
if (type == QTransform::TxNone || type == QTransform::TxTranslate) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1545 |
return true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1546 |
if (type == QTransform::TxRotate) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1547 |
// Check for 0, 90, 180, and 270 degree rotations. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1548 |
// (0 might happen after 4 rotations of 90 degrees). |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1549 |
qreal m11 = transform.m11(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1550 |
qreal m12 = transform.m12(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1551 |
qreal m21 = transform.m21(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1552 |
qreal m22 = transform.m22(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1553 |
if (m11 == 0.0f && m22 == 0.0f) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1554 |
if (m12 == 1.0f && m21 == -1.0f) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1555 |
return true; // 90 degrees. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1556 |
else if (m12 == -1.0f && m21 == 1.0f) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1557 |
return true; // 270 degrees. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1558 |
} else if (m12 == 0.0f && m21 == 0.0f) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1559 |
if (m11 == -1.0f && m22 == -1.0f) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1560 |
return true; // 180 degrees. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1561 |
else if (m11 == 1.0f && m22 == 1.0f) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1562 |
return true; // 0 degrees. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1563 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1564 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1565 |
return false; |
0 | 1566 |
} |
1567 |
||
1568 |
#if defined(QVG_SCISSOR_CLIP) |
|
1569 |
||
1570 |
void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) |
|
1571 |
{ |
|
1572 |
Q_D(QVGPaintEngine); |
|
1573 |
QVGPainterState *s = state(); |
|
1574 |
||
1575 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1576 |
||
1577 |
if (op == Qt::NoClip) { |
|
1578 |
s->clipRegion = defaultClipRegion(); |
|
1579 |
updateScissor(); |
|
1580 |
return; |
|
1581 |
} |
|
1582 |
||
1583 |
// We aren't using masking, so handle simple QRectF's only. |
|
1584 |
if (path.shape() == QVectorPath::RectangleHint && |
|
1585 |
path.elementCount() == 4 && clipTransformIsSimple(d->transform)) { |
|
1586 |
// Clipping region that resulted from QPainter::setClipRect(QRectF). |
|
1587 |
// Convert it into a QRect and apply. |
|
1588 |
const qreal *points = path.points(); |
|
1589 |
QRectF rect(points[0], points[1], points[2] - points[0], |
|
1590 |
points[5] - points[1]); |
|
1591 |
clip(rect.toRect(), op); |
|
1592 |
} else { |
|
1593 |
// The best we can do is clip to the bounding rectangle |
|
1594 |
// of all control points. |
|
1595 |
clip(path.controlPointRect().toRect(), op); |
|
1596 |
} |
|
1597 |
} |
|
1598 |
||
1599 |
void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) |
|
1600 |
{ |
|
1601 |
Q_D(QVGPaintEngine); |
|
1602 |
QVGPainterState *s = state(); |
|
1603 |
||
1604 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1605 |
||
1606 |
switch (op) { |
|
1607 |
case Qt::NoClip: |
|
1608 |
{ |
|
1609 |
s->clipRegion = defaultClipRegion(); |
|
1610 |
} |
|
1611 |
break; |
|
1612 |
||
1613 |
case Qt::ReplaceClip: |
|
1614 |
{ |
|
1615 |
s->clipRegion = d->transform.map(QRegion(rect)); |
|
1616 |
} |
|
1617 |
break; |
|
1618 |
||
1619 |
case Qt::IntersectClip: |
|
1620 |
{ |
|
1621 |
s->clipRegion = s->clipRegion.intersect(d->transform.map(QRegion(rect))); |
|
1622 |
} |
|
1623 |
break; |
|
1624 |
||
1625 |
case Qt::UniteClip: |
|
1626 |
{ |
|
1627 |
s->clipRegion = s->clipRegion.unite(d->transform.map(QRegion(rect))); |
|
1628 |
} |
|
1629 |
break; |
|
1630 |
} |
|
1631 |
||
1632 |
updateScissor(); |
|
1633 |
} |
|
1634 |
||
1635 |
void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) |
|
1636 |
{ |
|
1637 |
Q_D(QVGPaintEngine); |
|
1638 |
QVGPainterState *s = state(); |
|
1639 |
||
1640 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1641 |
||
1642 |
switch (op) { |
|
1643 |
case Qt::NoClip: |
|
1644 |
{ |
|
1645 |
s->clipRegion = defaultClipRegion(); |
|
1646 |
} |
|
1647 |
break; |
|
1648 |
||
1649 |
case Qt::ReplaceClip: |
|
1650 |
{ |
|
1651 |
s->clipRegion = d->transform.map(region); |
|
1652 |
} |
|
1653 |
break; |
|
1654 |
||
1655 |
case Qt::IntersectClip: |
|
1656 |
{ |
|
1657 |
s->clipRegion = s->clipRegion.intersect(d->transform.map(region)); |
|
1658 |
} |
|
1659 |
break; |
|
1660 |
||
1661 |
case Qt::UniteClip: |
|
1662 |
{ |
|
1663 |
s->clipRegion = s->clipRegion.unite(d->transform.map(region)); |
|
1664 |
} |
|
1665 |
break; |
|
1666 |
} |
|
1667 |
||
1668 |
updateScissor(); |
|
1669 |
} |
|
1670 |
||
1671 |
void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) |
|
1672 |
{ |
|
1673 |
QPaintEngineEx::clip(path, op); |
|
1674 |
} |
|
1675 |
||
1676 |
#else // !QVG_SCISSOR_CLIP |
|
1677 |
||
1678 |
void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) |
|
1679 |
{ |
|
1680 |
Q_D(QVGPaintEngine); |
|
1681 |
||
1682 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1683 |
||
1684 |
if (op == Qt::NoClip) { |
|
1685 |
d->maskValid = false; |
|
1686 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1687 |
d->scissorMask = false; |
0 | 1688 |
d->maskRect = QRect(); |
1689 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1690 |
return; |
|
1691 |
} |
|
1692 |
||
1693 |
// We don't have vgRenderToMask(), so handle simple QRectF's only. |
|
1694 |
if (path.shape() == QVectorPath::RectangleHint && |
|
1695 |
path.elementCount() == 4 && clipTransformIsSimple(d->transform)) { |
|
1696 |
// Clipping region that resulted from QPainter::setClipRect(QRectF). |
|
1697 |
// Convert it into a QRect and apply. |
|
1698 |
const qreal *points = path.points(); |
|
1699 |
QRectF rect(points[0], points[1], points[2] - points[0], |
|
1700 |
points[5] - points[1]); |
|
1701 |
clip(rect.toRect(), op); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1702 |
return; |
0 | 1703 |
} |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1704 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1705 |
#if !defined(QVG_NO_RENDER_TO_MASK) |
0 | 1706 |
QPaintDevice *pdev = paintDevice(); |
1707 |
int width = pdev->width(); |
|
1708 |
int height = pdev->height(); |
|
1709 |
||
1710 |
if (op == Qt::ReplaceClip) { |
|
1711 |
vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK, 0, 0, width, height); |
|
1712 |
d->maskRect = QRect(); |
|
1713 |
} else if (!d->maskValid) { |
|
1714 |
d->ensureMask(this, width, height); |
|
1715 |
} |
|
1716 |
||
1717 |
d->ensurePathTransform(); |
|
1718 |
VGPath vgpath = d->vectorPathToVGPath(path); |
|
1719 |
switch (op) { |
|
1720 |
case Qt::ReplaceClip: |
|
1721 |
case Qt::UniteClip: |
|
1722 |
vgRenderToMask(vgpath, VG_FILL_PATH, VG_UNION_MASK); |
|
1723 |
break; |
|
1724 |
||
1725 |
case Qt::IntersectClip: |
|
1726 |
vgRenderToMask(vgpath, VG_FILL_PATH, VG_INTERSECT_MASK); |
|
1727 |
break; |
|
1728 |
||
1729 |
default: break; |
|
1730 |
} |
|
1731 |
vgDestroyPath(vgpath); |
|
1732 |
||
1733 |
vgSeti(VG_MASKING, VG_TRUE); |
|
1734 |
d->maskValid = true; |
|
1735 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1736 |
d->scissorMask = false; |
0 | 1737 |
#endif |
1738 |
} |
|
1739 |
||
1740 |
void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) |
|
1741 |
{ |
|
1742 |
Q_D(QVGPaintEngine); |
|
1743 |
||
1744 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1745 |
||
1746 |
// If we have a non-simple transform, then use path-based clipping. |
|
1747 |
if (op != Qt::NoClip && !clipTransformIsSimple(d->transform)) { |
|
1748 |
QPaintEngineEx::clip(rect, op); |
|
1749 |
return; |
|
1750 |
} |
|
1751 |
||
1752 |
switch (op) { |
|
1753 |
case Qt::NoClip: |
|
1754 |
{ |
|
1755 |
d->maskValid = false; |
|
1756 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1757 |
d->scissorMask = false; |
0 | 1758 |
d->maskRect = QRect(); |
1759 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1760 |
} |
|
1761 |
break; |
|
1762 |
||
1763 |
case Qt::ReplaceClip: |
|
1764 |
{ |
|
1765 |
QRect r = d->transform.mapRect(rect); |
|
1766 |
if (isDefaultClipRect(r)) { |
|
1767 |
// Replacing the clip with a full-window region is the |
|
1768 |
// same as turning off clipping. |
|
1769 |
if (d->maskValid) |
|
1770 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1771 |
d->maskValid = false; |
|
1772 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1773 |
d->scissorMask = false; |
0 | 1774 |
d->maskRect = QRect(); |
1775 |
} else { |
|
1776 |
// Special case: if the intersection of the system |
|
1777 |
// clip and "r" is a single rectangle, then use the |
|
1778 |
// scissor for clipping. We try to avoid allocating a |
|
1779 |
// QRegion copy on the heap for the test if we can. |
|
1780 |
QRegion clip = d->systemClip; // Reference-counted, no alloc. |
|
1781 |
QRect clipRect; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1782 |
if (clip.rectCount() == 1) { |
0 | 1783 |
clipRect = clip.boundingRect().intersected(r); |
1784 |
} else if (clip.isEmpty()) { |
|
1785 |
clipRect = r; |
|
1786 |
} else { |
|
1787 |
clip = clip.intersect(r); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1788 |
if (clip.rectCount() != 1) { |
0 | 1789 |
d->maskValid = false; |
1790 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1791 |
d->scissorMask = false; |
0 | 1792 |
d->maskRect = QRect(); |
1793 |
d->modifyMask(this, VG_FILL_MASK, r); |
|
1794 |
break; |
|
1795 |
} |
|
1796 |
clipRect = clip.boundingRect(); |
|
1797 |
} |
|
1798 |
d->maskValid = false; |
|
1799 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1800 |
d->scissorMask = true; |
0 | 1801 |
d->maskRect = clipRect; |
1802 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1803 |
updateScissor(); |
|
1804 |
} |
|
1805 |
} |
|
1806 |
break; |
|
1807 |
||
1808 |
case Qt::IntersectClip: |
|
1809 |
{ |
|
1810 |
QRect r = d->transform.mapRect(rect); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1811 |
if (!d->maskValid) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1812 |
// Mask has not been used yet, so intersect with |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1813 |
// the previous scissor-based region in maskRect. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1814 |
if (d->scissorMask) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1815 |
r = r.intersect(d->maskRect); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1816 |
if (isDefaultClipRect(r)) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1817 |
// The clip is the full window, so turn off clipping. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1818 |
d->maskIsSet = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1819 |
d->maskRect = QRect(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1820 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1821 |
// Activate the scissor on a smaller maskRect. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1822 |
d->maskIsSet = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1823 |
d->maskRect = r; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1824 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1825 |
d->scissorMask = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1826 |
updateScissor(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1827 |
} else if (d->maskIsSet && isDefaultClipRect(r)) { |
0 | 1828 |
// Intersecting a full-window clip with a full-window |
1829 |
// region is the same as turning off clipping. |
|
1830 |
if (d->maskValid) |
|
1831 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1832 |
d->maskValid = false; |
|
1833 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1834 |
d->scissorMask = false; |
0 | 1835 |
d->maskRect = QRect(); |
1836 |
} else { |
|
1837 |
d->modifyMask(this, VG_INTERSECT_MASK, r); |
|
1838 |
} |
|
1839 |
} |
|
1840 |
break; |
|
1841 |
||
1842 |
case Qt::UniteClip: |
|
1843 |
{ |
|
1844 |
// If we already have a full-window clip, then uniting a |
|
1845 |
// region with it will do nothing. Otherwise union. |
|
1846 |
if (!(d->maskIsSet)) |
|
1847 |
d->modifyMask(this, VG_UNION_MASK, d->transform.mapRect(rect)); |
|
1848 |
} |
|
1849 |
break; |
|
1850 |
} |
|
1851 |
} |
|
1852 |
||
1853 |
void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) |
|
1854 |
{ |
|
1855 |
Q_D(QVGPaintEngine); |
|
1856 |
||
1857 |
// Use the QRect case if the region consists of a single rectangle. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1858 |
if (region.rectCount() == 1) { |
0 | 1859 |
clip(region.boundingRect(), op); |
1860 |
return; |
|
1861 |
} |
|
1862 |
||
1863 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
1864 |
||
1865 |
// If we have a non-simple transform, then use path-based clipping. |
|
1866 |
if (op != Qt::NoClip && !clipTransformIsSimple(d->transform)) { |
|
1867 |
QPaintEngineEx::clip(region, op); |
|
1868 |
return; |
|
1869 |
} |
|
1870 |
||
1871 |
switch (op) { |
|
1872 |
case Qt::NoClip: |
|
1873 |
{ |
|
1874 |
d->maskValid = false; |
|
1875 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1876 |
d->scissorMask = false; |
0 | 1877 |
d->maskRect = QRect(); |
1878 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1879 |
} |
|
1880 |
break; |
|
1881 |
||
1882 |
case Qt::ReplaceClip: |
|
1883 |
{ |
|
1884 |
QRegion r = d->transform.map(region); |
|
1885 |
if (isDefaultClipRegion(r)) { |
|
1886 |
// Replacing the clip with a full-window region is the |
|
1887 |
// same as turning off clipping. |
|
1888 |
if (d->maskValid) |
|
1889 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1890 |
d->maskValid = false; |
|
1891 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1892 |
d->scissorMask = false; |
0 | 1893 |
d->maskRect = QRect(); |
1894 |
} else { |
|
1895 |
// Special case: if the intersection of the system |
|
1896 |
// clip and the region is a single rectangle, then |
|
1897 |
// use the scissor for clipping. |
|
1898 |
QRegion clip = d->systemClip; |
|
1899 |
if (clip.isEmpty()) |
|
1900 |
clip = r; |
|
1901 |
else |
|
1902 |
clip = clip.intersect(r); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1903 |
if (clip.rectCount() == 1) { |
0 | 1904 |
d->maskValid = false; |
1905 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1906 |
d->scissorMask = true; |
0 | 1907 |
d->maskRect = clip.boundingRect(); |
1908 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1909 |
updateScissor(); |
|
1910 |
} else { |
|
1911 |
d->maskValid = false; |
|
1912 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1913 |
d->scissorMask = false; |
0 | 1914 |
d->maskRect = QRect(); |
1915 |
d->modifyMask(this, VG_FILL_MASK, r); |
|
1916 |
} |
|
1917 |
} |
|
1918 |
} |
|
1919 |
break; |
|
1920 |
||
1921 |
case Qt::IntersectClip: |
|
1922 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1923 |
if (region.rectCount() != 1) { |
0 | 1924 |
// If there is more than one rectangle, then intersecting |
1925 |
// the rectangles one by one in modifyMask() will not give |
|
1926 |
// the desired result. So fall back to path-based clipping. |
|
1927 |
QPaintEngineEx::clip(region, op); |
|
1928 |
return; |
|
1929 |
} |
|
1930 |
QRegion r = d->transform.map(region); |
|
1931 |
if (d->maskIsSet && isDefaultClipRegion(r)) { |
|
1932 |
// Intersecting a full-window clip with a full-window |
|
1933 |
// region is the same as turning off clipping. |
|
1934 |
if (d->maskValid) |
|
1935 |
vgSeti(VG_MASKING, VG_FALSE); |
|
1936 |
d->maskValid = false; |
|
1937 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1938 |
d->scissorMask = false; |
0 | 1939 |
d->maskRect = QRect(); |
1940 |
} else { |
|
1941 |
d->modifyMask(this, VG_INTERSECT_MASK, r); |
|
1942 |
} |
|
1943 |
} |
|
1944 |
break; |
|
1945 |
||
1946 |
case Qt::UniteClip: |
|
1947 |
{ |
|
1948 |
// If we already have a full-window clip, then uniting a |
|
1949 |
// region with it will do nothing. Otherwise union. |
|
1950 |
if (!(d->maskIsSet)) |
|
1951 |
d->modifyMask(this, VG_UNION_MASK, d->transform.map(region)); |
|
1952 |
} |
|
1953 |
break; |
|
1954 |
} |
|
1955 |
} |
|
1956 |
||
1957 |
#if !defined(QVG_NO_RENDER_TO_MASK) |
|
1958 |
||
1959 |
// Copied from qpathclipper.cpp. |
|
1960 |
static bool qt_vg_pathToRect(const QPainterPath &path, QRectF *rect) |
|
1961 |
{ |
|
1962 |
if (path.elementCount() != 5) |
|
1963 |
return false; |
|
1964 |
||
1965 |
const bool mightBeRect = path.elementAt(0).isMoveTo() |
|
1966 |
&& path.elementAt(1).isLineTo() |
|
1967 |
&& path.elementAt(2).isLineTo() |
|
1968 |
&& path.elementAt(3).isLineTo() |
|
1969 |
&& path.elementAt(4).isLineTo(); |
|
1970 |
||
1971 |
if (!mightBeRect) |
|
1972 |
return false; |
|
1973 |
||
1974 |
const qreal x1 = path.elementAt(0).x; |
|
1975 |
const qreal y1 = path.elementAt(0).y; |
|
1976 |
||
1977 |
const qreal x2 = path.elementAt(1).x; |
|
1978 |
const qreal y2 = path.elementAt(2).y; |
|
1979 |
||
1980 |
if (path.elementAt(1).y != y1) |
|
1981 |
return false; |
|
1982 |
||
1983 |
if (path.elementAt(2).x != x2) |
|
1984 |
return false; |
|
1985 |
||
1986 |
if (path.elementAt(3).x != x1 || path.elementAt(3).y != y2) |
|
1987 |
return false; |
|
1988 |
||
1989 |
if (path.elementAt(4).x != x1 || path.elementAt(4).y != y1) |
|
1990 |
return false; |
|
1991 |
||
1992 |
if (rect) |
|
1993 |
*rect = QRectF(QPointF(x1, y1), QPointF(x2, y2)); |
|
1994 |
||
1995 |
return true; |
|
1996 |
} |
|
1997 |
||
1998 |
#endif |
|
1999 |
||
2000 |
void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) |
|
2001 |
{ |
|
2002 |
#if !defined(QVG_NO_RENDER_TO_MASK) |
|
2003 |
Q_D(QVGPaintEngine); |
|
2004 |
||
2005 |
// If the path is a simple rectangle, then use clip(QRect) instead. |
|
2006 |
QRectF simpleRect; |
|
2007 |
if (qt_vg_pathToRect(path, &simpleRect)) { |
|
2008 |
clip(simpleRect.toRect(), op); |
|
2009 |
return; |
|
2010 |
} |
|
2011 |
||
2012 |
d->dirty |= QPaintEngine::DirtyClipRegion; |
|
2013 |
||
2014 |
if (op == Qt::NoClip) { |
|
2015 |
d->maskValid = false; |
|
2016 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2017 |
d->scissorMask = false; |
0 | 2018 |
d->maskRect = QRect(); |
2019 |
vgSeti(VG_MASKING, VG_FALSE); |
|
2020 |
return; |
|
2021 |
} |
|
2022 |
||
2023 |
QPaintDevice *pdev = paintDevice(); |
|
2024 |
int width = pdev->width(); |
|
2025 |
int height = pdev->height(); |
|
2026 |
||
2027 |
if (op == Qt::ReplaceClip) { |
|
2028 |
vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK, 0, 0, width, height); |
|
2029 |
d->maskRect = QRect(); |
|
2030 |
} else if (!d->maskValid) { |
|
2031 |
d->ensureMask(this, width, height); |
|
2032 |
} |
|
2033 |
||
2034 |
d->ensurePathTransform(); |
|
2035 |
VGPath vgpath = d->painterPathToVGPath(path); |
|
2036 |
switch (op) { |
|
2037 |
case Qt::ReplaceClip: |
|
2038 |
case Qt::UniteClip: |
|
2039 |
vgRenderToMask(vgpath, VG_FILL_PATH, VG_UNION_MASK); |
|
2040 |
break; |
|
2041 |
||
2042 |
case Qt::IntersectClip: |
|
2043 |
vgRenderToMask(vgpath, VG_FILL_PATH, VG_INTERSECT_MASK); |
|
2044 |
break; |
|
2045 |
||
2046 |
default: break; |
|
2047 |
} |
|
2048 |
vgDestroyPath(vgpath); |
|
2049 |
||
2050 |
vgSeti(VG_MASKING, VG_TRUE); |
|
2051 |
d->maskValid = true; |
|
2052 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2053 |
d->scissorMask = false; |
0 | 2054 |
#else |
2055 |
QPaintEngineEx::clip(path, op); |
|
2056 |
#endif |
|
2057 |
} |
|
2058 |
||
2059 |
void QVGPaintEnginePrivate::ensureMask |
|
2060 |
(QVGPaintEngine *engine, int width, int height) |
|
2061 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2062 |
scissorMask = false; |
0 | 2063 |
if (maskIsSet) { |
2064 |
vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, 0, 0, width, height); |
|
2065 |
maskRect = QRect(); |
|
2066 |
} else { |
|
2067 |
vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK, 0, 0, width, height); |
|
2068 |
if (maskRect.isValid()) { |
|
2069 |
vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, |
|
2070 |
maskRect.x(), height - maskRect.y() - maskRect.height(), |
|
2071 |
maskRect.width(), maskRect.height()); |
|
2072 |
maskRect = QRect(); |
|
2073 |
engine->updateScissor(); |
|
2074 |
} |
|
2075 |
} |
|
2076 |
} |
|
2077 |
||
2078 |
void QVGPaintEnginePrivate::modifyMask |
|
2079 |
(QVGPaintEngine *engine, VGMaskOperation op, const QRegion& region) |
|
2080 |
{ |
|
2081 |
QPaintDevice *pdev = engine->paintDevice(); |
|
2082 |
int width = pdev->width(); |
|
2083 |
int height = pdev->height(); |
|
2084 |
||
2085 |
if (!maskValid) |
|
2086 |
ensureMask(engine, width, height); |
|
2087 |
||
2088 |
QVector<QRect> rects = region.rects(); |
|
2089 |
for (int i = 0; i < rects.size(); ++i) { |
|
2090 |
vgMask(VG_INVALID_HANDLE, op, |
|
2091 |
rects[i].x(), height - rects[i].y() - rects[i].height(), |
|
2092 |
rects[i].width(), rects[i].height()); |
|
2093 |
} |
|
2094 |
||
2095 |
vgSeti(VG_MASKING, VG_TRUE); |
|
2096 |
maskValid = true; |
|
2097 |
maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2098 |
scissorMask = false; |
0 | 2099 |
} |
2100 |
||
2101 |
void QVGPaintEnginePrivate::modifyMask |
|
2102 |
(QVGPaintEngine *engine, VGMaskOperation op, const QRect& rect) |
|
2103 |
{ |
|
2104 |
QPaintDevice *pdev = engine->paintDevice(); |
|
2105 |
int width = pdev->width(); |
|
2106 |
int height = pdev->height(); |
|
2107 |
||
2108 |
if (!maskValid) |
|
2109 |
ensureMask(engine, width, height); |
|
2110 |
||
2111 |
if (rect.isValid()) { |
|
2112 |
vgMask(VG_INVALID_HANDLE, op, |
|
2113 |
rect.x(), height - rect.y() - rect.height(), |
|
2114 |
rect.width(), rect.height()); |
|
2115 |
} |
|
2116 |
||
2117 |
vgSeti(VG_MASKING, VG_TRUE); |
|
2118 |
maskValid = true; |
|
2119 |
maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2120 |
scissorMask = false; |
0 | 2121 |
} |
2122 |
||
2123 |
#endif // !QVG_SCISSOR_CLIP |
|
2124 |
||
2125 |
void QVGPaintEngine::updateScissor() |
|
2126 |
{ |
|
2127 |
Q_D(QVGPaintEngine); |
|
2128 |
||
2129 |
QRegion region = d->systemClip; |
|
2130 |
||
2131 |
#if defined(QVG_SCISSOR_CLIP) |
|
2132 |
// Using the scissor to do clipping, so combine the systemClip |
|
2133 |
// with the current painting clipRegion. |
|
2134 |
QVGPainterState *s = state(); |
|
2135 |
if (s->clipEnabled) { |
|
2136 |
if (region.isEmpty()) |
|
2137 |
region = s->clipRegion; |
|
2138 |
else |
|
2139 |
region = region.intersect(s->clipRegion); |
|
2140 |
if (isDefaultClipRegion(region)) { |
|
2141 |
// The scissor region is the entire drawing surface, |
|
2142 |
// so there is no point doing any scissoring. |
|
2143 |
vgSeti(VG_SCISSORING, VG_FALSE); |
|
2144 |
d->scissorActive = false; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2145 |
d->scissorDirty = false; |
0 | 2146 |
return; |
2147 |
} |
|
2148 |
} else |
|
2149 |
#endif |
|
2150 |
{ |
|
2151 |
#if !defined(QVG_SCISSOR_CLIP) |
|
2152 |
// Combine the system clip with the simple mask rectangle. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2153 |
if (d->scissorMask) { |
0 | 2154 |
if (region.isEmpty()) |
2155 |
region = d->maskRect; |
|
2156 |
else |
|
2157 |
region = region.intersect(d->maskRect); |
|
2158 |
if (isDefaultClipRegion(region)) { |
|
2159 |
// The scissor region is the entire drawing surface, |
|
2160 |
// so there is no point doing any scissoring. |
|
2161 |
vgSeti(VG_SCISSORING, VG_FALSE); |
|
2162 |
d->scissorActive = false; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2163 |
d->scissorDirty = false; |
0 | 2164 |
return; |
2165 |
} |
|
2166 |
} else |
|
2167 |
#endif |
|
2168 |
||
2169 |
// Disable the scissor completely if the system clip is empty. |
|
2170 |
if (region.isEmpty()) { |
|
2171 |
vgSeti(VG_SCISSORING, VG_FALSE); |
|
2172 |
d->scissorActive = false; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2173 |
d->scissorDirty = false; |
0 | 2174 |
return; |
2175 |
} |
|
2176 |
} |
|
2177 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2178 |
if (d->scissorActive && region == d->scissorRegion && !d->scissorDirty) |
0 | 2179 |
return; |
2180 |
||
2181 |
QVector<QRect> rects = region.rects(); |
|
2182 |
int count = rects.count(); |
|
2183 |
if (count > d->maxScissorRects) |
|
2184 |
count = d->maxScissorRects; |
|
2185 |
QVarLengthArray<VGint> params(count * 4); |
|
2186 |
int height = paintDevice()->height(); |
|
2187 |
for (int i = 0; i < count; ++i) { |
|
2188 |
params[i * 4 + 0] = rects[i].x(); |
|
2189 |
params[i * 4 + 1] = height - rects[i].y() - rects[i].height(); |
|
2190 |
params[i * 4 + 2] = rects[i].width(); |
|
2191 |
params[i * 4 + 3] = rects[i].height(); |
|
2192 |
} |
|
2193 |
||
2194 |
vgSetiv(VG_SCISSOR_RECTS, count * 4, params.data()); |
|
2195 |
vgSeti(VG_SCISSORING, VG_TRUE); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2196 |
d->scissorDirty = false; |
0 | 2197 |
d->scissorActive = true; |
2198 |
d->scissorRegion = region; |
|
2199 |
} |
|
2200 |
||
2201 |
QRegion QVGPaintEngine::defaultClipRegion() |
|
2202 |
{ |
|
2203 |
// The default clip region for a paint device is the whole drawing area. |
|
2204 |
QPaintDevice *pdev = paintDevice(); |
|
2205 |
return QRegion(0, 0, pdev->width(), pdev->height()); |
|
2206 |
} |
|
2207 |
||
2208 |
bool QVGPaintEngine::isDefaultClipRegion(const QRegion& region) |
|
2209 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2210 |
if (region.rectCount() != 1) |
0 | 2211 |
return false; |
2212 |
||
2213 |
QPaintDevice *pdev = paintDevice(); |
|
2214 |
int width = pdev->width(); |
|
2215 |
int height = pdev->height(); |
|
2216 |
||
2217 |
QRect rect = region.boundingRect(); |
|
2218 |
return (rect.x() == 0 && rect.y() == 0 && |
|
2219 |
rect.width() == width && rect.height() == height); |
|
2220 |
} |
|
2221 |
||
2222 |
bool QVGPaintEngine::isDefaultClipRect(const QRect& rect) |
|
2223 |
{ |
|
2224 |
QPaintDevice *pdev = paintDevice(); |
|
2225 |
int width = pdev->width(); |
|
2226 |
int height = pdev->height(); |
|
2227 |
||
2228 |
return (rect.x() == 0 && rect.y() == 0 && |
|
2229 |
rect.width() == width && rect.height() == height); |
|
2230 |
} |
|
2231 |
||
2232 |
void QVGPaintEngine::clipEnabledChanged() |
|
2233 |
{ |
|
2234 |
#if defined(QVG_SCISSOR_CLIP) |
|
2235 |
updateScissor(); |
|
2236 |
#else |
|
2237 |
Q_D(QVGPaintEngine); |
|
2238 |
QVGPainterState *s = state(); |
|
2239 |
d->dirty |= QPaintEngine::DirtyClipEnabled; |
|
2240 |
if (s->clipEnabled && s->clipOperation != Qt::NoClip) { |
|
2241 |
// Replay the entire clip stack to put the mask into the right state. |
|
2242 |
d->maskValid = false; |
|
2243 |
d->maskIsSet = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2244 |
d->scissorMask = false; |
0 | 2245 |
d->maskRect = QRect(); |
2246 |
s->clipRegion = defaultClipRegion(); |
|
2247 |
d->replayClipOperations(); |
|
2248 |
d->transform = s->transform(); |
|
2249 |
d->updateTransform(paintDevice()); |
|
2250 |
} else { |
|
2251 |
vgSeti(VG_MASKING, VG_FALSE); |
|
2252 |
d->maskValid = false; |
|
2253 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2254 |
d->scissorMask = false; |
0 | 2255 |
d->maskRect = QRect(); |
2256 |
} |
|
2257 |
#endif |
|
2258 |
} |
|
2259 |
||
2260 |
void QVGPaintEngine::penChanged() |
|
2261 |
{ |
|
2262 |
Q_D(QVGPaintEngine); |
|
2263 |
d->dirty |= QPaintEngine::DirtyPen; |
|
2264 |
} |
|
2265 |
||
2266 |
void QVGPaintEngine::brushChanged() |
|
2267 |
{ |
|
2268 |
Q_D(QVGPaintEngine); |
|
2269 |
d->dirty |= QPaintEngine::DirtyBrush; |
|
2270 |
} |
|
2271 |
||
2272 |
void QVGPaintEngine::brushOriginChanged() |
|
2273 |
{ |
|
2274 |
Q_D(QVGPaintEngine); |
|
2275 |
d->dirty |= QPaintEngine::DirtyBrushOrigin; |
|
2276 |
d->brushOrigin = state()->brushOrigin; |
|
2277 |
d->forcePenChange = true; |
|
2278 |
d->forceBrushChange = true; |
|
2279 |
} |
|
2280 |
||
2281 |
void QVGPaintEngine::opacityChanged() |
|
2282 |
{ |
|
2283 |
Q_D(QVGPaintEngine); |
|
2284 |
d->dirty |= QPaintEngine::DirtyOpacity; |
|
2285 |
d->opacity = state()->opacity; |
|
2286 |
d->forcePenChange = true; |
|
2287 |
d->forceBrushChange = true; |
|
2288 |
} |
|
2289 |
||
2290 |
void QVGPaintEngine::compositionModeChanged() |
|
2291 |
{ |
|
2292 |
Q_D(QVGPaintEngine); |
|
2293 |
d->dirty |= QPaintEngine::DirtyCompositionMode; |
|
2294 |
||
2295 |
VGBlendMode vgMode = VG_BLEND_SRC_OVER; |
|
2296 |
||
2297 |
switch (state()->composition_mode) { |
|
2298 |
case QPainter::CompositionMode_SourceOver: |
|
2299 |
vgMode = VG_BLEND_SRC_OVER; |
|
2300 |
break; |
|
2301 |
case QPainter::CompositionMode_DestinationOver: |
|
2302 |
vgMode = VG_BLEND_DST_OVER; |
|
2303 |
break; |
|
2304 |
case QPainter::CompositionMode_Source: |
|
2305 |
vgMode = VG_BLEND_SRC; |
|
2306 |
break; |
|
2307 |
case QPainter::CompositionMode_SourceIn: |
|
2308 |
vgMode = VG_BLEND_SRC_IN; |
|
2309 |
break; |
|
2310 |
case QPainter::CompositionMode_DestinationIn: |
|
2311 |
vgMode = VG_BLEND_DST_IN; |
|
2312 |
break; |
|
2313 |
case QPainter::CompositionMode_Plus: |
|
2314 |
vgMode = VG_BLEND_ADDITIVE; |
|
2315 |
break; |
|
2316 |
case QPainter::CompositionMode_Multiply: |
|
2317 |
vgMode = VG_BLEND_MULTIPLY; |
|
2318 |
break; |
|
2319 |
case QPainter::CompositionMode_Screen: |
|
2320 |
vgMode = VG_BLEND_SCREEN; |
|
2321 |
break; |
|
2322 |
case QPainter::CompositionMode_Darken: |
|
2323 |
vgMode = VG_BLEND_DARKEN; |
|
2324 |
break; |
|
2325 |
case QPainter::CompositionMode_Lighten: |
|
2326 |
vgMode = VG_BLEND_LIGHTEN; |
|
2327 |
break; |
|
2328 |
default: |
|
2329 |
qWarning() << "QVGPaintEngine::compositionModeChanged unsupported mode" << state()->composition_mode; |
|
2330 |
break; // Fall back to VG_BLEND_SRC_OVER. |
|
2331 |
} |
|
2332 |
||
2333 |
d->setBlendMode(vgMode); |
|
2334 |
} |
|
2335 |
||
2336 |
void QVGPaintEngine::renderHintsChanged() |
|
2337 |
{ |
|
2338 |
Q_D(QVGPaintEngine); |
|
2339 |
d->dirty |= QPaintEngine::DirtyHints; |
|
2340 |
||
2341 |
QPainter::RenderHints hints = state()->renderHints; |
|
2342 |
||
2343 |
VGRenderingQuality rq = |
|
2344 |
(hints & QPainter::Antialiasing) |
|
2345 |
? VG_RENDERING_QUALITY_BETTER |
|
2346 |
: VG_RENDERING_QUALITY_NONANTIALIASED; |
|
2347 |
VGImageQuality iq = |
|
2348 |
(hints & QPainter::SmoothPixmapTransform) |
|
2349 |
? VG_IMAGE_QUALITY_BETTER |
|
2350 |
: VG_IMAGE_QUALITY_NONANTIALIASED; |
|
2351 |
||
2352 |
d->setRenderingQuality(rq); |
|
2353 |
d->setImageQuality(iq); |
|
2354 |
} |
|
2355 |
||
2356 |
void QVGPaintEngine::transformChanged() |
|
2357 |
{ |
|
2358 |
Q_D(QVGPaintEngine); |
|
2359 |
QVGPainterState *s = state(); |
|
2360 |
d->dirty |= QPaintEngine::DirtyTransform; |
|
2361 |
d->transform = s->transform(); |
|
2362 |
qreal oldPenScale = d->penScale; |
|
2363 |
d->updateTransform(paintDevice()); |
|
2364 |
if (d->penScale != oldPenScale) |
|
2365 |
d->forcePenChange = true; |
|
2366 |
} |
|
2367 |
||
2368 |
bool QVGPaintEngine::clearRect(const QRectF &rect, const QColor &color) |
|
2369 |
{ |
|
2370 |
Q_D(QVGPaintEngine); |
|
2371 |
QVGPainterState *s = state(); |
|
2372 |
if (!s->clipEnabled || s->clipOperation == Qt::NoClip) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2373 |
QRect r = d->transform.mapRect(rect).toRect(); |
0 | 2374 |
int height = paintDevice()->height(); |
2375 |
if (d->clearColor != color || d->clearOpacity != s->opacity) { |
|
2376 |
VGfloat values[4]; |
|
2377 |
values[0] = color.redF(); |
|
2378 |
values[1] = color.greenF(); |
|
2379 |
values[2] = color.blueF(); |
|
2380 |
values[3] = color.alphaF() * s->opacity; |
|
2381 |
vgSetfv(VG_CLEAR_COLOR, 4, values); |
|
2382 |
d->clearColor = color; |
|
2383 |
d->clearOpacity = s->opacity; |
|
2384 |
} |
|
2385 |
vgClear(r.x(), height - r.y() - r.height(), |
|
2386 |
r.width(), r.height()); |
|
2387 |
return true; |
|
2388 |
} |
|
2389 |
return false; |
|
2390 |
} |
|
2391 |
||
2392 |
void QVGPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) |
|
2393 |
{ |
|
2394 |
Q_D(QVGPaintEngine); |
|
2395 |
||
2396 |
if (brush.style() == Qt::NoBrush) |
|
2397 |
return; |
|
2398 |
||
2399 |
// Check to see if we can use vgClear() for faster filling. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2400 |
if (brush.style() == Qt::SolidPattern && brush.isOpaque() && |
0 | 2401 |
clipTransformIsSimple(d->transform) && d->opacity == 1.0f && |
2402 |
clearRect(rect, brush.color())) { |
|
2403 |
return; |
|
2404 |
} |
|
2405 |
||
2406 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2407 |
VGfloat coords[8]; |
|
2408 |
if (d->simpleTransform) { |
|
2409 |
coords[0] = rect.x(); |
|
2410 |
coords[1] = rect.y(); |
|
2411 |
coords[2] = rect.x() + rect.width(); |
|
2412 |
coords[3] = coords[1]; |
|
2413 |
coords[4] = coords[2]; |
|
2414 |
coords[5] = rect.y() + rect.height(); |
|
2415 |
coords[6] = coords[0]; |
|
2416 |
coords[7] = coords[5]; |
|
2417 |
} else { |
|
2418 |
QPointF tl = d->transform.map(rect.topLeft()); |
|
2419 |
QPointF tr = d->transform.map(rect.topRight()); |
|
2420 |
QPointF bl = d->transform.map(rect.bottomLeft()); |
|
2421 |
QPointF br = d->transform.map(rect.bottomRight()); |
|
2422 |
coords[0] = tl.x(); |
|
2423 |
coords[1] = tl.y(); |
|
2424 |
coords[2] = tr.x(); |
|
2425 |
coords[3] = tr.y(); |
|
2426 |
coords[4] = br.x(); |
|
2427 |
coords[5] = br.y(); |
|
2428 |
coords[6] = bl.x(); |
|
2429 |
coords[7] = bl.y(); |
|
2430 |
} |
|
2431 |
vgModifyPathCoords(d->rectPath, 0, 4, coords); |
|
2432 |
d->fill(d->rectPath, brush); |
|
2433 |
#else |
|
2434 |
QPaintEngineEx::fillRect(rect, brush); |
|
2435 |
#endif |
|
2436 |
} |
|
2437 |
||
2438 |
void QVGPaintEngine::fillRect(const QRectF &rect, const QColor &color) |
|
2439 |
{ |
|
2440 |
Q_D(QVGPaintEngine); |
|
2441 |
||
2442 |
// Check to see if we can use vgClear() for faster filling. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2443 |
if (clipTransformIsSimple(d->transform) && d->opacity == 1.0f && color.alpha() == 255 && |
0 | 2444 |
clearRect(rect, color)) { |
2445 |
return; |
|
2446 |
} |
|
2447 |
||
2448 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2449 |
VGfloat coords[8]; |
|
2450 |
if (d->simpleTransform) { |
|
2451 |
coords[0] = rect.x(); |
|
2452 |
coords[1] = rect.y(); |
|
2453 |
coords[2] = rect.x() + rect.width(); |
|
2454 |
coords[3] = coords[1]; |
|
2455 |
coords[4] = coords[2]; |
|
2456 |
coords[5] = rect.y() + rect.height(); |
|
2457 |
coords[6] = coords[0]; |
|
2458 |
coords[7] = coords[5]; |
|
2459 |
} else { |
|
2460 |
QPointF tl = d->transform.map(rect.topLeft()); |
|
2461 |
QPointF tr = d->transform.map(rect.topRight()); |
|
2462 |
QPointF bl = d->transform.map(rect.bottomLeft()); |
|
2463 |
QPointF br = d->transform.map(rect.bottomRight()); |
|
2464 |
coords[0] = tl.x(); |
|
2465 |
coords[1] = tl.y(); |
|
2466 |
coords[2] = tr.x(); |
|
2467 |
coords[3] = tr.y(); |
|
2468 |
coords[4] = br.x(); |
|
2469 |
coords[5] = br.y(); |
|
2470 |
coords[6] = bl.x(); |
|
2471 |
coords[7] = bl.y(); |
|
2472 |
} |
|
2473 |
vgModifyPathCoords(d->rectPath, 0, 4, coords); |
|
2474 |
d->fill(d->rectPath, QBrush(color)); |
|
2475 |
#else |
|
2476 |
QPaintEngineEx::fillRect(rect, QBrush(color)); |
|
2477 |
#endif |
|
2478 |
} |
|
2479 |
||
2480 |
void QVGPaintEngine::drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode) |
|
2481 |
{ |
|
2482 |
Q_D(QVGPaintEngine); |
|
2483 |
if (d->simpleTransform) { |
|
2484 |
QVGPainterState *s = state(); |
|
2485 |
VGPath vgpath = d->roundedRectPath(rect, xrad, yrad, mode); |
|
2486 |
d->draw(vgpath, s->pen, s->brush); |
|
2487 |
#if defined(QVG_NO_MODIFY_PATH) |
|
2488 |
vgDestroyPath(vgpath); |
|
2489 |
#endif |
|
2490 |
} else { |
|
2491 |
QPaintEngineEx::drawRoundedRect(rect, xrad, yrad, mode); |
|
2492 |
} |
|
2493 |
} |
|
2494 |
||
2495 |
void QVGPaintEngine::drawRects(const QRect *rects, int rectCount) |
|
2496 |
{ |
|
2497 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2498 |
Q_D(QVGPaintEngine); |
|
2499 |
QVGPainterState *s = state(); |
|
2500 |
for (int i = 0; i < rectCount; ++i, ++rects) { |
|
2501 |
VGfloat coords[8]; |
|
2502 |
if (d->simpleTransform) { |
|
2503 |
coords[0] = rects->x(); |
|
2504 |
coords[1] = rects->y(); |
|
2505 |
coords[2] = rects->x() + rects->width(); |
|
2506 |
coords[3] = coords[1]; |
|
2507 |
coords[4] = coords[2]; |
|
2508 |
coords[5] = rects->y() + rects->height(); |
|
2509 |
coords[6] = coords[0]; |
|
2510 |
coords[7] = coords[5]; |
|
2511 |
} else { |
|
2512 |
QPointF tl = d->transform.map(QPointF(rects->x(), rects->y())); |
|
2513 |
QPointF tr = d->transform.map(QPointF(rects->x() + rects->width(), |
|
2514 |
rects->y())); |
|
2515 |
QPointF bl = d->transform.map(QPointF(rects->x(), |
|
2516 |
rects->y() + rects->height())); |
|
2517 |
QPointF br = d->transform.map(QPointF(rects->x() + rects->width(), |
|
2518 |
rects->y() + rects->height())); |
|
2519 |
coords[0] = tl.x(); |
|
2520 |
coords[1] = tl.y(); |
|
2521 |
coords[2] = tr.x(); |
|
2522 |
coords[3] = tr.y(); |
|
2523 |
coords[4] = br.x(); |
|
2524 |
coords[5] = br.y(); |
|
2525 |
coords[6] = bl.x(); |
|
2526 |
coords[7] = bl.y(); |
|
2527 |
} |
|
2528 |
vgModifyPathCoords(d->rectPath, 0, 4, coords); |
|
2529 |
d->draw(d->rectPath, s->pen, s->brush); |
|
2530 |
} |
|
2531 |
#else |
|
2532 |
QPaintEngineEx::drawRects(rects, rectCount); |
|
2533 |
#endif |
|
2534 |
} |
|
2535 |
||
2536 |
void QVGPaintEngine::drawRects(const QRectF *rects, int rectCount) |
|
2537 |
{ |
|
2538 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2539 |
Q_D(QVGPaintEngine); |
|
2540 |
QVGPainterState *s = state(); |
|
2541 |
for (int i = 0; i < rectCount; ++i, ++rects) { |
|
2542 |
VGfloat coords[8]; |
|
2543 |
if (d->simpleTransform) { |
|
2544 |
coords[0] = rects->x(); |
|
2545 |
coords[1] = rects->y(); |
|
2546 |
coords[2] = rects->x() + rects->width(); |
|
2547 |
coords[3] = coords[1]; |
|
2548 |
coords[4] = coords[2]; |
|
2549 |
coords[5] = rects->y() + rects->height(); |
|
2550 |
coords[6] = coords[0]; |
|
2551 |
coords[7] = coords[5]; |
|
2552 |
} else { |
|
2553 |
QPointF tl = d->transform.map(rects->topLeft()); |
|
2554 |
QPointF tr = d->transform.map(rects->topRight()); |
|
2555 |
QPointF bl = d->transform.map(rects->bottomLeft()); |
|
2556 |
QPointF br = d->transform.map(rects->bottomRight()); |
|
2557 |
coords[0] = tl.x(); |
|
2558 |
coords[1] = tl.y(); |
|
2559 |
coords[2] = tr.x(); |
|
2560 |
coords[3] = tr.y(); |
|
2561 |
coords[4] = br.x(); |
|
2562 |
coords[5] = br.y(); |
|
2563 |
coords[6] = bl.x(); |
|
2564 |
coords[7] = bl.y(); |
|
2565 |
} |
|
2566 |
vgModifyPathCoords(d->rectPath, 0, 4, coords); |
|
2567 |
d->draw(d->rectPath, s->pen, s->brush); |
|
2568 |
} |
|
2569 |
#else |
|
2570 |
QPaintEngineEx::drawRects(rects, rectCount); |
|
2571 |
#endif |
|
2572 |
} |
|
2573 |
||
2574 |
void QVGPaintEngine::drawLines(const QLine *lines, int lineCount) |
|
2575 |
{ |
|
2576 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2577 |
Q_D(QVGPaintEngine); |
|
2578 |
QVGPainterState *s = state(); |
|
2579 |
for (int i = 0; i < lineCount; ++i, ++lines) { |
|
2580 |
VGfloat coords[4]; |
|
2581 |
if (d->simpleTransform) { |
|
2582 |
coords[0] = lines->x1(); |
|
2583 |
coords[1] = lines->y1(); |
|
2584 |
coords[2] = lines->x2(); |
|
2585 |
coords[3] = lines->y2(); |
|
2586 |
} else { |
|
2587 |
QPointF p1 = d->transform.map(QPointF(lines->x1(), lines->y1())); |
|
2588 |
QPointF p2 = d->transform.map(QPointF(lines->x2(), lines->y2())); |
|
2589 |
coords[0] = p1.x(); |
|
2590 |
coords[1] = p1.y(); |
|
2591 |
coords[2] = p2.x(); |
|
2592 |
coords[3] = p2.y(); |
|
2593 |
} |
|
2594 |
vgModifyPathCoords(d->linePath, 0, 2, coords); |
|
2595 |
d->stroke(d->linePath, s->pen); |
|
2596 |
} |
|
2597 |
#else |
|
2598 |
QPaintEngineEx::drawLines(lines, lineCount); |
|
2599 |
#endif |
|
2600 |
} |
|
2601 |
||
2602 |
void QVGPaintEngine::drawLines(const QLineF *lines, int lineCount) |
|
2603 |
{ |
|
2604 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2605 |
Q_D(QVGPaintEngine); |
|
2606 |
QVGPainterState *s = state(); |
|
2607 |
for (int i = 0; i < lineCount; ++i, ++lines) { |
|
2608 |
VGfloat coords[4]; |
|
2609 |
if (d->simpleTransform) { |
|
2610 |
coords[0] = lines->x1(); |
|
2611 |
coords[1] = lines->y1(); |
|
2612 |
coords[2] = lines->x2(); |
|
2613 |
coords[3] = lines->y2(); |
|
2614 |
} else { |
|
2615 |
QPointF p1 = d->transform.map(lines->p1()); |
|
2616 |
QPointF p2 = d->transform.map(lines->p2()); |
|
2617 |
coords[0] = p1.x(); |
|
2618 |
coords[1] = p1.y(); |
|
2619 |
coords[2] = p2.x(); |
|
2620 |
coords[3] = p2.y(); |
|
2621 |
} |
|
2622 |
vgModifyPathCoords(d->linePath, 0, 2, coords); |
|
2623 |
d->stroke(d->linePath, s->pen); |
|
2624 |
} |
|
2625 |
#else |
|
2626 |
QPaintEngineEx::drawLines(lines, lineCount); |
|
2627 |
#endif |
|
2628 |
} |
|
2629 |
||
2630 |
void QVGPaintEngine::drawEllipse(const QRectF &r) |
|
2631 |
{ |
|
2632 |
// Based on the description of vguEllipse() in the OpenVG specification. |
|
2633 |
// We don't use vguEllipse(), to avoid unnecessary library dependencies. |
|
2634 |
Q_D(QVGPaintEngine); |
|
2635 |
if (d->simpleTransform) { |
|
2636 |
QVGPainterState *s = state(); |
|
2637 |
VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
2638 |
VG_PATH_DATATYPE_F, |
|
2639 |
1.0f, // scale |
|
2640 |
0.0f, // bias |
|
2641 |
4, // segmentCapacityHint |
|
2642 |
12, // coordCapacityHint |
|
2643 |
VG_PATH_CAPABILITY_ALL); |
|
2644 |
static VGubyte segments[4] = { |
|
2645 |
VG_MOVE_TO_ABS, |
|
2646 |
VG_SCCWARC_TO_REL, |
|
2647 |
VG_SCCWARC_TO_REL, |
|
2648 |
VG_CLOSE_PATH |
|
2649 |
}; |
|
2650 |
VGfloat coords[12]; |
|
2651 |
VGfloat halfwid = r.width() / 2; |
|
2652 |
VGfloat halfht = r.height() / 2; |
|
2653 |
coords[0] = r.x() + r.width(); |
|
2654 |
coords[1] = r.y() + halfht; |
|
2655 |
coords[2] = halfwid; |
|
2656 |
coords[3] = halfht; |
|
2657 |
coords[4] = 0.0f; |
|
2658 |
coords[5] = -r.width(); |
|
2659 |
coords[6] = 0.0f; |
|
2660 |
coords[7] = halfwid; |
|
2661 |
coords[8] = halfht; |
|
2662 |
coords[9] = 0.0f; |
|
2663 |
coords[10] = r.width(); |
|
2664 |
coords[11] = 0.0f; |
|
2665 |
vgAppendPathData(path, 4, segments, coords); |
|
2666 |
d->draw(path, s->pen, s->brush); |
|
2667 |
vgDestroyPath(path); |
|
2668 |
} else { |
|
2669 |
// The projective transform version of an ellipse is difficult. |
|
2670 |
// Generate a QVectorPath containing cubic curves and transform that. |
|
2671 |
QPaintEngineEx::drawEllipse(r); |
|
2672 |
} |
|
2673 |
} |
|
2674 |
||
2675 |
void QVGPaintEngine::drawEllipse(const QRect &r) |
|
2676 |
{ |
|
2677 |
drawEllipse(QRectF(r)); |
|
2678 |
} |
|
2679 |
||
2680 |
void QVGPaintEngine::drawPath(const QPainterPath &path) |
|
2681 |
{ |
|
2682 |
// Shortcut past the QPainterPath -> QVectorPath conversion, |
|
2683 |
// converting the QPainterPath directly into a VGPath. |
|
2684 |
Q_D(QVGPaintEngine); |
|
2685 |
QVGPainterState *s = state(); |
|
2686 |
VGPath vgpath = d->painterPathToVGPath(path); |
|
2687 |
if (path.fillRule() == Qt::OddEvenFill) |
|
2688 |
d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); |
|
2689 |
else |
|
2690 |
d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); |
|
2691 |
vgDestroyPath(vgpath); |
|
2692 |
} |
|
2693 |
||
2694 |
void QVGPaintEngine::drawPoints(const QPointF *points, int pointCount) |
|
2695 |
{ |
|
2696 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2697 |
Q_D(QVGPaintEngine); |
|
2698 |
||
2699 |
// Set up a new pen if necessary. |
|
2700 |
QPen pen = state()->pen; |
|
2701 |
if (pen.style() == Qt::NoPen) |
|
2702 |
return; |
|
2703 |
if (pen.capStyle() == Qt::FlatCap) |
|
2704 |
pen.setCapStyle(Qt::SquareCap); |
|
2705 |
||
2706 |
for (int i = 0; i < pointCount; ++i, ++points) { |
|
2707 |
VGfloat coords[4]; |
|
2708 |
if (d->simpleTransform) { |
|
2709 |
coords[0] = points->x(); |
|
2710 |
coords[1] = points->y(); |
|
2711 |
coords[2] = coords[0]; |
|
2712 |
coords[3] = coords[1]; |
|
2713 |
} else { |
|
2714 |
QPointF p = d->transform.map(*points); |
|
2715 |
coords[0] = p.x(); |
|
2716 |
coords[1] = p.y(); |
|
2717 |
coords[2] = coords[0]; |
|
2718 |
coords[3] = coords[1]; |
|
2719 |
} |
|
2720 |
vgModifyPathCoords(d->linePath, 0, 2, coords); |
|
2721 |
d->stroke(d->linePath, pen); |
|
2722 |
} |
|
2723 |
#else |
|
2724 |
QPaintEngineEx::drawPoints(points, pointCount); |
|
2725 |
#endif |
|
2726 |
} |
|
2727 |
||
2728 |
void QVGPaintEngine::drawPoints(const QPoint *points, int pointCount) |
|
2729 |
{ |
|
2730 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
2731 |
Q_D(QVGPaintEngine); |
|
2732 |
||
2733 |
// Set up a new pen if necessary. |
|
2734 |
QPen pen = state()->pen; |
|
2735 |
if (pen.style() == Qt::NoPen) |
|
2736 |
return; |
|
2737 |
if (pen.capStyle() == Qt::FlatCap) |
|
2738 |
pen.setCapStyle(Qt::SquareCap); |
|
2739 |
||
2740 |
for (int i = 0; i < pointCount; ++i, ++points) { |
|
2741 |
VGfloat coords[4]; |
|
2742 |
if (d->simpleTransform) { |
|
2743 |
coords[0] = points->x(); |
|
2744 |
coords[1] = points->y(); |
|
2745 |
coords[2] = coords[0]; |
|
2746 |
coords[3] = coords[1]; |
|
2747 |
} else { |
|
2748 |
QPointF p = d->transform.map(QPointF(*points)); |
|
2749 |
coords[0] = p.x(); |
|
2750 |
coords[1] = p.y(); |
|
2751 |
coords[2] = coords[0]; |
|
2752 |
coords[3] = coords[1]; |
|
2753 |
} |
|
2754 |
vgModifyPathCoords(d->linePath, 0, 2, coords); |
|
2755 |
d->stroke(d->linePath, pen); |
|
2756 |
} |
|
2757 |
#else |
|
2758 |
QPaintEngineEx::drawPoints(points, pointCount); |
|
2759 |
#endif |
|
2760 |
} |
|
2761 |
||
2762 |
void QVGPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) |
|
2763 |
{ |
|
2764 |
Q_D(QVGPaintEngine); |
|
2765 |
QVGPainterState *s = state(); |
|
2766 |
VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
2767 |
VG_PATH_DATATYPE_F, |
|
2768 |
1.0f, // scale |
|
2769 |
0.0f, // bias |
|
2770 |
pointCount + 1, // segmentCapacityHint |
|
2771 |
pointCount * 2, // coordCapacityHint |
|
2772 |
VG_PATH_CAPABILITY_ALL); |
|
2773 |
QVarLengthArray<VGfloat, 16> coords; |
|
2774 |
QVarLengthArray<VGubyte, 10> segments; |
|
2775 |
for (int i = 0; i < pointCount; ++i, ++points) { |
|
2776 |
if (d->simpleTransform) { |
|
2777 |
coords.append(points->x()); |
|
2778 |
coords.append(points->y()); |
|
2779 |
} else { |
|
2780 |
QPointF temp = d->transform.map(*points); |
|
2781 |
coords.append(temp.x()); |
|
2782 |
coords.append(temp.y()); |
|
2783 |
} |
|
2784 |
if (i == 0) |
|
2785 |
segments.append(VG_MOVE_TO_ABS); |
|
2786 |
else |
|
2787 |
segments.append(VG_LINE_TO_ABS); |
|
2788 |
} |
|
2789 |
if (mode != QPaintEngine::PolylineMode) |
|
2790 |
segments.append(VG_CLOSE_PATH); |
|
2791 |
vgAppendPathData(path, segments.count(), |
|
2792 |
segments.constData(), coords.constData()); |
|
2793 |
switch (mode) { |
|
2794 |
case QPaintEngine::WindingMode: |
|
2795 |
d->draw(path, s->pen, s->brush, VG_NON_ZERO); |
|
2796 |
break; |
|
2797 |
||
2798 |
case QPaintEngine::PolylineMode: |
|
2799 |
d->stroke(path, s->pen); |
|
2800 |
break; |
|
2801 |
||
2802 |
default: |
|
2803 |
d->draw(path, s->pen, s->brush, VG_EVEN_ODD); |
|
2804 |
break; |
|
2805 |
} |
|
2806 |
vgDestroyPath(path); |
|
2807 |
} |
|
2808 |
||
2809 |
void QVGPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) |
|
2810 |
{ |
|
2811 |
Q_D(QVGPaintEngine); |
|
2812 |
QVGPainterState *s = state(); |
|
2813 |
VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, |
|
2814 |
VG_PATH_DATATYPE_F, |
|
2815 |
1.0f, // scale |
|
2816 |
0.0f, // bias |
|
2817 |
pointCount + 1, // segmentCapacityHint |
|
2818 |
pointCount * 2, // coordCapacityHint |
|
2819 |
VG_PATH_CAPABILITY_ALL); |
|
2820 |
QVarLengthArray<VGfloat, 16> coords; |
|
2821 |
QVarLengthArray<VGubyte, 10> segments; |
|
2822 |
for (int i = 0; i < pointCount; ++i, ++points) { |
|
2823 |
if (d->simpleTransform) { |
|
2824 |
coords.append(points->x()); |
|
2825 |
coords.append(points->y()); |
|
2826 |
} else { |
|
2827 |
QPointF temp = d->transform.map(QPointF(*points)); |
|
2828 |
coords.append(temp.x()); |
|
2829 |
coords.append(temp.y()); |
|
2830 |
} |
|
2831 |
if (i == 0) |
|
2832 |
segments.append(VG_MOVE_TO_ABS); |
|
2833 |
else |
|
2834 |
segments.append(VG_LINE_TO_ABS); |
|
2835 |
} |
|
2836 |
if (mode != QPaintEngine::PolylineMode) |
|
2837 |
segments.append(VG_CLOSE_PATH); |
|
2838 |
vgAppendPathData(path, segments.count(), |
|
2839 |
segments.constData(), coords.constData()); |
|
2840 |
switch (mode) { |
|
2841 |
case QPaintEngine::WindingMode: |
|
2842 |
d->draw(path, s->pen, s->brush, VG_NON_ZERO); |
|
2843 |
break; |
|
2844 |
||
2845 |
case QPaintEngine::PolylineMode: |
|
2846 |
d->stroke(path, s->pen); |
|
2847 |
break; |
|
2848 |
||
2849 |
default: |
|
2850 |
d->draw(path, s->pen, s->brush, VG_EVEN_ODD); |
|
2851 |
break; |
|
2852 |
} |
|
2853 |
vgDestroyPath(path); |
|
2854 |
} |
|
2855 |
||
2856 |
void QVGPaintEnginePrivate::setImageOptions() |
|
2857 |
{ |
|
2858 |
if (opacity != 1.0f && simpleTransform) { |
|
2859 |
if (opacity != paintOpacity) { |
|
2860 |
VGfloat values[4]; |
|
2861 |
values[0] = 1.0f; |
|
2862 |
values[1] = 1.0f; |
|
2863 |
values[2] = 1.0f; |
|
2864 |
values[3] = opacity; |
|
2865 |
vgSetParameterfv(opacityPaint, VG_PAINT_COLOR, 4, values); |
|
2866 |
paintOpacity = opacity; |
|
2867 |
} |
|
2868 |
if (fillPaint != opacityPaint) { |
|
2869 |
vgSetPaint(opacityPaint, VG_FILL_PATH); |
|
2870 |
fillPaint = opacityPaint; |
|
2871 |
} |
|
2872 |
setImageMode(VG_DRAW_IMAGE_MULTIPLY); |
|
2873 |
} else { |
|
2874 |
setImageMode(VG_DRAW_IMAGE_NORMAL); |
|
2875 |
} |
|
2876 |
} |
|
2877 |
||
2878 |
static void drawVGImage(QVGPaintEnginePrivate *d, |
|
2879 |
const QRectF& r, VGImage vgImg, |
|
2880 |
const QSize& imageSize, const QRectF& sr) |
|
2881 |
{ |
|
2882 |
if (vgImg == VG_INVALID_HANDLE) |
|
2883 |
return; |
|
2884 |
VGImage child = VG_INVALID_HANDLE; |
|
2885 |
||
2886 |
if (sr.topLeft().isNull() && sr.size() == imageSize) { |
|
2887 |
child = vgImg; |
|
2888 |
} else { |
|
2889 |
QRect src = sr.toRect(); |
|
2890 |
#if !defined(QT_SHIVAVG) |
|
2891 |
child = vgChildImage(vgImg, src.x(), src.y(), src.width(), src.height()); |
|
2892 |
#else |
|
2893 |
child = vgImg; // XXX: ShivaVG doesn't have vgChildImage(). |
|
2894 |
#endif |
|
2895 |
} |
|
2896 |
||
2897 |
QTransform transform(d->imageTransform); |
|
2898 |
VGfloat scaleX = sr.width() == 0.0f ? 0.0f : r.width() / sr.width(); |
|
2899 |
VGfloat scaleY = sr.height() == 0.0f ? 0.0f : r.height() / sr.height(); |
|
2900 |
transform.translate(r.x(), r.y()); |
|
2901 |
transform.scale(scaleX, scaleY); |
|
2902 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
|
2903 |
||
2904 |
d->setImageOptions(); |
|
2905 |
vgDrawImage(child); |
|
2906 |
||
2907 |
if(child != vgImg) |
|
2908 |
vgDestroyImage(child); |
|
2909 |
} |
|
2910 |
||
2911 |
static void drawVGImage(QVGPaintEnginePrivate *d, |
|
2912 |
const QPointF& pos, VGImage vgImg) |
|
2913 |
{ |
|
2914 |
if (vgImg == VG_INVALID_HANDLE) |
|
2915 |
return; |
|
2916 |
||
2917 |
QTransform transform(d->imageTransform); |
|
2918 |
transform.translate(pos.x(), pos.y()); |
|
2919 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
|
2920 |
||
2921 |
d->setImageOptions(); |
|
2922 |
vgDrawImage(vgImg); |
|
2923 |
} |
|
2924 |
||
2925 |
// Used by qpixmapfilter_vg.cpp to draw filtered VGImage's. |
|
2926 |
void qt_vg_drawVGImage(QPainter *painter, const QPointF& pos, VGImage vgImg) |
|
2927 |
{ |
|
2928 |
QVGPaintEngine *engine = |
|
2929 |
static_cast<QVGPaintEngine *>(painter->paintEngine()); |
|
2930 |
drawVGImage(engine->vgPrivate(), pos, vgImg); |
|
2931 |
} |
|
2932 |
||
2933 |
// Used by qpixmapfilter_vg.cpp to draw filtered VGImage's as a stencil. |
|
2934 |
void qt_vg_drawVGImageStencil |
|
2935 |
(QPainter *painter, const QPointF& pos, VGImage vgImg, const QBrush& brush) |
|
2936 |
{ |
|
2937 |
QVGPaintEngine *engine = |
|
2938 |
static_cast<QVGPaintEngine *>(painter->paintEngine()); |
|
2939 |
||
2940 |
QVGPaintEnginePrivate *d = engine->vgPrivate(); |
|
2941 |
||
2942 |
QTransform transform(d->imageTransform); |
|
2943 |
transform.translate(pos.x(), pos.y()); |
|
2944 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
|
2945 |
||
2946 |
d->ensureBrush(brush); |
|
2947 |
d->setImageMode(VG_DRAW_IMAGE_STENCIL); |
|
2948 |
vgDrawImage(vgImg); |
|
2949 |
} |
|
2950 |
||
2951 |
void QVGPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) |
|
2952 |
{ |
|
2953 |
QPixmapData *pd = pm.pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2954 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2955 |
return; // null QPixmap |
0 | 2956 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
2957 |
Q_D(QVGPaintEngine); |
|
2958 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
2959 |
if (!vgpd->isValid()) |
|
2960 |
return; |
|
2961 |
if (d->simpleTransform) |
|
2962 |
drawVGImage(d, r, vgpd->toVGImage(), vgpd->size(), sr); |
|
2963 |
else |
|
2964 |
drawVGImage(d, r, vgpd->toVGImage(d->opacity), vgpd->size(), sr); |
|
2965 |
} else { |
|
2966 |
drawImage(r, *(pd->buffer()), sr, Qt::AutoColor); |
|
2967 |
} |
|
2968 |
} |
|
2969 |
||
2970 |
void QVGPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pm) |
|
2971 |
{ |
|
2972 |
QPixmapData *pd = pm.pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2973 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2974 |
return; // null QPixmap |
0 | 2975 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
2976 |
Q_D(QVGPaintEngine); |
|
2977 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
2978 |
if (!vgpd->isValid()) |
|
2979 |
return; |
|
2980 |
if (d->simpleTransform) |
|
2981 |
drawVGImage(d, pos, vgpd->toVGImage()); |
|
2982 |
else |
|
2983 |
drawVGImage(d, pos, vgpd->toVGImage(d->opacity)); |
|
2984 |
} else { |
|
2985 |
drawImage(pos, *(pd->buffer())); |
|
2986 |
} |
|
2987 |
} |
|
2988 |
||
2989 |
void QVGPaintEngine::drawImage |
|
2990 |
(const QRectF &r, const QImage &image, const QRectF &sr, |
|
2991 |
Qt::ImageConversionFlags flags) |
|
2992 |
{ |
|
2993 |
Q_D(QVGPaintEngine); |
|
2994 |
VGImage vgImg; |
|
2995 |
if (d->simpleTransform || d->opacity == 1.0f) |
|
2996 |
vgImg = toVGImageSubRect(image, sr.toRect(), flags); |
|
2997 |
else |
|
2998 |
vgImg = toVGImageWithOpacitySubRect(image, d->opacity, sr.toRect()); |
|
2999 |
if (vgImg != VG_INVALID_HANDLE) { |
|
3000 |
if (r.size() == sr.size()) { |
|
3001 |
drawVGImage(d, r.topLeft(), vgImg); |
|
3002 |
} else { |
|
3003 |
drawVGImage(d, r, vgImg, sr.size().toSize(), |
|
3004 |
QRectF(QPointF(0, 0), sr.size())); |
|
3005 |
} |
|
3006 |
} else { |
|
3007 |
// Monochrome images need to use the vgChildImage() path. |
|
3008 |
vgImg = toVGImage(image, flags); |
|
3009 |
drawVGImage(d, r, vgImg, image.size(), sr); |
|
3010 |
} |
|
3011 |
vgDestroyImage(vgImg); |
|
3012 |
} |
|
3013 |
||
3014 |
void QVGPaintEngine::drawImage(const QPointF &pos, const QImage &image) |
|
3015 |
{ |
|
3016 |
Q_D(QVGPaintEngine); |
|
3017 |
VGImage vgImg; |
|
3018 |
if (d->simpleTransform || d->opacity == 1.0f) |
|
3019 |
vgImg = toVGImage(image); |
|
3020 |
else |
|
3021 |
vgImg = toVGImageWithOpacity(image, d->opacity); |
|
3022 |
drawVGImage(d, pos, vgImg); |
|
3023 |
vgDestroyImage(vgImg); |
|
3024 |
} |
|
3025 |
||
3026 |
void QVGPaintEngine::drawTiledPixmap |
|
3027 |
(const QRectF &r, const QPixmap &pixmap, const QPointF &s) |
|
3028 |
{ |
|
3029 |
QBrush brush(state()->pen.color(), pixmap); |
|
3030 |
QTransform xform; |
|
3031 |
xform.translate(-s.x(), -s.y()); |
|
3032 |
brush.setTransform(xform); |
|
3033 |
fillRect(r, brush); |
|
3034 |
} |
|
3035 |
||
3036 |
// Best performance will be achieved with QDrawPixmaps::OpaqueHint |
|
3037 |
// (i.e. no opacity), no rotation or scaling, and drawing the full |
|
3038 |
// pixmap rather than parts of the pixmap. Even having just one of |
|
3039 |
// these conditions will improve performance. |
|
3040 |
void QVGPaintEngine::drawPixmaps |
|
3041 |
(const QDrawPixmaps::Data *drawingData, int dataCount, |
|
3042 |
const QPixmap &pixmap, QFlags<QDrawPixmaps::DrawingHint> hints) |
|
3043 |
{ |
|
3044 |
#if !defined(QT_SHIVAVG) |
|
3045 |
Q_D(QVGPaintEngine); |
|
3046 |
||
3047 |
// If the pixmap is not VG, or the transformation is projective, |
|
3048 |
// then fall back to the default implementation. |
|
3049 |
QPixmapData *pd = pixmap.pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3050 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3051 |
return; // null QPixmap |
0 | 3052 |
if (pd->classId() != QPixmapData::OpenVGClass || !d->simpleTransform) { |
3053 |
QPaintEngineEx::drawPixmaps(drawingData, dataCount, pixmap, hints); |
|
3054 |
return; |
|
3055 |
} |
|
3056 |
||
3057 |
// Bail out if nothing to do. |
|
3058 |
if (dataCount <= 0) |
|
3059 |
return; |
|
3060 |
||
3061 |
// Bail out if we don't have a usable VGImage for the pixmap. |
|
3062 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
3063 |
if (!vgpd->isValid()) |
|
3064 |
return; |
|
3065 |
VGImage vgImg = vgpd->toVGImage(); |
|
3066 |
if (vgImg == VG_INVALID_HANDLE) |
|
3067 |
return; |
|
3068 |
||
3069 |
// We cache the results of any vgChildImage() calls because the |
|
3070 |
// same child is very likely to be used over and over in particle |
|
3071 |
// systems. However, performance is even better if vgChildImage() |
|
3072 |
// isn't needed at all, so use full source rects where possible. |
|
3073 |
QVarLengthArray<VGImage> cachedImages; |
|
3074 |
QVarLengthArray<QRect> cachedSources; |
|
3075 |
||
3076 |
// Select the opacity paint object. |
|
3077 |
if ((hints & QDrawPixmaps::OpaqueHint) != 0 && d->opacity == 1.0f) { |
|
3078 |
d->setImageMode(VG_DRAW_IMAGE_NORMAL); |
|
3079 |
} else { |
|
3080 |
hints = 0; |
|
3081 |
if (d->fillPaint != d->opacityPaint) { |
|
3082 |
vgSetPaint(d->opacityPaint, VG_FILL_PATH); |
|
3083 |
d->fillPaint = d->opacityPaint; |
|
3084 |
} |
|
3085 |
} |
|
3086 |
||
3087 |
for (int i = 0; i < dataCount; ++i) { |
|
3088 |
QTransform transform(d->imageTransform); |
|
3089 |
transform.translate(drawingData[i].point.x(), drawingData[i].point.y()); |
|
3090 |
transform.rotate(drawingData[i].rotation); |
|
3091 |
||
3092 |
VGImage child; |
|
3093 |
QSize imageSize = vgpd->size(); |
|
3094 |
QRectF sr = drawingData[i].source; |
|
3095 |
if (sr.topLeft().isNull() && sr.size() == imageSize) { |
|
3096 |
child = vgImg; |
|
3097 |
} else { |
|
3098 |
// Look for a previous child with the same source rectangle |
|
3099 |
// to avoid constantly calling vgChildImage()/vgDestroyImage(). |
|
3100 |
QRect src = sr.toRect(); |
|
3101 |
int j; |
|
3102 |
for (j = 0; j < cachedSources.size(); ++j) { |
|
3103 |
if (cachedSources[j] == src) |
|
3104 |
break; |
|
3105 |
} |
|
3106 |
if (j < cachedSources.size()) { |
|
3107 |
child = cachedImages[j]; |
|
3108 |
} else { |
|
3109 |
child = vgChildImage |
|
3110 |
(vgImg, src.x(), src.y(), src.width(), src.height()); |
|
3111 |
cachedImages.append(child); |
|
3112 |
cachedSources.append(src); |
|
3113 |
} |
|
3114 |
} |
|
3115 |
||
3116 |
VGfloat scaleX = drawingData[i].scaleX; |
|
3117 |
VGfloat scaleY = drawingData[i].scaleY; |
|
3118 |
transform.translate(-0.5 * scaleX * sr.width(), |
|
3119 |
-0.5 * scaleY * sr.height()); |
|
3120 |
transform.scale(scaleX, scaleY); |
|
3121 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
|
3122 |
||
3123 |
if ((hints & QDrawPixmaps::OpaqueHint) == 0) { |
|
3124 |
qreal opacity = d->opacity * drawingData[i].opacity; |
|
3125 |
if (opacity != 1.0f) { |
|
3126 |
if (d->paintOpacity != opacity) { |
|
3127 |
VGfloat values[4]; |
|
3128 |
values[0] = 1.0f; |
|
3129 |
values[1] = 1.0f; |
|
3130 |
values[2] = 1.0f; |
|
3131 |
values[3] = opacity; |
|
3132 |
d->paintOpacity = opacity; |
|
3133 |
vgSetParameterfv |
|
3134 |
(d->opacityPaint, VG_PAINT_COLOR, 4, values); |
|
3135 |
} |
|
3136 |
d->setImageMode(VG_DRAW_IMAGE_MULTIPLY); |
|
3137 |
} else { |
|
3138 |
d->setImageMode(VG_DRAW_IMAGE_NORMAL); |
|
3139 |
} |
|
3140 |
} |
|
3141 |
||
3142 |
vgDrawImage(child); |
|
3143 |
} |
|
3144 |
||
3145 |
// Destroy the cached child sub-images. |
|
3146 |
for (int i = 0; i < cachedImages.size(); ++i) |
|
3147 |
vgDestroyImage(cachedImages[i]); |
|
3148 |
#else |
|
3149 |
QPaintEngineEx::drawPixmaps(drawingData, dataCount, pixmap, hints); |
|
3150 |
#endif |
|
3151 |
} |
|
3152 |
||
3153 |
QVGFontEngineCleaner::QVGFontEngineCleaner(QVGPaintEnginePrivate *d) |
|
3154 |
: QObject(), d_ptr(d) |
|
3155 |
{ |
|
3156 |
} |
|
3157 |
||
3158 |
QVGFontEngineCleaner::~QVGFontEngineCleaner() |
|
3159 |
{ |
|
3160 |
} |
|
3161 |
||
3162 |
void QVGFontEngineCleaner::fontEngineDestroyed() |
|
3163 |
{ |
|
3164 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
3165 |
QFontEngine *engine = static_cast<QFontEngine *>(sender()); |
|
3166 |
QVGFontCache::Iterator it = d_ptr->fontCache.find(engine); |
|
3167 |
if (it != d_ptr->fontCache.end()) { |
|
3168 |
delete it.value(); |
|
3169 |
d_ptr->fontCache.erase(it); |
|
3170 |
} |
|
3171 |
#endif |
|
3172 |
} |
|
3173 |
||
3174 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
3175 |
||
3176 |
QVGFontGlyphCache::QVGFontGlyphCache() |
|
3177 |
{ |
|
3178 |
font = vgCreateFont(0); |
|
3179 |
scaleX = scaleY = 0.0; |
|
3180 |
memset(cachedGlyphsMask, 0, sizeof(cachedGlyphsMask)); |
|
3181 |
} |
|
3182 |
||
3183 |
QVGFontGlyphCache::~QVGFontGlyphCache() |
|
3184 |
{ |
|
3185 |
if (font != VG_INVALID_HANDLE) |
|
3186 |
vgDestroyFont(font); |
|
3187 |
} |
|
3188 |
||
3189 |
void QVGFontGlyphCache::setScaleFromText(const QTextItemInt &ti) |
|
3190 |
{ |
|
3191 |
QFontInfo fi(ti.font()); |
|
3192 |
qreal pixelSize = fi.pixelSize(); |
|
3193 |
qreal emSquare = ti.fontEngine->properties().emSquare.toReal(); |
|
3194 |
scaleX = scaleY = static_cast<VGfloat>(pixelSize / emSquare); |
|
3195 |
} |
|
3196 |
||
3197 |
void QVGFontGlyphCache::cacheGlyphs |
|
3198 |
(QVGPaintEnginePrivate *d, const QTextItemInt &ti, |
|
3199 |
const QVarLengthArray<glyph_t> &glyphs) |
|
3200 |
{ |
|
3201 |
VGfloat origin[2]; |
|
3202 |
VGfloat escapement[2]; |
|
3203 |
const glyph_t *g = glyphs.constData(); |
|
3204 |
int count = glyphs.size(); |
|
3205 |
glyph_metrics_t metrics; |
|
3206 |
// Some Qt font engines don't set yoff in getUnscaledGlyph(). |
|
3207 |
// Zero the metric structure so that everything has a default value. |
|
3208 |
memset(&metrics, 0, sizeof(metrics)); |
|
3209 |
while (count-- > 0) { |
|
3210 |
// Skip this glyph if we have already cached it before. |
|
3211 |
glyph_t glyph = *g++; |
|
3212 |
if (glyph < 256) { |
|
3213 |
if ((cachedGlyphsMask[glyph / 32] & (1 << (glyph % 32))) != 0) |
|
3214 |
continue; |
|
3215 |
cachedGlyphsMask[glyph / 32] |= (1 << (glyph % 32)); |
|
3216 |
} else if (cachedGlyphs.contains(glyph)) { |
|
3217 |
continue; |
|
3218 |
} else { |
|
3219 |
cachedGlyphs.insert(glyph); |
|
3220 |
} |
|
3221 |
#if !defined(QVG_NO_IMAGE_GLYPHS) |
|
3222 |
Q_UNUSED(d); |
|
3223 |
QImage scaledImage = ti.fontEngine->alphaMapForGlyph(glyph); |
|
3224 |
VGImage vgImage = VG_INVALID_HANDLE; |
|
3225 |
metrics = ti.fontEngine->boundingBox(glyph); |
|
3226 |
if (!scaledImage.isNull()) { // Not a space character |
|
3227 |
if (scaledImage.format() == QImage::Format_Indexed8) { |
|
3228 |
vgImage = vgCreateImage(VG_A_8, scaledImage.width(), scaledImage.height(), VG_IMAGE_QUALITY_FASTER); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3229 |
vgImageSubData(vgImage, qt_vg_imageBits(scaledImage), scaledImage.bytesPerLine(), VG_A_8, 0, 0, scaledImage.width(), scaledImage.height()); |
0 | 3230 |
} else if (scaledImage.format() == QImage::Format_Mono) { |
3231 |
QImage img = scaledImage.convertToFormat(QImage::Format_Indexed8); |
|
3232 |
vgImage = vgCreateImage(VG_A_8, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3233 |
vgImageSubData(vgImage, qt_vg_imageBits(img), img.bytesPerLine(), VG_A_8, 0, 0, img.width(), img.height()); |
0 | 3234 |
} else { |
3235 |
QImage img = scaledImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
3236 |
vgImage = vgCreateImage(VG_sARGB_8888_PRE, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3237 |
vgImageSubData(vgImage, qt_vg_imageBits(img), img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, img.width(), img.height()); |
0 | 3238 |
} |
3239 |
} |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3240 |
origin[0] = -metrics.x.toReal(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3241 |
origin[1] = -metrics.y.toReal(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3242 |
escapement[0] = 0; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3243 |
escapement[1] = 0; |
0 | 3244 |
vgSetGlyphToImage(font, glyph, vgImage, origin, escapement); |
3245 |
vgDestroyImage(vgImage); // Reduce reference count. |
|
3246 |
#else |
|
3247 |
// Calculate the path for the glyph and cache it. |
|
3248 |
QPainterPath path; |
|
3249 |
ti.fontEngine->getUnscaledGlyph(glyph, &path, &metrics); |
|
3250 |
VGPath vgPath; |
|
3251 |
if (!path.isEmpty()) { |
|
3252 |
vgPath = d->painterPathToVGPath(path); |
|
3253 |
} else { |
|
3254 |
// Probably a "space" character with no visible outline. |
|
3255 |
vgPath = VG_INVALID_HANDLE; |
|
3256 |
} |
|
3257 |
origin[0] = 0; |
|
3258 |
origin[1] = 0; |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3259 |
escapement[0] = 0; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3260 |
escapement[1] = 0; |
0 | 3261 |
vgSetGlyphToPath(font, glyph, vgPath, VG_FALSE, origin, escapement); |
3262 |
vgDestroyPath(vgPath); // Reduce reference count. |
|
3263 |
#endif // !defined(QVG_NO_IMAGE_GLYPHS) |
|
3264 |
} |
|
3265 |
} |
|
3266 |
||
3267 |
#endif // !defined(QVG_NO_DRAW_GLYPHS) |
|
3268 |
||
3269 |
void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) |
|
3270 |
{ |
|
3271 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
3272 |
Q_D(QVGPaintEngine); |
|
3273 |
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); |
|
3274 |
||
3275 |
// If we are not using a simple transform, then fall back |
|
3276 |
// to the default Qt path stroking algorithm. |
|
3277 |
if (!d->simpleTransform) { |
|
3278 |
QPaintEngineEx::drawTextItem(p, textItem); |
|
3279 |
return; |
|
3280 |
} |
|
3281 |
||
3282 |
// Get the glyphs and positions associated with the text item. |
|
3283 |
QVarLengthArray<QFixedPoint> positions; |
|
3284 |
QVarLengthArray<glyph_t> glyphs; |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3285 |
QTransform matrix; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3286 |
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
0 | 3287 |
|
3288 |
// Find the glyph cache for this font. |
|
3289 |
QVGFontCache::ConstIterator it = d->fontCache.constFind(ti.fontEngine); |
|
3290 |
QVGFontGlyphCache *glyphCache; |
|
3291 |
if (it != d->fontCache.constEnd()) { |
|
3292 |
glyphCache = it.value(); |
|
3293 |
} else { |
|
3294 |
glyphCache = new QVGFontGlyphCache(); |
|
3295 |
if (glyphCache->font == VG_INVALID_HANDLE) { |
|
3296 |
qWarning("QVGPaintEngine::drawTextItem: OpenVG fonts are not supported by the OpenVG engine"); |
|
3297 |
delete glyphCache; |
|
3298 |
QPaintEngineEx::drawTextItem(p, textItem); |
|
3299 |
return; |
|
3300 |
} |
|
3301 |
glyphCache->setScaleFromText(ti); |
|
3302 |
d->fontCache.insert(ti.fontEngine, glyphCache); |
|
3303 |
if (!d->fontEngineCleaner) |
|
3304 |
d->fontEngineCleaner = new QVGFontEngineCleaner(d); |
|
3305 |
QObject::connect(ti.fontEngine, SIGNAL(destroyed()), |
|
3306 |
d->fontEngineCleaner, SLOT(fontEngineDestroyed())); |
|
3307 |
} |
|
3308 |
||
3309 |
// Set the transformation to use for drawing the current glyphs. |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3310 |
QTransform glyphTransform(d->pathTransform); |
0 | 3311 |
glyphTransform.translate(p.x(), p.y()); |
3312 |
#if defined(QVG_NO_IMAGE_GLYPHS) |
|
3313 |
glyphTransform.scale(glyphCache->scaleX, glyphCache->scaleY); |
|
3314 |
#endif |
|
3315 |
d->setTransform(VG_MATRIX_GLYPH_USER_TO_SURFACE, glyphTransform); |
|
3316 |
||
3317 |
// Add the glyphs from the text item into the glyph cache. |
|
3318 |
glyphCache->cacheGlyphs(d, ti, glyphs); |
|
3319 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3320 |
// Create the array of adjustments between glyphs |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3321 |
QVarLengthArray<VGfloat> adjustments_x(glyphs.size()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3322 |
QVarLengthArray<VGfloat> adjustments_y(glyphs.size()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3323 |
for (int i = 1; i < glyphs.size(); ++i) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3324 |
adjustments_x[i-1] = (positions[i].x - positions[i-1].x).toReal(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3325 |
adjustments_y[i-1] = (positions[i].y - positions[i-1].y).toReal(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3326 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3327 |
|
0 | 3328 |
// Set the glyph drawing origin. |
3329 |
VGfloat origin[2]; |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3330 |
origin[0] = positions[0].x.toReal(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3331 |
origin[1] = positions[0].y.toReal(); |
0 | 3332 |
vgSetfv(VG_GLYPH_ORIGIN, 2, origin); |
3333 |
||
3334 |
// Fast anti-aliasing for paths, better for images. |
|
3335 |
#if !defined(QVG_NO_IMAGE_GLYPHS) |
|
3336 |
d->setImageQuality(VG_IMAGE_QUALITY_BETTER); |
|
3337 |
d->setImageMode(VG_DRAW_IMAGE_STENCIL); |
|
3338 |
#else |
|
3339 |
d->setRenderingQuality(VG_RENDERING_QUALITY_FASTER); |
|
3340 |
#endif |
|
3341 |
||
3342 |
// Draw the glyphs. We need to fill with the brush associated with |
|
3343 |
// the Qt pen, not the Qt brush. |
|
3344 |
d->ensureBrush(state()->pen.brush()); |
|
3345 |
vgDrawGlyphs(glyphCache->font, glyphs.size(), (VGuint*)glyphs.data(), |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
3346 |
adjustments_x.data(), adjustments_y.data(), VG_FILL_PATH, VG_TRUE); |
0 | 3347 |
#else |
3348 |
// OpenGL 1.0 does not have support for VGFont and glyphs, |
|
3349 |
// so fall back to the default Qt path stroking algorithm. |
|
3350 |
QPaintEngineEx::drawTextItem(p, textItem); |
|
3351 |
#endif |
|
3352 |
} |
|
3353 |
||
3354 |
void QVGPaintEngine::setState(QPainterState *s) |
|
3355 |
{ |
|
3356 |
Q_D(QVGPaintEngine); |
|
3357 |
QPaintEngineEx::setState(s); |
|
3358 |
QVGPainterState *ps = static_cast<QVGPainterState *>(s); |
|
3359 |
if (ps->isNew) { |
|
3360 |
// Newly created state object. The call to setState() |
|
3361 |
// will either be followed by a call to begin(), or we are |
|
3362 |
// setting the state as part of a save(). |
|
3363 |
ps->isNew = false; |
|
3364 |
} else { |
|
3365 |
// This state object was set as part of a restore(). |
|
3366 |
restoreState(d->dirty); |
|
3367 |
d->dirty = ps->savedDirty; |
|
3368 |
} |
|
3369 |
} |
|
3370 |
||
3371 |
void QVGPaintEngine::beginNativePainting() |
|
3372 |
{ |
|
3373 |
Q_D(QVGPaintEngine); |
|
3374 |
||
3375 |
// About to enter raw VG mode: flush pending changes and make |
|
3376 |
// sure that all matrices are set to the current transformation. |
|
3377 |
QVGPainterState *s = this->state(); |
|
3378 |
d->ensurePen(s->pen); |
|
3379 |
d->ensureBrush(s->brush); |
|
3380 |
d->ensurePathTransform(); |
|
3381 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, d->imageTransform); |
|
3382 |
#if !defined(QVG_NO_DRAW_GLYPHS) |
|
3383 |
d->setTransform(VG_MATRIX_GLYPH_USER_TO_SURFACE, d->pathTransform); |
|
3384 |
#endif |
|
3385 |
d->rawVG = true; |
|
3386 |
} |
|
3387 |
||
3388 |
void QVGPaintEngine::endNativePainting() |
|
3389 |
{ |
|
3390 |
Q_D(QVGPaintEngine); |
|
3391 |
// Exiting raw VG mode: force all state values to be |
|
3392 |
// explicitly set on the VG engine to undo any changes |
|
3393 |
// that were made by the raw VG function calls. |
|
3394 |
QPaintEngine::DirtyFlags dirty = d->dirty; |
|
3395 |
d->clearModes(); |
|
3396 |
d->forcePenChange = true; |
|
3397 |
d->forceBrushChange = true; |
|
3398 |
d->penType = (VGPaintType)0; |
|
3399 |
d->brushType = (VGPaintType)0; |
|
3400 |
d->clearColor = QColor(); |
|
3401 |
d->fillPaint = d->brushPaint; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3402 |
d->scissorDirty = true; |
0 | 3403 |
restoreState(QPaintEngine::AllDirty); |
3404 |
d->dirty = dirty; |
|
3405 |
d->rawVG = false; |
|
3406 |
vgSetPaint(d->penPaint, VG_STROKE_PATH); |
|
3407 |
vgSetPaint(d->brushPaint, VG_FILL_PATH); |
|
3408 |
} |
|
3409 |
||
3410 |
QPixmapFilter *QVGPaintEngine::pixmapFilter(int type, const QPixmapFilter *prototype) |
|
3411 |
{ |
|
3412 |
#if !defined(QT_SHIVAVG) |
|
3413 |
Q_D(QVGPaintEngine); |
|
3414 |
switch (type) { |
|
3415 |
case QPixmapFilter::ConvolutionFilter: |
|
3416 |
if (!d->convolutionFilter) |
|
3417 |
d->convolutionFilter.reset(new QVGPixmapConvolutionFilter); |
|
3418 |
return d->convolutionFilter.data(); |
|
3419 |
case QPixmapFilter::ColorizeFilter: |
|
3420 |
if (!d->colorizeFilter) |
|
3421 |
d->colorizeFilter.reset(new QVGPixmapColorizeFilter); |
|
3422 |
return d->colorizeFilter.data(); |
|
3423 |
case QPixmapFilter::DropShadowFilter: |
|
3424 |
if (!d->dropShadowFilter) |
|
3425 |
d->dropShadowFilter.reset(new QVGPixmapDropShadowFilter); |
|
3426 |
return d->dropShadowFilter.data(); |
|
3427 |
case QPixmapFilter::BlurFilter: |
|
3428 |
if (!d->blurFilter) |
|
3429 |
d->blurFilter.reset(new QVGPixmapBlurFilter); |
|
3430 |
return d->blurFilter.data(); |
|
3431 |
default: break; |
|
3432 |
} |
|
3433 |
#endif |
|
3434 |
return QPaintEngineEx::pixmapFilter(type, prototype); |
|
3435 |
} |
|
3436 |
||
3437 |
void QVGPaintEngine::restoreState(QPaintEngine::DirtyFlags dirty) |
|
3438 |
{ |
|
3439 |
Q_D(QVGPaintEngine); |
|
3440 |
||
3441 |
// Restore the pen, brush, and other settings. |
|
3442 |
if ((dirty & QPaintEngine::DirtyBrushOrigin) != 0) |
|
3443 |
brushOriginChanged(); |
|
3444 |
d->fillRule = 0; |
|
3445 |
if ((dirty & QPaintEngine::DirtyOpacity) != 0) |
|
3446 |
opacityChanged(); |
|
3447 |
if ((dirty & QPaintEngine::DirtyTransform) != 0) |
|
3448 |
transformChanged(); |
|
3449 |
if ((dirty & QPaintEngine::DirtyCompositionMode) != 0) |
|
3450 |
compositionModeChanged(); |
|
3451 |
if ((dirty & QPaintEngine::DirtyHints) != 0) |
|
3452 |
renderHintsChanged(); |
|
3453 |
if ((dirty & (QPaintEngine::DirtyClipRegion | |
|
3454 |
QPaintEngine::DirtyClipPath | |
|
3455 |
QPaintEngine::DirtyClipEnabled)) != 0) { |
|
3456 |
d->maskValid = false; |
|
3457 |
d->maskIsSet = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3458 |
d->scissorMask = false; |
0 | 3459 |
d->maskRect = QRect(); |
3460 |
clipEnabledChanged(); |
|
3461 |
} |
|
3462 |
||
3463 |
#if defined(QVG_SCISSOR_CLIP) |
|
3464 |
if ((dirty & (QPaintEngine::DirtyClipRegion | |
|
3465 |
QPaintEngine::DirtyClipPath | |
|
3466 |
QPaintEngine::DirtyClipEnabled)) == 0) { |
|
3467 |
updateScissor(); |
|
3468 |
} |
|
3469 |
#else |
|
3470 |
updateScissor(); |
|
3471 |
#endif |
|
3472 |
} |
|
3473 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3474 |
void QVGPaintEngine::fillRegion |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3475 |
(const QRegion& region, const QColor& color, const QSize& surfaceSize) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3476 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3477 |
Q_D(QVGPaintEngine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3478 |
if (d->clearColor != color || d->clearOpacity != 1.0f) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3479 |
VGfloat values[4]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3480 |
values[0] = color.redF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3481 |
values[1] = color.greenF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3482 |
values[2] = color.blueF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3483 |
values[3] = color.alphaF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3484 |
vgSetfv(VG_CLEAR_COLOR, 4, values); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3485 |
d->clearColor = color; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3486 |
d->clearOpacity = 1.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3487 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3488 |
if (region.rectCount() == 1) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3489 |
QRect r = region.boundingRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3490 |
vgClear(r.x(), surfaceSize.height() - r.y() - r.height(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3491 |
r.width(), r.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3492 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3493 |
const QVector<QRect> rects = region.rects(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3494 |
for (int i = 0; i < rects.size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3495 |
QRect r = rects.at(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3496 |
vgClear(r.x(), surfaceSize.height() - r.y() - r.height(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3497 |
r.width(), r.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3498 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3499 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3500 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3501 |
|
0 | 3502 |
#if !defined(QVG_NO_SINGLE_CONTEXT) && !defined(QT_NO_EGL) |
3503 |
||
3504 |
QVGCompositionHelper::QVGCompositionHelper() |
|
3505 |
{ |
|
3506 |
d = qt_vg_create_paint_engine()->vgPrivate(); |
|
3507 |
} |
|
3508 |
||
3509 |
QVGCompositionHelper::~QVGCompositionHelper() |
|
3510 |
{ |
|
3511 |
} |
|
3512 |
||
3513 |
void QVGCompositionHelper::startCompositing(const QSize& screenSize) |
|
3514 |
{ |
|
3515 |
this->screenSize = screenSize; |
|
3516 |
clearScissor(); |
|
3517 |
d->setBlendMode(VG_BLEND_SRC_OVER); |
|
3518 |
} |
|
3519 |
||
3520 |
void QVGCompositionHelper::endCompositing() |
|
3521 |
{ |
|
3522 |
clearScissor(); |
|
3523 |
} |
|
3524 |
||
3525 |
void QVGCompositionHelper::blitWindow |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3526 |
(VGImage image, const QSize& imageSize, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3527 |
const QRect& rect, const QPoint& topLeft, int opacity) |
0 | 3528 |
{ |
3529 |
if (image == VG_INVALID_HANDLE) |
|
3530 |
return; |
|
3531 |
||
3532 |
// Determine which sub rectangle of the window to draw. |
|
3533 |
QRect sr = rect.translated(-topLeft); |
|
3534 |
||
3535 |
if (opacity >= 255) { |
|
3536 |
// Fully opaque: use vgSetPixels() to directly copy the sub-region. |
|
3537 |
int y = screenSize.height() - (rect.bottom() + 1); |
|
3538 |
vgSetPixels(rect.x(), y, image, sr.x(), |
|
3539 |
imageSize.height() - (sr.y() + sr.height()), |
|
3540 |
sr.width(), sr.height()); |
|
3541 |
} else { |
|
3542 |
// Extract the child image that we want to draw. |
|
3543 |
VGImage child; |
|
3544 |
if (sr.topLeft().isNull() && sr.size() == imageSize) |
|
3545 |
child = image; |
|
3546 |
else { |
|
3547 |
child = vgChildImage |
|
3548 |
(image, sr.x(), imageSize.height() - (sr.y() + sr.height()), |
|
3549 |
sr.width(), sr.height()); |
|
3550 |
} |
|
3551 |
||
3552 |
// Set the image transform. |
|
3553 |
QTransform transform; |
|
3554 |
int y = screenSize.height() - (rect.bottom() + 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3555 |
transform.translate(rect.x() - 0.5f, y - 0.5f); |
0 | 3556 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
3557 |
||
3558 |
// Enable opacity for image drawing if necessary. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3559 |
if (opacity != d->paintOpacity) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3560 |
VGfloat values[4]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3561 |
values[0] = 1.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3562 |
values[1] = 1.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3563 |
values[2] = 1.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3564 |
values[3] = ((VGfloat)opacity) / 255.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3565 |
vgSetParameterfv(d->opacityPaint, VG_PAINT_COLOR, 4, values); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3566 |
d->paintOpacity = values[3]; |
0 | 3567 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3568 |
if (d->fillPaint != d->opacityPaint) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3569 |
vgSetPaint(d->opacityPaint, VG_FILL_PATH); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3570 |
d->fillPaint = d->opacityPaint; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3571 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3572 |
d->setImageMode(VG_DRAW_IMAGE_MULTIPLY); |
0 | 3573 |
|
3574 |
// Draw the child image. |
|
3575 |
vgDrawImage(child); |
|
3576 |
||
3577 |
// Destroy the child image. |
|
3578 |
if(child != image) |
|
3579 |
vgDestroyImage(child); |
|
3580 |
} |
|
3581 |
} |
|
3582 |
||
3583 |
static void fillBackgroundRect(const QRect& rect, QVGPaintEnginePrivate *d) |
|
3584 |
{ |
|
3585 |
VGfloat coords[8]; |
|
3586 |
coords[0] = rect.x(); |
|
3587 |
coords[1] = rect.y(); |
|
3588 |
coords[2] = rect.x() + rect.width(); |
|
3589 |
coords[3] = coords[1]; |
|
3590 |
coords[4] = coords[2]; |
|
3591 |
coords[5] = rect.y() + rect.height(); |
|
3592 |
coords[6] = coords[0]; |
|
3593 |
coords[7] = coords[5]; |
|
3594 |
#if !defined(QVG_NO_MODIFY_PATH) |
|
3595 |
vgModifyPathCoords(d->rectPath, 0, 4, coords); |
|
3596 |
vgDrawPath(d->rectPath, VG_FILL_PATH); |
|
3597 |
#else |
|
3598 |
Q_UNUSED(d); |
|
3599 |
VGPath rectPath = vgCreatePath |
|
3600 |
(VG_PATH_FORMAT_STANDARD, |
|
3601 |
VG_PATH_DATATYPE_F, |
|
3602 |
1.0f, // scale |
|
3603 |
0.0f, // bias |
|
3604 |
5, // segmentCapacityHint |
|
3605 |
8, // coordCapacityHint |
|
3606 |
VG_PATH_CAPABILITY_ALL); |
|
3607 |
static VGubyte const segments[5] = { |
|
3608 |
VG_MOVE_TO_ABS, |
|
3609 |
VG_LINE_TO_ABS, |
|
3610 |
VG_LINE_TO_ABS, |
|
3611 |
VG_LINE_TO_ABS, |
|
3612 |
VG_CLOSE_PATH |
|
3613 |
}; |
|
3614 |
vgAppendPathData(rectPath, 5, segments, coords); |
|
3615 |
vgDrawPath(rectPath, VG_FILL_PATH); |
|
3616 |
vgDestroyPath(rectPath); |
|
3617 |
#endif |
|
3618 |
} |
|
3619 |
||
3620 |
void QVGCompositionHelper::fillBackground |
|
3621 |
(const QRegion& region, const QBrush& brush) |
|
3622 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3623 |
if (brush.style() == Qt::SolidPattern) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3624 |
// Use vgClear() to quickly fill the background. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3625 |
QColor color = brush.color(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3626 |
if (d->clearColor != color || d->clearOpacity != 1.0f) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3627 |
VGfloat values[4]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3628 |
values[0] = color.redF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3629 |
values[1] = color.greenF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3630 |
values[2] = color.blueF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3631 |
values[3] = color.alphaF(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3632 |
vgSetfv(VG_CLEAR_COLOR, 4, values); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3633 |
d->clearColor = color; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3634 |
d->clearOpacity = 1.0f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3635 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3636 |
if (region.rectCount() == 1) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3637 |
QRect r = region.boundingRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3638 |
vgClear(r.x(), screenSize.height() - r.y() - r.height(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3639 |
r.width(), r.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3640 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3641 |
const QVector<QRect> rects = region.rects(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3642 |
for (int i = 0; i < rects.size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3643 |
QRect r = rects.at(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3644 |
vgClear(r.x(), screenSize.height() - r.y() - r.height(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3645 |
r.width(), r.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3646 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3647 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3648 |
|
0 | 3649 |
} else { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3650 |
// Set the path transform to the default viewport transformation. |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3651 |
VGfloat devh = screenSize.height(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3652 |
QTransform viewport(1.0f, 0.0f, 0.0f, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3653 |
0.0f, -1.0f, 0.0f, |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3654 |
0.0f, devh, 1.0f); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3655 |
d->setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, viewport); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3656 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3657 |
// Set the brush to use to fill the background. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3658 |
d->ensureBrush(brush); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3659 |
d->setFillRule(VG_EVEN_ODD); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3660 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3661 |
if (region.rectCount() == 1) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3662 |
fillBackgroundRect(region.boundingRect(), d); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3663 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3664 |
const QVector<QRect> rects = region.rects(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3665 |
for (int i = 0; i < rects.size(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3666 |
fillBackgroundRect(rects.at(i), d); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3667 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3668 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3669 |
// We will need to reset the path transform during the next paint. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3670 |
d->pathTransformSet = false; |
0 | 3671 |
} |
3672 |
} |
|
3673 |
||
3674 |
void QVGCompositionHelper::drawCursorPixmap |
|
3675 |
(const QPixmap& pixmap, const QPoint& offset) |
|
3676 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3677 |
VGImage vgImage = VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3678 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3679 |
// Fetch the VGImage from the pixmap if possible. |
0 | 3680 |
QPixmapData *pd = pixmap.pixmapData(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3681 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3682 |
return; // null QPixmap |
0 | 3683 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
3684 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3685 |
if (vgpd->isValid()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3686 |
vgImage = vgpd->toVGImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3687 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3688 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3689 |
// Set the image transformation and modes. |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3690 |
VGfloat devh = screenSize.height(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3691 |
QTransform transform(1.0f, 0.0f, 0.0f, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3692 |
0.0f, -1.0f, 0.0f, |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3693 |
0.0f, devh, 1.0f); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3694 |
transform.translate(offset.x(), offset.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3695 |
d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3696 |
d->setImageMode(VG_DRAW_IMAGE_NORMAL); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3697 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3698 |
// Draw the VGImage. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3699 |
if (vgImage != VG_INVALID_HANDLE) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3700 |
vgDrawImage(vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3701 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3702 |
QImage img = pixmap.toImage().convertToFormat |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3703 |
(QImage::Format_ARGB32_Premultiplied); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3704 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3705 |
vgImage = vgCreateImage |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3706 |
(VG_sARGB_8888_PRE, img.width(), img.height(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3707 |
VG_IMAGE_QUALITY_FASTER); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3708 |
if (vgImage == VG_INVALID_HANDLE) |
0 | 3709 |
return; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3710 |
vgImageSubData |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3711 |
(vgImage, qt_vg_imageBits(img) + img.bytesPerLine() * (img.height() - 1), |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3712 |
-(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3713 |
img.width(), img.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3714 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3715 |
vgDrawImage(vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3716 |
vgDestroyImage(vgImage); |
0 | 3717 |
} |
3718 |
} |
|
3719 |
||
3720 |
void QVGCompositionHelper::setScissor(const QRegion& region) |
|
3721 |
{ |
|
3722 |
QVector<QRect> rects = region.rects(); |
|
3723 |
int count = rects.count(); |
|
3724 |
if (count > d->maxScissorRects) |
|
3725 |
count = d->maxScissorRects; |
|
3726 |
QVarLengthArray<VGint> params(count * 4); |
|
3727 |
int height = screenSize.height(); |
|
3728 |
for (int i = 0; i < count; ++i) { |
|
3729 |
params[i * 4 + 0] = rects[i].x(); |
|
3730 |
params[i * 4 + 1] = height - rects[i].y() - rects[i].height(); |
|
3731 |
params[i * 4 + 2] = rects[i].width(); |
|
3732 |
params[i * 4 + 3] = rects[i].height(); |
|
3733 |
} |
|
3734 |
||
3735 |
vgSetiv(VG_SCISSOR_RECTS, count * 4, params.data()); |
|
3736 |
vgSeti(VG_SCISSORING, VG_TRUE); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3737 |
d->scissorDirty = false; |
0 | 3738 |
d->scissorActive = true; |
3739 |
d->scissorRegion = region; |
|
3740 |
} |
|
3741 |
||
3742 |
void QVGCompositionHelper::clearScissor() |
|
3743 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3744 |
if (d->scissorActive || d->scissorDirty) { |
0 | 3745 |
vgSeti(VG_SCISSORING, VG_FALSE); |
3746 |
d->scissorActive = false; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3747 |
d->scissorDirty = false; |
0 | 3748 |
} |
3749 |
} |
|
3750 |
||
3751 |
#endif // !QVG_NO_SINGLE_CONTEXT && !QT_NO_EGL |
|
3752 |
||
3753 |
VGImageFormat qt_vg_image_to_vg_format(QImage::Format format) |
|
3754 |
{ |
|
3755 |
switch (format) { |
|
3756 |
case QImage::Format_MonoLSB: |
|
3757 |
return VG_BW_1; |
|
3758 |
case QImage::Format_ARGB32_Premultiplied: |
|
3759 |
return VG_sARGB_8888_PRE; |
|
3760 |
case QImage::Format_RGB32: |
|
3761 |
return VG_sXRGB_8888; |
|
3762 |
case QImage::Format_ARGB32: |
|
3763 |
return VG_sARGB_8888; |
|
3764 |
case QImage::Format_RGB16: |
|
3765 |
return VG_sRGB_565; |
|
3766 |
case QImage::Format_ARGB4444_Premultiplied: |
|
3767 |
return VG_sARGB_4444; |
|
3768 |
default: break; |
|
3769 |
} |
|
3770 |
return VG_sARGB_8888; // XXX |
|
3771 |
} |
|
3772 |
||
3773 |
QT_END_NAMESPACE |
|
3774 |
||
3775 |
#include "qpaintengine_vg.moc" |