gfx/skia/trunk/include/core/SkXfermode.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkXfermode_DEFINED
michael@0 11 #define SkXfermode_DEFINED
michael@0 12
michael@0 13 #include "SkFlattenable.h"
michael@0 14 #include "SkColor.h"
michael@0 15
michael@0 16 class GrEffectRef;
michael@0 17 class GrTexture;
michael@0 18 class SkString;
michael@0 19
michael@0 20 /** \class SkXfermode
michael@0 21 *
michael@0 22 * SkXfermode is the base class for objects that are called to implement custom
michael@0 23 * "transfer-modes" in the drawing pipeline. The static function Create(Modes)
michael@0 24 * can be called to return an instance of any of the predefined subclasses as
michael@0 25 * specified in the Modes enum. When an SkXfermode is assigned to an SkPaint,
michael@0 26 * then objects drawn with that paint have the xfermode applied.
michael@0 27 *
michael@0 28 * All subclasses are required to be reentrant-safe : it must be legal to share
michael@0 29 * the same instance between several threads.
michael@0 30 */
michael@0 31 class SK_API SkXfermode : public SkFlattenable {
michael@0 32 public:
michael@0 33 SK_DECLARE_INST_COUNT(SkXfermode)
michael@0 34
michael@0 35 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
michael@0 36 const SkAlpha aa[]) const;
michael@0 37 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
michael@0 38 const SkAlpha aa[]) const;
michael@0 39 virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
michael@0 40 const SkAlpha aa[]) const;
michael@0 41
michael@0 42 /** Enum of possible coefficients to describe some xfermodes
michael@0 43 */
michael@0 44 enum Coeff {
michael@0 45 kZero_Coeff, /** 0 */
michael@0 46 kOne_Coeff, /** 1 */
michael@0 47 kSC_Coeff, /** src color */
michael@0 48 kISC_Coeff, /** inverse src color (i.e. 1 - sc) */
michael@0 49 kDC_Coeff, /** dst color */
michael@0 50 kIDC_Coeff, /** inverse dst color (i.e. 1 - dc) */
michael@0 51 kSA_Coeff, /** src alpha */
michael@0 52 kISA_Coeff, /** inverse src alpha (i.e. 1 - sa) */
michael@0 53 kDA_Coeff, /** dst alpha */
michael@0 54 kIDA_Coeff, /** inverse dst alpha (i.e. 1 - da) */
michael@0 55
michael@0 56 kCoeffCount
michael@0 57 };
michael@0 58
michael@0 59 /** If the xfermode can be expressed as an equation using the coefficients
michael@0 60 in Coeff, then asCoeff() returns true, and sets (if not null) src and
michael@0 61 dst accordingly.
michael@0 62
michael@0 63 result = src_coeff * src_color + dst_coeff * dst_color;
michael@0 64
michael@0 65 As examples, here are some of the porterduff coefficients
michael@0 66
michael@0 67 MODE SRC_COEFF DST_COEFF
michael@0 68 clear zero zero
michael@0 69 src one zero
michael@0 70 dst zero one
michael@0 71 srcover one isa
michael@0 72 dstover ida one
michael@0 73 */
michael@0 74 virtual bool asCoeff(Coeff* src, Coeff* dst) const;
michael@0 75
michael@0 76 /**
michael@0 77 * The same as calling xfermode->asCoeff(..), except that this also checks
michael@0 78 * if the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
michael@0 79 */
michael@0 80 static bool AsCoeff(const SkXfermode*, Coeff* src, Coeff* dst);
michael@0 81
michael@0 82 /** List of predefined xfermodes.
michael@0 83 The algebra for the modes uses the following symbols:
michael@0 84 Sa, Sc - source alpha and color
michael@0 85 Da, Dc - destination alpha and color (before compositing)
michael@0 86 [a, c] - Resulting (alpha, color) values
michael@0 87 For these equations, the colors are in premultiplied state.
michael@0 88 If no xfermode is specified, kSrcOver is assumed.
michael@0 89 The modes are ordered by those that can be expressed as a pair of Coeffs, followed by those
michael@0 90 that aren't Coeffs but have separable r,g,b computations, and finally
michael@0 91 those that are not separable.
michael@0 92 */
michael@0 93 enum Mode {
michael@0 94 kClear_Mode, //!< [0, 0]
michael@0 95 kSrc_Mode, //!< [Sa, Sc]
michael@0 96 kDst_Mode, //!< [Da, Dc]
michael@0 97 kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
michael@0 98 kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
michael@0 99 kSrcIn_Mode, //!< [Sa * Da, Sc * Da]
michael@0 100 kDstIn_Mode, //!< [Sa * Da, Sa * Dc]
michael@0 101 kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)]
michael@0 102 kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)]
michael@0 103 kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc]
michael@0 104 kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)]
michael@0 105 kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
michael@0 106 kPlus_Mode, //!< [Sa + Da, Sc + Dc]
michael@0 107 kModulate_Mode, // multiplies all components (= alpha and color)
michael@0 108
michael@0 109 // Following blend modes are defined in the CSS Compositing standard:
michael@0 110 // https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blending
michael@0 111 kScreen_Mode,
michael@0 112 kLastCoeffMode = kScreen_Mode,
michael@0 113
michael@0 114 kOverlay_Mode,
michael@0 115 kDarken_Mode,
michael@0 116 kLighten_Mode,
michael@0 117 kColorDodge_Mode,
michael@0 118 kColorBurn_Mode,
michael@0 119 kHardLight_Mode,
michael@0 120 kSoftLight_Mode,
michael@0 121 kDifference_Mode,
michael@0 122 kExclusion_Mode,
michael@0 123 kMultiply_Mode,
michael@0 124 kLastSeparableMode = kMultiply_Mode,
michael@0 125
michael@0 126 kHue_Mode,
michael@0 127 kSaturation_Mode,
michael@0 128 kColor_Mode,
michael@0 129 kLuminosity_Mode,
michael@0 130 kLastMode = kLuminosity_Mode
michael@0 131 };
michael@0 132
michael@0 133 /**
michael@0 134 * Gets the name of the Mode as a string.
michael@0 135 */
michael@0 136 static const char* ModeName(Mode);
michael@0 137
michael@0 138 /**
michael@0 139 * If the xfermode is one of the modes in the Mode enum, then asMode()
michael@0 140 * returns true and sets (if not null) mode accordingly. Otherwise it
michael@0 141 * returns false and ignores the mode parameter.
michael@0 142 */
michael@0 143 virtual bool asMode(Mode* mode) const;
michael@0 144
michael@0 145 /**
michael@0 146 * The same as calling xfermode->asMode(mode), except that this also checks
michael@0 147 * if the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
michael@0 148 */
michael@0 149 static bool AsMode(const SkXfermode*, Mode* mode);
michael@0 150
michael@0 151 /**
michael@0 152 * Returns true if the xfermode claims to be the specified Mode. This works
michael@0 153 * correctly even if the xfermode is NULL (which equates to kSrcOver.) Thus
michael@0 154 * you can say this without checking for a null...
michael@0 155 *
michael@0 156 * If (SkXfermode::IsMode(paint.getXfermode(),
michael@0 157 * SkXfermode::kDstOver_Mode)) {
michael@0 158 * ...
michael@0 159 * }
michael@0 160 */
michael@0 161 static bool IsMode(const SkXfermode* xfer, Mode mode);
michael@0 162
michael@0 163 /** Return an SkXfermode object for the specified mode.
michael@0 164 */
michael@0 165 static SkXfermode* Create(Mode mode);
michael@0 166
michael@0 167 /** Return a function pointer to a routine that applies the specified
michael@0 168 porter-duff transfer mode.
michael@0 169 */
michael@0 170 static SkXfermodeProc GetProc(Mode mode);
michael@0 171
michael@0 172 /** Return a function pointer to a routine that applies the specified
michael@0 173 porter-duff transfer mode and srcColor to a 16bit device color. Note,
michael@0 174 if the mode+srcColor might return a non-opaque color, then there is not
michael@0 175 16bit proc, and this will return NULL.
michael@0 176 */
michael@0 177 static SkXfermodeProc16 GetProc16(Mode mode, SkColor srcColor);
michael@0 178
michael@0 179 /**
michael@0 180 * If the specified mode can be represented by a pair of Coeff, then return
michael@0 181 * true and set (if not NULL) the corresponding coeffs. If the mode is
michael@0 182 * not representable as a pair of Coeffs, return false and ignore the
michael@0 183 * src and dst parameters.
michael@0 184 */
michael@0 185 static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst);
michael@0 186
michael@0 187 SK_ATTR_DEPRECATED("use AsMode(...)")
michael@0 188 static bool IsMode(const SkXfermode* xfer, Mode* mode) {
michael@0 189 return AsMode(xfer, mode);
michael@0 190 }
michael@0 191
michael@0 192 /** A subclass may implement this factory function to work with the GPU backend. It is legal
michael@0 193 to call this with all params NULL to simply test the return value. If effect is non-NULL
michael@0 194 then the xfermode may optionally allocate an effect to return and the caller as *effect.
michael@0 195 The caller will install it and own a ref to it. Since the xfermode may or may not assign
michael@0 196 *effect, the caller should set *effect to NULL beforehand. background specifies the
michael@0 197 texture to use as the background for compositing, and should be accessed in the effect's
michael@0 198 fragment shader. If NULL, the effect should request access to destination color
michael@0 199 (setWillReadDstColor()), and use that in the fragment shader (builder->dstColor()).
michael@0 200 */
michael@0 201 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* background = NULL) const;
michael@0 202
michael@0 203 /** Returns true if the xfermode can be expressed as coeffs (src, dst), or as an effect
michael@0 204 (effect). This helper calls the asCoeff() and asNewEffect() virtuals. If the xfermode is
michael@0 205 NULL, it is treated as kSrcOver_Mode. It is legal to call this with all params NULL to
michael@0 206 simply test the return value. effect, src, and dst must all be NULL or all non-NULL.
michael@0 207 */
michael@0 208 static bool AsNewEffectOrCoeff(SkXfermode*,
michael@0 209 GrEffectRef** effect,
michael@0 210 Coeff* src,
michael@0 211 Coeff* dst,
michael@0 212 GrTexture* background = NULL);
michael@0 213
michael@0 214 SK_TO_STRING_PUREVIRT()
michael@0 215 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
michael@0 216 SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
michael@0 217
michael@0 218 protected:
michael@0 219 SkXfermode(SkReadBuffer& rb) : SkFlattenable(rb) {}
michael@0 220
michael@0 221 /** The default implementation of xfer32/xfer16/xferA8 in turn call this
michael@0 222 method, 1 color at a time (upscaled to a SkPMColor). The default
michael@0 223 implmentation of this method just returns dst. If performance is
michael@0 224 important, your subclass should override xfer32/xfer16/xferA8 directly.
michael@0 225
michael@0 226 This method will not be called directly by the client, so it need not
michael@0 227 be implemented if your subclass has overridden xfer32/xfer16/xferA8
michael@0 228 */
michael@0 229 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
michael@0 230
michael@0 231 #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
michael@0 232 public:
michael@0 233 #endif
michael@0 234 SkXfermode() {}
michael@0 235
michael@0 236 private:
michael@0 237 enum {
michael@0 238 kModeCount = kLastMode + 1
michael@0 239 };
michael@0 240
michael@0 241 friend class SkGraphics;
michael@0 242 static void Term();
michael@0 243
michael@0 244 typedef SkFlattenable INHERITED;
michael@0 245 };
michael@0 246
michael@0 247 ///////////////////////////////////////////////////////////////////////////////
michael@0 248
michael@0 249 /** \class SkProcXfermode
michael@0 250
michael@0 251 SkProcXfermode is a xfermode that applies the specified proc to its colors.
michael@0 252 This class is not exported to java.
michael@0 253 */
michael@0 254 class SkProcXfermode : public SkXfermode {
michael@0 255 public:
michael@0 256 static SkProcXfermode* Create(SkXfermodeProc proc) {
michael@0 257 return SkNEW_ARGS(SkProcXfermode, (proc));
michael@0 258 }
michael@0 259
michael@0 260 // overrides from SkXfermode
michael@0 261 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
michael@0 262 const SkAlpha aa[]) const SK_OVERRIDE;
michael@0 263 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
michael@0 264 const SkAlpha aa[]) const SK_OVERRIDE;
michael@0 265 virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
michael@0 266 const SkAlpha aa[]) const SK_OVERRIDE;
michael@0 267
michael@0 268 SK_TO_STRING_OVERRIDE()
michael@0 269 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcXfermode)
michael@0 270
michael@0 271 protected:
michael@0 272 SkProcXfermode(SkReadBuffer&);
michael@0 273 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
michael@0 274
michael@0 275 // allow subclasses to update this after we unflatten
michael@0 276 void setProc(SkXfermodeProc proc) {
michael@0 277 fProc = proc;
michael@0 278 }
michael@0 279
michael@0 280 SkXfermodeProc getProc() const {
michael@0 281 return fProc;
michael@0 282 }
michael@0 283
michael@0 284 #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
michael@0 285 public:
michael@0 286 #endif
michael@0 287 SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
michael@0 288
michael@0 289 private:
michael@0 290 SkXfermodeProc fProc;
michael@0 291
michael@0 292 typedef SkXfermode INHERITED;
michael@0 293 };
michael@0 294
michael@0 295 #endif

mercurial