|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite 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 <qtest.h> |
|
43 #include <QPainter> |
|
44 #include <QPixmap> |
|
45 #include <QDialog> |
|
46 #include <QImage> |
|
47 #include <QPaintEngine> |
|
48 #include <math.h> |
|
49 #ifndef M_PI |
|
50 #define M_PI 3.14159265358979323846 |
|
51 #endif |
|
52 |
|
53 Q_DECLARE_METATYPE(QLine) |
|
54 Q_DECLARE_METATYPE(QRect) |
|
55 Q_DECLARE_METATYPE(QSize) |
|
56 Q_DECLARE_METATYPE(QPoint) |
|
57 Q_DECLARE_METATYPE(QPainterPath) |
|
58 Q_DECLARE_METATYPE(QPainter::RenderHint) |
|
59 Q_DECLARE_METATYPE(QPainter::CompositionMode) |
|
60 Q_DECLARE_METATYPE(QImage::Format) |
|
61 |
|
62 enum PrimitiveType { |
|
63 Primitive_Int_DiagLine, |
|
64 Primitive_Int_VerLine, |
|
65 Primitive_Int_HorLine, |
|
66 Primitive_Int_Rect, |
|
67 Primitive_Int_Ellipse, |
|
68 Primitive_Int_Pie, |
|
69 Primitive_Int_Arc, |
|
70 Primitive_Int_Chord, |
|
71 Primitive_Int_TriPoly, |
|
72 Primitive_Int_RectPoly, |
|
73 Primitive_Int_2RectPoly, |
|
74 |
|
75 Primitive_Float_DiagLine, |
|
76 Primitive_Float_VerLine, |
|
77 Primitive_Float_HorLine, |
|
78 Primitive_Float_Rect, |
|
79 Primitive_Float_Ellipse, |
|
80 Primitive_Float_Pie, |
|
81 Primitive_Float_Arc, |
|
82 Primitive_Float_Chord, |
|
83 Primitive_Float_TriPoly, |
|
84 Primitive_Float_RectPoly, |
|
85 Primitive_Float_2RectPoly, |
|
86 |
|
87 Primitive_Float_TriPath, |
|
88 Primitive_Float_RectPath, |
|
89 Primitive_Float_2RectPath, |
|
90 Primitive_Float_EllipsePath, |
|
91 Primitive_Last_Primitive |
|
92 |
|
93 }; |
|
94 |
|
95 |
|
96 enum StateChanges { |
|
97 ChangePen = 0x0001, |
|
98 ChangeBrush = 0x0002, |
|
99 ChangeClip = 0x0004, |
|
100 ChangeTransform = 0x0008 |
|
101 }; |
|
102 |
|
103 |
|
104 struct PrimitiveSet { |
|
105 QRect i_rect; |
|
106 QLine i_line_diag; |
|
107 QLine i_line_ver; |
|
108 QLine i_line_hor; |
|
109 QPolygon i_poly_tri; |
|
110 QPolygon i_poly_2rects; |
|
111 QPolygon i_poly_rect; |
|
112 |
|
113 QRectF f_rect; |
|
114 QLineF f_line_diag; |
|
115 QLineF f_line_ver; |
|
116 QLineF f_line_hor; |
|
117 QPolygonF f_poly_tri; |
|
118 QPolygonF f_poly_2rects; |
|
119 QPolygonF f_poly_rect; |
|
120 |
|
121 QPainterPath f_path_tri; |
|
122 QPainterPath f_path_2rects; |
|
123 QPainterPath f_path_rect; |
|
124 QPainterPath f_path_ellipse; |
|
125 }; |
|
126 |
|
127 |
|
128 class tst_QPainter : public QObject |
|
129 { |
|
130 Q_OBJECT |
|
131 |
|
132 public: |
|
133 tst_QPainter() |
|
134 { |
|
135 setupBrushes(); |
|
136 createPrimitives(); |
|
137 m_surface = surface(); |
|
138 } |
|
139 |
|
140 private slots: |
|
141 void beginAndEnd(); |
|
142 |
|
143 void saveRestore_data(); |
|
144 void saveRestore(); |
|
145 |
|
146 void drawLine_data(); |
|
147 void drawLine(); |
|
148 void drawLine_clipped_data(); |
|
149 void drawLine_clipped(); |
|
150 void drawLine_antialiased_clipped_data(); |
|
151 void drawLine_antialiased_clipped(); |
|
152 |
|
153 void drawPixmap_data(); |
|
154 void drawPixmap(); |
|
155 |
|
156 void drawImage_data(); |
|
157 void drawImage(); |
|
158 |
|
159 void drawTiledPixmap_data(); |
|
160 void drawTiledPixmap(); |
|
161 |
|
162 void compositionModes_data(); |
|
163 void compositionModes(); |
|
164 |
|
165 void fillPrimitives_10_data() { drawPrimitives_data_helper(false); } |
|
166 void fillPrimitives_100_data() { drawPrimitives_data_helper(false); } |
|
167 void fillPrimitives_1000_data() { drawPrimitives_data_helper(false); } |
|
168 void fillPrimitives_10(); |
|
169 void fillPrimitives_100(); |
|
170 void fillPrimitives_1000(); |
|
171 |
|
172 void strokePrimitives_10_data() { drawPrimitives_data_helper(true); } |
|
173 void strokePrimitives_100_data() { drawPrimitives_data_helper(true); } |
|
174 void strokePrimitives_1000_data() { drawPrimitives_data_helper(true); } |
|
175 void strokePrimitives_10(); |
|
176 void strokePrimitives_100(); |
|
177 void strokePrimitives_1000(); |
|
178 |
|
179 void drawText_data(); |
|
180 void drawText(); |
|
181 |
|
182 void clipAndFill_data(); |
|
183 void clipAndFill(); |
|
184 |
|
185 void drawRoundedRect(); |
|
186 void drawScaledRoundedRect(); |
|
187 void drawTransformedRoundedRect(); |
|
188 |
|
189 void drawScaledAntialiasedRoundedRect_data(); |
|
190 void drawTransformedAntialiasedRoundedRect_data(); |
|
191 void drawAntialiasedRoundedRect(); |
|
192 void drawScaledAntialiasedRoundedRect(); |
|
193 void drawTransformedAntialiasedRoundedRect(); |
|
194 |
|
195 void drawScaledImageRoundedRect_data(); |
|
196 void drawTransformedImageRoundedRect_data(); |
|
197 void drawImageRoundedRect(); |
|
198 void drawScaledImageRoundedRect(); |
|
199 void drawTransformedImageRoundedRect(); |
|
200 |
|
201 void drawScaledBorderPixmapRoundedRect_data(); |
|
202 void drawTransformedBorderPixmapRoundedRect_data(); |
|
203 void drawBorderPixmapRoundedRect(); |
|
204 void drawScaledBorderPixmapRoundedRect(); |
|
205 void drawTransformedBorderPixmapRoundedRect(); |
|
206 |
|
207 void drawTransformedTransparentImage_data(); |
|
208 void drawTransformedSemiTransparentImage_data(); |
|
209 void drawTransformedFilledImage_data(); |
|
210 void drawTransformedTransparentImage(); |
|
211 void drawTransformedSemiTransparentImage(); |
|
212 void drawTransformedFilledImage(); |
|
213 |
|
214 private: |
|
215 void setupBrushes(); |
|
216 void createPrimitives(); |
|
217 |
|
218 void drawPrimitives_data_helper(bool fancypens); |
|
219 void fillPrimitives_helper(QPainter *painter, PrimitiveType type, PrimitiveSet *s); |
|
220 |
|
221 QTransform transformForAngle(qreal angle); |
|
222 |
|
223 QPaintDevice *surface() |
|
224 { |
|
225 return new QPixmap(1024, 1024); |
|
226 } |
|
227 |
|
228 |
|
229 QMap<QString, QPen> m_pens; |
|
230 QMap<QString, QBrush> m_brushes; |
|
231 |
|
232 PrimitiveSet m_primitives_10; |
|
233 PrimitiveSet m_primitives_100; |
|
234 PrimitiveSet m_primitives_1000; |
|
235 |
|
236 QPaintDevice *m_surface; |
|
237 QPainter m_painter; |
|
238 |
|
239 }; |
|
240 |
|
241 void tst_QPainter::createPrimitives() |
|
242 { |
|
243 for (int i=0; i<3; ++i) { |
|
244 PrimitiveSet *ps; |
|
245 int size; |
|
246 switch (i) { |
|
247 case 0: |
|
248 ps = &m_primitives_10; |
|
249 size = 10; |
|
250 break; |
|
251 case 1: |
|
252 ps = &m_primitives_100; |
|
253 size = 100; |
|
254 break; |
|
255 case 2: |
|
256 ps = &m_primitives_1000; |
|
257 size = 1000; |
|
258 break; |
|
259 } |
|
260 |
|
261 ps->f_rect = QRectF(0, 0, size, size); |
|
262 ps->f_line_diag = QLineF(0, 0, size, size); |
|
263 ps->f_line_ver = QLineF(10, 0, 10, size); |
|
264 ps->f_line_hor = QLineF(0, 10, size, 10); |
|
265 ps->f_poly_rect = QPolygonF() << QPointF(0, 0) |
|
266 << QPointF(size, 0) |
|
267 << QPointF(size, size) |
|
268 << QPointF(0, size); |
|
269 ps->f_poly_2rects = QPolygonF() << QPointF(0, 0) |
|
270 << QPointF(size * 0.75, 0) |
|
271 << QPointF(size * 0.75, size * 0.75) |
|
272 << QPointF(size * 0.25, size * 0.75) |
|
273 << QPointF(size * 0.25, size * 0.25) |
|
274 << QPointF(size, size * 0.25) |
|
275 << QPointF(size, size) |
|
276 << QPointF(0, size); |
|
277 ps->f_poly_tri = QPolygonF() << QPointF(size / 2.0, 0) |
|
278 << QPointF(0, size) |
|
279 << QPointF(size, size); |
|
280 |
|
281 ps->f_path_tri.addPolygon(ps->f_poly_tri); |
|
282 ps->f_path_rect.addRect(ps->f_rect); |
|
283 ps->f_path_2rects.addPolygon(ps->f_poly_2rects); |
|
284 ps->f_path_ellipse.addEllipse(ps->f_rect); |
|
285 |
|
286 ps->i_rect = ps->f_rect.toRect(); |
|
287 ps->i_line_diag = ps->f_line_diag.toLine(); |
|
288 ps->i_line_hor = ps->f_line_hor.toLine(); |
|
289 ps->i_line_ver = ps->f_line_ver.toLine(); |
|
290 ps->i_poly_tri = ps->f_poly_tri.toPolygon(); |
|
291 ps->i_poly_rect = ps->f_poly_rect.toPolygon(); |
|
292 ps->i_poly_2rects = ps->f_poly_2rects.toPolygon(); |
|
293 } |
|
294 } |
|
295 |
|
296 void tst_QPainter::drawLine_data() |
|
297 { |
|
298 QTest::addColumn<QLine>("line"); |
|
299 QTest::addColumn<QPen>("pen"); |
|
300 |
|
301 QVector<QPen> pens; |
|
302 pens << QPen(Qt::black) |
|
303 << QPen(Qt::black, 0, Qt::DashDotLine) |
|
304 << QPen(Qt::black, 4) |
|
305 << QPen(Qt::black, 4, Qt::DashDotLine) |
|
306 << QPen(QColor(255, 0, 0, 200)) |
|
307 << QPen(QColor(255, 0, 0, 200), 0, Qt::DashDotLine) |
|
308 << QPen(QColor(255, 0, 0, 200), 4) |
|
309 << QPen(QColor(255, 0, 0, 200), 4, Qt::DashDotLine); |
|
310 |
|
311 QStringList penNames; |
|
312 penNames << "black-0" |
|
313 << "black-0-dashdot" |
|
314 << "black-4" |
|
315 << "black-4-dashdot" |
|
316 << "alpha-0" |
|
317 << "alpha-0-dashdot" |
|
318 << "alpha-4" |
|
319 << "alpha-4-dashdot"; |
|
320 |
|
321 int i = 0; |
|
322 foreach (QPen pen, pens) { |
|
323 const QString s = QString(QLatin1String("%1:%2")).arg(penNames[i]); |
|
324 QTest::newRow(qPrintable(s.arg("horizontal"))) |
|
325 << QLine(0, 20, 100, 20) << pen; |
|
326 QTest::newRow(qPrintable(s.arg("vertical:"))) |
|
327 << QLine(20, 0, 20, 100) << pen; |
|
328 QTest::newRow(qPrintable(s.arg("0-45:"))) |
|
329 << QLine(0, 20, 100, 0) << pen; |
|
330 QTest::newRow(qPrintable(s.arg("45-90:"))) |
|
331 << QLine(0, 100, 20, 0) << pen; |
|
332 QTest::newRow(qPrintable(s.arg("90-135:"))) |
|
333 << QLine(20, 100, 0, 0) << pen; |
|
334 QTest::newRow(qPrintable(s.arg("135-180:"))) |
|
335 << QLine(100, 20, 0, 0) << pen; |
|
336 QTest::newRow(qPrintable(s.arg("180-225:"))) |
|
337 << QLine(100, 0, 0, 20) << pen; |
|
338 QTest::newRow(qPrintable(s.arg("225-270:"))) |
|
339 << QLine(20, 0, 0, 100) << pen; |
|
340 QTest::newRow(qPrintable(s.arg("270-315:"))) |
|
341 << QLine(0, 0, 20, 100) << pen; |
|
342 QTest::newRow(qPrintable(s.arg("315-360:"))) |
|
343 << QLine(0, 0, 100, 20) << pen; |
|
344 ++i; |
|
345 } |
|
346 } |
|
347 |
|
348 void tst_QPainter::setupBrushes() |
|
349 { |
|
350 // Solid brushes... |
|
351 m_brushes["black-brush"] = QBrush(Qt::black); |
|
352 m_brushes["white-brush"] = QBrush(Qt::white); |
|
353 m_brushes["transparent-brush"] = QBrush(QColor(255, 255, 255, 0)); |
|
354 m_brushes["alpha1-brush"] = QBrush(QColor(255, 255, 255, 100)); |
|
355 m_brushes["alpha2-brush"] = QBrush(QColor(255, 255, 255, 200)); |
|
356 |
|
357 |
|
358 // Patterns |
|
359 m_brushes["dense1-brush"] = QBrush(Qt::Dense1Pattern); |
|
360 m_brushes["dense2-brush"] = QBrush(Qt::Dense2Pattern); |
|
361 m_brushes["dense3-brush"] = QBrush(Qt::Dense3Pattern); |
|
362 m_brushes["dense4-brush"] = QBrush(Qt::Dense4Pattern); |
|
363 m_brushes["dense5-brush"] = QBrush(Qt::Dense5Pattern); |
|
364 m_brushes["dense6-brush"] = QBrush(Qt::Dense6Pattern); |
|
365 m_brushes["dense7-brush"] = QBrush(Qt::Dense7Pattern); |
|
366 m_brushes["hor-brush"] = QBrush(Qt::HorPattern); |
|
367 m_brushes["ver-brush"] = QBrush(Qt::VerPattern); |
|
368 m_brushes["cross-brush"] = QBrush(Qt::CrossPattern); |
|
369 m_brushes["bdiag-brush"] = QBrush(Qt::BDiagPattern); |
|
370 m_brushes["fdiag-brush"] = QBrush(Qt::FDiagPattern); |
|
371 m_brushes["diagcross-brush"] = QBrush(Qt::DiagCrossPattern); |
|
372 |
|
373 // Gradients |
|
374 QGradientStops gradient_white_black; |
|
375 gradient_white_black << QPair<qreal, QColor>(0, QColor(Qt::white)); |
|
376 gradient_white_black << QPair<qreal, QColor>(1, QColor(Qt::black)); |
|
377 |
|
378 QGradientStops gradient_white_black10; |
|
379 for (int i=0; i<10; ++i) { |
|
380 gradient_white_black10 << QPair<qreal, QColor>(i/10.0, QColor(Qt::white)); |
|
381 gradient_white_black10 << QPair<qreal, QColor>(i/10.0+0.05, QColor(Qt::black)); |
|
382 } |
|
383 |
|
384 QGradientStops gradient_white_alpha; |
|
385 gradient_white_alpha << QPair<qreal, QColor>(0, QColor(Qt::white)); |
|
386 gradient_white_alpha << QPair<qreal, QColor>(0, QColor(Qt::transparent)); |
|
387 |
|
388 QGradientStops gradient_white_alpha10; |
|
389 for (int i=0; i<10; ++i) { |
|
390 gradient_white_alpha10 << QPair<qreal, QColor>(i/10.0, QColor(Qt::white)); |
|
391 gradient_white_alpha10 << QPair<qreal, QColor>(i/10.0+0.05, QColor(Qt::black)); |
|
392 } |
|
393 |
|
394 |
|
395 for (int j=0; j<4; ++j) { |
|
396 QLinearGradient lg; |
|
397 lg.setStart(0, 0); |
|
398 |
|
399 QRadialGradient rg; |
|
400 QConicalGradient cg; |
|
401 |
|
402 QGradientStops stops; |
|
403 if (j == 0) stops = gradient_white_black; |
|
404 else if (j == 1) stops = gradient_white_black10; |
|
405 else if (j == 2) stops = gradient_white_alpha; |
|
406 else if (j == 3) stops = gradient_white_alpha10; |
|
407 lg.setStops(stops); |
|
408 rg.setStops(stops); |
|
409 cg.setStops(stops); |
|
410 |
|
411 for (int i=0; i<6; ++i) { |
|
412 lg.setSpread((QGradient::Spread) (i % 3)); |
|
413 lg.setCoordinateMode((QGradient::CoordinateMode) (j / 3)); |
|
414 |
|
415 QString name = QString::fromLatin1("-%1%2") |
|
416 .arg(lg.spread()) |
|
417 .arg(lg.coordinateMode()); |
|
418 |
|
419 lg.setFinalStop(100, 0); |
|
420 m_brushes["hor-lingrad-w/b-brush" + name] = QBrush(lg); |
|
421 |
|
422 lg.setFinalStop(0, 100); |
|
423 m_brushes["ver-lingrad-w/b-brush" + name] = QBrush(lg); |
|
424 |
|
425 lg.setFinalStop(100, 100); |
|
426 m_brushes["diag-lingrad-w/b-brush" + name] = QBrush(lg); |
|
427 |
|
428 rg.setRadius(100); |
|
429 rg.setCenter(0, 0); |
|
430 rg.setFocalPoint(50, 50); |
|
431 m_brushes["radgrad-brush" + name] = QBrush(rg); |
|
432 |
|
433 cg.setCenter(0, 0); |
|
434 cg.setAngle(40); |
|
435 m_brushes["congrad-brush" + name] = QBrush(cg); |
|
436 } |
|
437 } |
|
438 |
|
439 // Set up pens... |
|
440 |
|
441 |
|
442 // m_pens["black-pen"] = QPen(Qt::black); |
|
443 // m_pens["white-pen"] = QPen(Qt::white); |
|
444 // m_pens["transparent-pen"] = QPen(QColor(255, 255, 255, 0)); |
|
445 // m_pens["translucent1-pen"] = QPen(QColor(255, 255, 255, 100)); |
|
446 // m_pens["translucent2-pen"] = QPen(QColor(255, 255, 255, 200)); |
|
447 |
|
448 |
|
449 |
|
450 } |
|
451 |
|
452 |
|
453 // void QPainter_Primitives::fillRect_data() { |
|
454 |
|
455 // QTest::addColumn<QBrush>("brush"); |
|
456 // QTest::addColumn<QSize>("size"); |
|
457 |
|
458 // for (QMap<QString, QBrush>::const_iterator it = m_brushes.constBegin(); |
|
459 // it != m_brushes.constEnd(); ++it) { |
|
460 // for (int w=2; w<1025; w*=2) { |
|
461 // for (int h=2; h<1025; h*=2) { |
|
462 // QTest::newRow(QString("brush=%1; size=[%2,%3]").arg(it.key()).arg(w).arg(h).toAscii().data()) |
|
463 // << *it << QSize(w, h); |
|
464 // } |
|
465 // } |
|
466 // } |
|
467 // } |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 // void QPainter_Primitives::fillRect() |
|
474 // { |
|
475 // QFETCH(QBrush, brush); |
|
476 // QFETCH(QSize, size); |
|
477 |
|
478 // QImage img(1024, 1024, QImage::Format_ARGB32_Premultiplied); |
|
479 // QPainter p(&img); |
|
480 // p.setPen(Qt::NoPen); |
|
481 // p.setBrush(brush); |
|
482 // QRect rect(QPoint(0, 0), size); |
|
483 // QBENCHMARK { |
|
484 // p.drawRect(rect); |
|
485 // } |
|
486 // } |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 void tst_QPainter::beginAndEnd() |
|
492 { |
|
493 QPixmap pixmap(100, 100); |
|
494 |
|
495 QBENCHMARK { |
|
496 QPainter p; |
|
497 p.begin(&pixmap); |
|
498 p.end(); |
|
499 } |
|
500 } |
|
501 |
|
502 void tst_QPainter::drawLine() |
|
503 { |
|
504 QFETCH(QLine, line); |
|
505 QFETCH(QPen, pen); |
|
506 |
|
507 const int offset = 5; |
|
508 QPixmap pixmapUnclipped(qMin(line.x1(), line.x2()) |
|
509 + 2*offset + qAbs(line.dx()), |
|
510 qMin(line.y1(), line.y2()) |
|
511 + 2*offset + qAbs(line.dy())); |
|
512 pixmapUnclipped.fill(Qt::white); |
|
513 |
|
514 QPainter p(&pixmapUnclipped); |
|
515 p.translate(offset, offset); |
|
516 p.setPen(pen); |
|
517 p.paintEngine()->syncState(); |
|
518 |
|
519 QBENCHMARK { |
|
520 p.drawLine(line); |
|
521 } |
|
522 |
|
523 p.end(); |
|
524 |
|
525 } |
|
526 |
|
527 void tst_QPainter::drawLine_clipped_data() |
|
528 { |
|
529 drawLine_data(); |
|
530 } |
|
531 |
|
532 void tst_QPainter::drawLine_clipped() |
|
533 { |
|
534 QFETCH(QLine, line); |
|
535 QFETCH(QPen, pen); |
|
536 |
|
537 const int offset = 5; |
|
538 QPixmap pixmapClipped(qMin(line.x1(), line.x2()) |
|
539 + 2*offset + qAbs(line.dx()), |
|
540 qMin(line.y1(), line.y2()) |
|
541 + 2*offset + qAbs(line.dy())); |
|
542 |
|
543 const QRect clip = QRect(line.p1(), line.p2()).normalized(); |
|
544 |
|
545 pixmapClipped.fill(Qt::white); |
|
546 QPainter p(&pixmapClipped); |
|
547 p.translate(offset, offset); |
|
548 p.setClipRect(clip); |
|
549 p.setPen(pen); |
|
550 p.paintEngine()->syncState(); |
|
551 |
|
552 QBENCHMARK { |
|
553 p.drawLine(line); |
|
554 } |
|
555 |
|
556 p.end(); |
|
557 } |
|
558 |
|
559 |
|
560 void tst_QPainter::drawLine_antialiased_clipped_data() |
|
561 { |
|
562 drawLine_data(); |
|
563 } |
|
564 |
|
565 |
|
566 void tst_QPainter::drawLine_antialiased_clipped() |
|
567 { |
|
568 QFETCH(QLine, line); |
|
569 QFETCH(QPen, pen); |
|
570 |
|
571 const int offset = 5; |
|
572 QPixmap pixmapClipped(qMin(line.x1(), line.x2()) |
|
573 + 2*offset + qAbs(line.dx()), |
|
574 qMin(line.y1(), line.y2()) |
|
575 + 2*offset + qAbs(line.dy())); |
|
576 |
|
577 const QRect clip = QRect(line.p1(), line.p2()).normalized(); |
|
578 |
|
579 pixmapClipped.fill(Qt::white); |
|
580 QPainter p(&pixmapClipped); |
|
581 p.setRenderHint(QPainter::Antialiasing); |
|
582 p.translate(offset, offset); |
|
583 p.setClipRect(clip); |
|
584 p.setPen(pen); |
|
585 p.paintEngine()->syncState(); |
|
586 |
|
587 QBENCHMARK { |
|
588 p.drawLine(line); |
|
589 } |
|
590 |
|
591 p.end(); |
|
592 } |
|
593 |
|
594 void tst_QPainter::drawPixmap_data() |
|
595 { |
|
596 QTest::addColumn<QImage::Format>("sourceFormat"); |
|
597 QTest::addColumn<QImage::Format>("targetFormat"); |
|
598 QTest::addColumn<QSize>("size"); |
|
599 QTest::addColumn<int>("type"); // 0 = circle, 1 = diag line, 2 = solid rect, 3 = alpharect |
|
600 |
|
601 QList<QSize> sizes; |
|
602 sizes << QSize(1, 1) |
|
603 << QSize(10, 10) |
|
604 << QSize(100, 100) |
|
605 << QSize(1000, 1000); |
|
606 |
|
607 const char *typeNames[] = { |
|
608 "circle", |
|
609 "line", |
|
610 "solidrect", |
|
611 "alpharect" |
|
612 }; |
|
613 |
|
614 const char *formatNames[] = { |
|
615 "Invalid", |
|
616 "Mono", |
|
617 "MonoLSB", |
|
618 "Indexed8", |
|
619 "RGB32", |
|
620 "ARGB32", |
|
621 "ARGB32_pm", |
|
622 "RGB16", |
|
623 "ARGB8565_pm", |
|
624 "RGB666", |
|
625 "ARGB6666_pm", |
|
626 "RGB555", |
|
627 "ARGB8555_pm", |
|
628 "RGB888", |
|
629 "RGB444", |
|
630 "ARGB4444_pm" |
|
631 }; |
|
632 |
|
633 for (int tar=4; tar<QImage::NImageFormats; ++tar) { |
|
634 for (int src=4; src<QImage::NImageFormats; ++src) { |
|
635 |
|
636 // skip the low-priority formats to keep resultset manageable... |
|
637 if (tar == QImage::Format_RGB444 || src == QImage::Format_RGB444 |
|
638 || tar == QImage::Format_RGB555 || src == QImage::Format_RGB555 |
|
639 || tar == QImage::Format_RGB666 || src == QImage::Format_RGB666 |
|
640 || tar == QImage::Format_RGB888 || src == QImage::Format_RGB888 |
|
641 || tar == QImage::Format_ARGB4444_Premultiplied |
|
642 || src == QImage::Format_ARGB4444_Premultiplied |
|
643 || tar == QImage::Format_ARGB6666_Premultiplied |
|
644 || src == QImage::Format_ARGB6666_Premultiplied) |
|
645 continue; |
|
646 |
|
647 foreach (const QSize &s, sizes) { |
|
648 for (int type=0; type<=3; ++type) { |
|
649 QString name = QString::fromLatin1("%1 on %2, (%3x%4), %5") |
|
650 .arg(formatNames[src]) |
|
651 .arg(formatNames[tar]) |
|
652 .arg(s.width()).arg(s.height()) |
|
653 .arg(typeNames[type]); |
|
654 QTest::newRow(name.toLatin1()) << (QImage::Format) src |
|
655 << (QImage::Format) tar |
|
656 << s |
|
657 << type; |
|
658 } |
|
659 } |
|
660 } |
|
661 } |
|
662 } |
|
663 |
|
664 static QImage createImage(int type, const QSize &size) { |
|
665 QImage base(size, QImage::Format_ARGB32_Premultiplied); |
|
666 base.fill(0); |
|
667 QPainter p(&base); |
|
668 p.setRenderHint(QPainter::Antialiasing); |
|
669 switch (type) { |
|
670 case 0: // ellipse |
|
671 p.setBrush(Qt::red); |
|
672 p.drawEllipse(0, 0, size.width(), size.height()); |
|
673 break; |
|
674 case 1: // line |
|
675 p.drawLine(0, 0, size.width(), size.height()); |
|
676 break; |
|
677 case 2: |
|
678 p.fillRect(0, 0, size.width(), size.height(), Qt::red); |
|
679 break; |
|
680 case 3: |
|
681 p.fillRect(0, 0, size.width(), size.height(), QColor(0, 255, 0, 127)); |
|
682 break; |
|
683 } |
|
684 p.end(); |
|
685 return base; |
|
686 } |
|
687 |
|
688 |
|
689 void tst_QPainter::drawPixmap() |
|
690 { |
|
691 QFETCH(QImage::Format, sourceFormat); |
|
692 QFETCH(QImage::Format, targetFormat); |
|
693 QFETCH(QSize, size); |
|
694 QFETCH(int, type); |
|
695 |
|
696 QImage sourceImage = createImage(type, size).convertToFormat(sourceFormat); |
|
697 QImage targetImage(size, targetFormat); |
|
698 |
|
699 QPixmap sourcePixmap = QPixmap::fromImage(sourceImage); |
|
700 QPixmap targetPixmap = QPixmap::fromImage(targetImage); |
|
701 |
|
702 QPainter p(&targetPixmap); |
|
703 |
|
704 QBENCHMARK { |
|
705 p.drawPixmap(0, 0, sourcePixmap); |
|
706 } |
|
707 } |
|
708 |
|
709 void tst_QPainter::drawImage_data() |
|
710 { |
|
711 drawPixmap_data(); |
|
712 } |
|
713 |
|
714 |
|
715 void tst_QPainter::drawImage() |
|
716 { |
|
717 QFETCH(QImage::Format, sourceFormat); |
|
718 QFETCH(QImage::Format, targetFormat); |
|
719 QFETCH(QSize, size); |
|
720 QFETCH(int, type); |
|
721 |
|
722 QImage sourceImage = createImage(type, size).convertToFormat(sourceFormat); |
|
723 QImage targetImage(size, targetFormat); |
|
724 |
|
725 QPainter p(&targetImage); |
|
726 QBENCHMARK { |
|
727 p.drawImage(0, 0, sourceImage); |
|
728 } |
|
729 } |
|
730 |
|
731 |
|
732 void tst_QPainter::compositionModes_data() |
|
733 { |
|
734 QTest::addColumn<QPainter::CompositionMode>("mode"); |
|
735 QTest::addColumn<QSize>("size"); |
|
736 QTest::addColumn<QColor>("color"); |
|
737 |
|
738 const int n = QPainter::RasterOp_SourceAndNotDestination; |
|
739 for (int i = 0; i <= n; ++i) { |
|
740 QString title("%1:%2"); |
|
741 QTest::newRow(qPrintable(title.arg(i).arg("10x10:opaque"))) |
|
742 << (QPainter::CompositionMode)(i) |
|
743 << QSize(10, 10) << QColor(255, 0, 0); |
|
744 QTest::newRow(qPrintable(title.arg(i).arg("10x10:!opaque"))) |
|
745 << (QPainter::CompositionMode)(i) |
|
746 << QSize(10, 10) << QColor(127, 127, 127, 127); |
|
747 QTest::newRow(qPrintable(title.arg(i).arg("300x300:opaque"))) |
|
748 << (QPainter::CompositionMode)(i) |
|
749 << QSize(300, 300) << QColor(255, 0, 0); |
|
750 QTest::newRow(qPrintable(title.arg(i).arg("300x300:!opaque"))) |
|
751 << (QPainter::CompositionMode)(i) |
|
752 << QSize(300, 300) << QColor(127, 127, 127, 127); |
|
753 } |
|
754 } |
|
755 |
|
756 void tst_QPainter::compositionModes() |
|
757 { |
|
758 QFETCH(QPainter::CompositionMode, mode); |
|
759 QFETCH(QSize, size); |
|
760 QFETCH(QColor, color); |
|
761 |
|
762 QPixmap src(size); |
|
763 src.fill(color); |
|
764 |
|
765 QPixmap dest(size); |
|
766 if (mode < QPainter::RasterOp_SourceOrDestination) |
|
767 color.setAlpha(127); // porter-duff needs an alpha channel |
|
768 dest.fill(color); |
|
769 |
|
770 QPainter p(&dest); |
|
771 p.setCompositionMode(mode); |
|
772 |
|
773 QBENCHMARK { |
|
774 p.drawPixmap(0, 0, src); |
|
775 } |
|
776 } |
|
777 |
|
778 void tst_QPainter::drawTiledPixmap_data() |
|
779 { |
|
780 QTest::addColumn<QSize>("srcSize"); |
|
781 QTest::addColumn<QSize>("dstSize"); |
|
782 QTest::addColumn<QTransform>("transform"); |
|
783 QTest::addColumn<QColor>("color"); |
|
784 QTest::addColumn<QPainter::RenderHint>("renderHint"); |
|
785 |
|
786 QTest::newRow("10x10=>20x20") |
|
787 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
788 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
789 QTest::newRow("10x10=>20x20, smooth") |
|
790 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
791 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
792 QTest::newRow("10x10=>20x20, !opaque") |
|
793 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
794 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
795 QTest::newRow("10x10=>20x20, !opaque, smooth") |
|
796 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
797 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
798 |
|
799 QTest::newRow("10x10=>20x20, rotate(30)") |
|
800 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
801 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
802 QTest::newRow("10x10=>20x20, rotate(30), smooth") |
|
803 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
804 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
805 QTest::newRow("10x10=>20x20, rotate(30), !opaque") |
|
806 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
807 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
808 QTest::newRow("10x10=>20x20, rotate(30), !opaque, smooth") |
|
809 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
810 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
811 |
|
812 QTest::newRow("100x100=>200x200") |
|
813 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
814 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
815 QTest::newRow("100x100=>200x200, smooth") |
|
816 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
817 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
818 QTest::newRow("100x100=>200x200, !opaque") |
|
819 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
820 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
821 QTest::newRow("100x100=>200x200, !opaque, smooth") |
|
822 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
823 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
824 |
|
825 QTest::newRow("100x100=>200x200, rotate(30)") |
|
826 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
827 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
828 QTest::newRow("100x100=>200x200, rotate(30), smooth") |
|
829 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
830 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
831 QTest::newRow("100x100=>200x200, rotate(30), !opaque") |
|
832 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
833 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
834 QTest::newRow("100x100=>200x200, rotate(30), !opaque, smooth") |
|
835 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
836 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
837 } |
|
838 |
|
839 void tst_QPainter::drawTiledPixmap() |
|
840 { |
|
841 QFETCH(QSize, srcSize); |
|
842 QFETCH(QSize, dstSize); |
|
843 QFETCH(QTransform, transform); |
|
844 QFETCH(QColor, color); |
|
845 QFETCH(QPainter::RenderHint, renderHint); |
|
846 |
|
847 QPixmap src(srcSize); |
|
848 src.fill(color); |
|
849 |
|
850 const QRect dstRect = transform.mapRect(QRect(QPoint(), dstSize)); |
|
851 QPixmap dst(dstRect.right() + 5, dstRect.bottom() + 5); |
|
852 QPainter p(&dst); |
|
853 p.setTransform(transform); |
|
854 p.setRenderHint(renderHint); |
|
855 |
|
856 QBENCHMARK { |
|
857 p.drawTiledPixmap(QRect(QPoint(), dstSize), src); |
|
858 } |
|
859 } |
|
860 |
|
861 void tst_QPainter::fillPrimitives_helper(QPainter *p, PrimitiveType type, PrimitiveSet *s) |
|
862 { |
|
863 p->paintEngine()->syncState(); |
|
864 |
|
865 switch (type) { |
|
866 case Primitive_Int_DiagLine: QBENCHMARK { p->drawLine(s->i_line_diag); } break; |
|
867 case Primitive_Int_VerLine: QBENCHMARK { p->drawLine(s->i_line_ver); } break; |
|
868 case Primitive_Int_HorLine: QBENCHMARK { p->drawLine(s->i_line_hor); } break; |
|
869 case Primitive_Int_Rect: QBENCHMARK { p->drawRect(s->i_rect); } break; |
|
870 case Primitive_Int_Ellipse: QBENCHMARK { p->drawEllipse(s->i_rect); } break; |
|
871 case Primitive_Int_Pie: QBENCHMARK { p->drawPie(s->i_rect, 45*16, 270*16); } break; |
|
872 case Primitive_Int_Arc: QBENCHMARK { p->drawArc(s->i_rect, 45*16, 270*16); } break; |
|
873 case Primitive_Int_Chord: QBENCHMARK { p->drawChord(s->i_rect, 45*16, 270*16); } break; |
|
874 case Primitive_Int_TriPoly: QBENCHMARK { p->drawPolygon(s->i_poly_tri); } break; |
|
875 case Primitive_Int_RectPoly: QBENCHMARK { p->drawPolygon(s->i_poly_rect); } break; |
|
876 case Primitive_Int_2RectPoly: QBENCHMARK { p->drawPolygon(s->i_poly_2rects); } break; |
|
877 |
|
878 case Primitive_Float_DiagLine: QBENCHMARK { p->drawLine(s->f_line_diag); } break; |
|
879 case Primitive_Float_VerLine: QBENCHMARK { p->drawLine(s->f_line_ver); } break; |
|
880 case Primitive_Float_HorLine: QBENCHMARK { p->drawLine(s->f_line_hor); } break; |
|
881 case Primitive_Float_Rect: QBENCHMARK { p->drawRect(s->f_rect); } break; |
|
882 case Primitive_Float_Ellipse: QBENCHMARK { p->drawEllipse(s->f_rect); } break; |
|
883 case Primitive_Float_Pie: QBENCHMARK { p->drawPie(s->f_rect, 45*16, 270*16); } break; |
|
884 case Primitive_Float_Arc: QBENCHMARK { p->drawArc(s->f_rect, 45*16, 270*16); } break; |
|
885 case Primitive_Float_Chord: QBENCHMARK { p->drawChord(s->f_rect, 45*16, 270*16); } break; |
|
886 case Primitive_Float_TriPoly: QBENCHMARK { p->drawPolygon(s->f_poly_tri); } break; |
|
887 case Primitive_Float_RectPoly: QBENCHMARK { p->drawPolygon(s->f_poly_rect); } break; |
|
888 case Primitive_Float_2RectPoly: QBENCHMARK { p->drawPolygon(s->f_poly_2rects); } break; |
|
889 |
|
890 case Primitive_Float_TriPath: QBENCHMARK { p->drawPath(s->f_path_tri); } break; |
|
891 case Primitive_Float_RectPath: QBENCHMARK { p->drawPath(s->f_path_rect); } break; |
|
892 case Primitive_Float_2RectPath: QBENCHMARK { p->drawPath(s->f_path_2rects); } break; |
|
893 case Primitive_Float_EllipsePath: QBENCHMARK { p->drawPath(s->f_path_ellipse); } break; |
|
894 } |
|
895 } |
|
896 |
|
897 void tst_QPainter::drawPrimitives_data_helper(bool fancypens) |
|
898 { |
|
899 QTest::addColumn<int>("type"); |
|
900 QTest::addColumn<bool>("aa"); |
|
901 QTest::addColumn<bool>("dash"); |
|
902 QTest::addColumn<int>("width"); |
|
903 |
|
904 const char * const names[] = { |
|
905 "IDLine", |
|
906 "IVLine", |
|
907 "IHLine", |
|
908 "IRect", |
|
909 "IElli", |
|
910 "IPie", |
|
911 "IArc", |
|
912 "IChord", |
|
913 "ITriPol", |
|
914 "IRectPol", |
|
915 "I2RectPol", |
|
916 "FDLine", |
|
917 "FVLine", |
|
918 "FHLine", |
|
919 "FRect", |
|
920 "FElli", |
|
921 "FPie", |
|
922 "FArc", |
|
923 "FChord", |
|
924 "FTriPol", |
|
925 "FRectPol", |
|
926 "F2RectPol", |
|
927 "FTriPa", |
|
928 "FRectPa", |
|
929 "F2RectPa", |
|
930 "FElliPa" |
|
931 }; |
|
932 |
|
933 if (fancypens) { |
|
934 for (int dash=0; dash<2; ++dash) { |
|
935 for (int width=0; width<=4; width+=4) { |
|
936 for (int aa=0; aa<2; ++aa) { |
|
937 for (int type=0; type<Primitive_Last_Primitive; ++type) { |
|
938 QString name = QString::fromLatin1(names[type]); |
|
939 |
|
940 if (aa) name += " aa"; |
|
941 if (dash) name += " dotted"; |
|
942 if (width) name += QString::fromLatin1(" width=%1").arg(width); |
|
943 |
|
944 QTest::newRow(name.toLatin1()) << type << (bool) aa << (bool) dash << width; |
|
945 } |
|
946 } |
|
947 } |
|
948 } |
|
949 } else { |
|
950 for (int aa=0; aa<2; ++aa) { |
|
951 for (int type=0; type<Primitive_Last_Primitive; ++type) { |
|
952 QString name = QString::fromLatin1(names[type]); |
|
953 if (aa) name += " aa"; |
|
954 QTest::newRow(name.toLatin1()) << type << (bool) aa; |
|
955 } |
|
956 } |
|
957 } |
|
958 } |
|
959 |
|
960 |
|
961 void tst_QPainter::fillPrimitives_10() |
|
962 { |
|
963 QFETCH(int, type); |
|
964 QFETCH(bool, aa); |
|
965 QPainter p(m_surface); |
|
966 p.setPen(Qt::NoPen); |
|
967 p.setBrush(Qt::red); |
|
968 p.setRenderHint(QPainter::Antialiasing, aa); |
|
969 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_10); |
|
970 } |
|
971 |
|
972 |
|
973 void tst_QPainter::fillPrimitives_100() |
|
974 { |
|
975 QFETCH(int, type); |
|
976 QFETCH(bool, aa); |
|
977 QPainter p(m_surface); |
|
978 p.setPen(Qt::NoPen); |
|
979 p.setBrush(Qt::red); |
|
980 p.setRenderHint(QPainter::Antialiasing, aa); |
|
981 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_100); |
|
982 } |
|
983 |
|
984 |
|
985 void tst_QPainter::fillPrimitives_1000() |
|
986 { |
|
987 QFETCH(int, type); |
|
988 QFETCH(bool, aa); |
|
989 QPainter p(m_surface); |
|
990 p.setPen(Qt::NoPen); |
|
991 p.setBrush(Qt::red); |
|
992 p.setRenderHint(QPainter::Antialiasing, aa); |
|
993 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_1000); |
|
994 } |
|
995 |
|
996 void tst_QPainter::strokePrimitives_10() |
|
997 { |
|
998 QFETCH(int, type); |
|
999 QFETCH(bool, aa); |
|
1000 QFETCH(bool, dash); |
|
1001 QFETCH(int, width); |
|
1002 QPainter p(m_surface); |
|
1003 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
1004 p.setBrush(Qt::NoBrush); |
|
1005 p.setRenderHint(QPainter::Antialiasing, aa); |
|
1006 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_10); |
|
1007 } |
|
1008 |
|
1009 void tst_QPainter::strokePrimitives_100() |
|
1010 { |
|
1011 QFETCH(int, type); |
|
1012 QFETCH(bool, aa); |
|
1013 QFETCH(bool, dash); |
|
1014 QFETCH(int, width); |
|
1015 QPainter p(m_surface); |
|
1016 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
1017 p.setBrush(Qt::NoBrush); |
|
1018 p.setRenderHint(QPainter::Antialiasing, aa); |
|
1019 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_100); |
|
1020 } |
|
1021 |
|
1022 void tst_QPainter::strokePrimitives_1000() |
|
1023 { |
|
1024 QFETCH(int, type); |
|
1025 QFETCH(bool, aa); |
|
1026 QFETCH(bool, dash); |
|
1027 QFETCH(int, width); |
|
1028 QPainter p(m_surface); |
|
1029 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
1030 p.setBrush(Qt::NoBrush); |
|
1031 p.setRenderHint(QPainter::Antialiasing, aa); |
|
1032 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_1000); |
|
1033 } |
|
1034 |
|
1035 void tst_QPainter::drawText_data() |
|
1036 { |
|
1037 QTest::addColumn<QString>("text"); |
|
1038 |
|
1039 QTest::newRow("a") << QString::fromLatin1("a"); |
|
1040 QTest::newRow("ab") << QString::fromLatin1("ab"); |
|
1041 QTest::newRow("abc") << QString::fromLatin1("abc"); |
|
1042 QTest::newRow("abcd") << QString::fromLatin1("abcd"); |
|
1043 QTest::newRow("abcde") << QString::fromLatin1("abcde"); |
|
1044 QTest::newRow("abcdef") << QString::fromLatin1("abcdef"); |
|
1045 QTest::newRow("abcdefg") << QString::fromLatin1("abcdefg"); |
|
1046 } |
|
1047 |
|
1048 void tst_QPainter::drawText() |
|
1049 { |
|
1050 QFETCH(QString, text); |
|
1051 |
|
1052 QPainter p(m_surface); |
|
1053 |
|
1054 QBENCHMARK { |
|
1055 p.drawText(QPointF(5, 5), text); |
|
1056 } |
|
1057 } |
|
1058 |
|
1059 void tst_QPainter::saveRestore_data() |
|
1060 { |
|
1061 QTest::addColumn<int>("change"); |
|
1062 |
|
1063 for (int i=0; i<16; ++i) { |
|
1064 QString change = "change="; |
|
1065 if (i == 0) change += " none"; |
|
1066 if (i & ChangePen) change += " pen"; |
|
1067 if (i & ChangeBrush) change += " brush"; |
|
1068 if (i & ChangeClip) change += " clip"; |
|
1069 if (i & ChangeTransform) change += " xform"; |
|
1070 |
|
1071 QTest::newRow(change.toLatin1()) << i; |
|
1072 } |
|
1073 } |
|
1074 |
|
1075 void tst_QPainter::saveRestore() |
|
1076 { |
|
1077 QFETCH(int, change); |
|
1078 |
|
1079 QPen pen(Qt::blue); |
|
1080 QBrush brush(Qt::green); |
|
1081 QRect r(100, 100, 100, 20); |
|
1082 |
|
1083 QPainter p(m_surface); |
|
1084 |
|
1085 p.setPen(Qt::NoPen); |
|
1086 p.setBrush(Qt::NoBrush); |
|
1087 |
|
1088 QBENCHMARK { |
|
1089 p.save(); |
|
1090 if (change & ChangePen) { p.setPen(pen); p.setPen(Qt::NoPen); } |
|
1091 if (change & ChangeBrush) { p.setBrush(brush); p.setBrush(Qt::NoBrush); } |
|
1092 if (change & ChangeClip) p.setClipRect(r); |
|
1093 if (change & ChangeTransform) { p.scale(3, 5); p.scale(1/3.0, 1/5.0); } |
|
1094 p.drawRect(0, 0, 1, 1); |
|
1095 p.restore(); |
|
1096 }; |
|
1097 } |
|
1098 |
|
1099 enum ClipType { |
|
1100 RectClipType, |
|
1101 RectPathClipType, |
|
1102 RectRegionClipType, |
|
1103 RegionClipType, |
|
1104 PathClipType |
|
1105 }; |
|
1106 |
|
1107 void tst_QPainter::clipAndFill_data() |
|
1108 { |
|
1109 QTest::addColumn<int>("type"); |
|
1110 |
|
1111 QTest::newRow("rect") << (int) RectClipType; |
|
1112 QTest::newRow("rectpath") << (int) RectPathClipType; |
|
1113 QTest::newRow("rectregion") << (int) RectRegionClipType; |
|
1114 QTest::newRow("ellipseRegion") << (int) RegionClipType; |
|
1115 QTest::newRow("ellipsePath") << (int) PathClipType; |
|
1116 } |
|
1117 |
|
1118 |
|
1119 void tst_QPainter::clipAndFill() |
|
1120 { |
|
1121 QFETCH(int, type); |
|
1122 |
|
1123 QRegion region; |
|
1124 QPainterPath path; |
|
1125 QRectF rect; |
|
1126 |
|
1127 switch (type) { |
|
1128 case RectClipType: |
|
1129 rect = QRectF(100, 100, 100, 100); |
|
1130 break; |
|
1131 case RectPathClipType: |
|
1132 path.addRect(100, 100, 100, 100); |
|
1133 break; |
|
1134 case RectRegionClipType: |
|
1135 region = QRegion(100, 100, 100, 100); |
|
1136 break; |
|
1137 case RegionClipType: |
|
1138 region = QRegion(100, 100, 100, 100, QRegion::Ellipse); |
|
1139 break; |
|
1140 case PathClipType: |
|
1141 path.addEllipse(100, 100, 100, 100); |
|
1142 break; |
|
1143 } |
|
1144 |
|
1145 QPainter p(m_surface); |
|
1146 |
|
1147 p.setPen(Qt::NoPen); |
|
1148 p.setBrush(Qt::red); |
|
1149 |
|
1150 QBENCHMARK { |
|
1151 if (type == RectClipType) |
|
1152 p.setClipRect(rect); |
|
1153 else if (type == RectPathClipType || type == PathClipType) |
|
1154 p.setClipPath(path); |
|
1155 else |
|
1156 p.setClipRegion(region); |
|
1157 p.drawRect(110, 110, 10, 10); |
|
1158 } |
|
1159 } |
|
1160 |
|
1161 QTransform tst_QPainter::transformForAngle(qreal angle) |
|
1162 { |
|
1163 const qreal inv_dist_to_plane = 1. / 1024.; |
|
1164 |
|
1165 QTransform transform; |
|
1166 |
|
1167 QTransform rotTrans; |
|
1168 rotTrans.translate(-40, 0); |
|
1169 QTransform rotTrans2; |
|
1170 rotTrans2.translate(40, 0); |
|
1171 |
|
1172 qreal rad = angle * 2. * M_PI / 360.; |
|
1173 qreal c = ::cos(rad); |
|
1174 qreal s = ::sin(rad); |
|
1175 |
|
1176 qreal x = 0; |
|
1177 qreal y = 80; |
|
1178 qreal z = 0; |
|
1179 |
|
1180 qreal len = x * x + y * y + z * z; |
|
1181 if (len != 1.) { |
|
1182 len = ::sqrt(len); |
|
1183 x /= len; |
|
1184 y /= len; |
|
1185 z /= len; |
|
1186 } |
|
1187 |
|
1188 QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane, |
|
1189 y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, |
|
1190 0, 0, 1); |
|
1191 |
|
1192 transform *= rotTrans; |
|
1193 transform *= rot; |
|
1194 transform *= rotTrans2; |
|
1195 |
|
1196 return transform; |
|
1197 } |
|
1198 |
|
1199 void tst_QPainter::drawRoundedRect() |
|
1200 { |
|
1201 QImage surface(100, 100, QImage::Format_RGB16); |
|
1202 surface.fill(QColor(255,255,255).rgb()); |
|
1203 QPainter p(&surface); |
|
1204 |
|
1205 p.setPen(QPen(Qt::black, 1)); |
|
1206 p.setBrush(Qt::red); |
|
1207 |
|
1208 QBENCHMARK { |
|
1209 p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); |
|
1210 } |
|
1211 } |
|
1212 |
|
1213 void tst_QPainter::drawScaledRoundedRect() |
|
1214 { |
|
1215 QImage surface(400, 400, QImage::Format_RGB16); |
|
1216 surface.fill(QColor(255,255,255).rgb()); |
|
1217 QPainter p(&surface); |
|
1218 |
|
1219 p.setPen(QPen(Qt::black, 1)); |
|
1220 p.setBrush(Qt::red); |
|
1221 p.scale(3, 3); |
|
1222 |
|
1223 QBENCHMARK { |
|
1224 p.drawRoundedRect(10, 10, 80, 80, 10, 10); |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 void tst_QPainter::drawTransformedRoundedRect() |
|
1229 { |
|
1230 QImage surface(400, 400, QImage::Format_RGB16); |
|
1231 surface.fill(QColor(255,255,255).rgb()); |
|
1232 QPainter p(&surface); |
|
1233 |
|
1234 p.setPen(QPen(Qt::black, 1)); |
|
1235 p.setBrush(Qt::red); |
|
1236 |
|
1237 QBENCHMARK { |
|
1238 p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); |
|
1239 p.drawRoundedRect(100, 100, 80, 80, 10, 10); |
|
1240 } |
|
1241 } |
|
1242 |
|
1243 void tst_QPainter::drawAntialiasedRoundedRect() |
|
1244 { |
|
1245 QImage surface(100, 100, QImage::Format_RGB16); |
|
1246 surface.fill(QColor(255,255,255).rgb()); |
|
1247 QPainter p(&surface); |
|
1248 |
|
1249 p.setRenderHint(QPainter::Antialiasing, true); |
|
1250 p.setPen(QPen(Qt::black, 1)); |
|
1251 p.setBrush(Qt::red); |
|
1252 |
|
1253 QBENCHMARK { |
|
1254 p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); |
|
1255 } |
|
1256 } |
|
1257 |
|
1258 void tst_QPainter::drawScaledAntialiasedRoundedRect_data() |
|
1259 { |
|
1260 QTest::addColumn<float>("scale"); |
|
1261 |
|
1262 for (float i = 0; i < 3; i += .1) |
|
1263 QTest::newRow(QString(QLatin1String("scale=%1")).arg(i).toLatin1()) << i; |
|
1264 } |
|
1265 |
|
1266 void tst_QPainter::drawScaledAntialiasedRoundedRect() |
|
1267 { |
|
1268 QFETCH(float, scale); |
|
1269 |
|
1270 QImage surface(400, 400, QImage::Format_RGB16); |
|
1271 surface.fill(QColor(255,255,255).rgb()); |
|
1272 QPainter p(&surface); |
|
1273 |
|
1274 p.setRenderHint(QPainter::Antialiasing, true); |
|
1275 p.setPen(QPen(Qt::black, 1)); |
|
1276 p.setBrush(Qt::red); |
|
1277 p.scale(scale, scale); |
|
1278 |
|
1279 QBENCHMARK { |
|
1280 p.drawRoundedRect(10, 10, 80, 80, 10, 10); |
|
1281 } |
|
1282 } |
|
1283 |
|
1284 void tst_QPainter::drawTransformedAntialiasedRoundedRect_data() |
|
1285 { |
|
1286 QTest::addColumn<QTransform>("transform"); |
|
1287 |
|
1288 for (float angle = 0; angle < 360; angle += 10) |
|
1289 QTest::newRow(QString(QLatin1String("angle=%1")).arg(angle).toLatin1()) << transformForAngle(angle); |
|
1290 } |
|
1291 |
|
1292 void tst_QPainter::drawTransformedAntialiasedRoundedRect() |
|
1293 { |
|
1294 QFETCH(QTransform, transform); |
|
1295 |
|
1296 QImage surface(400, 400, QImage::Format_RGB16); |
|
1297 surface.fill(QColor(255,255,255).rgb()); |
|
1298 QPainter p(&surface); |
|
1299 |
|
1300 p.setRenderHint(QPainter::Antialiasing, true); |
|
1301 p.setPen(QPen(Qt::black, 1)); |
|
1302 p.setBrush(Qt::red); |
|
1303 |
|
1304 QBENCHMARK { |
|
1305 p.setWorldTransform(transform); |
|
1306 p.drawRoundedRect(100, 100, 80, 80, 10, 10); |
|
1307 } |
|
1308 } |
|
1309 |
|
1310 void tst_QPainter::drawImageRoundedRect() |
|
1311 { |
|
1312 //setup image |
|
1313 const int radius = 10; |
|
1314 QImage rectImage(81, 81, QImage::Format_ARGB32_Premultiplied); |
|
1315 rectImage.fill(0); |
|
1316 QPainter rp(&rectImage); |
|
1317 rp.setRenderHint(QPainter::Antialiasing); |
|
1318 rp.setPen(Qt::black); |
|
1319 rp.setBrush(Qt::red); |
|
1320 rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); |
|
1321 |
|
1322 //setup surface |
|
1323 QImage surface(100, 100, QImage::Format_RGB16); |
|
1324 surface.fill(QColor(255,255,255).rgb()); |
|
1325 QPainter p(&surface); |
|
1326 |
|
1327 QBENCHMARK { |
|
1328 p.drawImage(0,0, rectImage); |
|
1329 } |
|
1330 } |
|
1331 |
|
1332 void tst_QPainter::drawScaledImageRoundedRect_data() |
|
1333 { |
|
1334 QTest::addColumn<int>("imageType"); |
|
1335 |
|
1336 QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; |
|
1337 QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1338 } |
|
1339 |
|
1340 void tst_QPainter::drawScaledImageRoundedRect() |
|
1341 { |
|
1342 QFETCH(int, imageType); |
|
1343 |
|
1344 //setup image |
|
1345 const int radius = 10; |
|
1346 QImage rectImage(81, 81, (QImage::Format)imageType); |
|
1347 rectImage.fill(0); |
|
1348 QPainter rp(&rectImage); |
|
1349 rp.setRenderHint(QPainter::Antialiasing); |
|
1350 rp.setPen(Qt::black); |
|
1351 rp.setBrush(Qt::red); |
|
1352 rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); |
|
1353 |
|
1354 //setup surface |
|
1355 QImage surface(400, 400, QImage::Format_RGB16); |
|
1356 surface.fill(QColor(255,255,255).rgb()); |
|
1357 QPainter p(&surface); |
|
1358 p.scale(3, 3); |
|
1359 |
|
1360 QBENCHMARK { |
|
1361 p.drawImage(0,0, rectImage); |
|
1362 } |
|
1363 } |
|
1364 |
|
1365 void tst_QPainter::drawTransformedImageRoundedRect_data() |
|
1366 { |
|
1367 QTest::addColumn<int>("imageType"); |
|
1368 |
|
1369 QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; |
|
1370 QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1371 } |
|
1372 |
|
1373 void tst_QPainter::drawTransformedImageRoundedRect() |
|
1374 { |
|
1375 QFETCH(int, imageType); |
|
1376 |
|
1377 //setup image |
|
1378 const int radius = 10; |
|
1379 QImage rectImage(81, 81, (QImage::Format)imageType); |
|
1380 rectImage.fill(0); |
|
1381 QPainter rp(&rectImage); |
|
1382 rp.setRenderHint(QPainter::Antialiasing); |
|
1383 rp.setPen(Qt::black); |
|
1384 rp.setBrush(Qt::red); |
|
1385 rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); |
|
1386 |
|
1387 //setup surface |
|
1388 QImage surface(400, 400, QImage::Format_RGB16); |
|
1389 surface.fill(QColor(255,255,255).rgb()); |
|
1390 QPainter p(&surface); |
|
1391 |
|
1392 QBENCHMARK { |
|
1393 p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); |
|
1394 p.drawImage(100,100, rectImage); |
|
1395 } |
|
1396 } |
|
1397 |
|
1398 //code from QmlGraphicsRectangle for drawing rounded rects |
|
1399 void tst_QPainter::drawBorderPixmapRoundedRect() |
|
1400 { |
|
1401 //setup image |
|
1402 const int pw = 1; |
|
1403 const int radius = 10; |
|
1404 QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); |
|
1405 rectImage.fill(0); |
|
1406 QPainter rp(&rectImage); |
|
1407 rp.setRenderHint(QPainter::Antialiasing); |
|
1408 rp.setPen(Qt::black); |
|
1409 rp.setBrush(Qt::red); |
|
1410 if (pw%2) |
|
1411 rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); |
|
1412 else |
|
1413 rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); |
|
1414 QPixmap rectPixmap = QPixmap::fromImage(rectImage); |
|
1415 |
|
1416 //setup surface |
|
1417 QImage surface(100, 100, QImage::Format_RGB16); |
|
1418 surface.fill(QColor(255,255,255).rgb()); |
|
1419 QPainter p(&surface); |
|
1420 |
|
1421 QBENCHMARK { |
|
1422 const int pw = 2; |
|
1423 int width = 80; |
|
1424 int height = 80; |
|
1425 |
|
1426 int xOffset = (rectPixmap.width()-1)/2; |
|
1427 int yOffset = (rectPixmap.height()-1)/2; |
|
1428 Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); |
|
1429 Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); |
|
1430 |
|
1431 QMargins margins(xOffset, yOffset, xOffset, yOffset); |
|
1432 QTileRules rules(Qt::StretchTile, Qt::StretchTile); |
|
1433 //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects |
|
1434 qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); |
|
1435 } |
|
1436 } |
|
1437 |
|
1438 void tst_QPainter::drawScaledBorderPixmapRoundedRect_data() |
|
1439 { |
|
1440 QTest::addColumn<float>("scale"); |
|
1441 QTest::addColumn<int>("imageType"); |
|
1442 |
|
1443 for (float i = 0; i < 3; i += .1) |
|
1444 QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB32_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB32_Premultiplied; |
|
1445 //for (float i = 0; i < 3; i += .1) |
|
1446 // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1447 } |
|
1448 |
|
1449 //code from QmlGraphicsRectangle for drawing rounded rects |
|
1450 void tst_QPainter::drawScaledBorderPixmapRoundedRect() |
|
1451 { |
|
1452 QFETCH(float, scale); |
|
1453 QFETCH(int, imageType); |
|
1454 |
|
1455 //setup image |
|
1456 const int pw = 1; |
|
1457 const int radius = 10; |
|
1458 QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); |
|
1459 rectImage.fill(0); |
|
1460 QPainter rp(&rectImage); |
|
1461 rp.setRenderHint(QPainter::Antialiasing); |
|
1462 rp.setPen(Qt::black); |
|
1463 rp.setBrush(Qt::red); |
|
1464 if (pw%2) |
|
1465 rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); |
|
1466 else |
|
1467 rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); |
|
1468 |
|
1469 QPixmap rectPixmap = QPixmap::fromImage(rectImage); |
|
1470 |
|
1471 //setup surface |
|
1472 QImage surface(400, 400, QImage::Format_RGB16); |
|
1473 surface.fill(QColor(255,255,255).rgb()); |
|
1474 QPainter p(&surface); |
|
1475 p.scale(scale, scale); |
|
1476 |
|
1477 QBENCHMARK { |
|
1478 const int pw = 2; |
|
1479 int width = 80; |
|
1480 int height = 80; |
|
1481 |
|
1482 int xOffset = (rectPixmap.width()-1)/2; |
|
1483 int yOffset = (rectPixmap.height()-1)/2; |
|
1484 Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); |
|
1485 Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); |
|
1486 |
|
1487 QMargins margins(xOffset, yOffset, xOffset, yOffset); |
|
1488 QTileRules rules(Qt::StretchTile, Qt::StretchTile); |
|
1489 qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); |
|
1490 } |
|
1491 } |
|
1492 |
|
1493 void tst_QPainter::drawTransformedBorderPixmapRoundedRect_data() |
|
1494 { |
|
1495 QTest::addColumn<QTransform>("transform"); |
|
1496 QTest::addColumn<int>("imageType"); |
|
1497 |
|
1498 for (float angle = 0; angle < 360; angle += 10) |
|
1499 QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB32_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB32_Premultiplied; |
|
1500 //for (float angle = 0; angle < 360; angle += 10) |
|
1501 // QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB8565_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1502 |
|
1503 } |
|
1504 |
|
1505 //code from QmlGraphicsRectangle for drawing rounded rects |
|
1506 void tst_QPainter::drawTransformedBorderPixmapRoundedRect() |
|
1507 { |
|
1508 QFETCH(QTransform, transform); |
|
1509 QFETCH(int, imageType); |
|
1510 |
|
1511 //setup image |
|
1512 const int pw = 1; |
|
1513 const int radius = 10; |
|
1514 QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); |
|
1515 rectImage.fill(0); |
|
1516 QPainter rp(&rectImage); |
|
1517 rp.setRenderHint(QPainter::Antialiasing); |
|
1518 rp.setPen(Qt::black); |
|
1519 rp.setBrush(Qt::red); |
|
1520 if (pw%2) |
|
1521 rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); |
|
1522 else |
|
1523 rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); |
|
1524 |
|
1525 QPixmap rectPixmap = QPixmap::fromImage(rectImage); |
|
1526 |
|
1527 //setup surface |
|
1528 QImage surface(400, 400, QImage::Format_RGB16); |
|
1529 surface.fill(QColor(255,255,255).rgb()); |
|
1530 QPainter p(&surface); |
|
1531 |
|
1532 QBENCHMARK { |
|
1533 p.setWorldTransform(transform); |
|
1534 const int pw = 2; |
|
1535 int width = 80; |
|
1536 int height = 80; |
|
1537 |
|
1538 int xOffset = (rectPixmap.width()-1)/2; |
|
1539 int yOffset = (rectPixmap.height()-1)/2; |
|
1540 Q_ASSERT(rectPixmap.width() == 2*xOffset + 1); |
|
1541 Q_ASSERT(rectPixmap.height() == 2*yOffset + 1); |
|
1542 |
|
1543 QMargins margins(xOffset, yOffset, xOffset, yOffset); |
|
1544 QTileRules rules(Qt::StretchTile, Qt::StretchTile); |
|
1545 qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width+pw, height+pw), margins, rectPixmap, rectPixmap.rect(), margins, rules); |
|
1546 } |
|
1547 } |
|
1548 |
|
1549 void tst_QPainter::drawTransformedTransparentImage_data() |
|
1550 { |
|
1551 QTest::addColumn<int>("imageType"); |
|
1552 |
|
1553 QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; |
|
1554 QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1555 } |
|
1556 |
|
1557 void tst_QPainter::drawTransformedTransparentImage() |
|
1558 { |
|
1559 QFETCH(int, imageType); |
|
1560 |
|
1561 //setup image |
|
1562 QImage transImage(200, 200, (QImage::Format)imageType); |
|
1563 transImage.fill(0); |
|
1564 |
|
1565 //setup surface |
|
1566 QImage surface(200, 200, QImage::Format_RGB16); |
|
1567 surface.fill(QColor(255,255,255).rgb()); |
|
1568 QPainter p(&surface); |
|
1569 |
|
1570 QBENCHMARK { |
|
1571 p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); |
|
1572 p.drawImage(0,0, transImage); |
|
1573 } |
|
1574 } |
|
1575 |
|
1576 void tst_QPainter::drawTransformedSemiTransparentImage_data() |
|
1577 { |
|
1578 QTest::addColumn<int>("imageType"); |
|
1579 |
|
1580 QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; |
|
1581 QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1582 } |
|
1583 |
|
1584 void tst_QPainter::drawTransformedSemiTransparentImage() |
|
1585 { |
|
1586 QFETCH(int, imageType); |
|
1587 |
|
1588 //setup image |
|
1589 QImage transImage(200, 200, (QImage::Format)imageType); |
|
1590 transImage.fill(QColor(0,0,0, 128).rgba()); |
|
1591 |
|
1592 //setup surface |
|
1593 QImage surface(200, 200, QImage::Format_RGB16); |
|
1594 surface.fill(QColor(255,255,255).rgb()); |
|
1595 QPainter p(&surface); |
|
1596 |
|
1597 QBENCHMARK { |
|
1598 p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); |
|
1599 p.drawImage(0,0, transImage); |
|
1600 } |
|
1601 } |
|
1602 |
|
1603 void tst_QPainter::drawTransformedFilledImage_data() |
|
1604 { |
|
1605 QTest::addColumn<int>("imageType"); |
|
1606 |
|
1607 QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; |
|
1608 QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; |
|
1609 } |
|
1610 |
|
1611 void tst_QPainter::drawTransformedFilledImage() |
|
1612 { |
|
1613 QFETCH(int, imageType); |
|
1614 |
|
1615 //setup image |
|
1616 QImage filledImage(200, 200, (QImage::Format)imageType); |
|
1617 filledImage.fill(QColor(0,0,0).rgb()); |
|
1618 |
|
1619 //setup surface |
|
1620 QImage surface(200, 200, QImage::Format_RGB16); |
|
1621 surface.fill(QColor(255,255,255).rgb()); |
|
1622 QPainter p(&surface); |
|
1623 |
|
1624 QBENCHMARK { |
|
1625 p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); |
|
1626 p.drawImage(0,0, filledImage); |
|
1627 } |
|
1628 } |
|
1629 |
|
1630 |
|
1631 QTEST_MAIN(tst_QPainter) |
|
1632 |
|
1633 #include "tst_qpainter.moc" |