Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Modulate.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4// HASH=3fdac2b2f48bd227d2e74234c260bc8e
5REG_FIDDLE(Modulate, 256, 256, false, 0) {
6void draw(SkCanvas* canvas) {
7 auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void {
8 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
9 const SkPoint horz[] = { { 0, 0 }, { 128, 0 } };
11 paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, std::size(colors),
13 paint.setBlendMode(mode);
14 canvas->translate(dx, dy);
15 canvas->drawRect({0, 0, 128, 128}, paint);
16 paint.setBlendMode(SkBlendMode::kXor);
17 SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {}));
18 canvas->drawString(label, 40, 100, font, paint);
19 };
20 drawSquare(0, 0, SkBlendMode::kSrc, "destination");
21 drawSquare(128, 0, SkBlendMode::kSrc, "");
22 drawSquare(0, 128, SkBlendMode::kSrc, "");
23 canvas->translate(-128, -128);
24 canvas->rotate(90, 0, 128);
25 drawSquare(0, 0, SkBlendMode::kSrc, "source");
26 drawSquare(0, -128, SkBlendMode::kModulate, "modulate");
27 drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply");
28}
29} // END FIDDLE
SkBlendMode
Definition SkBlendMode.h:38
@ kModulate
r = s*d
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kXor
r = s*(1-da) + d*(1-sa)
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
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)
void translate(SkScalar dx, SkScalar dy)
void rotate(SkScalar degrees)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
const Paint & paint
sk_sp< SkFontMgr > fontMgr
Definition examples.cpp:32
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60