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 SkPathEffect_DEFINED 11 #define SkPathEffect_DEFINED 12 13 #include "SkFlattenable.h" 14 15 class SkPath; 16 17 /** \class SkPathEffect 18 19 SkPathEffect is the base class for objects in the SkPaint that affect 20 the geometry of a drawing primitive before it is transformed by the 21 canvas' matrix and drawn. 22 23 Dashing is implemented as a subclass of SkPathEffect. 24 */ 25 class SK_API SkPathEffect : public SkFlattenable { 26 public: 27 SkPathEffect() {} 28 29 /** Given a src path and a width value, return true if the patheffect 30 has produced a new path (dst) and a new width value. If false is returned, 31 ignore dst and width. 32 On input, width >= 0 means the src should be stroked 33 On output, width >= 0 means the dst should be stroked 34 */ 35 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) = 0; 36 37 SK_DECLARE_FLATTENABLE_REGISTRAR() 38 private: 39 // illegal 40 SkPathEffect(const SkPathEffect&); 41 SkPathEffect& operator=(const SkPathEffect&); 42 }; 43 44 /** \class SkPairPathEffect 45 46 Common baseclass for Compose and Sum. This subclass manages two pathEffects, 47 including flattening them. It does nothing in filterPath, and is only useful 48 for managing the lifetimes of its two arguments. 49 */ 50 class SkPairPathEffect : public SkPathEffect { 51 public: 52 SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); 53 virtual ~SkPairPathEffect(); 54 55 protected: 56 SkPairPathEffect(SkFlattenableReadBuffer&); 57 virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE; 58 // these are visible to our subclasses 59 SkPathEffect* fPE0, *fPE1; 60 61 private: 62 typedef SkPathEffect INHERITED; 63 }; 64 65 /** \class SkComposePathEffect 66 67 This subclass of SkPathEffect composes its two arguments, to create 68 a compound pathEffect. 69 */ 70 class SkComposePathEffect : public SkPairPathEffect { 71 public: 72 /** Construct a pathEffect whose effect is to apply first the inner pathEffect 73 and the the outer pathEffect (e.g. outer(inner(path))) 74 The reference counts for outer and inner are both incremented in the constructor, 75 and decremented in the destructor. 76 */ 77 SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) 78 : INHERITED(outer, inner) {} 79 80 // overrides 81 82 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 83 84 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 85 return SkNEW_ARGS(SkComposePathEffect, (buffer)); 86 } 87 88 protected: 89 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } 90 91 private: 92 SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 93 94 // illegal 95 SkComposePathEffect(const SkComposePathEffect&); 96 SkComposePathEffect& operator=(const SkComposePathEffect&); 97 98 typedef SkPairPathEffect INHERITED; 99 }; 100 101 /** \class SkSumPathEffect 102 103 This subclass of SkPathEffect applies two pathEffects, one after the other. 104 Its filterPath() returns true if either of the effects succeeded. 105 */ 106 class SkSumPathEffect : public SkPairPathEffect { 107 public: 108 /** Construct a pathEffect whose effect is to apply two effects, in sequence. 109 (e.g. first(path) + second(path)) 110 The reference counts for first and second are both incremented in the constructor, 111 and decremented in the destructor. 112 */ 113 SkSumPathEffect(SkPathEffect* first, SkPathEffect* second) 114 : INHERITED(first, second) {} 115 116 // overrides 117 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 118 119 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 120 return SkNEW_ARGS(SkSumPathEffect, (buffer)); 121 } 122 123 protected: 124 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } 125 126 private: 127 SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 128 129 // illegal 130 SkSumPathEffect(const SkSumPathEffect&); 131 SkSumPathEffect& operator=(const SkSumPathEffect&); 132 133 typedef SkPairPathEffect INHERITED; 134 }; 135 136 #endif 137 138