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.
3 
4 #include "gm/gm.h"
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"
13 #include "tools/Resources.h"
14 
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);
30             SkMatrix matrix = SkMatrix::Translate(rect.x(), rect.y());
31             SkPaint paint(SkColor4f{0, 0, 0, 0.5f});
32             paint.setShader(image->makeShader(kModes[x], kModes[y], &matrix));
33             canvas->drawRect(rect, paint);
34         }
35     }
36 }
37