aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2016-10-03 12:57:32 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-03 17:17:10 +0000
commit0591897548c8fcb7d53cc94053e01702e58f1ac5 (patch)
tree099bf31c7bf4bd3062d2e7a8b4268a89f1fd61a2 /include
parenta224bb7027f022cf78376cb7afa2fff83d59153e (diff)
replace SkXfermode obj with SkBlendMode enum in paints
BUG=skia:5814 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2714 Change-Id: I4fb489ba6b3f77b458f7e4a99f79c7ad10859135 Reviewed-on: https://skia-review.googlesource.com/2714 Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBlendMode.h51
-rw-r--r--include/core/SkCanvas.h18
-rw-r--r--include/core/SkColorFilter.h3
-rw-r--r--include/core/SkPaint.h13
-rw-r--r--include/core/SkPicture.h3
-rw-r--r--include/core/SkXfermode.h32
-rw-r--r--include/effects/SkXfermodeImageFilter.h17
-rw-r--r--include/gpu/GrPaint.h6
-rw-r--r--include/gpu/effects/GrPorterDuffXferProcessor.h3
9 files changed, 134 insertions, 12 deletions
diff --git a/include/core/SkBlendMode.h b/include/core/SkBlendMode.h
new file mode 100644
index 0000000000..eb3469f256
--- /dev/null
+++ b/include/core/SkBlendMode.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBlendMode_DEFINED
+#define SkBlendMode_DEFINED
+
+enum class SkBlendMode {
+ kClear, //!< [0, 0]
+ kSrc, //!< [Sa, Sc]
+ kDst, //!< [Da, Dc]
+ kSrcOver, //!< [Sa + Da * (1 - Sa), Sc + Dc * (1 - Sa)]
+ kDstOver, //!< [Da + Sa * (1 - Da), Dc + Sc * (1 - Da)]
+ kSrcIn, //!< [Sa * Da, Sc * Da]
+ kDstIn, //!< [Da * Sa, Dc * Sa]
+ kSrcOut, //!< [Sa * (1 - Da), Sc * (1 - Da)]
+ kDstOut, //!< [Da * (1 - Sa), Dc * (1 - Sa)]
+ kSrcATop, //!< [Da, Sc * Da + Dc * (1 - Sa)]
+ kDstATop, //!< [Sa, Dc * Sa + Sc * (1 - Da)]
+ kXor, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa)]
+ kPlus, //!< [Sa + Da, Sc + Dc]
+ kModulate, // multiplies all components (= alpha and color)
+
+ // Following blend modes are defined in the CSS Compositing standard:
+ // https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blending
+ kScreen,
+ kLastCoeffMode = kScreen,
+
+ kOverlay,
+ kDarken,
+ kLighten,
+ kColorDodge,
+ kColorBurn,
+ kHardLight,
+ kSoftLight,
+ kDifference,
+ kExclusion,
+ kMultiply,
+ kLastSeparableMode = kMultiply,
+
+ kHue,
+ kSaturation,
+ kColor,
+ kLuminosity,
+ kLastMode = kLuminosity
+};
+
+#endif
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 8d98e5024f..5078f4255c 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -9,6 +9,7 @@
#define SkCanvas_DEFINED
#include "SkTypes.h"
+#include "SkBlendMode.h"
#include "SkBitmap.h"
#include "SkClipOp.h"
#include "SkDeque.h"
@@ -595,22 +596,31 @@ public:
@param b the blue component (0..255) of the color to fill the canvas
@param mode the mode to apply the color in (defaults to SrcOver)
*/
- void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
- SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
+ void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkBlendMode mode = SkBlendMode::kSrcOver);
+#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
+ void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkXfermode::Mode mode) {
+ this->drawARGB(a, r, g, b, (SkBlendMode)mode);
+ }
+#endif
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified color and mode.
@param color the color to draw with
@param mode the mode to apply the color in (defaults to SrcOver)
*/
- void drawColor(SkColor color, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
+ void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
+#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
+ void drawColor(SkColor color, SkXfermode::Mode mode) {
+ this->drawColor(color, (SkBlendMode)mode);
+ }
+#endif
/**
* Helper method for drawing a color in SRC mode, completely replacing all the pixels
* in the current clip with this color.
*/
void clear(SkColor color) {
- this->drawColor(color, SkXfermode::kSrc_Mode);
+ this->drawColor(color, SkBlendMode::kSrc);
}
/**
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h
index 609550f676..5a23a343a2 100644
--- a/include/core/SkColorFilter.h
+++ b/include/core/SkColorFilter.h
@@ -115,6 +115,9 @@ public:
or NULL if the mode will have no effect.
*/
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkXfermode::Mode mode);
+ static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkBlendMode mode) {
+ return MakeModeFilter(c, (SkXfermode::Mode)mode);
+ }
/** Construct a colorfilter whose effect is to first apply the inner filter and then apply
* the outer filter to the result of the inner's.
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index e28d2fc92d..ddc90ae19c 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -8,11 +8,14 @@
#ifndef SkPaint_DEFINED
#define SkPaint_DEFINED
+#include "SkBlendMode.h"
#include "SkColor.h"
#include "SkFilterQuality.h"
#include "SkMatrix.h"
#include "SkXfermode.h"
+//#define SK_SUPPORT_LEGACY_XFERMODE_OBJECT
+
class SkAutoDescriptor;
class SkAutoGlyphCache;
class SkColorFilter;
@@ -525,12 +528,13 @@ public:
#endif
void setColorFilter(sk_sp<SkColorFilter>);
+#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
/** Get the paint's xfermode object.
<p />
The xfermode's reference count is not affected.
@return the paint's xfermode (or NULL)
*/
- SkXfermode* getXfermode() const { return fXfermode.get(); }
+ SkXfermode* getXfermode() const;
/** Set or clear the xfermode object.
<p />
@@ -552,6 +556,11 @@ public:
the paint's xfermode is set to null.
*/
SkXfermode* setXfermodeMode(SkXfermode::Mode);
+#endif
+
+ SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
+ bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
+ void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
/** Get the paint's patheffect object.
<p />
@@ -1090,7 +1099,6 @@ private:
sk_sp<SkTypeface> fTypeface;
sk_sp<SkPathEffect> fPathEffect;
sk_sp<SkShader> fShader;
- sk_sp<SkXfermode> fXfermode;
sk_sp<SkMaskFilter> fMaskFilter;
sk_sp<SkColorFilter> fColorFilter;
sk_sp<SkRasterizer> fRasterizer;
@@ -1103,6 +1111,7 @@ private:
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
+ uint32_t fBlendMode; // just need 5-6 bits for SkXfermode::Mode
union {
struct {
// all of these bitfields should add up to 32
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index c398d3a4ec..c2d05f9c41 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -224,10 +224,11 @@ private:
// V47: Add occluder rect to SkBlurMaskFilter
// V48: Read and write extended SkTextBlobs.
// V49: Gradients serialized as SkColor4f + SkColorSpace
+ // V50: SkXfermode -> SkBlendMode
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39.
- static const uint32_t CURRENT_PICTURE_VERSION = 49;
+ static const uint32_t CURRENT_PICTURE_VERSION = 50;
static_assert(MIN_PICTURE_VERSION <= 41,
"Remove kFontFileName and related code from SkFontDescriptor.cpp.");
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 2d12b3c931..8319ad6882 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -8,8 +8,9 @@
#ifndef SkXfermode_DEFINED
#define SkXfermode_DEFINED
-#include "SkFlattenable.h"
+#include "SkBlendMode.h"
#include "SkColor.h"
+#include "SkFlattenable.h"
class GrFragmentProcessor;
class GrTexture;
@@ -112,6 +113,9 @@ public:
* Gets the name of the Mode as a string.
*/
static const char* ModeName(Mode);
+ static const char* ModeName(SkBlendMode mode) {
+ return ModeName(Mode(mode));
+ }
/**
* If the xfermode is one of the modes in the Mode enum, then asMode()
@@ -157,6 +161,31 @@ public:
}
#endif
+ /**
+ * Skia maintains global xfermode objects corresponding to each BlendMode. This returns a
+ * ptr to that global xfermode (or null if the mode is srcover). Thus the caller may use
+ * the returned ptr, but it should leave its refcnt untouched.
+ */
+ static SkXfermode* Peek(SkBlendMode mode) {
+ sk_sp<SkXfermode> xfer = Make(mode);
+ if (!xfer) {
+ SkASSERT(SkBlendMode::kSrcOver == mode);
+ return nullptr;
+ }
+ SkASSERT(!xfer->unique());
+ return xfer.get();
+ }
+
+ static sk_sp<SkXfermode> Make(SkBlendMode bm) {
+ return Make((Mode)bm);
+ }
+
+ SkBlendMode blend() const {
+ Mode mode;
+ SkAssertResult(this->asMode(&mode));
+ return (SkBlendMode)mode;
+ }
+
/** Return a function pointer to a routine that applies the specified
porter-duff transfer mode.
*/
@@ -215,6 +244,7 @@ public:
static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityType) {
return IsOpaque(xfer.get(), opacityType);
}
+ static bool IsOpaque(SkBlendMode, SrcColorOpacity);
#if SK_SUPPORT_GPU
/** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentProcessor.
diff --git a/include/effects/SkXfermodeImageFilter.h b/include/effects/SkXfermodeImageFilter.h
index 6066b8d2e0..fa9c857a7e 100644
--- a/include/effects/SkXfermodeImageFilter.h
+++ b/include/effects/SkXfermodeImageFilter.h
@@ -8,6 +8,7 @@
#ifndef SkXfermodeImageFilter_DEFINED
#define SkXfermodeImageFilter_DEFINED
+#include "SkBlendMode.h"
#include "SkImageFilter.h"
class SkXfermode;
@@ -19,11 +20,11 @@ class SkXfermode;
*/
class SK_API SkXfermodeImageFilter {
public:
- static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background,
+ static sk_sp<SkImageFilter> Make(SkBlendMode, sk_sp<SkImageFilter> background,
sk_sp<SkImageFilter> foreground,
const SkImageFilter::CropRect* cropRect);
- static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background) {
- return Make(std::move(mode), std::move(background), nullptr, nullptr);
+ static sk_sp<SkImageFilter> Make(SkBlendMode mode, sk_sp<SkImageFilter> background) {
+ return Make(mode, std::move(background), nullptr, nullptr);
}
static sk_sp<SkImageFilter> MakeArithmetic(float k1, float k2, float k3, float k4,
@@ -38,6 +39,16 @@ public:
nullptr, nullptr);
}
+#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT
+ static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background,
+ sk_sp<SkImageFilter> foreground,
+ const SkImageFilter::CropRect* cropRect);
+ static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background) {
+ return Make(std::move(mode), std::move(background), nullptr, nullptr);
+ }
+
+#endif
+
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL,
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index 6120348792..a8af3c2f17 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -16,9 +16,9 @@
#include "effects/GrPorterDuffXferProcessor.h"
#include "GrFragmentProcessor.h"
+#include "SkBlendMode.h"
#include "SkRefCnt.h"
#include "SkRegion.h"
-#include "SkXfermode.h"
/**
* The paint describes how color and coverage are computed at each pixel by GrContext draw
@@ -95,6 +95,10 @@ public:
fXPFactory = std::move(xpFactory);
}
+ void setPorterDuffXPFactory(SkBlendMode mode) {
+ fXPFactory = GrPorterDuffXPFactory::Make((SkXfermode::Mode)mode);
+ }
+
void setPorterDuffXPFactory(SkXfermode::Mode mode) {
fXPFactory = GrPorterDuffXPFactory::Make(mode);
}
diff --git a/include/gpu/effects/GrPorterDuffXferProcessor.h b/include/gpu/effects/GrPorterDuffXferProcessor.h
index 8399d5805e..6777d76046 100644
--- a/include/gpu/effects/GrPorterDuffXferProcessor.h
+++ b/include/gpu/effects/GrPorterDuffXferProcessor.h
@@ -17,6 +17,9 @@ class GrProcOptInfo;
class GrPorterDuffXPFactory : public GrXPFactory {
public:
static sk_sp<GrXPFactory> Make(SkXfermode::Mode mode);
+ static sk_sp<GrXPFactory> Make(SkBlendMode mode) {
+ return Make((SkXfermode::Mode)mode);
+ }
void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
GrXPFactory::InvariantBlendedColor*) const override;