|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 |
|
49 Q_DECLARE_METATYPE(QLine) |
|
50 Q_DECLARE_METATYPE(QRect) |
|
51 Q_DECLARE_METATYPE(QSize) |
|
52 Q_DECLARE_METATYPE(QPoint) |
|
53 Q_DECLARE_METATYPE(QPainterPath) |
|
54 Q_DECLARE_METATYPE(QPainter::RenderHint) |
|
55 Q_DECLARE_METATYPE(QPainter::CompositionMode) |
|
56 Q_DECLARE_METATYPE(QImage::Format) |
|
57 |
|
58 enum PrimitiveType { |
|
59 Primitive_Int_DiagLine, |
|
60 Primitive_Int_VerLine, |
|
61 Primitive_Int_HorLine, |
|
62 Primitive_Int_Rect, |
|
63 Primitive_Int_Ellipse, |
|
64 Primitive_Int_Pie, |
|
65 Primitive_Int_Arc, |
|
66 Primitive_Int_Chord, |
|
67 Primitive_Int_TriPoly, |
|
68 Primitive_Int_RectPoly, |
|
69 Primitive_Int_2RectPoly, |
|
70 |
|
71 Primitive_Float_DiagLine, |
|
72 Primitive_Float_VerLine, |
|
73 Primitive_Float_HorLine, |
|
74 Primitive_Float_Rect, |
|
75 Primitive_Float_Ellipse, |
|
76 Primitive_Float_Pie, |
|
77 Primitive_Float_Arc, |
|
78 Primitive_Float_Chord, |
|
79 Primitive_Float_TriPoly, |
|
80 Primitive_Float_RectPoly, |
|
81 Primitive_Float_2RectPoly, |
|
82 |
|
83 Primitive_Float_TriPath, |
|
84 Primitive_Float_RectPath, |
|
85 Primitive_Float_2RectPath, |
|
86 Primitive_Float_EllipsePath, |
|
87 Primitive_Last_Primitive |
|
88 |
|
89 }; |
|
90 |
|
91 |
|
92 enum StateChanges { |
|
93 ChangePen = 0x0001, |
|
94 ChangeBrush = 0x0002, |
|
95 ChangeClip = 0x0004, |
|
96 ChangeTransform = 0x0008 |
|
97 }; |
|
98 |
|
99 |
|
100 struct PrimitiveSet { |
|
101 QRect i_rect; |
|
102 QLine i_line_diag; |
|
103 QLine i_line_ver; |
|
104 QLine i_line_hor; |
|
105 QPolygon i_poly_tri; |
|
106 QPolygon i_poly_2rects; |
|
107 QPolygon i_poly_rect; |
|
108 |
|
109 QRectF f_rect; |
|
110 QLineF f_line_diag; |
|
111 QLineF f_line_ver; |
|
112 QLineF f_line_hor; |
|
113 QPolygonF f_poly_tri; |
|
114 QPolygonF f_poly_2rects; |
|
115 QPolygonF f_poly_rect; |
|
116 |
|
117 QPainterPath f_path_tri; |
|
118 QPainterPath f_path_2rects; |
|
119 QPainterPath f_path_rect; |
|
120 QPainterPath f_path_ellipse; |
|
121 }; |
|
122 |
|
123 |
|
124 class tst_QPainter : public QObject |
|
125 { |
|
126 Q_OBJECT |
|
127 |
|
128 public: |
|
129 tst_QPainter() |
|
130 { |
|
131 setupBrushes(); |
|
132 createPrimitives(); |
|
133 m_surface = surface(); |
|
134 } |
|
135 |
|
136 private slots: |
|
137 void beginAndEnd(); |
|
138 |
|
139 void saveRestore_data(); |
|
140 void saveRestore(); |
|
141 |
|
142 void drawLine_data(); |
|
143 void drawLine(); |
|
144 void drawLine_clipped_data(); |
|
145 void drawLine_clipped(); |
|
146 void drawLine_antialiased_clipped_data(); |
|
147 void drawLine_antialiased_clipped(); |
|
148 |
|
149 void drawPixmap_data(); |
|
150 void drawPixmap(); |
|
151 |
|
152 void drawImage_data(); |
|
153 void drawImage(); |
|
154 |
|
155 void drawTiledPixmap_data(); |
|
156 void drawTiledPixmap(); |
|
157 |
|
158 void compositionModes_data(); |
|
159 void compositionModes(); |
|
160 |
|
161 void fillPrimitives_10_data() { drawPrimitives_data_helper(false); } |
|
162 void fillPrimitives_100_data() { drawPrimitives_data_helper(false); } |
|
163 void fillPrimitives_1000_data() { drawPrimitives_data_helper(false); } |
|
164 void fillPrimitives_10(); |
|
165 void fillPrimitives_100(); |
|
166 void fillPrimitives_1000(); |
|
167 |
|
168 void strokePrimitives_10_data() { drawPrimitives_data_helper(true); } |
|
169 void strokePrimitives_100_data() { drawPrimitives_data_helper(true); } |
|
170 void strokePrimitives_1000_data() { drawPrimitives_data_helper(true); } |
|
171 void strokePrimitives_10(); |
|
172 void strokePrimitives_100(); |
|
173 void strokePrimitives_1000(); |
|
174 |
|
175 void drawText_data(); |
|
176 void drawText(); |
|
177 |
|
178 void clipAndFill_data(); |
|
179 void clipAndFill(); |
|
180 |
|
181 private: |
|
182 void setupBrushes(); |
|
183 void createPrimitives(); |
|
184 |
|
185 void drawPrimitives_data_helper(bool fancypens); |
|
186 void fillPrimitives_helper(QPainter *painter, PrimitiveType type, PrimitiveSet *s); |
|
187 |
|
188 QPaintDevice *surface() |
|
189 { |
|
190 return new QPixmap(1024, 1024); |
|
191 } |
|
192 |
|
193 |
|
194 QMap<QString, QPen> m_pens; |
|
195 QMap<QString, QBrush> m_brushes; |
|
196 |
|
197 PrimitiveSet m_primitives_10; |
|
198 PrimitiveSet m_primitives_100; |
|
199 PrimitiveSet m_primitives_1000; |
|
200 |
|
201 QPaintDevice *m_surface; |
|
202 QPainter m_painter; |
|
203 |
|
204 }; |
|
205 |
|
206 void tst_QPainter::createPrimitives() |
|
207 { |
|
208 for (int i=0; i<3; ++i) { |
|
209 PrimitiveSet *ps; |
|
210 int size; |
|
211 switch (i) { |
|
212 case 0: |
|
213 ps = &m_primitives_10; |
|
214 size = 10; |
|
215 break; |
|
216 case 1: |
|
217 ps = &m_primitives_100; |
|
218 size = 100; |
|
219 break; |
|
220 case 2: |
|
221 ps = &m_primitives_1000; |
|
222 size = 1000; |
|
223 break; |
|
224 } |
|
225 |
|
226 ps->f_rect = QRectF(0, 0, size, size); |
|
227 ps->f_line_diag = QLineF(0, 0, size, size); |
|
228 ps->f_line_ver = QLineF(10, 0, 10, size); |
|
229 ps->f_line_hor = QLineF(0, 10, size, 10); |
|
230 ps->f_poly_rect = QPolygonF() << QPointF(0, 0) |
|
231 << QPointF(size, 0) |
|
232 << QPointF(size, size) |
|
233 << QPointF(0, size); |
|
234 ps->f_poly_2rects = QPolygonF() << QPointF(0, 0) |
|
235 << QPointF(size * 0.75, 0) |
|
236 << QPointF(size * 0.75, size * 0.75) |
|
237 << QPointF(size * 0.25, size * 0.75) |
|
238 << QPointF(size * 0.25, size * 0.25) |
|
239 << QPointF(size, size * 0.25) |
|
240 << QPointF(size, size) |
|
241 << QPointF(0, size); |
|
242 ps->f_poly_tri = QPolygonF() << QPointF(size / 2.0, 0) |
|
243 << QPointF(0, size) |
|
244 << QPointF(size, size); |
|
245 |
|
246 ps->f_path_tri.addPolygon(ps->f_poly_tri); |
|
247 ps->f_path_rect.addRect(ps->f_rect); |
|
248 ps->f_path_2rects.addPolygon(ps->f_poly_2rects); |
|
249 ps->f_path_ellipse.addEllipse(ps->f_rect); |
|
250 |
|
251 ps->i_rect = ps->f_rect.toRect(); |
|
252 ps->i_line_diag = ps->f_line_diag.toLine(); |
|
253 ps->i_line_hor = ps->f_line_hor.toLine(); |
|
254 ps->i_line_ver = ps->f_line_ver.toLine(); |
|
255 ps->i_poly_tri = ps->f_poly_tri.toPolygon(); |
|
256 ps->i_poly_rect = ps->f_poly_rect.toPolygon(); |
|
257 ps->i_poly_2rects = ps->f_poly_2rects.toPolygon(); |
|
258 } |
|
259 } |
|
260 |
|
261 void tst_QPainter::drawLine_data() |
|
262 { |
|
263 QTest::addColumn<QLine>("line"); |
|
264 QTest::addColumn<QPen>("pen"); |
|
265 |
|
266 QVector<QPen> pens; |
|
267 pens << QPen(Qt::black) |
|
268 << QPen(Qt::black, 0, Qt::DashDotLine) |
|
269 << QPen(Qt::black, 4) |
|
270 << QPen(Qt::black, 4, Qt::DashDotLine) |
|
271 << QPen(QColor(255, 0, 0, 200)) |
|
272 << QPen(QColor(255, 0, 0, 200), 0, Qt::DashDotLine) |
|
273 << QPen(QColor(255, 0, 0, 200), 4) |
|
274 << QPen(QColor(255, 0, 0, 200), 4, Qt::DashDotLine); |
|
275 |
|
276 QStringList penNames; |
|
277 penNames << "black-0" |
|
278 << "black-0-dashdot" |
|
279 << "black-4" |
|
280 << "black-4-dashdot" |
|
281 << "alpha-0" |
|
282 << "alpha-0-dashdot" |
|
283 << "alpha-4" |
|
284 << "alpha-4-dashdot"; |
|
285 |
|
286 int i = 0; |
|
287 foreach (QPen pen, pens) { |
|
288 const QString s = QString(QLatin1String("%1:%2")).arg(penNames[i]); |
|
289 QTest::newRow(qPrintable(s.arg("horizontal"))) |
|
290 << QLine(0, 20, 100, 20) << pen; |
|
291 QTest::newRow(qPrintable(s.arg("vertical:"))) |
|
292 << QLine(20, 0, 20, 100) << pen; |
|
293 QTest::newRow(qPrintable(s.arg("0-45:"))) |
|
294 << QLine(0, 20, 100, 0) << pen; |
|
295 QTest::newRow(qPrintable(s.arg("45-90:"))) |
|
296 << QLine(0, 100, 20, 0) << pen; |
|
297 QTest::newRow(qPrintable(s.arg("90-135:"))) |
|
298 << QLine(20, 100, 0, 0) << pen; |
|
299 QTest::newRow(qPrintable(s.arg("135-180:"))) |
|
300 << QLine(100, 20, 0, 0) << pen; |
|
301 QTest::newRow(qPrintable(s.arg("180-225:"))) |
|
302 << QLine(100, 0, 0, 20) << pen; |
|
303 QTest::newRow(qPrintable(s.arg("225-270:"))) |
|
304 << QLine(20, 0, 0, 100) << pen; |
|
305 QTest::newRow(qPrintable(s.arg("270-315:"))) |
|
306 << QLine(0, 0, 20, 100) << pen; |
|
307 QTest::newRow(qPrintable(s.arg("315-360:"))) |
|
308 << QLine(0, 0, 100, 20) << pen; |
|
309 ++i; |
|
310 } |
|
311 } |
|
312 |
|
313 void tst_QPainter::setupBrushes() |
|
314 { |
|
315 // Solid brushes... |
|
316 m_brushes["black-brush"] = QBrush(Qt::black); |
|
317 m_brushes["white-brush"] = QBrush(Qt::white); |
|
318 m_brushes["transparent-brush"] = QBrush(QColor(255, 255, 255, 0)); |
|
319 m_brushes["alpha1-brush"] = QBrush(QColor(255, 255, 255, 100)); |
|
320 m_brushes["alpha2-brush"] = QBrush(QColor(255, 255, 255, 200)); |
|
321 |
|
322 |
|
323 // Patterns |
|
324 m_brushes["dense1-brush"] = QBrush(Qt::Dense1Pattern); |
|
325 m_brushes["dense2-brush"] = QBrush(Qt::Dense2Pattern); |
|
326 m_brushes["dense3-brush"] = QBrush(Qt::Dense3Pattern); |
|
327 m_brushes["dense4-brush"] = QBrush(Qt::Dense4Pattern); |
|
328 m_brushes["dense5-brush"] = QBrush(Qt::Dense5Pattern); |
|
329 m_brushes["dense6-brush"] = QBrush(Qt::Dense6Pattern); |
|
330 m_brushes["dense7-brush"] = QBrush(Qt::Dense7Pattern); |
|
331 m_brushes["hor-brush"] = QBrush(Qt::HorPattern); |
|
332 m_brushes["ver-brush"] = QBrush(Qt::VerPattern); |
|
333 m_brushes["cross-brush"] = QBrush(Qt::CrossPattern); |
|
334 m_brushes["bdiag-brush"] = QBrush(Qt::BDiagPattern); |
|
335 m_brushes["fdiag-brush"] = QBrush(Qt::FDiagPattern); |
|
336 m_brushes["diagcross-brush"] = QBrush(Qt::DiagCrossPattern); |
|
337 |
|
338 // Gradients |
|
339 QGradientStops gradient_white_black; |
|
340 gradient_white_black << QPair<qreal, QColor>(0, QColor(Qt::white)); |
|
341 gradient_white_black << QPair<qreal, QColor>(1, QColor(Qt::black)); |
|
342 |
|
343 QGradientStops gradient_white_black10; |
|
344 for (int i=0; i<10; ++i) { |
|
345 gradient_white_black10 << QPair<qreal, QColor>(i/10.0, QColor(Qt::white)); |
|
346 gradient_white_black10 << QPair<qreal, QColor>(i/10.0+0.05, QColor(Qt::black)); |
|
347 } |
|
348 |
|
349 QGradientStops gradient_white_alpha; |
|
350 gradient_white_alpha << QPair<qreal, QColor>(0, QColor(Qt::white)); |
|
351 gradient_white_alpha << QPair<qreal, QColor>(0, QColor(Qt::transparent)); |
|
352 |
|
353 QGradientStops gradient_white_alpha10; |
|
354 for (int i=0; i<10; ++i) { |
|
355 gradient_white_alpha10 << QPair<qreal, QColor>(i/10.0, QColor(Qt::white)); |
|
356 gradient_white_alpha10 << QPair<qreal, QColor>(i/10.0+0.05, QColor(Qt::black)); |
|
357 } |
|
358 |
|
359 |
|
360 for (int j=0; j<4; ++j) { |
|
361 QLinearGradient lg; |
|
362 lg.setStart(0, 0); |
|
363 |
|
364 QRadialGradient rg; |
|
365 QConicalGradient cg; |
|
366 |
|
367 QGradientStops stops; |
|
368 if (j == 0) stops = gradient_white_black; |
|
369 else if (j == 1) stops = gradient_white_black10; |
|
370 else if (j == 2) stops = gradient_white_alpha; |
|
371 else if (j == 3) stops = gradient_white_alpha10; |
|
372 lg.setStops(stops); |
|
373 rg.setStops(stops); |
|
374 cg.setStops(stops); |
|
375 |
|
376 for (int i=0; i<6; ++i) { |
|
377 lg.setSpread((QGradient::Spread) (i % 3)); |
|
378 lg.setCoordinateMode((QGradient::CoordinateMode) (j / 3)); |
|
379 |
|
380 QString name = QString::fromLatin1("-%1%2") |
|
381 .arg(lg.spread()) |
|
382 .arg(lg.coordinateMode()); |
|
383 |
|
384 lg.setFinalStop(100, 0); |
|
385 m_brushes["hor-lingrad-w/b-brush" + name] = QBrush(lg); |
|
386 |
|
387 lg.setFinalStop(0, 100); |
|
388 m_brushes["ver-lingrad-w/b-brush" + name] = QBrush(lg); |
|
389 |
|
390 lg.setFinalStop(100, 100); |
|
391 m_brushes["diag-lingrad-w/b-brush" + name] = QBrush(lg); |
|
392 |
|
393 rg.setRadius(100); |
|
394 rg.setCenter(0, 0); |
|
395 rg.setFocalPoint(50, 50); |
|
396 m_brushes["radgrad-brush" + name] = QBrush(rg); |
|
397 |
|
398 cg.setCenter(0, 0); |
|
399 cg.setAngle(40); |
|
400 m_brushes["congrad-brush" + name] = QBrush(cg); |
|
401 } |
|
402 } |
|
403 |
|
404 // Set up pens... |
|
405 |
|
406 |
|
407 // m_pens["black-pen"] = QPen(Qt::black); |
|
408 // m_pens["white-pen"] = QPen(Qt::white); |
|
409 // m_pens["transparent-pen"] = QPen(QColor(255, 255, 255, 0)); |
|
410 // m_pens["translucent1-pen"] = QPen(QColor(255, 255, 255, 100)); |
|
411 // m_pens["translucent2-pen"] = QPen(QColor(255, 255, 255, 200)); |
|
412 |
|
413 |
|
414 |
|
415 } |
|
416 |
|
417 |
|
418 // void QPainter_Primitives::fillRect_data() { |
|
419 |
|
420 // QTest::addColumn<QBrush>("brush"); |
|
421 // QTest::addColumn<QSize>("size"); |
|
422 |
|
423 // for (QMap<QString, QBrush>::const_iterator it = m_brushes.constBegin(); |
|
424 // it != m_brushes.constEnd(); ++it) { |
|
425 // for (int w=2; w<1025; w*=2) { |
|
426 // for (int h=2; h<1025; h*=2) { |
|
427 // QTest::newRow(QString("brush=%1; size=[%2,%3]").arg(it.key()).arg(w).arg(h).toAscii().data()) |
|
428 // << *it << QSize(w, h); |
|
429 // } |
|
430 // } |
|
431 // } |
|
432 // } |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 // void QPainter_Primitives::fillRect() |
|
439 // { |
|
440 // QFETCH(QBrush, brush); |
|
441 // QFETCH(QSize, size); |
|
442 |
|
443 // QImage img(1024, 1024, QImage::Format_ARGB32_Premultiplied); |
|
444 // QPainter p(&img); |
|
445 // p.setPen(Qt::NoPen); |
|
446 // p.setBrush(brush); |
|
447 // QRect rect(QPoint(0, 0), size); |
|
448 // QBENCHMARK { |
|
449 // p.drawRect(rect); |
|
450 // } |
|
451 // } |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 void tst_QPainter::beginAndEnd() |
|
457 { |
|
458 QPixmap pixmap(100, 100); |
|
459 |
|
460 QBENCHMARK { |
|
461 QPainter p; |
|
462 p.begin(&pixmap); |
|
463 p.end(); |
|
464 } |
|
465 } |
|
466 |
|
467 void tst_QPainter::drawLine() |
|
468 { |
|
469 QFETCH(QLine, line); |
|
470 QFETCH(QPen, pen); |
|
471 |
|
472 const int offset = 5; |
|
473 QPixmap pixmapUnclipped(qMin(line.x1(), line.x2()) |
|
474 + 2*offset + qAbs(line.dx()), |
|
475 qMin(line.y1(), line.y2()) |
|
476 + 2*offset + qAbs(line.dy())); |
|
477 pixmapUnclipped.fill(Qt::white); |
|
478 |
|
479 QPainter p(&pixmapUnclipped); |
|
480 p.translate(offset, offset); |
|
481 p.setPen(pen); |
|
482 p.paintEngine()->syncState(); |
|
483 |
|
484 QBENCHMARK { |
|
485 p.drawLine(line); |
|
486 } |
|
487 |
|
488 p.end(); |
|
489 |
|
490 } |
|
491 |
|
492 void tst_QPainter::drawLine_clipped_data() |
|
493 { |
|
494 drawLine_data(); |
|
495 } |
|
496 |
|
497 void tst_QPainter::drawLine_clipped() |
|
498 { |
|
499 QFETCH(QLine, line); |
|
500 QFETCH(QPen, pen); |
|
501 |
|
502 const int offset = 5; |
|
503 QPixmap pixmapClipped(qMin(line.x1(), line.x2()) |
|
504 + 2*offset + qAbs(line.dx()), |
|
505 qMin(line.y1(), line.y2()) |
|
506 + 2*offset + qAbs(line.dy())); |
|
507 |
|
508 const QRect clip = QRect(line.p1(), line.p2()).normalized(); |
|
509 |
|
510 pixmapClipped.fill(Qt::white); |
|
511 QPainter p(&pixmapClipped); |
|
512 p.translate(offset, offset); |
|
513 p.setClipRect(clip); |
|
514 p.setPen(pen); |
|
515 p.paintEngine()->syncState(); |
|
516 |
|
517 QBENCHMARK { |
|
518 p.drawLine(line); |
|
519 } |
|
520 |
|
521 p.end(); |
|
522 } |
|
523 |
|
524 |
|
525 void tst_QPainter::drawLine_antialiased_clipped_data() |
|
526 { |
|
527 drawLine_data(); |
|
528 } |
|
529 |
|
530 |
|
531 void tst_QPainter::drawLine_antialiased_clipped() |
|
532 { |
|
533 QFETCH(QLine, line); |
|
534 QFETCH(QPen, pen); |
|
535 |
|
536 const int offset = 5; |
|
537 QPixmap pixmapClipped(qMin(line.x1(), line.x2()) |
|
538 + 2*offset + qAbs(line.dx()), |
|
539 qMin(line.y1(), line.y2()) |
|
540 + 2*offset + qAbs(line.dy())); |
|
541 |
|
542 const QRect clip = QRect(line.p1(), line.p2()).normalized(); |
|
543 |
|
544 pixmapClipped.fill(Qt::white); |
|
545 QPainter p(&pixmapClipped); |
|
546 p.setRenderHint(QPainter::Antialiasing); |
|
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 void tst_QPainter::drawPixmap_data() |
|
560 { |
|
561 QTest::addColumn<QImage::Format>("sourceFormat"); |
|
562 QTest::addColumn<QImage::Format>("targetFormat"); |
|
563 QTest::addColumn<QSize>("size"); |
|
564 QTest::addColumn<int>("type"); // 0 = circle, 1 = diag line, 2 = solid rect, 3 = alpharect |
|
565 |
|
566 QList<QSize> sizes; |
|
567 sizes << QSize(1, 1) |
|
568 << QSize(10, 10) |
|
569 << QSize(100, 100) |
|
570 << QSize(1000, 1000); |
|
571 |
|
572 const char *typeNames[] = { |
|
573 "circle", |
|
574 "line", |
|
575 "solidrect", |
|
576 "alpharect" |
|
577 }; |
|
578 |
|
579 const char *formatNames[] = { |
|
580 "Invalid", |
|
581 "Mono", |
|
582 "MonoLSB", |
|
583 "Indexed8", |
|
584 "RGB32", |
|
585 "ARGB32", |
|
586 "ARGB32_pm", |
|
587 "RGB16", |
|
588 "ARGB8565_pm", |
|
589 "RGB666", |
|
590 "ARGB6666_pm", |
|
591 "RGB555", |
|
592 "ARGB8555_pm", |
|
593 "RGB888", |
|
594 "RGB444", |
|
595 "ARGB4444_pm" |
|
596 }; |
|
597 |
|
598 for (int tar=4; tar<QImage::NImageFormats; ++tar) { |
|
599 for (int src=4; src<QImage::NImageFormats; ++src) { |
|
600 |
|
601 // skip the low-priority formats to keep resultset manageable... |
|
602 if (tar == QImage::Format_RGB444 || src == QImage::Format_RGB444 |
|
603 || tar == QImage::Format_RGB555 || src == QImage::Format_RGB555 |
|
604 || tar == QImage::Format_RGB666 || src == QImage::Format_RGB666 |
|
605 || tar == QImage::Format_RGB888 || src == QImage::Format_RGB888 |
|
606 || tar == QImage::Format_ARGB4444_Premultiplied |
|
607 || src == QImage::Format_ARGB4444_Premultiplied |
|
608 || tar == QImage::Format_ARGB6666_Premultiplied |
|
609 || src == QImage::Format_ARGB6666_Premultiplied) |
|
610 continue; |
|
611 |
|
612 foreach (const QSize &s, sizes) { |
|
613 for (int type=0; type<=3; ++type) { |
|
614 QString name = QString::fromLatin1("%1 on %2, (%3x%4), %5") |
|
615 .arg(formatNames[src]) |
|
616 .arg(formatNames[tar]) |
|
617 .arg(s.width()).arg(s.height()) |
|
618 .arg(typeNames[type]); |
|
619 QTest::newRow(name.toLatin1()) << (QImage::Format) src |
|
620 << (QImage::Format) tar |
|
621 << s |
|
622 << type; |
|
623 } |
|
624 } |
|
625 } |
|
626 } |
|
627 } |
|
628 |
|
629 static QImage createImage(int type, const QSize &size) { |
|
630 QImage base(size, QImage::Format_ARGB32_Premultiplied); |
|
631 base.fill(0); |
|
632 QPainter p(&base); |
|
633 p.setRenderHint(QPainter::Antialiasing); |
|
634 switch (type) { |
|
635 case 0: // ellipse |
|
636 p.setBrush(Qt::red); |
|
637 p.drawEllipse(0, 0, size.width(), size.height()); |
|
638 break; |
|
639 case 1: // line |
|
640 p.drawLine(0, 0, size.width(), size.height()); |
|
641 break; |
|
642 case 2: |
|
643 p.fillRect(0, 0, size.width(), size.height(), Qt::red); |
|
644 break; |
|
645 case 3: |
|
646 p.fillRect(0, 0, size.width(), size.height(), QColor(0, 255, 0, 127)); |
|
647 break; |
|
648 } |
|
649 p.end(); |
|
650 return base; |
|
651 } |
|
652 |
|
653 |
|
654 void tst_QPainter::drawPixmap() |
|
655 { |
|
656 QFETCH(QImage::Format, sourceFormat); |
|
657 QFETCH(QImage::Format, targetFormat); |
|
658 QFETCH(QSize, size); |
|
659 QFETCH(int, type); |
|
660 |
|
661 QImage sourceImage = createImage(type, size).convertToFormat(sourceFormat); |
|
662 QImage targetImage(size, targetFormat); |
|
663 |
|
664 QPixmap sourcePixmap = QPixmap::fromImage(sourceImage); |
|
665 QPixmap targetPixmap = QPixmap::fromImage(targetImage); |
|
666 |
|
667 QPainter p(&targetPixmap); |
|
668 |
|
669 QBENCHMARK { |
|
670 p.drawPixmap(0, 0, sourcePixmap); |
|
671 } |
|
672 } |
|
673 |
|
674 void tst_QPainter::drawImage_data() |
|
675 { |
|
676 drawPixmap_data(); |
|
677 } |
|
678 |
|
679 |
|
680 void tst_QPainter::drawImage() |
|
681 { |
|
682 QFETCH(QImage::Format, sourceFormat); |
|
683 QFETCH(QImage::Format, targetFormat); |
|
684 QFETCH(QSize, size); |
|
685 QFETCH(int, type); |
|
686 |
|
687 QImage sourceImage = createImage(type, size).convertToFormat(sourceFormat); |
|
688 QImage targetImage(size, targetFormat); |
|
689 |
|
690 QPainter p(&targetImage); |
|
691 QBENCHMARK { |
|
692 p.drawImage(0, 0, sourceImage); |
|
693 } |
|
694 } |
|
695 |
|
696 |
|
697 void tst_QPainter::compositionModes_data() |
|
698 { |
|
699 QTest::addColumn<QPainter::CompositionMode>("mode"); |
|
700 QTest::addColumn<QSize>("size"); |
|
701 QTest::addColumn<QColor>("color"); |
|
702 |
|
703 const int n = QPainter::RasterOp_SourceAndNotDestination; |
|
704 for (int i = 0; i <= n; ++i) { |
|
705 QString title("%1:%2"); |
|
706 QTest::newRow(qPrintable(title.arg(i).arg("10x10:opaque"))) |
|
707 << (QPainter::CompositionMode)(i) |
|
708 << QSize(10, 10) << QColor(255, 0, 0); |
|
709 QTest::newRow(qPrintable(title.arg(i).arg("10x10:!opaque"))) |
|
710 << (QPainter::CompositionMode)(i) |
|
711 << QSize(10, 10) << QColor(127, 127, 127, 127); |
|
712 QTest::newRow(qPrintable(title.arg(i).arg("300x300:opaque"))) |
|
713 << (QPainter::CompositionMode)(i) |
|
714 << QSize(300, 300) << QColor(255, 0, 0); |
|
715 QTest::newRow(qPrintable(title.arg(i).arg("300x300:!opaque"))) |
|
716 << (QPainter::CompositionMode)(i) |
|
717 << QSize(300, 300) << QColor(127, 127, 127, 127); |
|
718 } |
|
719 } |
|
720 |
|
721 void tst_QPainter::compositionModes() |
|
722 { |
|
723 QFETCH(QPainter::CompositionMode, mode); |
|
724 QFETCH(QSize, size); |
|
725 QFETCH(QColor, color); |
|
726 |
|
727 QPixmap src(size); |
|
728 src.fill(color); |
|
729 |
|
730 QPixmap dest(size); |
|
731 if (mode < QPainter::RasterOp_SourceOrDestination) |
|
732 color.setAlpha(127); // porter-duff needs an alpha channel |
|
733 dest.fill(color); |
|
734 |
|
735 QPainter p(&dest); |
|
736 p.setCompositionMode(mode); |
|
737 |
|
738 QBENCHMARK { |
|
739 p.drawPixmap(0, 0, src); |
|
740 } |
|
741 } |
|
742 |
|
743 void tst_QPainter::drawTiledPixmap_data() |
|
744 { |
|
745 QTest::addColumn<QSize>("srcSize"); |
|
746 QTest::addColumn<QSize>("dstSize"); |
|
747 QTest::addColumn<QTransform>("transform"); |
|
748 QTest::addColumn<QColor>("color"); |
|
749 QTest::addColumn<QPainter::RenderHint>("renderHint"); |
|
750 |
|
751 QTest::newRow("10x10=>20x20") |
|
752 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
753 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
754 QTest::newRow("10x10=>20x20, smooth") |
|
755 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
756 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
757 QTest::newRow("10x10=>20x20, !opaque") |
|
758 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
759 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
760 QTest::newRow("10x10=>20x20, !opaque, smooth") |
|
761 << QSize(10, 10) << QSize(20, 20) << (QTransform()) |
|
762 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
763 |
|
764 QTest::newRow("10x10=>20x20, rotate(30)") |
|
765 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
766 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
767 QTest::newRow("10x10=>20x20, rotate(30), smooth") |
|
768 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
769 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
770 QTest::newRow("10x10=>20x20, rotate(30), !opaque") |
|
771 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
772 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
773 QTest::newRow("10x10=>20x20, rotate(30), !opaque, smooth") |
|
774 << QSize(10, 10) << QSize(20, 20) << (QTransform().rotate(30)) |
|
775 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
776 |
|
777 QTest::newRow("100x100=>200x200") |
|
778 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
779 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
780 QTest::newRow("100x100=>200x200, smooth") |
|
781 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
782 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
783 QTest::newRow("100x100=>200x200, !opaque") |
|
784 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
785 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
786 QTest::newRow("100x100=>200x200, !opaque, smooth") |
|
787 << QSize(100, 100) << QSize(200, 200) << (QTransform()) |
|
788 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
789 |
|
790 QTest::newRow("100x100=>200x200, rotate(30)") |
|
791 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
792 << QColor(Qt::black) << QPainter::RenderHint(0); |
|
793 QTest::newRow("100x100=>200x200, rotate(30), smooth") |
|
794 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
795 << QColor(Qt::black) << QPainter::SmoothPixmapTransform; |
|
796 QTest::newRow("100x100=>200x200, rotate(30), !opaque") |
|
797 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
798 << QColor(127, 127, 127, 127) << QPainter::RenderHint(0); |
|
799 QTest::newRow("100x100=>200x200, rotate(30), !opaque, smooth") |
|
800 << QSize(100, 100) << QSize(200, 200) << (QTransform().rotate(30)) |
|
801 << QColor(127, 127, 127, 127) << QPainter::SmoothPixmapTransform; |
|
802 } |
|
803 |
|
804 void tst_QPainter::drawTiledPixmap() |
|
805 { |
|
806 QFETCH(QSize, srcSize); |
|
807 QFETCH(QSize, dstSize); |
|
808 QFETCH(QTransform, transform); |
|
809 QFETCH(QColor, color); |
|
810 QFETCH(QPainter::RenderHint, renderHint); |
|
811 |
|
812 QPixmap src(srcSize); |
|
813 src.fill(color); |
|
814 |
|
815 const QRect dstRect = transform.mapRect(QRect(QPoint(), dstSize)); |
|
816 QPixmap dst(dstRect.right() + 5, dstRect.bottom() + 5); |
|
817 QPainter p(&dst); |
|
818 p.setTransform(transform); |
|
819 p.setRenderHint(renderHint); |
|
820 |
|
821 QBENCHMARK { |
|
822 p.drawTiledPixmap(QRect(QPoint(), dstSize), src); |
|
823 } |
|
824 } |
|
825 |
|
826 void tst_QPainter::fillPrimitives_helper(QPainter *p, PrimitiveType type, PrimitiveSet *s) |
|
827 { |
|
828 p->paintEngine()->syncState(); |
|
829 |
|
830 switch (type) { |
|
831 case Primitive_Int_DiagLine: QBENCHMARK { p->drawLine(s->i_line_diag); } break; |
|
832 case Primitive_Int_VerLine: QBENCHMARK { p->drawLine(s->i_line_ver); } break; |
|
833 case Primitive_Int_HorLine: QBENCHMARK { p->drawLine(s->i_line_hor); } break; |
|
834 case Primitive_Int_Rect: QBENCHMARK { p->drawRect(s->i_rect); } break; |
|
835 case Primitive_Int_Ellipse: QBENCHMARK { p->drawEllipse(s->i_rect); } break; |
|
836 case Primitive_Int_Pie: QBENCHMARK { p->drawPie(s->i_rect, 45*16, 270*16); } break; |
|
837 case Primitive_Int_Arc: QBENCHMARK { p->drawArc(s->i_rect, 45*16, 270*16); } break; |
|
838 case Primitive_Int_Chord: QBENCHMARK { p->drawChord(s->i_rect, 45*16, 270*16); } break; |
|
839 case Primitive_Int_TriPoly: QBENCHMARK { p->drawPolygon(s->i_poly_tri); } break; |
|
840 case Primitive_Int_RectPoly: QBENCHMARK { p->drawPolygon(s->i_poly_rect); } break; |
|
841 case Primitive_Int_2RectPoly: QBENCHMARK { p->drawPolygon(s->i_poly_2rects); } break; |
|
842 |
|
843 case Primitive_Float_DiagLine: QBENCHMARK { p->drawLine(s->f_line_diag); } break; |
|
844 case Primitive_Float_VerLine: QBENCHMARK { p->drawLine(s->f_line_ver); } break; |
|
845 case Primitive_Float_HorLine: QBENCHMARK { p->drawLine(s->f_line_hor); } break; |
|
846 case Primitive_Float_Rect: QBENCHMARK { p->drawRect(s->f_rect); } break; |
|
847 case Primitive_Float_Ellipse: QBENCHMARK { p->drawEllipse(s->f_rect); } break; |
|
848 case Primitive_Float_Pie: QBENCHMARK { p->drawPie(s->f_rect, 45*16, 270*16); } break; |
|
849 case Primitive_Float_Arc: QBENCHMARK { p->drawArc(s->f_rect, 45*16, 270*16); } break; |
|
850 case Primitive_Float_Chord: QBENCHMARK { p->drawChord(s->f_rect, 45*16, 270*16); } break; |
|
851 case Primitive_Float_TriPoly: QBENCHMARK { p->drawPolygon(s->f_poly_tri); } break; |
|
852 case Primitive_Float_RectPoly: QBENCHMARK { p->drawPolygon(s->f_poly_rect); } break; |
|
853 case Primitive_Float_2RectPoly: QBENCHMARK { p->drawPolygon(s->f_poly_2rects); } break; |
|
854 |
|
855 case Primitive_Float_TriPath: QBENCHMARK { p->drawPath(s->f_path_tri); } break; |
|
856 case Primitive_Float_RectPath: QBENCHMARK { p->drawPath(s->f_path_rect); } break; |
|
857 case Primitive_Float_2RectPath: QBENCHMARK { p->drawPath(s->f_path_2rects); } break; |
|
858 case Primitive_Float_EllipsePath: QBENCHMARK { p->drawPath(s->f_path_ellipse); } break; |
|
859 } |
|
860 } |
|
861 |
|
862 void tst_QPainter::drawPrimitives_data_helper(bool fancypens) |
|
863 { |
|
864 QTest::addColumn<int>("type"); |
|
865 QTest::addColumn<bool>("aa"); |
|
866 QTest::addColumn<bool>("dash"); |
|
867 QTest::addColumn<int>("width"); |
|
868 |
|
869 const char * const names[] = { |
|
870 "IDLine", |
|
871 "IVLine", |
|
872 "IHLine", |
|
873 "IRect", |
|
874 "IElli", |
|
875 "IPie", |
|
876 "IArc", |
|
877 "IChord", |
|
878 "ITriPol", |
|
879 "IRectPol", |
|
880 "I2RectPol", |
|
881 "FDLine", |
|
882 "FVLine", |
|
883 "FHLine", |
|
884 "FRect", |
|
885 "FElli", |
|
886 "FPie", |
|
887 "FArc", |
|
888 "FChord", |
|
889 "FTriPol", |
|
890 "FRectPol", |
|
891 "F2RectPol", |
|
892 "FTriPa", |
|
893 "FRectPa", |
|
894 "F2RectPa", |
|
895 "FElliPa" |
|
896 }; |
|
897 |
|
898 if (fancypens) { |
|
899 for (int dash=0; dash<2; ++dash) { |
|
900 for (int width=0; width<=4; width+=4) { |
|
901 for (int aa=0; aa<2; ++aa) { |
|
902 for (int type=0; type<Primitive_Last_Primitive; ++type) { |
|
903 QString name = QString::fromLatin1(names[type]); |
|
904 |
|
905 if (aa) name += " aa"; |
|
906 if (dash) name += " dotted"; |
|
907 if (width) name += QString::fromLatin1(" width=%1").arg(width); |
|
908 |
|
909 QTest::newRow(name.toLatin1()) << type << (bool) aa << (bool) dash << width; |
|
910 } |
|
911 } |
|
912 } |
|
913 } |
|
914 } else { |
|
915 for (int aa=0; aa<2; ++aa) { |
|
916 for (int type=0; type<Primitive_Last_Primitive; ++type) { |
|
917 QString name = QString::fromLatin1(names[type]); |
|
918 if (aa) name += " aa"; |
|
919 QTest::newRow(name.toLatin1()) << type << (bool) aa; |
|
920 } |
|
921 } |
|
922 } |
|
923 } |
|
924 |
|
925 |
|
926 void tst_QPainter::fillPrimitives_10() |
|
927 { |
|
928 QFETCH(int, type); |
|
929 QFETCH(bool, aa); |
|
930 QPainter p(m_surface); |
|
931 p.setPen(Qt::NoPen); |
|
932 p.setBrush(Qt::red); |
|
933 p.setRenderHint(QPainter::Antialiasing, aa); |
|
934 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_10); |
|
935 } |
|
936 |
|
937 |
|
938 void tst_QPainter::fillPrimitives_100() |
|
939 { |
|
940 QFETCH(int, type); |
|
941 QFETCH(bool, aa); |
|
942 QPainter p(m_surface); |
|
943 p.setPen(Qt::NoPen); |
|
944 p.setBrush(Qt::red); |
|
945 p.setRenderHint(QPainter::Antialiasing, aa); |
|
946 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_100); |
|
947 } |
|
948 |
|
949 |
|
950 void tst_QPainter::fillPrimitives_1000() |
|
951 { |
|
952 QFETCH(int, type); |
|
953 QFETCH(bool, aa); |
|
954 QPainter p(m_surface); |
|
955 p.setPen(Qt::NoPen); |
|
956 p.setBrush(Qt::red); |
|
957 p.setRenderHint(QPainter::Antialiasing, aa); |
|
958 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_1000); |
|
959 } |
|
960 |
|
961 void tst_QPainter::strokePrimitives_10() |
|
962 { |
|
963 QFETCH(int, type); |
|
964 QFETCH(bool, aa); |
|
965 QFETCH(bool, dash); |
|
966 QFETCH(int, width); |
|
967 QPainter p(m_surface); |
|
968 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
969 p.setBrush(Qt::NoBrush); |
|
970 p.setRenderHint(QPainter::Antialiasing, aa); |
|
971 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_10); |
|
972 } |
|
973 |
|
974 void tst_QPainter::strokePrimitives_100() |
|
975 { |
|
976 QFETCH(int, type); |
|
977 QFETCH(bool, aa); |
|
978 QFETCH(bool, dash); |
|
979 QFETCH(int, width); |
|
980 QPainter p(m_surface); |
|
981 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
982 p.setBrush(Qt::NoBrush); |
|
983 p.setRenderHint(QPainter::Antialiasing, aa); |
|
984 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_100); |
|
985 } |
|
986 |
|
987 void tst_QPainter::strokePrimitives_1000() |
|
988 { |
|
989 QFETCH(int, type); |
|
990 QFETCH(bool, aa); |
|
991 QFETCH(bool, dash); |
|
992 QFETCH(int, width); |
|
993 QPainter p(m_surface); |
|
994 p.setPen(QPen(Qt::red, width, dash ? Qt::DashLine : Qt::SolidLine)); |
|
995 p.setBrush(Qt::NoBrush); |
|
996 p.setRenderHint(QPainter::Antialiasing, aa); |
|
997 fillPrimitives_helper(&p, (PrimitiveType) type, &m_primitives_1000); |
|
998 } |
|
999 |
|
1000 void tst_QPainter::drawText_data() |
|
1001 { |
|
1002 QTest::addColumn<QString>("text"); |
|
1003 |
|
1004 QTest::newRow("a") << QString::fromLatin1("a"); |
|
1005 QTest::newRow("ab") << QString::fromLatin1("ab"); |
|
1006 QTest::newRow("abc") << QString::fromLatin1("abc"); |
|
1007 QTest::newRow("abcd") << QString::fromLatin1("abcd"); |
|
1008 QTest::newRow("abcde") << QString::fromLatin1("abcde"); |
|
1009 QTest::newRow("abcdef") << QString::fromLatin1("abcdef"); |
|
1010 QTest::newRow("abcdefg") << QString::fromLatin1("abcdefg"); |
|
1011 } |
|
1012 |
|
1013 void tst_QPainter::drawText() |
|
1014 { |
|
1015 QFETCH(QString, text); |
|
1016 |
|
1017 QPainter p(m_surface); |
|
1018 |
|
1019 QBENCHMARK { |
|
1020 p.drawText(QPointF(5, 5), text); |
|
1021 } |
|
1022 } |
|
1023 |
|
1024 void tst_QPainter::saveRestore_data() |
|
1025 { |
|
1026 QTest::addColumn<int>("change"); |
|
1027 |
|
1028 for (int i=0; i<16; ++i) { |
|
1029 QString change = "change="; |
|
1030 if (i == 0) change += " none"; |
|
1031 if (i & ChangePen) change += " pen"; |
|
1032 if (i & ChangeBrush) change += " brush"; |
|
1033 if (i & ChangeClip) change += " clip"; |
|
1034 if (i & ChangeTransform) change += " xform"; |
|
1035 |
|
1036 QTest::newRow(change.toLatin1()) << i; |
|
1037 } |
|
1038 } |
|
1039 |
|
1040 void tst_QPainter::saveRestore() |
|
1041 { |
|
1042 QFETCH(int, change); |
|
1043 |
|
1044 QPen pen(Qt::blue); |
|
1045 QBrush brush(Qt::green); |
|
1046 QRect r(100, 100, 100, 20); |
|
1047 |
|
1048 QPainter p(m_surface); |
|
1049 |
|
1050 p.setPen(Qt::NoPen); |
|
1051 p.setBrush(Qt::NoBrush); |
|
1052 |
|
1053 QBENCHMARK { |
|
1054 p.save(); |
|
1055 if (change & ChangePen) { p.setPen(pen); p.setPen(Qt::NoPen); } |
|
1056 if (change & ChangeBrush) { p.setBrush(brush); p.setBrush(Qt::NoBrush); } |
|
1057 if (change & ChangeClip) p.setClipRect(r); |
|
1058 if (change & ChangeTransform) { p.scale(3, 5); p.scale(1/3.0, 1/5.0); } |
|
1059 p.drawRect(0, 0, 1, 1); |
|
1060 p.restore(); |
|
1061 }; |
|
1062 } |
|
1063 |
|
1064 enum ClipType { |
|
1065 RectClipType, |
|
1066 RectPathClipType, |
|
1067 RectRegionClipType, |
|
1068 RegionClipType, |
|
1069 PathClipType |
|
1070 }; |
|
1071 |
|
1072 void tst_QPainter::clipAndFill_data() |
|
1073 { |
|
1074 QTest::addColumn<int>("type"); |
|
1075 |
|
1076 QTest::newRow("rect") << (int) RectClipType; |
|
1077 QTest::newRow("rectpath") << (int) RectPathClipType; |
|
1078 QTest::newRow("rectregion") << (int) RectRegionClipType; |
|
1079 QTest::newRow("ellipseRegion") << (int) RegionClipType; |
|
1080 QTest::newRow("ellipsePath") << (int) PathClipType; |
|
1081 } |
|
1082 |
|
1083 |
|
1084 void tst_QPainter::clipAndFill() |
|
1085 { |
|
1086 QFETCH(int, type); |
|
1087 |
|
1088 QRegion region; |
|
1089 QPainterPath path; |
|
1090 QRectF rect; |
|
1091 |
|
1092 switch (type) { |
|
1093 case RectClipType: |
|
1094 rect = QRectF(100, 100, 100, 100); |
|
1095 break; |
|
1096 case RectPathClipType: |
|
1097 path.addRect(100, 100, 100, 100); |
|
1098 break; |
|
1099 case RectRegionClipType: |
|
1100 region = QRegion(100, 100, 100, 100); |
|
1101 break; |
|
1102 case RegionClipType: |
|
1103 region = QRegion(100, 100, 100, 100, QRegion::Ellipse); |
|
1104 break; |
|
1105 case PathClipType: |
|
1106 path.addEllipse(100, 100, 100, 100); |
|
1107 break; |
|
1108 } |
|
1109 |
|
1110 QPainter p(m_surface); |
|
1111 |
|
1112 p.setPen(Qt::NoPen); |
|
1113 p.setBrush(Qt::red); |
|
1114 |
|
1115 QBENCHMARK { |
|
1116 if (type == RectClipType) |
|
1117 p.setClipRect(rect); |
|
1118 else if (type == RectPathClipType || type == PathClipType) |
|
1119 p.setClipPath(path); |
|
1120 else |
|
1121 p.setClipRegion(region); |
|
1122 p.drawRect(110, 110, 10, 10); |
|
1123 } |
|
1124 } |
|
1125 |
|
1126 |
|
1127 |
|
1128 QTEST_MAIN(tst_QPainter) |
|
1129 |
|
1130 #include "tst_qpainter.moc" |