diff options
author | Matt Sarett <msarett@google.com> | 2017-04-17 17:18:57 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-17 23:48:17 +0000 |
commit | c1b879f11b937142f5478bd3b416b26be93dea23 (patch) | |
tree | bde95d4d09938f3332687e84eb9f5dfa9593b48e | |
parent | 30229ac6282981c28ced8f513c8d09684d9d0581 (diff) |
SkColorSpaceXformer: Handle compose color filters
We could alternatively use the makeColorSpace() approach that we
adoped for loopers and imagefilters, but this seems fine.
This should finish xform canvas work on color filters. We have
plenty of color filters that do math on colors, but only two
that might actually hold colors.
Bug: skia:6516
Change-Id: I1aee8c35d6886fdc149d4659d1bac2edc0d32b67
Reviewed-on: https://skia-review.googlesource.com/13649
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
-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)); } |