Flutter Engine
The Flutter Engine
50_percent_srgb.cpp
Go to the documentation of this file.
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.
4REG_FIDDLE_SRGB(50_percent_srgb, 256, 256, false, 0, 0, false) {
5static sk_sp<SkShader> make() {
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,
13}
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());
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
REG_FIDDLE_SRGB(50_percent_srgb, 256, 256, false, 0, 0, false)
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
Definition: encode_srgb.cpp:35
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)