Chromium Code Reviews| Index: src/core/SkImageFilter.cpp |
| diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp |
| index 56fb1ae47e356e25d1df5e847797152a42ac7a42..ba19a9772366818c620a8051f6c96a2e37698737 100644 |
| --- a/src/core/SkImageFilter.cpp |
| +++ b/src/core/SkImageFilter.cpp |
| @@ -10,6 +10,11 @@ |
| #include "SkBitmap.h" |
| #include "SkFlattenableBuffers.h" |
| #include "SkRect.h" |
| +#if SK_SUPPORT_GPU |
| +#include "GrContext.h" |
| +#include "GrTexture.h" |
| +#include "SkImageFilterUtils.h" |
| +#endif |
| SK_DEFINE_INST_COUNT(SkImageFilter) |
| @@ -104,12 +109,45 @@ bool SkImageFilter::onFilterImage(Proxy*, const SkBitmap&, const SkMatrix&, |
| } |
| bool SkImageFilter::canFilterImageGPU() const { |
| - return false; |
| + return asNewEffect(NULL, NULL); |
|
bsalomon
2013/04/08 19:38:30
this->
|
| } |
| bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result) { |
| - SkASSERT(false); // Should never be called, since canFilterImageGPU() returned false. |
| +#if SK_SUPPORT_GPU |
| + SkBitmap input; |
| + SkASSERT(fInputCount == 1); |
| + if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, &input)) { |
|
bsalomon
2013/04/08 19:38:30
this->
|
| + return false; |
| + } |
| + GrTexture* srcTexture = (GrTexture*) input.getTexture(); |
| + SkRect rect; |
| + src.getBounds(&rect); |
| + GrContext* context = srcTexture->getContext(); |
| + |
| + GrTextureDesc desc; |
| + desc.fFlags = kRenderTarget_GrTextureFlagBit, |
| + desc.fWidth = input.width(); |
| + desc.fHeight = input.height(); |
| + desc.fConfig = kRGBA_8888_GrPixelConfig; |
| + |
| + GrAutoScratchTexture dst(context, desc); |
| + GrContext::AutoMatrix am; |
| + am.setIdentity(context); |
| + GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); |
| + GrContext::AutoClip acs(context, rect); |
| + GrEffectRef* effect; |
| + asNewEffect(&effect, srcTexture); |
|
bsalomon
2013/04/08 19:38:30
this->
|
| + SkASSERT(effect); |
| + SkAutoUnref effectRef(effect); |
| + GrPaint paint; |
| + paint.colorStage(0)->setEffect(effect); |
| + context->drawRect(paint, rect); |
| + SkAutoTUnref<GrTexture> resultTex(dst.detach()); |
| + SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), result); |
| + return true; |
| +#else |
| return false; |
| +#endif |
| } |
| bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |