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