author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the 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 |
#include <QtGui> |
|
42 |
#include <QString> |
|
43 |
||
44 |
#include <qtest.h> |
|
45 |
||
46 |
void paint(QPaintDevice *device) |
|
47 |
{ |
|
48 |
QPainter p(device); |
|
49 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
50 |
p.fillRect(0, 0, device->width(), device->height(), Qt::transparent); |
|
51 |
||
52 |
QLinearGradient g(QPoint(0, 0), QPoint(1, 1)); |
|
53 |
// g.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 |
g.setColorAt(0, Qt::magenta); |
|
55 |
g.setColorAt(0, Qt::white); |
|
56 |
||
57 |
// p.setOpacity(0.8); |
|
58 |
p.setPen(Qt::NoPen); |
|
59 |
p.setBrush(g); |
|
60 |
p.setRenderHint(QPainter::Antialiasing); |
|
61 |
p.setOpacity(0.9); |
|
62 |
p.drawEllipse(0, 0, device->width(), device->height()); |
|
63 |
} |
|
64 |
||
65 |
QLatin1String compositionModes[] = { |
|
66 |
QLatin1String("SourceOver"), |
|
67 |
QLatin1String("DestinationOver"), |
|
68 |
QLatin1String("Clear"), |
|
69 |
QLatin1String("Source"), |
|
70 |
QLatin1String("Destination"), |
|
71 |
QLatin1String("SourceIn"), |
|
72 |
QLatin1String("DestinationIn"), |
|
73 |
QLatin1String("SourceOut"), |
|
74 |
QLatin1String("DestinationOut"), |
|
75 |
QLatin1String("SourceAtop"), |
|
76 |
QLatin1String("DestinationAtop"), |
|
77 |
QLatin1String("Xor"), |
|
78 |
||
79 |
//svg 1.2 blend modes |
|
80 |
QLatin1String("Plus"), |
|
81 |
QLatin1String("Multiply"), |
|
82 |
QLatin1String("Screen"), |
|
83 |
QLatin1String("Overlay"), |
|
84 |
QLatin1String("Darken"), |
|
85 |
QLatin1String("Lighten"), |
|
86 |
QLatin1String("ColorDodge"), |
|
87 |
QLatin1String("ColorBurn"), |
|
88 |
QLatin1String("HardLight"), |
|
89 |
QLatin1String("SoftLight"), |
|
90 |
QLatin1String("Difference"), |
|
91 |
QLatin1String("Exclusion") |
|
92 |
}; |
|
93 |
||
94 |
enum BrushType { ImageBrush, SolidBrush }; |
|
95 |
QLatin1String brushTypes[] = { |
|
96 |
QLatin1String("ImageBrush"), |
|
97 |
QLatin1String("SolidBrush"), |
|
98 |
}; |
|
99 |
||
100 |
class BlendBench : public QObject |
|
101 |
{ |
|
102 |
Q_OBJECT |
|
103 |
private slots: |
|
104 |
void blendBench_data(); |
|
105 |
void blendBench(); |
|
106 |
}; |
|
107 |
||
108 |
void BlendBench::blendBench_data() |
|
109 |
{ |
|
110 |
int first = 0; |
|
111 |
int limit = 12; |
|
112 |
if (qApp->arguments().contains("--extended")) { |
|
113 |
first = 12; |
|
114 |
limit = 24; |
|
115 |
} |
|
116 |
||
117 |
QTest::addColumn<int>("brushType"); |
|
118 |
QTest::addColumn<int>("compositionMode"); |
|
119 |
||
120 |
for (int brush = ImageBrush; brush <= SolidBrush; ++brush) |
|
121 |
for (int mode = first; mode < limit; ++mode) |
|
122 |
QTest::newRow(QString("brush=%1; mode=%2") |
|
123 |
.arg(brushTypes[brush]).arg(compositionModes[mode]).toAscii().data()) |
|
124 |
<< brush << mode; |
|
125 |
} |
|
126 |
||
127 |
void BlendBench::blendBench() |
|
128 |
{ |
|
129 |
QFETCH(int, brushType); |
|
130 |
QFETCH(int, compositionMode); |
|
131 |
||
132 |
QImage img(512, 512, QImage::Format_ARGB32_Premultiplied); |
|
133 |
QImage src(512, 512, QImage::Format_ARGB32_Premultiplied); |
|
134 |
paint(&src); |
|
135 |
QPainter p(&img); |
|
136 |
p.setPen(Qt::NoPen); |
|
137 |
||
138 |
p.setCompositionMode(QPainter::CompositionMode(compositionMode)); |
|
139 |
if (brushType == ImageBrush) { |
|
140 |
p.setBrush(QBrush(src)); |
|
141 |
} else if (brushType == SolidBrush) { |
|
142 |
p.setBrush(QColor(127, 127, 127, 127)); |
|
143 |
} |
|
144 |
||
145 |
QBENCHMARK { |
|
146 |
p.drawRect(0, 0, 512, 512); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
QTEST_MAIN(BlendBench) |
|
151 |
||
152 |
#include "main.moc" |