OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 SkBitmap fColorBitmap; | 215 SkBitmap fColorBitmap; |
216 SkBitmap fAlpha8Bitmap; | 216 SkBitmap fAlpha8Bitmap; |
217 sk_sp<SkShader> fColorBitmapShader; | 217 sk_sp<SkShader> fColorBitmapShader; |
218 sk_sp<SkShader> fAlpha8BitmapShader; | 218 sk_sp<SkShader> fAlpha8BitmapShader; |
219 sk_sp<SkShader> fLinearGradientShader; | 219 sk_sp<SkShader> fLinearGradientShader; |
220 | 220 |
221 typedef GM INHERITED; | 221 typedef GM INHERITED; |
222 }; | 222 }; |
223 | 223 |
| 224 DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) { |
| 225 int width = 255; |
| 226 int height = 255; |
| 227 SkTDArray<uint8_t> dst8Storage; |
| 228 dst8Storage.setCount(width * height); |
| 229 SkTDArray<uint32_t> dst32Storage; |
| 230 dst32Storage.setCount(width * height * sizeof(int32_t)); |
| 231 for (int y = 0; y < height; ++y) { |
| 232 for (int x = 0; x < width; ++x) { |
| 233 dst8Storage[y * width + x] = (y + x) / 2; |
| 234 dst32Storage[y * width + x] = SkPackARGB32(0xFF, x, y, 0); |
| 235 } |
| 236 } |
| 237 SkPaint paint; |
| 238 paint.setAntiAlias(true); |
| 239 paint.setColor(SK_ColorBLUE); |
| 240 SkRect r = {0, 0, SkIntToScalar(width), SkIntToScalar(height)}; |
| 241 canvas->drawRect(r, paint); |
| 242 SkBitmap skBitmap, skMask; |
| 243 SkImageInfo imageInfo = SkImageInfo::Make(width, height, |
| 244 SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
| 245 skBitmap.installPixels(imageInfo, dst32Storage.begin(), width * sizeof(int32
_t), |
| 246 nullptr, nullptr, nullptr); |
| 247 imageInfo = SkImageInfo::Make(width, height, |
| 248 SkColorType::kAlpha_8_SkColorType, kPremul_SkAlphaType); |
| 249 skMask.installPixels(imageInfo, dst8Storage.begin(), width, nullptr, nullptr
, nullptr); |
| 250 sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap); |
| 251 sk_sp<SkShader> skSrcShader = |
| 252 skSrc->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 253 sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask); |
| 254 sk_sp<SkShader> skMaskShader = skMaskImage->makeShader( |
| 255 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 256 sk_sp<SkXfermode> dstInMode = SkXfermode::Make(SkXfermode::kSrcIn_Mode); |
| 257 paint.setShader( |
| 258 SkShader::MakeComposeShader(skMaskShader, skSrcShader, dstInMode)); |
| 259 canvas->drawRect(r, paint); |
| 260 } |
| 261 |
224 ////////////////////////////////////////////////////////////////////////////// | 262 ////////////////////////////////////////////////////////////////////////////// |
225 | 263 |
226 DEF_GM( return new ComposeShaderGM; ) | 264 DEF_GM( return new ComposeShaderGM; ) |
227 DEF_GM( return new ComposeShaderAlphaGM; ) | 265 DEF_GM( return new ComposeShaderAlphaGM; ) |
228 DEF_GM( return new ComposeShaderBitmapGM; ) | 266 DEF_GM( return new ComposeShaderBitmapGM; ) |
OLD | NEW |