OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 183 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
184 static const uint32_t kCheckData[] = { | 184 static const uint32_t kCheckData[] = { |
185 SkPackARGB32(0xFF, 0x40, 0x40, 0x40), | 185 SkPackARGB32(0xFF, 0x40, 0x40, 0x40), |
186 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), | 186 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), |
187 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), | 187 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), |
188 SkPackARGB32(0xFF, 0x40, 0x40, 0x40) | 188 SkPackARGB32(0xFF, 0x40, 0x40, 0x40) |
189 }; | 189 }; |
190 SkBitmap bg; | 190 SkBitmap bg; |
191 bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType); | 191 bg.allocN32Pixels(2, 2, true); |
192 bg.allocPixels(); | |
193 SkAutoLockPixels bgAlp(bg); | 192 SkAutoLockPixels bgAlp(bg); |
194 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); | 193 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); |
195 | 194 |
196 fBGShader.reset(SkShader::CreateBitmapShader(bg, | 195 fBGShader.reset(SkShader::CreateBitmapShader(bg, |
197 SkShader::kRepeat_TileMode, | 196 SkShader::kRepeat_TileMode, |
198 SkShader::kRepeat_TileMode)
); | 197 SkShader::kRepeat_TileMode)
); |
199 SkMatrix lm; | 198 SkMatrix lm; |
200 lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize)); | 199 lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize)); |
201 fBGShader->setLocalMatrix(lm); | 200 fBGShader->setLocalMatrix(lm); |
202 | 201 |
203 SkPaint bmpPaint; | 202 SkPaint bmpPaint; |
204 static const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar
(kSize) / 2 }; | 203 static const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar
(kSize) / 2 }; |
205 static const SkColor kColors[] = { SK_ColorTRANSPARENT, 0x80800000, | 204 static const SkColor kColors[] = { SK_ColorTRANSPARENT, 0x80800000, |
206 0xF020F060, SK_ColorWHITE }; | 205 0xF020F060, SK_ColorWHITE }; |
207 bmpPaint.setShader(SkGradientShader::CreateRadial(kCenter, | 206 bmpPaint.setShader(SkGradientShader::CreateRadial(kCenter, |
208 3 * SkIntToScalar(kSiz
e) / 4, | 207 3 * SkIntToScalar(kSiz
e) / 4, |
209 kColors, | 208 kColors, |
210 NULL, | 209 NULL, |
211 SK_ARRAY_COUNT(kColors
), | 210 SK_ARRAY_COUNT(kColors
), |
212 SkShader::kRepeat_Tile
Mode))->unref(); | 211 SkShader::kRepeat_Tile
Mode))->unref(); |
213 | 212 |
214 SkBitmap bmp; | 213 SkBitmap bmp; |
215 bmp.setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize); | 214 bmp.allocN32Pixels(kSize, kSize); |
216 bmp.allocPixels(); | |
217 SkCanvas bmpCanvas(bmp); | 215 SkCanvas bmpCanvas(bmp); |
218 | 216 |
219 bmpCanvas.clear(SK_ColorTRANSPARENT); | 217 bmpCanvas.clear(SK_ColorTRANSPARENT); |
220 SkRect rect = { SkIntToScalar(kSize) / 8, SkIntToScalar(kSize) / 8, | 218 SkRect rect = { SkIntToScalar(kSize) / 8, SkIntToScalar(kSize) / 8, |
221 7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) /
8}; | 219 7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) /
8}; |
222 bmpCanvas.drawRect(rect, bmpPaint); | 220 bmpCanvas.drawRect(rect, bmpPaint); |
223 | 221 |
224 fBmpShader.reset(SkShader::CreateBitmapShader(bmp, | 222 fBmpShader.reset(SkShader::CreateBitmapShader(bmp, |
225 SkShader::kClamp_TileMode, | 223 SkShader::kClamp_TileMode, |
226 SkShader::kClamp_TileMode)
); | 224 SkShader::kClamp_TileMode)
); |
227 } | 225 } |
228 | 226 |
229 enum { | 227 enum { |
230 kCheckSize = 8, | 228 kCheckSize = 8, |
231 kSize = 30, | 229 kSize = 30, |
232 kTestsPerRow = 15, | 230 kTestsPerRow = 15, |
233 }; | 231 }; |
234 | 232 |
235 SkAutoTUnref<SkShader> fBGShader; | 233 SkAutoTUnref<SkShader> fBGShader; |
236 SkAutoTUnref<SkShader> fBmpShader; | 234 SkAutoTUnref<SkShader> fBmpShader; |
237 | 235 |
238 typedef GM INHERITED; | 236 typedef GM INHERITED; |
239 }; | 237 }; |
240 | 238 |
241 ////////////////////////////////////////////////////////////////////////////// | 239 ////////////////////////////////////////////////////////////////////////////// |
242 | 240 |
243 DEF_GM(return new Xfermodes3GM;) | 241 DEF_GM(return new Xfermodes3GM;) |
244 | 242 |
245 } | 243 } |
OLD | NEW |