Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkBlendModeBlender.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
19
21#define RETURN_SINGLETON_BLENDER(m) \
22 case m: { \
23 static SkNoDestructor<SkBlendModeBlender> sBlender(m); \
24 return sk_ref_sp(sBlender.get()); \
25 }
26
27 switch (mode) {
57 }
58
59 SkDEBUGFAILF("invalid blend mode %d", (int)mode);
60 return nullptr;
61
62#undef RETURN_SINGLETON_BLENDER
63}
64
65sk_sp<SkFlattenable> SkBlendModeBlender::CreateProc(SkReadBuffer& buffer) {
67 return SkBlender::Mode(mode);
68}
69
71 buffer.writeInt((int)fMode);
72}
73
76 return true;
77}
78
80 if (auto blendMode = this->asBlendMode()) {
81 SkBlendModeCoeff src, dst;
82 if (SkBlendMode_AsCoeff(*blendMode, &src, &dst)) {
83 // If the source is (0,0,0,0), then dst is preserved as long as its coefficient
84 // evaluates to 1.0. This is true for kOne, kISA, and kISC. Anything else means the
85 // blend mode affects transparent black.
86 return dst != SkBlendModeCoeff::kOne &&
89 } else {
90 // An advanced blend mode, which do not affect transparent black
91 return false;
92 }
93 } else {
94 // Blenders that aren't blend modes are assumed to modify transparent black.
95 return true;
96 }
97}
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119
#define RETURN_SINGLETON_BLENDER(m)
void SkBlendMode_AppendStages(SkBlendMode mode, SkRasterPipeline *p)
SK_API bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff *src, SkBlendModeCoeff *dst)
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
@ kLastMode
last valid value
@ 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
SkBlendModeCoeff
Definition SkBlendMode.h:84
void flatten(SkWriteBuffer &buffer) const override
bool onAppendStages(const SkStageRec &rec) const override
SkBlendMode mode() const
bool affectsTransparentBlack() const
virtual std::optional< SkBlendMode > asBlendMode() const
static sk_sp< SkBlender > Mode(SkBlendMode mode)
static const uint8_t buffer[]
SkRasterPipeline * fPipeline