diff options
-rw-r--r-- | include/core/SkImageFilter.h | 37 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 13 | ||||
-rw-r--r-- | src/effects/SkBlurImageFilter.cpp | 12 | ||||
-rw-r--r-- | src/effects/SkColorFilterImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 8 | ||||
-rw-r--r-- | src/effects/SkDropShadowImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkOffsetImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkPaintImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 8 |
9 files changed, 51 insertions, 41 deletions
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h index 44231cc7ee..689d52b827 100644 --- a/include/core/SkImageFilter.h +++ b/include/core/SkImageFilter.h @@ -390,26 +390,25 @@ protected: return false; } - /** Given a "src" bitmap and its "srcOffset", computes source and - * destination bounds for this filter. Initial bounds are the - * "src" bitmap bounds offset by "srcOffset". "dstBounds" are - * computed by transforming the crop rect by the context's CTM, - * applying it to the initial bounds, and intersecting the result - * with the context's clip bounds. "srcBounds" (if non-null) are - * computed by intersecting the initial bounds with "dstBounds", to - * ensure that we never sample outside of the crop rect (this restriction - * may be relaxed in the future). + /** Given a "srcBounds" rect, computes destination bounds for this + * destination bounds for this filter. "dstBounds" are computed by + * transforming the crop rect by the context's CTM, applying it to the + * initial bounds, and intersecting the result with the context's clip + * bounds. "srcBounds" (if non-null) are computed by intersecting the + * initial bounds with "dstBounds", to ensure that we never sample + * outside of the crop rect (this restriction may be relaxed in the + * future). */ - bool applyCropRect(const Context&, const SkBitmap& src, const SkIPoint& srcOffset, - SkIRect* dstBounds, SkIRect* srcBounds = nullptr) const; - - /** Same as the above call, except that if the resulting crop rect is not - * entirely contained by the source bitmap's bounds, it creates a new - * bitmap in "result" and pads the edges with transparent black. In that - * case, the srcOffset is modified to be the same as the bounds, since no - * further adjustment is needed by the caller. This version should only - * be used by filters which are not capable of processing a smaller - * source bitmap into a larger destination. + bool applyCropRect(const Context&, const SkIRect& srcBounds, SkIRect* dstBounds) const; + + /** A variant of the above call which takes the original source bitmap and + * source offset. If the resulting crop rect is not entirely contained by + * the source bitmap's bounds, it creates a new bitmap in "result" and + * pads the edges with transparent black. In that case, the srcOffset is + * modified to be the same as the bounds, since no further adjustment is + * needed by the caller. This version should only be used by filters + * which are not capable of processing a smaller source bitmap into a + * larger destination. */ bool applyCropRect(const Context&, Proxy* proxy, const SkBitmap& src, SkIPoint* srcOffset, SkIRect* bounds, SkBitmap* result) const; diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 94d6ab6a16..55abb8887f 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -394,16 +394,9 @@ bool SkImageFilter::asAColorFilter(SkColorFilter** filterPtr) const { return true; } -bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, - const SkIPoint& srcOffset, SkIRect* dstBounds, - SkIRect* srcBounds) const { - SkIRect storage; - if (!srcBounds) { - srcBounds = &storage; - } - src.getBounds(srcBounds); - srcBounds->offset(srcOffset); - this->onFilterNodeBounds(*srcBounds, ctx.ctm(), dstBounds, kForward_MapDirection); +bool SkImageFilter::applyCropRect(const Context& ctx, const SkIRect& srcBounds, + SkIRect* dstBounds) const { + this->onFilterNodeBounds(srcBounds, ctx.ctm(), dstBounds, kForward_MapDirection); fCropRect.applyTo(*dstBounds, ctx.ctm(), dstBounds); // Intersect against the clip bounds, in case the crop rect has // grown the bounds beyond the original clip. This can happen for diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index a1d6a2f80e..6ba9e0b640 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -82,8 +82,10 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, return false; } - SkIRect srcBounds, dstBounds; - if (!this->applyCropRect(this->mapContext(ctx), src, srcOffset, &dstBounds, &srcBounds)) { + SkIRect srcBounds = src.bounds(); + srcBounds.offset(srcOffset); + SkIRect dstBounds; + if (!this->applyCropRect(this->mapContext(ctx), srcBounds, &dstBounds)) { return false; } if (!srcBounds.intersect(dstBounds)) { @@ -204,8 +206,10 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { return false; } - SkIRect srcBounds, dstBounds; - if (!this->applyCropRect(this->mapContext(ctx), input, srcOffset, &dstBounds, &srcBounds)) { + SkIRect srcBounds = input.bounds(); + srcBounds.offset(srcOffset); + SkIRect dstBounds; + if (!this->applyCropRect(this->mapContext(ctx), srcBounds, &dstBounds)) { return false; } if (!srcBounds.intersect(dstBounds)) { diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index b0e47505a7..5b97d1bc36 100644 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -66,7 +66,9 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc } SkIRect bounds; - if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { + SkIRect srcBounds = src.bounds(); + srcBounds.offset(srcOffset); + if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return false; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index ec306cca3b..2f95474a76 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -228,7 +228,9 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, SkIRect bounds; // Since computeDisplacement does bounds checking on color pixel access, we don't need to pad // the color bitmap to bounds here. - if (!this->applyCropRect(ctx, color, colorOffset, &bounds)) { + SkIRect srcBounds = color.bounds(); + srcBounds.offset(colorOffset); + if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return false; } SkIRect displBounds; @@ -396,10 +398,12 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, if (!this->filterInputGPU(0, proxy, src, ctx, &displacementBM, &displacementOffset)) { return false; } + SkIRect srcBounds = colorBM.bounds(); + srcBounds.offset(colorOffset); SkIRect bounds; // Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to // pad the color bitmap to bounds here. - if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) { + if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return false; } SkIRect displBounds; diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp index eb05cf09ec..5f8736f3a5 100644 --- a/src/effects/SkDropShadowImageFilter.cpp +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -62,8 +62,10 @@ bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) return false; + SkIRect srcBounds = src.bounds(); + srcBounds.offset(srcOffset); SkIRect bounds; - if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { + if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return false; } diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp index 70247f2a19..2aac4f32d1 100644 --- a/src/effects/SkOffsetImageFilter.cpp +++ b/src/effects/SkOffsetImageFilter.cpp @@ -37,7 +37,9 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, } SkIRect bounds; - if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { + SkIRect srcBounds = src.bounds(); + srcBounds.offset(srcOffset); + if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return false; } diff --git a/src/effects/SkPaintImageFilter.cpp b/src/effects/SkPaintImageFilter.cpp index d141f34dfb..c0210513ac 100644 --- a/src/effects/SkPaintImageFilter.cpp +++ b/src/effects/SkPaintImageFilter.cpp @@ -39,7 +39,7 @@ bool SkPaintImageFilter::onFilterImage(Proxy* proxy, SkBitmap* result, SkIPoint* offset) const { SkIRect bounds; - if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) { + if (!this->applyCropRect(ctx, source.bounds(), &bounds)) { return false; } diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index fbceedb0dd..3f702e69c4 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -57,11 +57,15 @@ bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy, } SkIRect bounds, foregroundBounds; - if (!applyCropRect(ctx, foreground, foregroundOffset, &foregroundBounds)) { + SkIRect foregroundSrcBounds = foreground.bounds(); + foregroundSrcBounds.offset(foregroundOffset); + if (!applyCropRect(ctx, foregroundSrcBounds, &foregroundBounds)) { foregroundBounds.setEmpty(); foreground.reset(); } - if (!applyCropRect(ctx, background, backgroundOffset, &bounds)) { + SkIRect backgroundSrcBounds = background.bounds(); + backgroundSrcBounds.offset(backgroundOffset); + if (!applyCropRect(ctx, backgroundSrcBounds, &bounds)) { bounds.setEmpty(); background.reset(); } |