Hal Canary | b82ac366 | 2019-05-02 10:47:46 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 3 | |
Hal Canary | b82ac366 | 2019-05-02 10:47:46 -0400 | [diff] [blame] | 4 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 5 | #include "include/core/SkCanvas.h" |
| 6 | #include "include/core/SkImage.h" |
| 7 | #include "include/core/SkMatrix.h" |
| 8 | #include "include/core/SkPaint.h" |
| 9 | #include "include/core/SkRect.h" |
| 10 | #include "include/core/SkRefCnt.h" |
| 11 | #include "include/core/SkShader.h" |
| 12 | #include "include/core/SkTileMode.h" |
Hal Canary | b82ac366 | 2019-05-02 10:47:46 -0400 | [diff] [blame] | 13 | #include "tools/Resources.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | |
Hal Canary | b82ac366 | 2019-05-02 10:47:46 -0400 | [diff] [blame] | 15 | // http://crbug.com/957275 |
| 16 | DEF_SIMPLE_GM(tilemodes_alpha, canvas, 512, 512) { |
| 17 | sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_64.png"); |
| 18 | if (!image) { |
| 19 | return; |
| 20 | } |
| 21 | constexpr SkTileMode kModes[4] = { |
| 22 | SkTileMode::kClamp, |
| 23 | SkTileMode::kRepeat, |
| 24 | SkTileMode::kMirror, |
| 25 | SkTileMode::kDecal, |
| 26 | }; |
| 27 | for (int y = 0; y < 4; ++y) { |
| 28 | for (int x = 0; x < 4; ++x) { |
| 29 | SkRect rect = SkRect::MakeXYWH(128 * x + 1, 128 * y + 1, 126, 126); |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 30 | SkMatrix matrix = SkMatrix::Translate(rect.x(), rect.y()); |
Hal Canary | 0a7b393 | 2019-05-02 11:31:28 -0400 | [diff] [blame] | 31 | SkPaint paint(SkColor4f{0, 0, 0, 0.5f}); |
Hal Canary | b82ac366 | 2019-05-02 10:47:46 -0400 | [diff] [blame] | 32 | paint.setShader(image->makeShader(kModes[x], kModes[y], &matrix)); |
| 33 | canvas->drawRect(rect, paint); |
| 34 | } |
| 35 | } |
| 36 | } |