blob: d26491d593adf5959aedd531198dd8ce63d891ee [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,
Mike Reedb339d052021-01-28 11:20:41 -050011 SkTileMode::kRepeat,
12 SkSamplingOptions(SkFilterMode::kLinear));
Hal Canary9d9312b2020-01-16 12:45:33 -050013}
14
15void draw(SkCanvas* canvas) {
16 canvas->drawColor(SK_ColorWHITE);
17
18 const SkRect r = { 0, 0, 100, 100 };
19 SkPaint p;
20 p.setShader(make());
Hal Canary9d9312b2020-01-16 12:45:33 -050021 // 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