Flutter Engine
The Flutter Engine
Enumerations | Functions | Variables
SkBlendMode.h File Reference
#include "include/core/SkTypes.h"

Go to the source code of this file.

Enumerations

enum class  SkBlendMode {
  kClear , kSrc , kDst , kSrcOver ,
  kDstOver , kSrcIn , kDstIn , kSrcOut ,
  kDstOut , kSrcATop , kDstATop , kXor ,
  kPlus , kModulate , kScreen , kOverlay ,
  kDarken , kLighten , kColorDodge , kColorBurn ,
  kHardLight , kSoftLight , kDifference , kExclusion ,
  kMultiply , kHue , kSaturation , kColor ,
  kLuminosity , kLastCoeffMode = kScreen , kLastSeparableMode = kMultiply , kLastMode = kLuminosity
}
 
enum class  SkBlendModeCoeff {
  kZero , kOne , kSC , kISC ,
  kDC , kIDC , kSA , kISA ,
  kDA , kIDA , kCoeffCount
}
 

Functions

SK_API bool SkBlendMode_AsCoeff (SkBlendMode mode, SkBlendModeCoeff *src, SkBlendModeCoeff *dst)
 
SK_API const char * SkBlendMode_Name (SkBlendMode blendMode)
 

Variables

static constexpr int kSkBlendModeCount = static_cast<int>(SkBlendMode::kLastMode) + 1
 

Enumeration Type Documentation

◆ SkBlendMode

enum class SkBlendMode
strong

Blends are operators that take in two colors (source, destination) and return a new color. Many of these operate the same on all 4 components: red, green, blue, alpha. For these, we just document what happens to one component, rather than naming each one separately.

Different SkColorTypes have different representations for color components: 8-bit: 0..255 6-bit: 0..63 5-bit: 0..31 4-bit: 0..15 floats: 0...1

The documentation is expressed as if the component values are always 0..1 (floats).

For brevity, the documentation uses the following abbreviations s : source d : destination sa : source alpha da : destination alpha

Results are abbreviated r : if all 4 components are computed in the same manner ra : result alpha component rc : result "color": red, green, blue components

Enumerator
kClear 

r = 0

kSrc 

r = s

kDst 

r = d

kSrcOver 

r = s + (1-sa)*d

kDstOver 

r = d + (1-da)*s

kSrcIn 

r = s * da

kDstIn 

r = d * sa

kSrcOut 

r = s * (1-da)

kDstOut 

r = d * (1-sa)

kSrcATop 

r = s*da + d*(1-sa)

kDstATop 

r = d*sa + s*(1-da)

kXor 

r = s*(1-da) + d*(1-sa)

kPlus 

r = min(s + d, 1)

kModulate 

r = s*d

kScreen 

r = s + d - s*d

kOverlay 

multiply or screen, depending on destination

kDarken 

rc = s + d - max(s*da, d*sa), ra = kSrcOver

kLighten 

rc = s + d - min(s*da, d*sa), ra = kSrcOver

kColorDodge 

brighten destination to reflect source

kColorBurn 

darken destination to reflect source

kHardLight 

multiply or screen, depending on source

kSoftLight 

lighten or darken, depending on source

kDifference 

rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver

kExclusion 

rc = s + d - two(s*d), ra = kSrcOver

kMultiply 

r = s*(1-da) + d*(1-sa) + s*d

kHue 

hue of source with saturation and luminosity of destination

kSaturation 

saturation of source with hue and luminosity of destination

kColor 

hue and saturation of source with luminosity of destination

kLuminosity 

luminosity of source with hue and saturation of destination

kLastCoeffMode 

last porter duff blend mode

kLastSeparableMode 

last blend mode operating separately on components

kLastMode 

last valid value

Definition at line 38 of file SkBlendMode.h.

38 {
39 kClear, //!< r = 0
40 kSrc, //!< r = s
41 kDst, //!< r = d
42 kSrcOver, //!< r = s + (1-sa)*d
43 kDstOver, //!< r = d + (1-da)*s
44 kSrcIn, //!< r = s * da
45 kDstIn, //!< r = d * sa
46 kSrcOut, //!< r = s * (1-da)
47 kDstOut, //!< r = d * (1-sa)
48 kSrcATop, //!< r = s*da + d*(1-sa)
49 kDstATop, //!< r = d*sa + s*(1-da)
50 kXor, //!< r = s*(1-da) + d*(1-sa)
51 kPlus, //!< r = min(s + d, 1)
52 kModulate, //!< r = s*d
53 kScreen, //!< r = s + d - s*d
54
55 kOverlay, //!< multiply or screen, depending on destination
56 kDarken, //!< rc = s + d - max(s*da, d*sa), ra = kSrcOver
57 kLighten, //!< rc = s + d - min(s*da, d*sa), ra = kSrcOver
58 kColorDodge, //!< brighten destination to reflect source
59 kColorBurn, //!< darken destination to reflect source
60 kHardLight, //!< multiply or screen, depending on source
61 kSoftLight, //!< lighten or darken, depending on source
62 kDifference, //!< rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
63 kExclusion, //!< rc = s + d - two(s*d), ra = kSrcOver
64 kMultiply, //!< r = s*(1-da) + d*(1-sa) + s*d
65
66 kHue, //!< hue of source with saturation and luminosity of destination
67 kSaturation, //!< saturation of source with hue and luminosity of destination
68 kColor, //!< hue and saturation of source with luminosity of destination
69 kLuminosity, //!< luminosity of source with hue and saturation of destination
70
71 kLastCoeffMode = kScreen, //!< last porter duff blend mode
72 kLastSeparableMode = kMultiply, //!< last blend mode operating separately on components
73 kLastMode = kLuminosity, //!< last valid value
74};
@ 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
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kLastCoeffMode
last porter duff blend mode
@ 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)
@ kLastSeparableMode
last blend mode operating separately on components
@ 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

◆ SkBlendModeCoeff

enum class SkBlendModeCoeff
strong

For Porter-Duff SkBlendModes (those <= kLastCoeffMode), these coefficients describe the blend equation used. Coefficient-based blend modes specify an equation: ('dstCoeff' * dst + 'srcCoeff' * src), where the coefficient values are constants, functions of the src or dst alpha, or functions of the src or dst color.

Enumerator
kZero 
kOne 

0

kSC 

1

kISC 

src color

kDC 

inverse src color (i.e. 1 - sc)

kIDC 

dst color

kSA 

inverse dst color (i.e. 1 - dc)

kISA 

src alpha

kDA 

inverse src alpha (i.e. 1 - sa)

kIDA 

dst alpha

kCoeffCount 

inverse dst alpha (i.e. 1 - da)

Definition at line 84 of file SkBlendMode.h.

84 {
85 kZero, /** 0 */
86 kOne, /** 1 */
87 kSC, /** src color */
88 kISC, /** inverse src color (i.e. 1 - sc) */
89 kDC, /** dst color */
90 kIDC, /** inverse dst color (i.e. 1 - dc) */
91 kSA, /** src alpha */
92 kISA, /** inverse src alpha (i.e. 1 - sa) */
93 kDA, /** dst alpha */
94 kIDA, /** inverse dst alpha (i.e. 1 - da) */
95
97};

Function Documentation

◆ SkBlendMode_AsCoeff()

SK_API bool SkBlendMode_AsCoeff ( SkBlendMode  mode,
SkBlendModeCoeff src,
SkBlendModeCoeff dst 
)

Returns true if 'mode' is a coefficient-based blend mode (<= kLastCoeffMode). If true is returned, the mode's src and dst coefficient functions are set in 'src' and 'dst'.

Definition at line 57 of file SkBlendMode.cpp.

57 {
58 struct CoeffRec {
61 };
62
63 static constexpr CoeffRec kCoeffs[] = {
64 // For Porter-Duff blend functions, color = src * src coeff + dst * dst coeff
65 // src coeff dst coeff blend func
66 // ---------------------- ----------------------- ----------
79
83 };
84
86 return false;
87 }
88 if (src) {
89 *src = kCoeffs[static_cast<int>(mode)].fSrc;
90 }
91 if (dst) {
92 *dst = kCoeffs[static_cast<int>(mode)].fDst;
93 }
94 return true;
95}
SkRect fDst
Definition: LatticeOp.cpp:381
@ kScreen
r = s + d - s*d
SkBlendModeCoeff
Definition: SkBlendMode.h:84
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
dst
Definition: cp.py:12

◆ SkBlendMode_Name()

SK_API const char * SkBlendMode_Name ( SkBlendMode  blendMode)

Returns name of blendMode as null-terminated C string.

Returns
C string

Definition at line 167 of file SkBlendMode.cpp.

167 {
168 switch (bm) {
169 case SkBlendMode::kClear: return "Clear";
170 case SkBlendMode::kSrc: return "Src";
171 case SkBlendMode::kDst: return "Dst";
172 case SkBlendMode::kSrcOver: return "SrcOver";
173 case SkBlendMode::kDstOver: return "DstOver";
174 case SkBlendMode::kSrcIn: return "SrcIn";
175 case SkBlendMode::kDstIn: return "DstIn";
176 case SkBlendMode::kSrcOut: return "SrcOut";
177 case SkBlendMode::kDstOut: return "DstOut";
178 case SkBlendMode::kSrcATop: return "SrcATop";
179 case SkBlendMode::kDstATop: return "DstATop";
180 case SkBlendMode::kXor: return "Xor";
181 case SkBlendMode::kPlus: return "Plus";
182 case SkBlendMode::kModulate: return "Modulate";
183 case SkBlendMode::kScreen: return "Screen";
184
185 case SkBlendMode::kOverlay: return "Overlay";
186 case SkBlendMode::kDarken: return "Darken";
187 case SkBlendMode::kLighten: return "Lighten";
188 case SkBlendMode::kColorDodge: return "ColorDodge";
189 case SkBlendMode::kColorBurn: return "ColorBurn";
190 case SkBlendMode::kHardLight: return "HardLight";
191 case SkBlendMode::kSoftLight: return "SoftLight";
192 case SkBlendMode::kDifference: return "Difference";
193 case SkBlendMode::kExclusion: return "Exclusion";
194 case SkBlendMode::kMultiply: return "Multiply";
195
196 case SkBlendMode::kHue: return "Hue";
197 case SkBlendMode::kSaturation: return "Saturation";
198 case SkBlendMode::kColor: return "Color";
199 case SkBlendMode::kLuminosity: return "Luminosity";
200 }
202}
#define SkUNREACHABLE
Definition: SkAssert.h:135
@ 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
@ 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

Variable Documentation

◆ kSkBlendModeCount

constexpr int kSkBlendModeCount = static_cast<int>(SkBlendMode::kLastMode) + 1
staticconstexpr

Definition at line 76 of file SkBlendMode.h.