aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-06-22 17:38:10 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-06-22 17:38:10 +0000
commita0f5d1546d499ef0cd7dbfba9a866ae5a27e1541 (patch)
tree4e74bc93f6d794826a8eb1a78d4642ab9b215143 /include
parent1a2fec55d914f0a01cbee37077105ef6c8a7366f (diff)
move xfermode modes from porterduff into xfermode itself
git-svn-id: http://skia.googlecode.com/svn/trunk@232 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkMath.h7
-rw-r--r--include/core/SkPaint.h15
-rw-r--r--include/core/SkPorterDuff.h2
-rw-r--r--include/core/SkXfermode.h66
4 files changed, 87 insertions, 3 deletions
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 0c89065855..9198412634 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -217,5 +217,12 @@ static inline unsigned SkMul16ShiftRound(unsigned a, unsigned b, int shift) {
return (prod + (prod >> shift)) >> shift;
}
+/** Just the rounding step in SkDiv255Round: round(value / 255)
+ */
+static inline unsigned SkDiv255Round(unsigned prod) {
+ prod += 128;
+ return (prod + (prod >> 8)) >> 8;
+}
+
#endif
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index dd3aa13d11..5865fe85bd 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -19,6 +19,9 @@
#include "SkColor.h"
#include "SkMath.h"
+#include "SkXfermode.h"
+
+// DEPRECATED - remove
#include "SkPorterDuff.h"
class SkAutoGlyphCache;
@@ -37,7 +40,6 @@ class SkRasterizer;
class SkShader;
class SkDrawLooper;
class SkTypeface;
-class SkXfermode;
typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**,
SkFixed x, SkFixed y);
@@ -456,8 +458,15 @@ public:
@return xfermode
*/
SkXfermode* setXfermode(SkXfermode* xfermode);
-
- /** Helper for setXfermode, passing the corresponding xfermode object
+
+ /** Create an xfermode based on the specified Mode, and assign it into the
+ paint, returning the mode that was set. If the Mode is SrcOver, then
+ the paint's xfermode is set to null.
+ */
+ SkXfermode* setXfermode(SkXfermode::Mode);
+
+ /** DEPRECATED
+ Helper for setXfermode, passing the corresponding xfermode object
returned from the PorterDuff factory.
@param mode The porter-duff mode used to create an xfermode for the
paint.
diff --git a/include/core/SkPorterDuff.h b/include/core/SkPorterDuff.h
index 44c5477352..52021b1e7b 100644
--- a/include/core/SkPorterDuff.h
+++ b/include/core/SkPorterDuff.h
@@ -21,6 +21,8 @@
class SkXfermode;
+/** DEPRECATED - use SkXfermode::Mode instead
+ */
class SkPorterDuff {
public:
/** List of predefined xfermodes. In general, the algebra for the modes
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 6a7edecc3f..7a064673eb 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -75,6 +75,69 @@ public:
*/
virtual bool asCoeff(Coeff* src, Coeff* dst);
+ /** List of predefined xfermodes.
+ The algebra for the modes uses the following symbols:
+ Sa, Sc - source alpha and color
+ Da, Dc - destination alpha and color (before compositing)
+ [a, c] - Resulting (alpha, color) values
+ For these equations, the colors are in premultiplied state.
+ If no xfermode is specified, kSrcOver is assumed.
+ */
+ enum Mode {
+ kClear_Mode, //!< [0, 0]
+ kSrc_Mode, //!< [Sa, Sc]
+ kDst_Mode, //!< [Da, Dc]
+ kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
+ kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
+ kSrcIn_Mode, //!< [Sa * Da, Sc * Da]
+ kDstIn_Mode, //!< [Sa * Da, Sa * Dc]
+ kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)]
+ kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)]
+ kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc]
+ kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)]
+ kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
+
+ // these modes are defined in the SVG Compositing standard
+ // http://www.w3.org/TR/2009/WD-SVGCompositing-20090430/
+ kPlus_Mode,
+ kMultiply_Mode,
+ kScreen_Mode,
+ kOverlay_Mode,
+ kDarken_Mode,
+ kLighten_Mode,
+ kColorDodge_Mode,
+ kColorBurn_Mode,
+ kHardLight_Mode,
+ kSoftLight_Mode,
+ kDifference_Mode,
+ kExclusion_Mode,
+
+ kLastMode = kExclusion_Mode
+ };
+
+ /** Return an SkXfermode object for the specified mode.
+ */
+ static SkXfermode* Create(Mode mode);
+
+ /** Return a function pointer to a routine that applies the specified
+ porter-duff transfer mode.
+ */
+ static SkXfermodeProc GetProc(Mode mode);
+
+ /** Return a function pointer to a routine that applies the specified
+ porter-duff transfer mode and srcColor to a 16bit device color. Note,
+ if the mode+srcColor might return a non-opaque color, then there is not
+ 16bit proc, and this will return NULL.
+ */
+ static SkXfermodeProc16 GetProc16(Mode mode, SkColor srcColor);
+
+ /** If the specified xfermode advertises itself as one of the porterduff
+ modes (via SkXfermode::Coeff), return true and if not null, set mode
+ to the corresponding porterduff mode. If it is not recognized as a one,
+ return false and ignore the mode parameter.
+ */
+ static bool IsMode(SkXfermode*, Mode* mode);
+
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
@@ -89,6 +152,9 @@ protected:
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst);
private:
+ enum {
+ kModeCount = kLastMode + 1
+ };
typedef SkFlattenable INHERITED;
};