halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Resources.h" |
| 9 | #include "SkBitmap.h" |
Florin Malita | ab244f0 | 2017-05-03 19:16:58 +0000 | [diff] [blame] | 10 | #include "SkShader.h" |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 11 | #include "gm.h" |
| 12 | |
| 13 | DEF_SIMPLE_GM(bitmap_subset_shader, canvas, 256, 256) { |
| 14 | canvas->clear(SK_ColorWHITE); |
| 15 | |
| 16 | SkBitmap source; |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 17 | if (!GetResourceAsBitmap("images/color_wheel.png", &source)) { |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 18 | return; |
| 19 | } |
| 20 | SkIRect left = SkIRect::MakeWH(source.width()/2, source.height()); |
| 21 | SkIRect right = SkIRect::MakeXYWH(source.width()/2, 0, |
| 22 | source.width()/2, source.height()); |
| 23 | SkBitmap leftBitmap, rightBitmap; |
| 24 | source.extractSubset(&leftBitmap, left); |
| 25 | source.extractSubset(&rightBitmap, right); |
| 26 | |
| 27 | SkMatrix matrix; |
| 28 | matrix.setScale(0.75f, 0.75f); |
| 29 | matrix.preRotate(30.0f); |
| 30 | SkShader::TileMode tm = SkShader::kRepeat_TileMode; |
| 31 | SkPaint paint; |
| 32 | paint.setShader(SkShader::MakeBitmapShader(leftBitmap, tm, tm, &matrix)); |
| 33 | canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint); |
| 34 | paint.setShader(SkShader::MakeBitmapShader(rightBitmap, tm, tm, &matrix)); |
| 35 | canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint); |
| 36 | } |