Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkXfermode.h
1 /*
2  * Copyright 2006 The Android Open Source Project
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 
8 #ifndef SkXfermode_DEFINED
9 #define SkXfermode_DEFINED
10 
11 #include "SkFlattenable.h"
12 #include "SkColor.h"
13 
15 class GrTexture;
16 class GrXPFactory;
17 class SkRasterPipeline;
18 class SkString;
19 
20 struct SkPM4f;
21 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst);
22 
34 class SK_API SkXfermode : public SkFlattenable {
35 public:
36  virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
37  const SkAlpha aa[]) const;
38  virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
39  const SkAlpha aa[]) const;
40  virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
41  const SkAlpha aa[]) const;
42 
45  enum Coeff {
46  kZero_Coeff,
57  kCoeffCount
58  };
59 
71  enum Mode {
85  kModulate_Mode, // multiplies all components (= alpha and color)
86 
87  // Following blend modes are defined in the CSS Compositing standard:
88  // https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blending
89  kScreen_Mode,
90  kLastCoeffMode = kScreen_Mode,
91 
92  kOverlay_Mode,
93  kDarken_Mode,
94  kLighten_Mode,
95  kColorDodge_Mode,
96  kColorBurn_Mode,
97  kHardLight_Mode,
98  kSoftLight_Mode,
99  kDifference_Mode,
100  kExclusion_Mode,
101  kMultiply_Mode,
102  kLastSeparableMode = kMultiply_Mode,
103 
104  kHue_Mode,
105  kSaturation_Mode,
106  kColor_Mode,
107  kLuminosity_Mode,
108  kLastMode = kLuminosity_Mode
109  };
110 
114  static const char* ModeName(Mode);
115 
121  virtual bool asMode(Mode* mode) const;
122 
127  static bool AsMode(const SkXfermode*, Mode* mode);
128  static bool AsMode(const sk_sp<SkXfermode>& xfer, Mode* mode) {
129  return AsMode(xfer.get(), mode);
130  }
131 
142  static bool IsMode(const SkXfermode* xfer, Mode mode);
143  static bool IsMode(const sk_sp<SkXfermode>& xfer, Mode mode) {
144  return IsMode(xfer.get(), mode);
145  }
146 
149  static sk_sp<SkXfermode> Make(Mode);
150 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
151  static SkXfermode* Create(Mode mode) {
152  return Make(mode).release();
153  }
154  SK_ATTR_DEPRECATED("use AsMode(...)")
155  static bool IsMode(const SkXfermode* xfer, Mode* mode) {
156  return AsMode(xfer, mode);
157  }
158 #endif
159 
163  static SkXfermodeProc GetProc(Mode mode);
164  static SkXfermodeProc4f GetProc4f(Mode);
165 
166  virtual SkXfermodeProc4f getProc4f() const;
167 
168  bool appendStages(SkRasterPipeline*) const;
169 
176  static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst);
177 
181  virtual bool supportsCoverageAsAlpha() const;
182 
187  static bool SupportsCoverageAsAlpha(const SkXfermode* xfer);
188  static bool SupportsCoverageAsAlpha(const sk_sp<SkXfermode>& xfer) {
189  return SupportsCoverageAsAlpha(xfer.get());
190  }
191 
192  enum SrcColorOpacity {
193  // The src color is known to be opaque (alpha == 255)
194  kOpaque_SrcColorOpacity = 0,
195  // The src color is known to be fully transparent (color == 0)
196  kTransparentBlack_SrcColorOpacity = 1,
197  // The src alpha is known to be fully transparent (alpha == 0)
198  kTransparentAlpha_SrcColorOpacity = 2,
199  // The src color opacity is unknown
200  kUnknown_SrcColorOpacity = 3
201  };
202 
208  virtual bool isOpaque(SrcColorOpacity opacityType) const;
209 
214  static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType);
215  static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityType) {
216  return IsOpaque(xfer.get(), opacityType);
217  }
218 
219 #if SK_SUPPORT_GPU
220 
226  virtual sk_sp<GrFragmentProcessor> makeFragmentProcessorForImageFilter(
227  sk_sp<GrFragmentProcessor> dst) const;
228 
233  virtual sk_sp<GrXPFactory> asXPFactory() const;
234 #endif
235 
236  SK_TO_STRING_PUREVIRT()
237  SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
238  SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
239 
240  enum D32Flags {
241  kSrcIsOpaque_D32Flag = 1 << 0,
242  kSrcIsSingle_D32Flag = 1 << 1,
243  kDstIsSRGB_D32Flag = 1 << 2,
244  };
245  typedef void (*D32Proc)(const SkXfermode*, uint32_t dst[], const SkPM4f src[],
246  int count, const SkAlpha coverage[]);
247  static D32Proc GetD32Proc(SkXfermode*, uint32_t flags);
248  static D32Proc GetD32Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
249  return GetD32Proc(xfer.get(), flags);
250  }
251 
252  enum F16Flags {
253  kSrcIsOpaque_F16Flag = 1 << 0,
254  kSrcIsSingle_F16Flag = 1 << 1,
255  };
256  typedef void (*F16Proc)(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
257  const SkAlpha coverage[]);
258  static F16Proc GetF16Proc(SkXfermode*, uint32_t flags);
259  static F16Proc GetF16Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
260  return GetF16Proc(xfer.get(), flags);
261  }
262 
263  enum LCDFlags {
264  kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1
265  kSrcIsSingle_LCDFlag = 1 << 1, // else src[count]
266  kDstIsSRGB_LCDFlag = 1 << 2, // else l32 or f16
267  };
268  typedef void (*LCD32Proc)(uint32_t* dst, const SkPM4f* src, int count, const uint16_t lcd[]);
269  typedef void (*LCDF16Proc)(uint64_t* dst, const SkPM4f* src, int count, const uint16_t lcd[]);
270  static LCD32Proc GetLCD32Proc(uint32_t flags);
271  static LCDF16Proc GetLCDF16Proc(uint32_t) { return nullptr; }
272 
273 protected:
274  SkXfermode() {}
283  virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
284 
285  virtual D32Proc onGetD32Proc(uint32_t flags) const;
286  virtual F16Proc onGetF16Proc(uint32_t flags) const;
287  virtual bool onAppendStages(SkRasterPipeline*) const;
288 
289 private:
290  enum {
291  kModeCount = kLastMode + 1
292  };
293 
294  typedef SkFlattenable INHERITED;
295 };
296 
297 #endif
0
Definition: SkXfermode.h:47
src alpha
Definition: SkXfermode.h:53
[Sa * (1 - Da), Sc * (1 - Da)]
Definition: SkXfermode.h:79
src color
Definition: SkXfermode.h:49
[Sa, Sc]
Definition: SkXfermode.h:73
Provides custom fragment shader code.
Definition: GrFragmentProcessor.h:24
inverse src color (i.e.
Definition: SkXfermode.h:50
Mode
List of predefined xfermodes.
Definition: SkXfermode.h:71
inverse dst color (i.e.
Definition: SkXfermode.h:52
[Sa + Da * (1 - Sa), Sc + Dc * (1 - Sa)]
Definition: SkXfermode.h:75
[Da * Sa, Dc * Sa]
Definition: SkXfermode.h:78
[Da, Sc * Da + Dc * (1 - Sa)]
Definition: SkXfermode.h:81
[Sa + Da, Sc + Dc]
Definition: SkXfermode.h:84
uint8_t SkAlpha
8-bit type for an alpha value.
Definition: SkColor.h:22
inverse src alpha (i.e.
Definition: SkXfermode.h:54
[0, 0]
Definition: SkXfermode.h:72
SkXfermode is the base class for objects that are called to implement custom "transfer-modes" in the ...
Definition: SkXfermode.h:34
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
[Sa * Da, Sc * Da]
Definition: SkXfermode.h:77
[Da + Sa * (1 - Da), Dc + Sc * (1 - Da)]
Definition: SkXfermode.h:76
SkPMColor(* SkXfermodeProc)(SkPMColor src, SkPMColor dst)
Define a function pointer type for combining two premultiplied colors.
Definition: SkColor.h:160
[Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa)]
Definition: SkXfermode.h:83
1
Definition: SkXfermode.h:48
[Sa, Dc * Sa + Sc * (1 - Da)]
Definition: SkXfermode.h:82
dst alpha
Definition: SkXfermode.h:55
[Da * (1 - Sa), Dc * (1 - Sa)]
Definition: SkXfermode.h:80
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
dst color
Definition: SkXfermode.h:51
[Da, Dc]
Definition: SkXfermode.h:74
Definition: GrTexture.h:19
We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is know...
Definition: GrXferProcessor.h:301
Coeff
Enum of possible coefficients to describe some xfermodes.
Definition: SkXfermode.h:45
Light weight class for managing strings.
Definition: SkString.h:121
Types and macros for colors.