1 // Copyright 2020 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE_SRGB(50_percent_srgb, 256, 256, false, 0, 0, false) {
make()5 static sk_sp<SkShader> make() {
6 auto surf = SkSurface::MakeRasterN32Premul(2, 2);
7 surf->getCanvas()->drawColor(SK_ColorWHITE);
8 surf->getCanvas()->drawRect({0, 0, 1, 1}, SkPaint());
9 surf->getCanvas()->drawRect({1, 1, 2, 2}, SkPaint());
10 return surf->makeImageSnapshot()->makeShader(SkTileMode::kRepeat,
11 SkTileMode::kRepeat,
12 SkSamplingOptions(SkFilterMode::kLinear));
13 }
14
draw(SkCanvas * canvas)15 void draw(SkCanvas* canvas) {
16 canvas->drawColor(SK_ColorWHITE);
17
18 const SkRect r = { 0, 0, 100, 100 };
19 SkPaint p;
20 p.setShader(make());
21 // this is a dither
22 canvas->drawRect({0, 0, 50, 50}, p);
23
24 canvas->scale(0.5, 0.5);
25 canvas->translate(100, 0);
26 canvas->drawRect(r, p);
27 p.setShader(nullptr);
28
29 p.setColor(0xFF808080);
30 canvas->translate(100, 0);
31 canvas->drawRect(r, p);
32
33 p.setColor(0x80000000);
34 canvas->translate(100, 0);
35 canvas->drawRect(r, p);
36 }
37 } // END FIDDLE
38