blob: 29d8932d8b1cfc4d1cdc8857e37010daa5717982 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
reed@android.com1a2fec52009-06-22 02:17:34 +00007
Ben Wagner7fde8e12019-05-01 17:28:53 -04008#include "gm/gm.h"
9#include "include/core/SkBitmap.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkFont.h"
13#include "include/core/SkImage.h"
14#include "include/core/SkImageInfo.h"
15#include "include/core/SkPaint.h"
16#include "include/core/SkPoint.h"
17#include "include/core/SkRect.h"
18#include "include/core/SkRefCnt.h"
19#include "include/core/SkScalar.h"
20#include "include/core/SkShader.h"
21#include "include/core/SkSize.h"
22#include "include/core/SkString.h"
23#include "include/core/SkTileMode.h"
24#include "include/core/SkTypeface.h"
25#include "include/core/SkTypes.h"
26#include "include/effects/SkGradientShader.h"
27#include "include/utils/SkTextUtils.h"
Kevin Lubick8b741882023-10-06 11:41:38 -040028#include "tools/DecodeUtils.h"
Kevin Lubick9b028372023-10-05 15:04:54 -040029#include "tools/GpuToolUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "tools/Resources.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040031#include "tools/ToolUtils.h"
Kevin Lubicke836c3a2023-10-20 06:55:35 -040032#include "tools/fonts/FontToolUtils.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040033
34#include <functional>
Mike Reeddfc0e912018-02-16 12:40:18 -050035
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000036static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
37 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
junov@google.comdbfac8a2012-12-06 21:47:40 +000038 bm->eraseColor(SK_ColorTRANSPARENT);
rmistry@google.comae933ce2012-08-23 18:19:56 +000039
reed@android.com1a2fec52009-06-22 02:17:34 +000040 SkCanvas canvas(*bm);
41 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} };
42 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
43 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
44 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000045
reed@android.com1a2fec52009-06-22 02:17:34 +000046 paint.setDither(true);
Herb Derbyc37b3862022-06-21 09:49:17 -040047 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, std::size(colors),
Mike Reedfae8fce2019-04-03 10:27:45 -040048 SkTileMode::kClamp));
reed@android.com1a2fec52009-06-22 02:17:34 +000049 canvas.drawPaint(paint);
50}
51
Robert Phillips6a423972022-04-29 09:43:45 -040052static void setup(SkCanvas* canvas, SkPaint* paint, const SkBitmap& bm, SkFilterMode fm,
Mike Reedfae8fce2019-04-03 10:27:45 -040053 SkTileMode tmx, SkTileMode tmy) {
Kevin Lubick77472bf2023-03-24 07:11:17 -040054 sk_sp<SkImage> img = SkImages::RasterFromBitmap(bm);
Robert Phillips6a423972022-04-29 09:43:45 -040055 img = ToolUtils::MakeTextureImage(canvas, std::move(img));
Kevin Lubickc2ec5d02022-10-17 15:49:00 -040056 if (img) {
57 // img can be null if the GPU context has been abandoned.
58 paint->setShader(img->makeShader(tmx, tmy, SkSamplingOptions(fm)));
59 }
reed@android.com1a2fec52009-06-22 02:17:34 +000060}
61
mtkleindbfd7ab2016-09-01 11:24:54 -070062constexpr SkColorType gColorTypes[] = {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000063 kN32_SkColorType,
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000064 kRGB_565_SkColorType,
reed@android.com1a2fec52009-06-22 02:17:34 +000065};
reed@android.com1a2fec52009-06-22 02:17:34 +000066
mike@reedtribe.orga0591692012-10-18 02:01:59 +000067class TilingGM : public skiagm::GM {
reed@android.com1a2fec52009-06-22 02:17:34 +000068public:
commit-bot@chromium.org37799e12013-07-25 17:52:32 +000069 TilingGM(bool powerOfTwoSize)
robertphillips@google.com6db2ae22013-08-30 12:41:42 +000070 : fPowerOfTwoSize(powerOfTwoSize) {
reed@android.com1a2fec52009-06-22 02:17:34 +000071 }
72
Herb Derbyc37b3862022-06-21 09:49:17 -040073 SkBitmap fTexture[std::size(gColorTypes)];
rmistry@google.comae933ce2012-08-23 18:19:56 +000074
reed@android.com1a2fec52009-06-22 02:17:34 +000075protected:
commit-bot@chromium.org37799e12013-07-25 17:52:32 +000076
77 enum {
78 kPOTSize = 32,
79 kNPOTSize = 21,
80 };
81
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000082 SkString getName() const override {
commit-bot@chromium.org37799e12013-07-25 17:52:32 +000083 SkString name("tilemodes");
84 if (!fPowerOfTwoSize) {
85 name.append("_npot");
86 }
87 return name;
reed@android.com1a2fec52009-06-22 02:17:34 +000088 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000089
Leandro Lovisolo8f023882023-08-15 21:13:52 +000090 SkISize getISize() override { return SkISize::Make(880, 560); }
rmistry@google.comae933ce2012-08-23 18:19:56 +000091
mtklein36352bf2015-03-25 18:17:31 -070092 void onOnceBeforeDraw() override {
commit-bot@chromium.org37799e12013-07-25 17:52:32 +000093 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
Herb Derbyc37b3862022-06-21 09:49:17 -040094 for (size_t i = 0; i < std::size(gColorTypes); i++) {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000095 makebm(&fTexture[i], gColorTypes[i], size, size);
reed@google.com7775d662012-11-27 15:15:58 +000096 }
97 }
98
mtklein36352bf2015-03-25 18:17:31 -070099 void onDraw(SkCanvas* canvas) override {
Hal Canarydf2d27e2019-01-08 09:38:02 -0500100 SkPaint textPaint;
Kevin Lubicke836c3a2023-10-20 06:55:35 -0400101 SkFont font = ToolUtils::DefaultPortableFont();
rmistry@google.comae933ce2012-08-23 18:19:56 +0000102
commit-bot@chromium.org37799e12013-07-25 17:52:32 +0000103 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
104
105 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) };
reed@android.com1a2fec52009-06-22 02:17:34 +0000106
Robert Phillips6a423972022-04-29 09:43:45 -0400107 const char* gConfigNames[] = { "8888", "565" };
rmistry@google.comae933ce2012-08-23 18:19:56 +0000108
Mike Reed057fcbe2020-12-12 14:31:25 -0500109 constexpr SkFilterMode gFilters[] = { SkFilterMode::kNearest, SkFilterMode::kLinear };
mtkleindbfd7ab2016-09-01 11:24:54 -0700110 static const char* gFilterNames[] = { "point", "bilinear" };
rmistry@google.comae933ce2012-08-23 18:19:56 +0000111
Mike Reedfae8fce2019-04-03 10:27:45 -0400112 constexpr SkTileMode gModes[] = {
113 SkTileMode::kClamp, SkTileMode::kRepeat, SkTileMode::kMirror };
mtkleindbfd7ab2016-09-01 11:24:54 -0700114 static const char* gModeNames[] = { "C", "R", "M" };
reed@android.com1a2fec52009-06-22 02:17:34 +0000115
116 SkScalar y = SkIntToScalar(24);
117 SkScalar x = SkIntToScalar(10);
118
Herb Derbyc37b3862022-06-21 09:49:17 -0400119 for (size_t kx = 0; kx < std::size(gModes); kx++) {
120 for (size_t ky = 0; ky < std::size(gModes); ky++) {
reed@android.com1a2fec52009-06-22 02:17:34 +0000121 SkPaint p;
reed@android.com1a2fec52009-06-22 02:17:34 +0000122 p.setDither(true);
Mike Reeddc5863c2018-12-23 23:19:14 -0500123 SkString str;
reed@android.com1a2fec52009-06-22 02:17:34 +0000124 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]);
125
Mike Reeddc5863c2018-12-23 23:19:14 -0500126 SkTextUtils::DrawString(canvas, str.c_str(), x + r.width()/2, y, font, p,
Mike Reed3a42ec02018-10-30 12:53:21 -0400127 SkTextUtils::kCenter_Align);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000128
reed@android.com1a2fec52009-06-22 02:17:34 +0000129 x += r.width() * 4 / 3;
130 }
131 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000132
reed@android.com1a2fec52009-06-22 02:17:34 +0000133 y += SkIntToScalar(16);
134
Herb Derbyc37b3862022-06-21 09:49:17 -0400135 for (size_t i = 0; i < std::size(gColorTypes); i++) {
136 for (size_t j = 0; j < std::size(gFilters); j++) {
reed@android.com1a2fec52009-06-22 02:17:34 +0000137 x = SkIntToScalar(10);
Herb Derbyc37b3862022-06-21 09:49:17 -0400138 for (size_t kx = 0; kx < std::size(gModes); kx++) {
139 for (size_t ky = 0; ky < std::size(gModes); ky++) {
reed@android.com1a2fec52009-06-22 02:17:34 +0000140 SkPaint paint;
bsalomon@google.comab3c6782013-08-06 20:47:52 +0000141#if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue
142 // on SGX where resizing NPOT textures to POT textures exhibits a driver bug.
143 if (!fPowerOfTwoSize) {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000144 makebm(&fTexture[i], gColorTypes[i], size, size);
bsalomon@google.comab3c6782013-08-06 20:47:52 +0000145 }
146#endif
Robert Phillips6a423972022-04-29 09:43:45 -0400147 setup(canvas, &paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]);
reed@android.com1a2fec52009-06-22 02:17:34 +0000148 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000149
reed@android.com1a2fec52009-06-22 02:17:34 +0000150 canvas->save();
151 canvas->translate(x, y);
152 canvas->drawRect(r, paint);
153 canvas->restore();
rmistry@google.comae933ce2012-08-23 18:19:56 +0000154
reed@android.com1a2fec52009-06-22 02:17:34 +0000155 x += r.width() * 4 / 3;
156 }
157 }
Hal Canarydf2d27e2019-01-08 09:38:02 -0500158 canvas->drawString(SkStringPrintf("%s, %s", gConfigNames[i], gFilterNames[j]),
159 x, y + r.height() * 2 / 3, font, textPaint);
reed@android.com1a2fec52009-06-22 02:17:34 +0000160
161 y += r.height() * 4 / 3;
162 }
163 }
164 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000165
reed@android.com1a2fec52009-06-22 02:17:34 +0000166private:
commit-bot@chromium.org37799e12013-07-25 17:52:32 +0000167 bool fPowerOfTwoSize;
John Stiles7571f9e2020-09-02 22:42:33 -0400168 using INHERITED = skiagm::GM;
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000169};
Mike Reeddfc0e912018-02-16 12:40:18 -0500170DEF_GM( return new TilingGM(true); )
171DEF_GM( return new TilingGM(false); )
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000172
mtkleindbfd7ab2016-09-01 11:24:54 -0700173constexpr int gWidth = 32;
174constexpr int gHeight = 32;
commit-bot@chromium.org37799e12013-07-25 17:52:32 +0000175
Mike Reedfae8fce2019-04-03 10:27:45 -0400176static sk_sp<SkShader> make_bm(SkTileMode tx, SkTileMode ty) {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000177 SkBitmap bm;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000178 makebm(&bm, kN32_SkColorType, gWidth, gHeight);
Mike Reed057fcbe2020-12-12 14:31:25 -0500179 return bm.makeShader(tx, ty, SkSamplingOptions());
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000180}
181
Mike Reedfae8fce2019-04-03 10:27:45 -0400182static sk_sp<SkShader> make_grad(SkTileMode tx, SkTileMode ty) {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000183 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
184 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
185 SkScalar rad = SkIntToScalar(gWidth)/2;
Mike Kleinea3f0142019-03-20 11:12:10 -0500186 SkColor colors[] = {0xFFFF0000, ToolUtils::color_to_565(0xFF0044FF)};
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000187
188 int index = (int)ty;
189 switch (index % 3) {
190 case 0:
Herb Derbyc37b3862022-06-21 09:49:17 -0400191 return SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors), tx);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000192 case 1:
Herb Derbyc37b3862022-06-21 09:49:17 -0400193 return SkGradientShader::MakeRadial(center, rad, colors, nullptr, std::size(colors), tx);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000194 case 2:
Florin Malita5a9a9812017-08-01 16:38:08 -0400195 return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr,
Herb Derbyc37b3862022-06-21 09:49:17 -0400196 std::size(colors), tx, 135, 225, 0, nullptr);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000197 }
halcanary96fcdcc2015-08-27 07:41:13 -0700198 return nullptr;
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000199}
200
Mike Reedfae8fce2019-04-03 10:27:45 -0400201typedef sk_sp<SkShader> (*ShaderProc)(SkTileMode, SkTileMode);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000202
203class Tiling2GM : public skiagm::GM {
204 ShaderProc fProc;
Hal Canary594fe852019-07-18 13:35:49 -0400205 const char* fName;
206
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000207public:
Hal Canary594fe852019-07-18 13:35:49 -0400208 Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc), fName(name) {}
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000209
Hal Canary594fe852019-07-18 13:35:49 -0400210private:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +0000211 SkString getName() const override { return SkString(fName); }
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000212
Leandro Lovisolo8f023882023-08-15 21:13:52 +0000213 SkISize getISize() override { return SkISize::Make(650, 610); }
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000214
mtklein36352bf2015-03-25 18:17:31 -0700215 void onDraw(SkCanvas* canvas) override {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000216 canvas->scale(SkIntToScalar(3)/2, SkIntToScalar(3)/2);
217
218 const SkScalar w = SkIntToScalar(gWidth);
219 const SkScalar h = SkIntToScalar(gHeight);
220 SkRect r = { -w, -h, w*2, h*2 };
221
Mike Reedfae8fce2019-04-03 10:27:45 -0400222 constexpr SkTileMode gModes[] = {
223 SkTileMode::kClamp, SkTileMode::kRepeat, SkTileMode::kMirror
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000224 };
mtkleindbfd7ab2016-09-01 11:24:54 -0700225 const char* gModeNames[] = {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000226 "Clamp", "Repeat", "Mirror"
227 };
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000228
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000229 SkScalar y = SkIntToScalar(24);
230 SkScalar x = SkIntToScalar(66);
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000231
Kevin Lubicke836c3a2023-10-20 06:55:35 -0400232 SkFont font = ToolUtils::DefaultPortableFont();
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000233
Herb Derbyc37b3862022-06-21 09:49:17 -0400234 for (size_t kx = 0; kx < std::size(gModes); kx++) {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000235 SkString str(gModeNames[kx]);
Mike Reeddc5863c2018-12-23 23:19:14 -0500236 SkTextUtils::DrawString(canvas, str.c_str(), x + r.width()/2, y, font, SkPaint(),
237 SkTextUtils::kCenter_Align);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000238 x += r.width() * 4 / 3;
239 }
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000240
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000241 y += SkIntToScalar(16) + h;
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000242
Herb Derbyc37b3862022-06-21 09:49:17 -0400243 for (size_t ky = 0; ky < std::size(gModes); ky++) {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000244 x = SkIntToScalar(16) + w;
245
246 SkString str(gModeNames[ky]);
Mike Reeddc5863c2018-12-23 23:19:14 -0500247 SkTextUtils::DrawString(canvas, str.c_str(), x, y + h/2, font, SkPaint(),
248 SkTextUtils::kRight_Align);
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000249
250 x += SkIntToScalar(50);
Herb Derbyc37b3862022-06-21 09:49:17 -0400251 for (size_t kx = 0; kx < std::size(gModes); kx++) {
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000252 SkPaint paint;
reed1a9b9642016-03-13 14:13:58 -0700253 paint.setShader(fProc(gModes[kx], gModes[ky]));
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000254
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000255 canvas->save();
256 canvas->translate(x, y);
257 canvas->drawRect(r, paint);
258 canvas->restore();
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000259
mike@reedtribe.orga0591692012-10-18 02:01:59 +0000260 x += r.width() * 4 / 3;
261 }
262 y += r.height() * 4 / 3;
263 }
264 }
reed@android.com1a2fec52009-06-22 02:17:34 +0000265};
Hal Canary594fe852019-07-18 13:35:49 -0400266
267DEF_GM( return new Tiling2GM(make_bm, "tilemode_bitmap"); )
268DEF_GM( return new Tiling2GM(make_grad, "tilemode_gradient"); )
Mike Reeddfc0e912018-02-16 12:40:18 -0500269
270////////////////////
271
Michael Ludwigbe315a22018-12-17 09:50:51 -0500272DEF_SIMPLE_GM(tilemode_decal, canvas, 720, 1100) {
Kevin Lubick8b741882023-10-06 11:41:38 -0400273 auto img = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
Mike Reeddfc0e912018-02-16 12:40:18 -0500274 SkPaint bgpaint;
275 bgpaint.setColor(SK_ColorYELLOW);
276
277 SkRect r = { -20, -20, img->width() + 20.0f, img->height() + 20.0f };
Michael Ludwigbe315a22018-12-17 09:50:51 -0500278 canvas->translate(45, 45);
Mike Reeddfc0e912018-02-16 12:40:18 -0500279
Mike Reedfae8fce2019-04-03 10:27:45 -0400280 std::function<void(SkPaint*, SkTileMode, SkTileMode)> shader_procs[] = {
281 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
Michael Ludwigbe315a22018-12-17 09:50:51 -0500282 // Test no filtering with decal mode
Mike Reed2bdf6ed2021-07-15 21:34:48 -0400283 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kNearest)));
Michael Ludwigbe315a22018-12-17 09:50:51 -0500284 },
Mike Reedfae8fce2019-04-03 10:27:45 -0400285 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
Michael Ludwigbe315a22018-12-17 09:50:51 -0500286 // Test bilerp approximation for decal mode (or clamp to border HW)
Mike Reed2bdf6ed2021-07-15 21:34:48 -0400287 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kLinear)));
Michael Ludwigbe315a22018-12-17 09:50:51 -0500288 },
Mike Reedfae8fce2019-04-03 10:27:45 -0400289 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
Michael Ludwigbe315a22018-12-17 09:50:51 -0500290 // Test bicubic filter with decal mode
Mike Reed2bdf6ed2021-07-15 21:34:48 -0400291 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkCubicResampler::Mitchell())));
Mike Reeddfc0e912018-02-16 12:40:18 -0500292 },
Mike Reedfae8fce2019-04-03 10:27:45 -0400293 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
Mike Reeddfc0e912018-02-16 12:40:18 -0500294 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
295 const SkPoint pts[] = {{ 0, 0 }, {img->width()*1.0f, img->height()*1.0f }};
296 const SkScalar* pos = nullptr;
Herb Derbyc37b3862022-06-21 09:49:17 -0400297 const int count = std::size(colors);
Mike Reeddfc0e912018-02-16 12:40:18 -0500298 paint->setShader(SkGradientShader::MakeLinear(pts, colors, pos, count, tx));
299 },
Mike Reedfae8fce2019-04-03 10:27:45 -0400300 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
Mike Reeddfc0e912018-02-16 12:40:18 -0500301 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
302 const SkScalar* pos = nullptr;
Herb Derbyc37b3862022-06-21 09:49:17 -0400303 const int count = std::size(colors);
Mike Reeddfc0e912018-02-16 12:40:18 -0500304 paint->setShader(SkGradientShader::MakeRadial({ img->width()*0.5f, img->width()*0.5f },
305 img->width()*0.5f, colors, pos, count, tx));
306 },
307 };
308
309 const struct XY {
Mike Reedfae8fce2019-04-03 10:27:45 -0400310 SkTileMode fX;
311 SkTileMode fY;
Mike Reeddfc0e912018-02-16 12:40:18 -0500312 } pairs[] = {
Mike Reedfae8fce2019-04-03 10:27:45 -0400313 { SkTileMode::kClamp, SkTileMode::kClamp },
314 { SkTileMode::kClamp, SkTileMode::kDecal },
315 { SkTileMode::kDecal, SkTileMode::kClamp },
316 { SkTileMode::kDecal, SkTileMode::kDecal },
Mike Reeddfc0e912018-02-16 12:40:18 -0500317 };
318 for (const auto& p : pairs) {
319 SkPaint paint;
320 canvas->save();
321 for (const auto& proc : shader_procs) {
Michael Ludwigbe315a22018-12-17 09:50:51 -0500322 canvas->save();
323 // Apply a slight rotation to highlight the differences between filtered and unfiltered
324 // decal edges
325 canvas->rotate(4);
Mike Reeddfc0e912018-02-16 12:40:18 -0500326 canvas->drawRect(r, bgpaint);
327 proc(&paint, p.fX, p.fY);
328 canvas->drawRect(r, paint);
Michael Ludwigbe315a22018-12-17 09:50:51 -0500329 canvas->restore();
Mike Reeddfc0e912018-02-16 12:40:18 -0500330 canvas->translate(0, r.height() + 20);
331 }
332 canvas->restore();
333 canvas->translate(r.width() + 10, 0);
334 }
335}