OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
11 #include "SkShader.h" | 11 #include "SkShader.h" |
12 #include "SkUtils.h" | 12 #include "SkUtils.h" |
13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
14 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 | 16 |
17 // effects | 17 // effects |
18 #include "SkGradientShader.h" | 18 #include "SkGradientShader.h" |
19 #include "SkUnitMappers.h" | 19 #include "SkUnitMappers.h" |
20 #include "SkBlurDrawLooper.h" | 20 #include "SkBlurDrawLooper.h" |
21 | 21 |
22 static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) { | 22 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { |
23 bm->allocConfigPixels(config, w, h); | 23 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); |
24 bm->eraseColor(SK_ColorTRANSPARENT); | 24 bm->eraseColor(SK_ColorTRANSPARENT); |
25 | 25 |
26 SkCanvas canvas(*bm); | 26 SkCanvas canvas(*bm); |
27 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} }; | 27 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} }; |
28 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; | 28 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
29 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 29 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
30 SkPaint paint; | 30 SkPaint paint; |
31 | 31 |
32 SkUnitMapper* um = NULL; | 32 SkUnitMapper* um = NULL; |
33 | 33 |
34 um = new SkCosineMapper; | 34 um = new SkCosineMapper; |
35 // um = new SkDiscreteMapper(12); | 35 // um = new SkDiscreteMapper(12); |
36 | 36 |
37 SkAutoUnref au(um); | 37 SkAutoUnref au(um); |
38 | 38 |
39 paint.setDither(true); | 39 paint.setDither(true); |
40 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, | 40 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, |
41 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref()
; | 41 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref()
; |
42 canvas.drawPaint(paint); | 42 canvas.drawPaint(paint); |
43 } | 43 } |
44 | 44 |
45 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, | 45 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, |
46 SkShader::TileMode tmx, SkShader::TileMode tmy) { | 46 SkShader::TileMode tmx, SkShader::TileMode tmy) { |
47 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); | 47 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); |
48 paint->setShader(shader)->unref(); | 48 paint->setShader(shader)->unref(); |
49 paint->setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_Fi
lterLevel); | 49 paint->setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_Fi
lterLevel); |
50 } | 50 } |
51 | 51 |
52 static const SkBitmap::Config gConfigs[] = { | 52 static const SkColorType gColorTypes[] = { |
53 SkBitmap::kARGB_8888_Config, | 53 kPMColor_SkColorType, |
54 SkBitmap::kRGB_565_Config, | 54 kRGB_565_SkColorType, |
55 }; | 55 }; |
56 | 56 |
57 class TilingGM : public skiagm::GM { | 57 class TilingGM : public skiagm::GM { |
58 public: | 58 public: |
59 TilingGM(bool powerOfTwoSize) | 59 TilingGM(bool powerOfTwoSize) |
60 : fPowerOfTwoSize(powerOfTwoSize) { | 60 : fPowerOfTwoSize(powerOfTwoSize) { |
61 } | 61 } |
62 | 62 |
63 SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)]; | 63 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; |
64 | 64 |
65 protected: | 65 protected: |
66 | 66 |
67 enum { | 67 enum { |
68 kPOTSize = 32, | 68 kPOTSize = 32, |
69 kNPOTSize = 21, | 69 kNPOTSize = 21, |
70 }; | 70 }; |
71 | 71 |
72 SkString onShortName() { | 72 SkString onShortName() { |
73 SkString name("tilemodes"); | 73 SkString name("tilemodes"); |
74 if (!fPowerOfTwoSize) { | 74 if (!fPowerOfTwoSize) { |
75 name.append("_npot"); | 75 name.append("_npot"); |
76 } | 76 } |
77 return name; | 77 return name; |
78 } | 78 } |
79 | 79 |
80 SkISize onISize() { return SkISize::Make(880, 560); } | 80 SkISize onISize() { return SkISize::Make(880, 560); } |
81 | 81 |
82 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 82 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
83 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; | 83 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; |
84 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { | 84 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { |
85 makebm(&fTexture[i], gConfigs[i], size, size); | 85 makebm(&fTexture[i], gColorTypes[i], size, size); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 89 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
90 | 90 |
91 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; | 91 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; |
92 | 92 |
93 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; | 93 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; |
94 | 94 |
95 static const char* gConfigNames[] = { "8888", "565", "4444" }; | 95 static const char* gConfigNames[] = { "8888", "565", "4444" }; |
(...skipping 17 matching lines...) Expand all Loading... |
113 | 113 |
114 p.setTextAlign(SkPaint::kCenter_Align); | 114 p.setTextAlign(SkPaint::kCenter_Align); |
115 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p)
; | 115 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p)
; |
116 | 116 |
117 x += r.width() * 4 / 3; | 117 x += r.width() * 4 / 3; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 y += SkIntToScalar(16); | 121 y += SkIntToScalar(16); |
122 | 122 |
123 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { | 123 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { |
124 for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { | 124 for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { |
125 x = SkIntToScalar(10); | 125 x = SkIntToScalar(10); |
126 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 126 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
127 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 127 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
128 SkPaint paint; | 128 SkPaint paint; |
129 #if 1 // Temporary change to regen bitmap before each draw. This may help tracki
ng down an issue | 129 #if 1 // Temporary change to regen bitmap before each draw. This may help tracki
ng down an issue |
130 // on SGX where resizing NPOT textures to POT textures exhibits a driver b
ug. | 130 // on SGX where resizing NPOT textures to POT textures exhibits a driver b
ug. |
131 if (!fPowerOfTwoSize) { | 131 if (!fPowerOfTwoSize) { |
132 makebm(&fTexture[i], gConfigs[i], size, size); | 132 makebm(&fTexture[i], gColorTypes[i], size, size); |
133 } | 133 } |
134 #endif | 134 #endif |
135 setup(&paint, fTexture[i], gFilters[j], gModes[kx], gMod
es[ky]); | 135 setup(&paint, fTexture[i], gFilters[j], gModes[kx], gMod
es[ky]); |
136 paint.setDither(true); | 136 paint.setDither(true); |
137 | 137 |
138 canvas->save(); | 138 canvas->save(); |
139 canvas->translate(x, y); | 139 canvas->translate(x, y); |
140 canvas->drawRect(r, paint); | 140 canvas->drawRect(r, paint); |
141 canvas->restore(); | 141 canvas->restore(); |
142 | 142 |
(...skipping 16 matching lines...) Expand all Loading... |
159 private: | 159 private: |
160 bool fPowerOfTwoSize; | 160 bool fPowerOfTwoSize; |
161 typedef skiagm::GM INHERITED; | 161 typedef skiagm::GM INHERITED; |
162 }; | 162 }; |
163 | 163 |
164 static const int gWidth = 32; | 164 static const int gWidth = 32; |
165 static const int gHeight = 32; | 165 static const int gHeight = 32; |
166 | 166 |
167 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 167 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
168 SkBitmap bm; | 168 SkBitmap bm; |
169 makebm(&bm, SkBitmap::kARGB_8888_Config, gWidth, gHeight); | 169 makebm(&bm, kPMColor_SkColorType, gWidth, gHeight); |
170 return SkShader::CreateBitmapShader(bm, tx, ty); | 170 return SkShader::CreateBitmapShader(bm, tx, ty); |
171 } | 171 } |
172 | 172 |
173 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 173 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
174 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 174 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
175 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 175 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
176 SkScalar rad = SkIntToScalar(gWidth)/2; | 176 SkScalar rad = SkIntToScalar(gWidth)/2; |
177 SkColor colors[] = { 0xFFFF0000, 0xFF0044FF }; | 177 SkColor colors[] = { 0xFFFF0000, 0xFF0044FF }; |
178 | 178 |
179 int index = (int)ty; | 179 int index = (int)ty; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 private: | 261 private: |
262 typedef skiagm::GM INHERITED; | 262 typedef skiagm::GM INHERITED; |
263 }; | 263 }; |
264 | 264 |
265 ////////////////////////////////////////////////////////////////////////////// | 265 ////////////////////////////////////////////////////////////////////////////// |
266 | 266 |
267 DEF_GM( return new TilingGM(true); ) | 267 DEF_GM( return new TilingGM(true); ) |
268 DEF_GM( return new TilingGM(false); ) | 268 DEF_GM( return new TilingGM(false); ) |
269 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) | 269 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) |
270 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) | 270 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) |
OLD | NEW |