1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #ifndef SkMaskFilter_DEFINED 11 #define SkMaskFilter_DEFINED 12 13 #include "SkFlattenable.h" 14 #include "SkMask.h" 15 16 class SkBlitter; 17 class SkBounder; 18 class SkMatrix; 19 class SkPath; 20 class SkRasterClip; 21 22 /** \class SkMaskFilter 23 24 SkMaskFilter is the base class for object that perform transformations on 25 an alpha-channel mask before drawing it. A subclass of SkMaskFilter may be 26 installed into a SkPaint. Once there, each time a primitive is drawn, it 27 is first scan converted into a SkMask::kA8_Format mask, and handed to the 28 filter, calling its filterMask() method. If this returns true, then the 29 new mask is used to render into the device. 30 31 Blur and emboss are implemented as subclasses of SkMaskFilter. 32 */ 33 class SkMaskFilter : public SkFlattenable { 34 public: SkMaskFilter()35 SkMaskFilter() {} 36 37 /** Returns the format of the resulting mask that this subclass will return 38 when its filterMask() method is called. 39 */ 40 virtual SkMask::Format getFormat() = 0; 41 42 /** Create a new mask by filter the src mask. 43 If src.fImage == null, then do not allocate or create the dst image 44 but do fill out the other fields in dstMask. 45 If you do allocate a dst image, use SkMask::AllocImage() 46 If this returns false, dst mask is ignored. 47 @param dst the result of the filter. If src.fImage == null, dst should not allocate its image 48 @param src the original image to be filtered. 49 @param matrix the CTM 50 @param margin if not null, return the buffer dx/dy need when calculating the effect. Used when 51 drawing a clipped object to know how much larger to allocate the src before 52 applying the filter. If returning false, ignore this parameter. 53 @return true if the dst mask was correctly created. 54 */ 55 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, 56 SkIPoint* margin); 57 flatten(SkFlattenableWriteBuffer &)58 virtual void flatten(SkFlattenableWriteBuffer& ) {} 59 60 enum BlurType { 61 kNone_BlurType, //!< this maskfilter is not a blur 62 kNormal_BlurType, //!< fuzzy inside and outside 63 kSolid_BlurType, //!< solid inside, fuzzy outside 64 kOuter_BlurType, //!< nothing inside, fuzzy outside 65 kInner_BlurType, //!< fuzzy inside, nothing outside 66 }; 67 68 struct BlurInfo { 69 SkScalar fRadius; 70 bool fIgnoreTransform; 71 bool fHighQuality; 72 }; 73 74 /** 75 * Optional method for maskfilters that can be described as a blur. If so, 76 * they return the corresponding BlurType and set the fields in BlurInfo 77 * (if not null). If they cannot be described as a blur, they return 78 * kNone_BlurType and ignore the info parameter. 79 */ 80 virtual BlurType asABlur(BlurInfo*) const; 81 82 /** 83 * The fast bounds function is used to enable the paint to be culled early 84 * in the drawing pipeline. This function accepts the current bounds of the 85 * paint as its src param and the filter adjust those bounds using its 86 * current mask and returns the result using the dest param. Callers are 87 * allowed to provide the same struct for both src and dest so each 88 * implementation must accomodate that behavior. 89 * 90 * The default impl calls filterMask with the src mask having no image, 91 * but subclasses may override this if they can compute the rect faster. 92 */ 93 virtual void computeFastBounds(const SkRect& src, SkRect* dest); 94 95 protected: 96 // empty for now, but lets get our subclass to remember to init us for the future SkMaskFilter(SkFlattenableReadBuffer &)97 SkMaskFilter(SkFlattenableReadBuffer&) {} 98 99 private: 100 friend class SkDraw; 101 102 /** Helper method that, given a path in device space, will rasterize it into a kA8_Format mask 103 and then call filterMask(). If this returns true, the specified blitter will be called 104 to render that mask. Returns false if filterMask() returned false. 105 This method is not exported to java. 106 */ 107 bool filterPath(const SkPath& devPath, const SkMatrix& devMatrix, 108 const SkRasterClip&, SkBounder*, SkBlitter* blitter); 109 }; 110 111 #endif 112 113