blob: 48181eea46931308262e0c096e6c8f2e42803b3a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000025class SK_API SkPathEffect : public SkFlattenable {
reed@android.com8a1c16f2008-12-17 15:59:43 +000026public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 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.comba28d032012-03-26 17:57:35 +000037protected:
38 SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
39
reed@android.com8a1c16f2008-12-17 15:59:43 +000040private:
41 // illegal
42 SkPathEffect(const SkPathEffect&);
43 SkPathEffect& operator=(const SkPathEffect&);
djsollen@google.comba28d032012-03-26 17:57:35 +000044
45 typedef SkFlattenable INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000046};
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*/
54class SkPairPathEffect : public SkPathEffect {
55public:
56 SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
57 virtual ~SkPairPathEffect();
58
59protected:
60 SkPairPathEffect(SkFlattenableReadBuffer&);
tomhudson@google.com13413042011-10-03 16:01:10 +000061 virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 // these are visible to our subclasses
63 SkPathEffect* fPE0, *fPE1;
64
65private:
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*/
74class SkComposePathEffect : public SkPairPathEffect {
75public:
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.com8a1c16f2008-12-17 15:59:43 +000086 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
87
djsollen@google.comba28d032012-03-26 17:57:35 +000088 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
reed@android.com8a1c16f2008-12-17 15:59:43 +000089
90private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000091 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
reed@android.com8a1c16f2008-12-17 15:59:43 +0000116 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
117
djsollen@google.comba28d032012-03-26 17:57:35 +0000118 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119
120private:
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121 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