blob: 61746dd04557e14a963bc67e576555e0324cf432 [file] [log] [blame]
Hal Canary9d9312b2020-01-16 12:45:33 -05001// 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"
4REG_FIDDLE_SRGB(50_percent_srgb, 256, 256, false, 0, 0, false) {
5static 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}
13
14void draw(SkCanvas* canvas) {
15 canvas->drawColor(SK_ColorWHITE);
16
17 const SkRect r = { 0, 0, 100, 100 };
18 SkPaint p;
19 p.setShader(make());
20 p.setFilterQuality(kLow_SkFilterQuality);
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