2d1b7165a4
//tools/fiddle/make_all_examples_cpp.py had not run in a while, so some of these fiddles were not being compiled regularly and bit-rotted. A follow-up CL will try running that script as a presubmit. Change-Id: Ib851cb5d70485e354de3388abf56666492335d46 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423956 Commit-Queue: Kevin Lubick <kjlubick@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
56 lines
1.9 KiB
C++
56 lines
1.9 KiB
C++
// Copyright 2020 Google LLC.
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
#include "tools/fiddle/examples.h"
|
|
REG_FIDDLE_SRGB(50_percent_gray, 530, 150, false, 0, 0, false) {
|
|
static sk_sp<SkShader> make_bw_dither() {
|
|
auto surf = SkSurface::MakeRasterN32Premul(2, 2);
|
|
surf->getCanvas()->drawColor(SK_ColorWHITE);
|
|
surf->getCanvas()->drawRect({0, 0, 1, 1}, SkPaint());
|
|
surf->getCanvas()->drawRect({1, 1, 2, 2}, SkPaint());
|
|
return surf->makeImageSnapshot()->makeShader(SkTileMode::kRepeat,
|
|
SkTileMode::kRepeat,
|
|
SkSamplingOptions(SkFilterMode::kLinear));
|
|
}
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
SkFont font(nullptr, 12);
|
|
|
|
// BW Dither
|
|
canvas->translate(5, 5);
|
|
SkPaint p;
|
|
p.setShader(make_bw_dither());
|
|
canvas->drawRect({0, 0, 100, 100}, p);
|
|
SkPaint black;
|
|
canvas->drawString("BW Dither", 0, 125, font, black);
|
|
|
|
// Scaled BW Dither
|
|
canvas->translate(105, 0);
|
|
canvas->save();
|
|
canvas->scale(0.5, 0.5);
|
|
canvas->drawRect({0, 0, 200, 200}, p);
|
|
canvas->restore();
|
|
canvas->drawString("Scaled Dither", 0, 125, font, black);
|
|
|
|
// Blend black on to white
|
|
canvas->translate(105, 0);
|
|
p.setColor(0x80000000);
|
|
p.setShader(nullptr);
|
|
canvas->drawRect({0, 0, 100, 100}, p);
|
|
p.setShader(nullptr);
|
|
canvas->drawString("Blend", 0, 125, font, black);
|
|
|
|
// Opaque color (0xFFBCBCBC)
|
|
canvas->translate(105, 0);
|
|
p.setColor(0xFFBCBCBC);
|
|
canvas->drawRect({0, 0, 100, 100}, p);
|
|
canvas->drawString("0xFFBCBCBC", 0, 125, font, black);
|
|
|
|
// Opaque color (0xFF808080)
|
|
canvas->translate(105, 0);
|
|
p.setColor(0xFF808080);
|
|
canvas->drawRect({0, 0, 100, 100}, p);
|
|
canvas->drawString("0xFF808080", 0, 125, font, black);
|
|
}
|
|
} // END FIDDLE
|