diff options
-rw-r--r-- | include/core/SkColorFilter.h | 10 | ||||
-rw-r--r-- | src/core/SkColorFilter.cpp | 6 | ||||
-rw-r--r-- | src/core/SkColorSpaceXformer.cpp | 10 |
3 files changed, 25 insertions, 1 deletions
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h index a59308774f..3fb27fab7a 100644 --- a/include/core/SkColorFilter.h +++ b/include/core/SkColorFilter.h @@ -172,6 +172,16 @@ private: * e.g. compose(filter, compose(compose(filter, filter), filter)) --> 4 */ virtual int privateComposedFilterCount() const { return 1; } + + /* + * Returns true and sets |outer| and |inner| if this is a compose color filter. + * Returns false otherwise. + */ + virtual bool asACompose(SkColorFilter** /*outer*/, SkColorFilter** /*inner*/) const { + return false; + } + + friend class SkColorSpaceXformer; friend class SkComposeColorFilter; typedef SkFlattenable INHERITED; diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index 8f660e99f0..210ca6d346 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -155,6 +155,12 @@ private: return fComposedFilterCount; } + bool asACompose(SkColorFilter** outer, SkColorFilter** inner) const override { + *outer = fOuter.get(); + *inner = fInner.get(); + return true; + } + sk_sp<SkColorFilter> fOuter; sk_sp<SkColorFilter> fInner; const int fComposedFilterCount; diff --git a/src/core/SkColorSpaceXformer.cpp b/src/core/SkColorSpaceXformer.cpp index fe66e74c79..7a9f24b631 100644 --- a/src/core/SkColorSpaceXformer.cpp +++ b/src/core/SkColorSpaceXformer.cpp @@ -44,7 +44,9 @@ sk_sp<SkImage> SkColorSpaceXformer::apply(const SkBitmap& src) { return xformed; } -// As far as I know, SkModeColorFilter is the only color filter that holds a color. +// Currently, SkModeColorFilter is the only color filter that holds a color. And +// SkComposeColorFilter is the only color filter that holds another color filter. If this +// changes, this function will need updating. sk_sp<SkColorFilter> SkColorSpaceXformer::apply(const SkColorFilter* colorFilter) { SkColor color; SkBlendMode mode; @@ -52,6 +54,12 @@ sk_sp<SkColorFilter> SkColorSpaceXformer::apply(const SkColorFilter* colorFilter return SkColorFilter::MakeModeFilter(this->apply(color), mode); } + SkColorFilter* outer; + SkColorFilter* inner; + if (colorFilter->asACompose(&outer, &inner)) { + return SkColorFilter::MakeComposeFilter(this->apply(outer), this->apply(inner)); + } + return sk_ref_sp(const_cast<SkColorFilter*>(colorFilter)); } |