OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
9 #include "SkMaskFilter.h" | 9 #include "SkMaskFilter.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 SkShader::kClamp_TileMode)); | 32 SkShader::kClamp_TileMode)); |
33 canvas.drawPaint(paint); | 33 canvas.drawPaint(paint); |
34 } | 34 } |
35 | 35 |
36 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, | 36 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, |
37 SkShader::TileMode tmx, SkShader::TileMode tmy) { | 37 SkShader::TileMode tmx, SkShader::TileMode tmy) { |
38 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy)); | 38 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy)); |
39 paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQualit
y); | 39 paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQualit
y); |
40 } | 40 } |
41 | 41 |
42 static const SkColorType gColorTypes[] = { | 42 constexpr SkColorType gColorTypes[] = { |
43 kN32_SkColorType, | 43 kN32_SkColorType, |
44 kRGB_565_SkColorType, | 44 kRGB_565_SkColorType, |
45 }; | 45 }; |
46 | 46 |
47 class TilingGM : public skiagm::GM { | 47 class TilingGM : public skiagm::GM { |
48 public: | 48 public: |
49 TilingGM(bool powerOfTwoSize) | 49 TilingGM(bool powerOfTwoSize) |
50 : fPowerOfTwoSize(powerOfTwoSize) { | 50 : fPowerOfTwoSize(powerOfTwoSize) { |
51 } | 51 } |
52 | 52 |
(...skipping 22 matching lines...) Expand all Loading... |
75 makebm(&fTexture[i], gColorTypes[i], size, size); | 75 makebm(&fTexture[i], gColorTypes[i], size, size); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void onDraw(SkCanvas* canvas) override { | 79 void onDraw(SkCanvas* canvas) override { |
80 | 80 |
81 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; | 81 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; |
82 | 82 |
83 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; | 83 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; |
84 | 84 |
85 static const char* gConfigNames[] = { "8888", "565", "4444" }; | 85 const char* gConfigNames[] = { "8888", "565", "4444" }; |
86 | 86 |
87 static const bool gFilters[] = { false, true }; | 87 constexpr bool gFilters[] = { false, true }; |
88 static const char* gFilterNames[] = { "point",
"bilinear" }; | 88 static const char* gFilterNames[] = { "point", "bilinear" }; |
89 | 89 |
90 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode,
SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; | 90 constexpr SkShader::TileMode gModes[] = { |
91 static const char* gModeNames[] = { "C",
"R", "M" }; | 91 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode }; |
| 92 static const char* gModeNames[] = { "C", "R", "M" }; |
92 | 93 |
93 SkScalar y = SkIntToScalar(24); | 94 SkScalar y = SkIntToScalar(24); |
94 SkScalar x = SkIntToScalar(10); | 95 SkScalar x = SkIntToScalar(10); |
95 | 96 |
96 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 97 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
97 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 98 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
98 SkPaint p; | 99 SkPaint p; |
99 SkString str; | 100 SkString str; |
100 p.setAntiAlias(true); | 101 p.setAntiAlias(true); |
101 sk_tool_utils::set_portable_typeface(&p); | 102 sk_tool_utils::set_portable_typeface(&p); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 y += r.height() * 4 / 3; | 147 y += r.height() * 4 / 3; |
147 } | 148 } |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 private: | 152 private: |
152 bool fPowerOfTwoSize; | 153 bool fPowerOfTwoSize; |
153 typedef skiagm::GM INHERITED; | 154 typedef skiagm::GM INHERITED; |
154 }; | 155 }; |
155 | 156 |
156 static const int gWidth = 32; | 157 constexpr int gWidth = 32; |
157 static const int gHeight = 32; | 158 constexpr int gHeight = 32; |
158 | 159 |
159 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 160 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
160 SkBitmap bm; | 161 SkBitmap bm; |
161 makebm(&bm, kN32_SkColorType, gWidth, gHeight); | 162 makebm(&bm, kN32_SkColorType, gWidth, gHeight); |
162 return SkShader::MakeBitmapShader(bm, tx, ty); | 163 return SkShader::MakeBitmapShader(bm, tx, ty); |
163 } | 164 } |
164 | 165 |
165 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 166 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
166 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 167 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
167 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 168 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
(...skipping 30 matching lines...) Expand all Loading... |
198 | 199 |
199 SkISize onISize() override { return SkISize::Make(650, 610); } | 200 SkISize onISize() override { return SkISize::Make(650, 610); } |
200 | 201 |
201 void onDraw(SkCanvas* canvas) override { | 202 void onDraw(SkCanvas* canvas) override { |
202 canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); | 203 canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); |
203 | 204 |
204 const SkScalar w = SkIntToScalar(gWidth); | 205 const SkScalar w = SkIntToScalar(gWidth); |
205 const SkScalar h = SkIntToScalar(gHeight); | 206 const SkScalar h = SkIntToScalar(gHeight); |
206 SkRect r = { -w, -h, w*2, h*2 }; | 207 SkRect r = { -w, -h, w*2, h*2 }; |
207 | 208 |
208 static const SkShader::TileMode gModes[] = { | 209 constexpr SkShader::TileMode gModes[] = { |
209 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode | 210 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMi
rror_TileMode |
210 }; | 211 }; |
211 static const char* gModeNames[] = { | 212 const char* gModeNames[] = { |
212 "Clamp", "Repeat", "Mirror" | 213 "Clamp", "Repeat", "Mirror" |
213 }; | 214 }; |
214 | 215 |
215 SkScalar y = SkIntToScalar(24); | 216 SkScalar y = SkIntToScalar(24); |
216 SkScalar x = SkIntToScalar(66); | 217 SkScalar x = SkIntToScalar(66); |
217 | 218 |
218 SkPaint p; | 219 SkPaint p; |
219 p.setAntiAlias(true); | 220 p.setAntiAlias(true); |
220 sk_tool_utils::set_portable_typeface(&p); | 221 sk_tool_utils::set_portable_typeface(&p); |
221 p.setTextAlign(SkPaint::kCenter_Align); | 222 p.setTextAlign(SkPaint::kCenter_Align); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 private: | 255 private: |
255 typedef skiagm::GM INHERITED; | 256 typedef skiagm::GM INHERITED; |
256 }; | 257 }; |
257 | 258 |
258 ////////////////////////////////////////////////////////////////////////////// | 259 ////////////////////////////////////////////////////////////////////////////// |
259 | 260 |
260 DEF_GM( return new TilingGM(true); ) | 261 DEF_GM( return new TilingGM(true); ) |
261 DEF_GM( return new TilingGM(false); ) | 262 DEF_GM( return new TilingGM(false); ) |
262 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) | 263 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) |
263 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) | 264 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) |
OLD | NEW |