SkPathEffect.h revision d3521f1a8dc07fe84d6a8f2151b0c176ff1ec8ca
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 15class 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*/ 25class SK_API SkPathEffect : public SkFlattenable { 26public: 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 /** 38 * Compute a conservative bounds for its effect, given the src bounds. 39 * The baseline implementation just assigns src to dst. 40 */ 41 virtual void computeFastBounds(SkRect* dst, const SkRect& src); 42 43protected: 44 SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 45 46private: 47 // illegal 48 SkPathEffect(const SkPathEffect&); 49 SkPathEffect& operator=(const SkPathEffect&); 50 51 typedef SkFlattenable INHERITED; 52}; 53 54/** \class SkPairPathEffect 55 56 Common baseclass for Compose and Sum. This subclass manages two pathEffects, 57 including flattening them. It does nothing in filterPath, and is only useful 58 for managing the lifetimes of its two arguments. 59*/ 60class SkPairPathEffect : public SkPathEffect { 61public: 62 SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); 63 virtual ~SkPairPathEffect(); 64 65protected: 66 SkPairPathEffect(SkFlattenableReadBuffer&); 67 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 68 69 // these are visible to our subclasses 70 SkPathEffect* fPE0, *fPE1; 71 72private: 73 typedef SkPathEffect INHERITED; 74}; 75 76/** \class SkComposePathEffect 77 78 This subclass of SkPathEffect composes its two arguments, to create 79 a compound pathEffect. 80*/ 81class SkComposePathEffect : public SkPairPathEffect { 82public: 83 /** Construct a pathEffect whose effect is to apply first the inner pathEffect 84 and the the outer pathEffect (e.g. outer(inner(path))) 85 The reference counts for outer and inner are both incremented in the constructor, 86 and decremented in the destructor. 87 */ 88 SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) 89 : INHERITED(outer, inner) {} 90 91 // overrides 92 93 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 94 95 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect) 96 97protected: 98 SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 99 100private: 101 // illegal 102 SkComposePathEffect(const SkComposePathEffect&); 103 SkComposePathEffect& operator=(const SkComposePathEffect&); 104 105 typedef SkPairPathEffect INHERITED; 106}; 107 108/** \class SkSumPathEffect 109 110 This subclass of SkPathEffect applies two pathEffects, one after the other. 111 Its filterPath() returns true if either of the effects succeeded. 112*/ 113class SkSumPathEffect : public SkPairPathEffect { 114public: 115 /** Construct a pathEffect whose effect is to apply two effects, in sequence. 116 (e.g. first(path) + second(path)) 117 The reference counts for first and second are both incremented in the constructor, 118 and decremented in the destructor. 119 */ 120 SkSumPathEffect(SkPathEffect* first, SkPathEffect* second) 121 : INHERITED(first, second) {} 122 123 // overrides 124 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 125 126 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect) 127 128protected: 129 SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 130 131private: 132 // illegal 133 SkSumPathEffect(const SkSumPathEffect&); 134 SkSumPathEffect& operator=(const SkSumPathEffect&); 135 136 typedef SkPairPathEffect INHERITED; 137}; 138 139#endif 140 141