Flutter Engine
The Flutter Engine
skpaint_xfer.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(skpaint_xfer, 576, 640, false, 0) {
5static void draw_utf8_string(SkCanvas* c, const char* t, SkScalar x, SkScalar y,
6 const SkFont& f, const SkPaint& p) {
8}
9
10void draw(SkCanvas* canvas) {
11 SkBlendMode modes[] = {
41 };
42 SkRect rect = SkRect::MakeWH(64.0f, 64.0f);
45 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 24);
46 SkPoint srcPoints[2] = {
47 SkPoint::Make(0.0f, 0.0f),
48 SkPoint::Make(64.0f, 0.0f)
49 };
50 SkColor srcColors[2] = {
51 SK_ColorMAGENTA & 0x00FFFFFF,
54 srcPoints, srcColors, nullptr, 2,
55 SkTileMode::kClamp, 0, nullptr));
56
57 SkPoint dstPoints[2] = {
58 SkPoint::Make(0.0f, 0.0f),
59 SkPoint::Make(0.0f, 64.0f)
60 };
61 SkColor dstColors[2] = {
62 SK_ColorCYAN & 0x00FFFFFF,
65 dstPoints, dstColors, nullptr, 2,
66 SkTileMode::kClamp, 0, nullptr));
67 canvas->clear(SK_ColorWHITE);
68 size_t N = sizeof(modes) / sizeof(modes[0]);
69 size_t K = (N - 1) / 3 + 1;
70 SkASSERT(K * 64 == 640); // tall enough
71 for (size_t i = 0; i < N; ++i) {
72 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
73 canvas->translate(192.0f * (i / K), 64.0f * (i % K));
74 const char* desc = SkBlendMode_Name(modes[i]);
75 draw_utf8_string(canvas, desc, 68.0f, 30.0f, font, SkPaint());
76 canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f));
78 (void)canvas->saveLayer(nullptr, nullptr);
80 canvas->drawPaint(dst);
81 src.setBlendMode(modes[i]);
82 canvas->drawPaint(src);
83 canvas->drawRect(rect, stroke);
84 }
85}
86} // END FIDDLE
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOut
r = s * (1-da)
@ kExclusion
rc = s + d - two(s*d), ra = kSrcOver
@ kSaturation
saturation of source with hue and luminosity of destination
@ kColorBurn
darken destination to reflect source
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kHue
hue of source with saturation and luminosity of destination
@ kDstIn
r = d * sa
@ kModulate
r = s*d
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kColorDodge
brighten destination to reflect source
@ kScreen
r = s + d - s*d
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kSoftLight
lighten or darken, depending on source
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
@ 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
@ kColor
hue and saturation of source with luminosity of destination
@ kHardLight
multiply or screen, depending on source
@ kDstOut
r = d * (1-sa)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ kSrcIn
r = s * da
@ kClear
r = 0
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
#define N
Definition: beziers.cpp:19
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
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)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.h:115
static const int K
Definition: daa.cpp:21
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
font
Font Metadata and Metrics.
dst
Definition: cp.py:12
const myers::Point & get(const myers::Segment &)
REG_FIDDLE(skpaint_xfer, 576, 640, false, 0)
Definition: skpaint_xfer.cpp:4
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