1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
* Copyright 2012 Intel Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkGradientShader.h"
#include "SkMatrix.h"
#include "SkRandom.h"
#include "SkTArray.h"
namespace skiagm {
class CircleGM : public GM {
public:
CircleGM() {
this->setBGColor(0xFF000000);
this->makePaints();
this->makeMatrices();
}
protected:
SkString onShortName() override {
return SkString("circles");
}
SkISize onISize() override {
return SkISize::Make(1200, 900);
}
void makePaints() {
{
// no AA
SkPaint p;
fPaints.push_back(p);
}
{
// AA
SkPaint p;
p.setAntiAlias(true);
fPaints.push_back(p);
}
{
// AA with mask filter
SkPaint p;
p.setAntiAlias(true);
SkMaskFilter* mf = SkBlurMaskFilter::Create(
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkBlurMaskFilter::kHighQuality_BlurFlag);
p.setMaskFilter(mf)->unref();
fPaints.push_back(p);
}
{
// AA with radial shader
SkPaint p;
p.setAntiAlias(true);
SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
SkShader* s = SkGradientShader::CreateRadial(center,
SkIntToScalar(20),
colors,
pos,
SK_ARRAY_COUNT(colors),
SkShader::kClamp_TileMode);
p.setShader(s)->unref();
fPaints.push_back(p);
}
{
// AA with blur
SkPaint p;
p.setAntiAlias(true);
SkDrawLooper* shadowLooper =
SkBlurDrawLooper::Create(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag);
SkAutoUnref aurL0(shadowLooper);
p.setLooper(shadowLooper);
fPaints.push_back(p);
}
{
// AA with stroke style
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SkIntToScalar(3));
fPaints.push_back(p);
}
{
// AA with stroke style, width = 0
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
fPaints.push_back(p);
}
{
// AA with stroke and fill style
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStrokeAndFill_Style);
p.setStrokeWidth(SkIntToScalar(2));
fPaints.push_back(p);
}
}
void makeMatrices() {
{
SkMatrix m;
m.setScale(SkIntToScalar(2), SkIntToScalar(3));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setScale(SkIntToScalar(2), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setSkew(SkIntToScalar(2), SkIntToScalar(3));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setSkew(SkIntToScalar(2), SkIntToScalar(2));
fMatrices.push_back(m);
}
{
SkMatrix m;
m.setRotate(SkIntToScalar(30));
fMatrices.push_back(m);
}
}
void onDraw(SkCanvas* canvas) override {
// Draw a giant AA circle as the background.
SkISize size = this->getISize();
SkScalar giantRadius = SkTMin(SkIntToScalar(size.fWidth),
SkIntToScalar(size.fHeight)) / 2.f;
SkPoint giantCenter = SkPoint::Make(SkIntToScalar(size.fWidth/2),
SkIntToScalar(size.fHeight/2));
SkPaint giantPaint;
giantPaint.setAntiAlias(true);
giantPaint.setColor(0x80808080);
canvas->drawCircle(giantCenter.fX, giantCenter.fY, giantRadius, giantPaint);
SkRandom rand;
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
int i;
for (i = 0; i < fPaints.count(); ++i) {
canvas->save();
// position the path, and make it at off-integer coords.
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
SkColor color = rand.nextU();
color |= 0xff000000;
fPaints[i].setColor(color);
canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
SkIntToScalar(20),
fPaints[i]);
canvas->restore();
}
for (int j = 0; j < fMatrices.count(); ++j, ++i) {
canvas->save();
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
canvas->concat(fMatrices[j]);
SkPaint paint;
paint.setAntiAlias(true);
SkColor color = rand.nextU();
color |= 0xff000000;
paint.setColor(color);
canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
SkIntToScalar(20),
paint);
canvas->restore();
}
}
private:
typedef GM INHERITED;
SkTArray<SkPaint> fPaints;
SkTArray<SkMatrix> fMatrices;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new CircleGM; }
static GMRegistry reg(MyFactory);
}
|