epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 25 | class SK_API SkPathEffect : public SkFlattenable { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 37 | protected: |
| 38 | SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} |
| 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | private: |
| 41 | // illegal |
| 42 | SkPathEffect(const SkPathEffect&); |
| 43 | SkPathEffect& operator=(const SkPathEffect&); |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 44 | |
| 45 | typedef SkFlattenable INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /** \class SkPairPathEffect |
| 49 | |
| 50 | Common baseclass for Compose and Sum. This subclass manages two pathEffects, |
| 51 | including flattening them. It does nothing in filterPath, and is only useful |
| 52 | for managing the lifetimes of its two arguments. |
| 53 | */ |
| 54 | class SkPairPathEffect : public SkPathEffect { |
| 55 | public: |
| 56 | SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); |
| 57 | virtual ~SkPairPathEffect(); |
| 58 | |
| 59 | protected: |
| 60 | SkPairPathEffect(SkFlattenableReadBuffer&); |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 61 | virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | // these are visible to our subclasses |
| 63 | SkPathEffect* fPE0, *fPE1; |
| 64 | |
| 65 | private: |
| 66 | typedef SkPathEffect INHERITED; |
| 67 | }; |
| 68 | |
| 69 | /** \class SkComposePathEffect |
| 70 | |
| 71 | This subclass of SkPathEffect composes its two arguments, to create |
| 72 | a compound pathEffect. |
| 73 | */ |
| 74 | class SkComposePathEffect : public SkPairPathEffect { |
| 75 | public: |
| 76 | /** Construct a pathEffect whose effect is to apply first the inner pathEffect |
| 77 | and the the outer pathEffect (e.g. outer(inner(path))) |
| 78 | The reference counts for outer and inner are both incremented in the constructor, |
| 79 | and decremented in the destructor. |
| 80 | */ |
| 81 | SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) |
| 82 | : INHERITED(outer, inner) {} |
| 83 | |
| 84 | // overrides |
| 85 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); |
| 87 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 88 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | |
| 90 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
| 105 | class SkSumPathEffect : public SkPairPathEffect { |
| 106 | public: |
| 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 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); |
| 117 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 118 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | |
| 120 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 121 | SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} |
| 122 | |
| 123 | // illegal |
| 124 | SkSumPathEffect(const SkSumPathEffect&); |
| 125 | SkSumPathEffect& operator=(const SkSumPathEffect&); |
| 126 | |
| 127 | typedef SkPairPathEffect INHERITED; |
| 128 | }; |
| 129 | |
| 130 | #endif |
| 131 | |