From 1aa54bf6696afc7d06fc8ecc63dad2840a4d6179 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Mon, 5 Aug 2013 16:53:50 +0000 Subject: [PATCH] Added ctm matrix to GPU path There should be no changes in behavior caused by this cl, it just adds the ctm matrix to filterImageGPU so that it may be used for scaling on all platforms when it is implemented on the blink side. BUG= R=senorblanco@google.com, senorblanco@chromium.org Author: sugoi@chromium.org Review URL: https://chromiumcodereview.appspot.com/22209002 git-svn-id: http://skia.googlecode.com/svn/trunk@10536 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkImageFilter.h | 3 ++- include/core/SkImageFilterUtils.h | 3 ++- include/effects/SkBicubicImageFilter.h | 4 ++-- include/effects/SkBlurImageFilter.h | 4 ++-- include/effects/SkDisplacementMapEffect.h | 4 ++-- include/effects/SkMorphologyImageFilter.h | 8 ++++---- include/effects/SkXfermodeImageFilter.h | 4 ++-- src/core/SkImageFilter.cpp | 6 +++--- src/core/SkImageFilterUtils.cpp | 10 ++++------ src/effects/SkBicubicImageFilter.cpp | 5 +++-- src/effects/SkBlurImageFilter.cpp | 6 +++--- src/effects/SkDisplacementMapEffect.cpp | 10 +++++----- src/effects/SkMorphologyImageFilter.cpp | 12 ++++++------ src/effects/SkXfermodeImageFilter.cpp | 5 +++-- src/gpu/SkGpuDevice.cpp | 14 +++++++++----- 15 files changed, 52 insertions(+), 46 deletions(-) diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h index 54de2881d5..78eb9aed2a 100644 --- a/include/core/SkImageFilter.h +++ b/include/core/SkImageFilter.h @@ -114,7 +114,8 @@ public: * relative to the src when it is drawn. The default implementation does * single-pass processing using asNewEffect(). */ - virtual bool filterImageGPU(Proxy*, const SkBitmap& src, SkBitmap* result, SkIPoint* offset); + virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset); /** * Returns whether this image filter is a color filter and puts the color filter into the diff --git a/include/core/SkImageFilterUtils.h b/include/core/SkImageFilterUtils.h index 5b9f192a0f..b3921cdaf6 100644 --- a/include/core/SkImageFilterUtils.h +++ b/include/core/SkImageFilterUtils.h @@ -29,7 +29,8 @@ public: * will be processed in software and uploaded to the GPU. */ static bool GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy, - const SkBitmap& src, SkBitmap* result, SkIPoint* offset); + const SkBitmap& src, const SkMatrix& ctm, SkBitmap* result, + SkIPoint* offset); }; #endif diff --git a/include/effects/SkBicubicImageFilter.h b/include/effects/SkBicubicImageFilter.h index 75cd27df74..bd918eb769 100644 --- a/include/effects/SkBicubicImageFilter.h +++ b/include/effects/SkBicubicImageFilter.h @@ -43,8 +43,8 @@ protected: #if SK_SUPPORT_GPU virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #endif private: diff --git a/include/effects/SkBlurImageFilter.h b/include/effects/SkBlurImageFilter.h index f2677353e0..ef03a99d46 100644 --- a/include/effects/SkBlurImageFilter.h +++ b/include/effects/SkBlurImageFilter.h @@ -28,8 +28,8 @@ protected: SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; bool canFilterImageGPU() const SK_OVERRIDE { return true; } - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; private: SkSize fSigma; diff --git a/include/effects/SkDisplacementMapEffect.h b/include/effects/SkDisplacementMapEffect.h index 5efbf50e44..ed9d15b15a 100644 --- a/include/effects/SkDisplacementMapEffect.h +++ b/include/effects/SkDisplacementMapEffect.h @@ -38,8 +38,8 @@ public: SkIPoint* offset) SK_OVERRIDE; #if SK_SUPPORT_GPU virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #endif protected: diff --git a/include/effects/SkMorphologyImageFilter.h b/include/effects/SkMorphologyImageFilter.h index 635fe42428..def01e8e0a 100644 --- a/include/effects/SkMorphologyImageFilter.h +++ b/include/effects/SkMorphologyImageFilter.h @@ -38,8 +38,8 @@ public: virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #if SK_SUPPORT_GPU - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #endif SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) @@ -59,8 +59,8 @@ public: virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #if SK_SUPPORT_GPU - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #endif SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) diff --git a/include/effects/SkXfermodeImageFilter.h b/include/effects/SkXfermodeImageFilter.h index d13c4b2d24..89a277304c 100644 --- a/include/effects/SkXfermodeImageFilter.h +++ b/include/effects/SkXfermodeImageFilter.h @@ -35,8 +35,8 @@ public: SkIPoint* offset) SK_OVERRIDE; #if SK_SUPPORT_GPU virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } - virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) SK_OVERRIDE; + virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; #endif protected: diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index f37a220a39..222a029997 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -105,12 +105,12 @@ bool SkImageFilter::canFilterImageGPU() const { return this->asNewEffect(NULL, NULL, SkIPoint::Make(0, 0)); } -bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { +bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { #if SK_SUPPORT_GPU SkBitmap input; SkASSERT(fInputCount == 1); - if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, &input, offset)) { + if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, ctm, &input, offset)) { return false; } GrTexture* srcTexture = input.getTexture(); diff --git a/src/core/SkImageFilterUtils.cpp b/src/core/SkImageFilterUtils.cpp index 0680ccf45a..a4ce51eb91 100644 --- a/src/core/SkImageFilterUtils.cpp +++ b/src/core/SkImageFilterUtils.cpp @@ -21,17 +21,15 @@ bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, } bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy, - const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { + const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { if (!filter) { *result = src; return true; } else if (filter->canFilterImageGPU()) { - return filter->filterImageGPU(proxy, src, result, offset); + return filter->filterImageGPU(proxy, src, ctm, result, offset); } else { - SkMatrix matrix; - matrix.reset(); - if (filter->filterImage(proxy, src, matrix, result, offset)) { + if (filter->filterImage(proxy, src, ctm, result, offset)) { if (!result->getTexture()) { GrContext* context = ((GrTexture *) src.getTexture())->getContext(); GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp index 5161f6dd8d..db8dbfd028 100644 --- a/src/effects/SkBicubicImageFilter.cpp +++ b/src/effects/SkBicubicImageFilter.cpp @@ -341,9 +341,10 @@ GrEffectRef* GrBicubicEffect::TestCreate(SkMWCRandom* random, return GrBicubicEffect::Create(textures[texIdx], coefficients); } -bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, SkIPoint* offset) { +bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { SkBitmap srcBM; - if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &srcBM, offset)) { + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &srcBM, offset)) { return false; } GrTexture* srcTexture = srcBM.getTexture(); diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index 25383cda06..4b2d3b88ff 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -206,11 +206,11 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, return true; } -bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { +bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { #if SK_SUPPORT_GPU SkBitmap input; - if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &input, offset)) { + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, offset)) { return false; } GrTexture* source = input.getTexture(); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 7b64d1da1a..dad0623d2f 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -275,19 +275,19 @@ private: typedef GrEffect INHERITED; }; -bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { +bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { SkBitmap colorBM; SkIPoint colorOffset = SkIPoint::Make(0, 0); - if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, &colorBM, + if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, ctm, &colorBM, &colorOffset)) { return false; } GrTexture* color = colorBM.getTexture(); SkBitmap displacementBM; SkIPoint displacementOffset = SkIPoint::Make(0, 0); - if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, src, &displacementBM, - &displacementOffset)) { + if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, src, ctm, + &displacementBM, &displacementOffset)) { return false; } GrTexture* displacement = displacementBM.getTexture(); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index ab3458c55e..fb8fd00081 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -502,10 +502,10 @@ GrTexture* apply_morphology(GrTexture* srcTexture, }; -bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { +bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { SkBitmap inputBM; - if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &inputBM, offset)) { + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &inputBM, offset)) { return false; } GrTexture* input = inputBM.getTexture(); @@ -516,10 +516,10 @@ bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBi return SkImageFilterUtils::WrapTexture(resultTex, src.width(), src.height(), result); } -bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result, - SkIPoint* offset) { +bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, + SkBitmap* result, SkIPoint* offset) { SkBitmap inputBM; - if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &inputBM, offset)) { + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &inputBM, offset)) { return false; } GrTexture* input = inputBM.getTexture(); diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index 3df59a87d2..898bad1100 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -78,18 +78,19 @@ bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy, bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, + const SkMatrix& ctm, SkBitmap* result, SkIPoint* offset) { SkBitmap background; SkIPoint backgroundOffset = SkIPoint::Make(0, 0); - if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &background, + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &background, &backgroundOffset)) { return false; } GrTexture* backgroundTex = background.getTexture(); SkBitmap foreground; SkIPoint foregroundOffset = SkIPoint::Make(0, 0); - if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, &foreground, + if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, ctm, &foreground, &foregroundOffset)) { return false; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 61de9822f4..be56eb67dc 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1372,7 +1372,8 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, static bool filter_texture(SkDevice* device, GrContext* context, GrTexture* texture, SkImageFilter* filter, - int w, int h, SkBitmap* result, SkIPoint* offset) { + int w, int h, const SkMatrix& ctm, SkBitmap* result, + SkIPoint* offset) { GrAssert(filter); SkDeviceImageFilterProxy proxy(device); @@ -1380,7 +1381,7 @@ static bool filter_texture(SkDevice* device, GrContext* context, // Save the render target and set it to NULL, so we don't accidentally draw to it in the // filter. Also set the clip wide open and the matrix to identity. GrContext::AutoWideOpenIdentityDraw awo(context, NULL); - return filter->filterImageGPU(&proxy, wrap_texture(texture), result, offset); + return filter->filterImageGPU(&proxy, wrap_texture(texture), ctm, result, offset); } else { return false; } @@ -1409,7 +1410,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, SkBitmap filteredBitmap; if (NULL != filter) { - if (filter_texture(this, fContext, texture, filter, w, h, &filteredBitmap, &offset)) { + if (filter_texture(this, fContext, texture, filter, w, h, SkMatrix::I(), &filteredBitmap, + &offset)) { texture = (GrTexture*) filteredBitmap.getTexture(); w = filteredBitmap.width(); h = filteredBitmap.height(); @@ -1494,7 +1496,8 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device, if (NULL != filter) { SkIPoint offset = SkIPoint::Make(0, 0); - if (filter_texture(this, fContext, devTex, filter, w, h, &filteredBitmap, &offset)) { + if (filter_texture(this, fContext, devTex, filter, w, h, SkMatrix::I(), &filteredBitmap, + &offset)) { devTex = filteredBitmap.getTexture(); w = filteredBitmap.width(); h = filteredBitmap.height(); @@ -1547,7 +1550,8 @@ bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, // must be pushed upstack. SkAutoCachedTexture act(this, src, NULL, &texture); - return filter_texture(this, fContext, texture, filter, src.width(), src.height(), result, offset); + return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctm, result, + offset); } ///////////////////////////////////////////////////////////////////////////////