diff options
author | 2015-08-20 07:42:11 -0700 | |
---|---|---|
committer | 2015-08-20 07:42:11 -0700 | |
commit | 915881fe743f9a789037695f543bc6ea189cd0cb (patch) | |
tree | 9236b8acd8ef7ca0f7ee33bded19532c1b7833fc /src | |
parent | a7f4c435bc1dcd845990a5515828bbe8cccfab41 (diff) |
Implement canComputeFastBounds() for image filters.
Image filters have never implemented this check, which means that
filters which affect transparent black falsely claim they can compute
their bounds.
Implemented an affectsTransparentBlack() virtual for image
filters, and a similar helper function for color filters.
This will affect the following GMs: imagefiltersscaled
(lighting, perlin noise now filter to clip),
colorfilterimagefilter (new test case), imagefiltersclipped
(perlin noise now filters to clip).
Note: I de-inlined SkPaint::canComputeFastBounds() to avoid adding
a dependency from SkPaint.h to SkImageFilter.h.h. Skia benches show
no impact from this change, but will watch the perf bots carefully.
BUG=4212
Review URL: https://codereview.chromium.org/1296943002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkImageFilter.cpp | 17 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 10 | ||||
-rwxr-xr-x | src/effects/SkColorFilterImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkRectShaderImageFilter.cpp | 4 |
4 files changed, 35 insertions, 0 deletions
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 3214eeb40e..5f9fa64110 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -284,6 +284,23 @@ void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { } } +bool SkImageFilter::canComputeFastBounds() const { + if (this->affectsTransparentBlack()) { + return false; + } + for (int i = 0; i < fInputCount; i++) { + SkImageFilter* input = this->getInput(i); + if (input && !input->canComputeFastBounds()) { + return false; + } + } + return true; +} + +bool SkImageFilter::affectsTransparentBlack() const { + return false; +} + bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const Context&, SkBitmap*, SkIPoint*) const { return false; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index f64ab1d844..4ab8927114 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -2063,6 +2063,16 @@ bool SkPaint::getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect return !rec.isHairlineStyle(); } +bool SkPaint::canComputeFastBounds() const { + if (this->getLooper()) { + return this->getLooper()->canComputeFastBounds(*this); + } + if (this->getImageFilter() && !this->getImageFilter()->canComputeFastBounds()) { + return false; + } + return !this->getRasterizer(); +} + const SkRect& SkPaint::doComputeFastBounds(const SkRect& origSrc, SkRect* storage, Style style) const { diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 2eb720e5c4..94b530da8d 100755 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -98,6 +98,10 @@ bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const return false; } +bool SkColorFilterImageFilter::affectsTransparentBlack() const { + return fColorFilter->affectsTransparentBlack(); +} + #ifndef SK_IGNORE_TO_STRING void SkColorFilterImageFilter::toString(SkString* str) const { str->appendf("SkColorFilterImageFilter: ("); diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp index cdf03131c1..45962537c8 100644 --- a/src/effects/SkRectShaderImageFilter.cpp +++ b/src/effects/SkRectShaderImageFilter.cpp @@ -79,6 +79,10 @@ bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, return true; } +bool SkRectShaderImageFilter::affectsTransparentBlack() const { + return true; +} + #ifndef SK_IGNORE_TO_STRING void SkRectShaderImageFilter::toString(SkString* str) const { str->appendf("SkRectShaderImageFilter: ("); |