diff options
author | 2013-07-03 15:34:35 +0000 | |
---|---|---|
committer | 2013-07-03 15:34:35 +0000 | |
commit | 491493119c11206c5823b76eb6420a705be243a1 (patch) | |
tree | 4fe04b434de7061a325a42fcb190691443bc559f /src/core | |
parent | 6c035f6c873d02d3cf46ecf67b6d9c2af3c374d8 (diff) |
Add canFilterMaskGPU & filterMaskGPU to SkMaskFilter
https://codereview.chromium.org/18110012/
git-svn-id: http://skia.googlecode.com/svn/trunk@9888 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkMaskFilter.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp index 0346ce0e9c..fbee4dc09b 100644 --- a/src/core/SkMaskFilter.cpp +++ b/src/core/SkMaskFilter.cpp @@ -11,7 +11,11 @@ #include "SkBlitter.h" #include "SkBounder.h" #include "SkDraw.h" +#include "SkGr.h" +#include "SkGrPixelRef.h" #include "SkRasterClip.h" +#include "SkTypes.h" +#include "GrTexture.h" SK_DEFINE_INST_COUNT(SkMaskFilter) @@ -266,8 +270,69 @@ SkMaskFilter::filterRectsToNine(const SkRect[], int count, const SkMatrix&, return kUnimplemented_FilterReturn; } -SkMaskFilter::BlurType SkMaskFilter::asABlur(BlurInfo*) const { - return kNone_BlurType; +bool SkMaskFilter::asNewEffect(GrEffectRef** effect, GrTexture*) const { + return false; +} + +bool SkMaskFilter::canFilterMaskGPU(const SkRect& devBounds, + const SkIRect& clipBounds, + const SkMatrix& ctm, + SkRect* maskRect) const { + return false; +} + +bool SkMaskFilter::filterMaskGPU(GrContext* context, + const SkBitmap& srcBM, + const SkRect& maskRect, + SkBitmap* resultBM) const { + SkAutoTUnref<GrTexture> src; + bool canOverwriteSrc = false; + if (NULL == srcBM.getTexture()) { + GrTextureDesc desc; + // Needs to be a render target to be overwritten in filterMaskGPU + desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; + desc.fConfig = SkBitmapConfig2GrPixelConfig(srcBM.config()); + desc.fWidth = srcBM.width(); + desc.fHeight = srcBM.height(); + + // TODO: right now this is exact to guard against out of bounds reads + // by the filter code. More thought needs to be devoted to the + // "filterMaskGPU" contract and then enforced (i.e., clamp the code + // in "filterMaskGPU" so it never samples beyond maskRect) + GrAutoScratchTexture ast(context, desc, GrContext::kExact_ScratchTexMatch); + if (NULL == ast.texture()) { + return false; + } + + SkAutoLockPixels alp(srcBM); + ast.texture()->writePixels(0, 0, srcBM.width(), srcBM.height(), + desc.fConfig, + srcBM.getPixels(), srcBM.rowBytes()); + + src.reset(ast.detach()); + canOverwriteSrc = true; + } else { + src.reset((GrTexture*) srcBM.getTexture()); + src.get()->ref(); + } + GrTexture* dst; + + bool result = this->filterMaskGPU(src, maskRect, &dst, canOverwriteSrc); + if (!result) { + return false; + } + + resultBM->setConfig(srcBM.config(), dst->width(), dst->height()); + resultBM->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (dst)))->unref(); + dst->unref(); + return true; +} + +bool SkMaskFilter::filterMaskGPU(GrTexture* src, + const SkRect& maskRect, + GrTexture** result, + bool canOverwriteSrc) const { + return false; } void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |