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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkBitmap.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColor.h" |
| 12 | #include "include/core/SkMatrix.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "include/core/SkShader.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 16 | #include "include/core/SkString.h" |
| 17 | #include "include/core/SkTileMode.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/Resources.h" |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 19 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 20 | DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) { |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 21 | canvas->clear(SK_ColorWHITE); |
| 22 | |
| 23 | SkBitmap source; |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 24 | if (!GetResourceAsBitmap("images/color_wheel.png", &source)) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 25 | *errorMsg = "Could not load images/color_wheel.png. " |
| 26 | "Did you forget to set the resourcePath?"; |
| 27 | return skiagm::DrawResult::kFail; |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 28 | } |
| 29 | SkIRect left = SkIRect::MakeWH(source.width()/2, source.height()); |
| 30 | SkIRect right = SkIRect::MakeXYWH(source.width()/2, 0, |
| 31 | source.width()/2, source.height()); |
| 32 | SkBitmap leftBitmap, rightBitmap; |
| 33 | source.extractSubset(&leftBitmap, left); |
| 34 | source.extractSubset(&rightBitmap, right); |
| 35 | |
| 36 | SkMatrix matrix; |
| 37 | matrix.setScale(0.75f, 0.75f); |
| 38 | matrix.preRotate(30.0f); |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 39 | SkTileMode tm = SkTileMode::kRepeat; |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 40 | SkPaint paint; |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 41 | paint.setShader(leftBitmap.makeShader(tm, tm, &matrix)); |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 42 | canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 43 | paint.setShader(rightBitmap.makeShader(tm, tm, &matrix)); |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 44 | canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint); |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 45 | return skiagm::DrawResult::kOk; |
halcanary | 895f3f0 | 2016-04-01 11:51:00 -0700 | [diff] [blame] | 46 | } |