From 491493119c11206c5823b76eb6420a705be243a1 Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Wed, 3 Jul 2013 15:34:35 +0000 Subject: 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 --- include/core/SkMaskFilter.h | 64 +++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h index aa499ecd23..40a03a5205 100644 --- a/include/core/SkMaskFilter.h +++ b/include/core/SkMaskFilter.h @@ -14,6 +14,7 @@ #include "SkMask.h" #include "SkPaint.h" +class SkBitmap; class SkBlitter; class SkBounder; class SkMatrix; @@ -58,27 +59,56 @@ public: virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, SkIPoint* margin) const; - enum BlurType { - kNone_BlurType, //!< this maskfilter is not a blur - kNormal_BlurType, //!< fuzzy inside and outside - kSolid_BlurType, //!< solid inside, fuzzy outside - kOuter_BlurType, //!< nothing inside, fuzzy outside - kInner_BlurType //!< fuzzy inside, nothing outside - }; +#if SK_SUPPORT_GPU + /** + * Returns true if the filter can be expressed a single-pass + * GrEffect, used to process this filter on the GPU, or false if + * not. + * + * If effect is non-NULL, a new GrEffect instance is stored + * in it. The caller assumes ownership of the stage, and it is up to the + * caller to unref it. + */ + virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const; - struct BlurInfo { - SkScalar fRadius; - bool fIgnoreTransform; - bool fHighQuality; - }; + /** + * Returns true if the filter can be processed on the GPU. This is most + * often used for multi-pass effects, where intermediate results must be + * rendered to textures. For single-pass effects, use asNewEffect(). + * + * 'maskRect' returns the device space portion of the mask the the filter + * needs. The mask passed into 'filterMaskGPU' should have the same extent + * as 'maskRect' but be translated to the upper-left corner of the mask + * (i.e., (maskRect.fLeft, maskRect.fTop) appears at (0, 0) in the mask). + */ + virtual bool canFilterMaskGPU(const SkRect& devBounds, + const SkIRect& clipBounds, + const SkMatrix& ctm, + SkRect* maskRect) const; + + /** + * Perform this mask filter on the GPU. This is most often used for + * multi-pass effects, where intermediate results must be rendered to + * textures. For single-pass effects, use asNewEffect(). 'src' is the + * source image for processing, as a texture-backed bitmap. 'result' is + * the destination bitmap, which should contain a texture-backed pixelref + * on success. 'maskRect' should be the rect returned from canFilterMaskGPU. + */ + bool filterMaskGPU(GrContext* context, + const SkBitmap& src, + const SkRect& maskRect, + SkBitmap* result) const; /** - * Optional method for maskfilters that can be described as a blur. If so, - * they return the corresponding BlurType and set the fields in BlurInfo - * (if not null). If they cannot be described as a blur, they return - * kNone_BlurType and ignore the info parameter. + * This flavor of 'filterMaskGPU' provides a more direct means of accessing + * the filtering capabilities. Setting 'canOverwriteSrc' can allow some + * filters to skip the allocation of an additional texture. */ - virtual BlurType asABlur(BlurInfo*) const; + virtual bool filterMaskGPU(GrTexture* src, + const SkRect& maskRect, + GrTexture** result, + bool canOverwriteSrc) const; +#endif /** * The fast bounds function is used to enable the paint to be culled early -- cgit v1.2.3