diff options
author | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-14 15:44:01 +0000 |
---|---|---|
committer | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-14 15:44:01 +0000 |
commit | 4cb543d6057b692e1099e9f115155f0bf323a0c8 (patch) | |
tree | 66f8cbe4e7ef74221766ade874096f934c8b2031 /src/core | |
parent | 0d30c51c6cf45b3a08a3000b6d348c16bdec7f05 (diff) |
Implement support for a Context parameter in image filters
Some upcoming work (support for expanding crop rects) requires
the clip bounds to be available during filter traversal. This change
replaces the SkMatrix parameter in the onFilterImage() traversals
with a Context parameter. It contains the CTM, as well as the clip
bounds.
BUG=skia:
R=reed@google.com
Review URL: https://codereview.chromium.org/189913021
git-svn-id: http://skia.googlecode.com/svn/trunk@13803 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 2 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 8 | ||||
-rw-r--r-- | src/core/SkDeviceImageFilterProxy.h | 4 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 22 |
4 files changed, 20 insertions, 16 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 724f17fe51..96f4e40298 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -164,7 +164,7 @@ bool SkBitmapDevice::canHandleImageFilter(const SkImageFilter*) { } bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, - const SkMatrix& ctm, SkBitmap* result, + const SkImageFilter::Context& ctx, SkBitmap* result, SkIPoint* offset) { return false; } diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 1443f5e575..4ac7b29826 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1164,7 +1164,9 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkBitmap& src = srcDev->accessBitmap(false); SkMatrix matrix = *iter.fMatrix; matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); - if (filter->filterImage(&proxy, src, matrix, &dst, &offset)) { + SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height()); + SkImageFilter::Context ctx(matrix, clipBounds); + if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) { SkPaint tmpUnfiltered(*paint); tmpUnfiltered.setImageFilter(NULL); dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + offset.y(), @@ -1202,7 +1204,9 @@ void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, SkIPoint offset = SkIPoint::Make(0, 0); SkMatrix matrix = *iter.fMatrix; matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); - if (filter->filterImage(&proxy, bitmap, matrix, &dst, &offset)) { + SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); + SkImageFilter::Context ctx(matrix, clipBounds); + if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { SkPaint tmpUnfiltered(*paint); tmpUnfiltered.setImageFilter(NULL); iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + offset.y(), diff --git a/src/core/SkDeviceImageFilterProxy.h b/src/core/SkDeviceImageFilterProxy.h index 6c968e945e..5ee563484e 100644 --- a/src/core/SkDeviceImageFilterProxy.h +++ b/src/core/SkDeviceImageFilterProxy.h @@ -21,9 +21,9 @@ public: return fDevice->canHandleImageFilter(filter); } virtual bool filterImage(const SkImageFilter* filter, const SkBitmap& src, - const SkMatrix& ctm, + const SkImageFilter::Context& ctx, SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { - return fDevice->filterImage(filter, src, ctm, result, offset); + return fDevice->filterImage(filter, src, ctx, result, offset); } private: diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 4a380c52eb..6613f09b93 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -93,7 +93,7 @@ void SkImageFilter::flatten(SkWriteBuffer& buffer) const { } bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, - const SkMatrix& ctm, + const Context& context, SkBitmap* result, SkIPoint* offset) const { SkASSERT(result); SkASSERT(offset); @@ -101,8 +101,8 @@ bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, * Give the proxy first shot at the filter. If it returns false, ask * the filter to do it. */ - return (proxy && proxy->filterImage(this, src, ctm, result, offset)) || - this->onFilterImage(proxy, src, ctm, result, offset); + return (proxy && proxy->filterImage(this, src, context, result, offset)) || + this->onFilterImage(proxy, src, context, result, offset); } bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, @@ -134,7 +134,7 @@ void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { } } -bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, +bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const Context&, SkBitmap*, SkIPoint*) const { return false; } @@ -143,21 +143,21 @@ bool SkImageFilter::canFilterImageGPU() const { return this->asNewEffect(NULL, NULL, SkMatrix::I(), SkIRect()); } -bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, +bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, SkBitmap* result, SkIPoint* offset) const { #if SK_SUPPORT_GPU SkBitmap input = src; SkASSERT(fInputCount == 1); SkIPoint srcOffset = SkIPoint::Make(0, 0); if (this->getInput(0) && - !this->getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) { + !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) { return false; } GrTexture* srcTexture = input.getTexture(); SkIRect bounds; src.getBounds(&bounds); bounds.offset(srcOffset); - if (!this->applyCropRect(&bounds, ctm)) { + if (!this->applyCropRect(&bounds, ctx.ctm())) { return false; } SkRect srcRect = SkRect::Make(bounds); @@ -179,7 +179,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMa offset->fX = bounds.left(); offset->fY = bounds.top(); bounds.offset(-srcOffset); - SkMatrix matrix(ctm); + SkMatrix matrix(ctx.ctm()); matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())); this->asNewEffect(&effect, srcTexture, matrix, bounds); SkASSERT(effect); @@ -253,7 +253,7 @@ void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit } bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, - const SkBitmap& src, const SkMatrix& ctm, + const SkBitmap& src, const Context& ctx, SkBitmap* result, SkIPoint* offset) const { // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity // matrix with no clip and that the matrix, clip, and render target set before this function was @@ -261,9 +261,9 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, GrContext* context = src.getTexture()->getContext(); GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); if (this->canFilterImageGPU()) { - return this->filterImageGPU(proxy, src, ctm, result, offset); + return this->filterImageGPU(proxy, src, ctx, result, offset); } else { - if (this->filterImage(proxy, src, ctm, result, offset)) { + if (this->filterImage(proxy, src, ctx, result, offset)) { if (!result->getTexture()) { SkImageInfo info; if (!result->asImageInfo(&info)) { |