Flutter Engine
The Flutter Engine
BlendModes.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(BlendModes, 256, 4352, false, 0) {
5void drawBG(SkCanvas* canvas) {
6 SkColor radColors[] = {0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF};
7 auto rad = SkGradientShader::MakeRadial(SkPoint::Make(128, 128), 128, radColors, nullptr, 3,
9
10 SkMatrix rotMtx;
11 rotMtx.setRotate(-90, 128, 128);
12 SkColor sweepColors[] = {0xFFFF00FF, 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00,
13 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF};
14 auto sweep = SkGradientShader::MakeSweep(128, 128, sweepColors, nullptr, 7, 0, &rotMtx);
15
16 auto comp = SkShaders::Blend(SkBlendMode::kModulate, std::move(rad), std::move(sweep));
17 SkPaint p;
18 p.setShader(std::move(comp));
19
20 canvas->drawPaint(p);
21}
22
23void draw(SkCanvas* canvas) {
24 SkBlendMode blendModes[] = {
42 };
43
44 SkPaint labelPaint;
45 labelPaint.setAntiAlias(true);
46 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12);
47
48 for (auto mode : blendModes) {
49 SkPaint layerPaint;
50 layerPaint.setBlendMode(mode);
51
52 canvas->save();
53 canvas->clipRect(SkRect::MakeWH(256, 256));
54
55 drawBG(canvas);
56
57 canvas->saveLayer(nullptr, &layerPaint);
58 const SkScalar r = 80;
59 SkPaint discP;
60 discP.setAntiAlias(true);
62 discP.setColor(SK_ColorGREEN); canvas->drawCircle(128, r, r, discP);
63 discP.setColor(SK_ColorRED); canvas->drawCircle(r, 256 - r, r, discP);
64 discP.setColor(SK_ColorBLUE); canvas->drawCircle(256 - r, 256 - r, r, discP);
65 canvas->restore();
66
68 SkTextEncoding::kUTF8, 10, 10, font, labelPaint);
69 canvas->restore();
70 canvas->translate(0, 256);
71 }
72}
73} // END FIDDLE
static void drawBG(SkCanvas *canvas)
Definition: BlurTest.cpp:66
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOut
r = s * (1-da)
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kDstIn
r = d * sa
@ kModulate
r = s*d
@ kScreen
r = s + d - s*d
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kOverlay
multiply or screen, depending on destination
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
@ kDstOut
r = d * (1-sa)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ kSrcIn
r = s * da
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
int save()
Definition: SkCanvas.cpp:447
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
REG_FIDDLE(BlendModes, 256, 4352, false, 0)
Definition: BlendModes.cpp:4
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
font
Font Metadata and Metrics.
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609