Chromium Code Reviews| Index: src/core/SkImageFilter.cpp |
| diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp |
| index 56fb1ae47e356e25d1df5e847797152a42ac7a42..66d067c7792e0e7e29bb887e1c6d69c6c7aa82a2 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) |
| @@ -108,8 +113,39 @@ bool SkImageFilter::canFilterImageGPU() const { |
| } |
| 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)) { |
| + 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); |
| + SkAutoTUnref<GrEffectRef> effect(asNewEffect(srcTexture)); |
|
bsalomon
2013/04/08 17:52:17
this->asNewEffect()
|
| + SkASSERT(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, |
| @@ -118,8 +154,8 @@ bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| return true; |
| } |
| -bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const { |
| - return false; |
| +GrEffectRef* SkImageFilter::asNewEffect(GrTexture*) const { |
| + return NULL; |
| } |
| bool SkImageFilter::asColorFilter(SkColorFilter**) const { |