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