OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrShape_DEFINED | 8 #ifndef GrShape_DEFINED |
9 #define GrShape_DEFINED | 9 #define GrShape_DEFINED |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 GrShape& operator=(const GrShape& that); | 99 GrShape& operator=(const GrShape& that); |
100 | 100 |
101 ~GrShape() { | 101 ~GrShape() { |
102 if (Type::kPath == fType) { | 102 if (Type::kPath == fType) { |
103 fPath.reset(); | 103 fPath.reset(); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 const GrStyle& style() const { return fStyle; } | 107 const GrStyle& style() const { return fStyle; } |
108 | 108 |
109 /** | 109 GrShape applyStyle(GrStyle::Apply apply) { return GrShape(*this, apply); } |
110 * Returns a GrShape where the shape's geometry fully reflects the original
shape's GrStyle. | |
111 * The GrStyle of the returned shape will either be fill or hairline. | |
112 */ | |
113 GrShape applyFullStyle() { return GrShape(*this, false); } | |
114 | |
115 /** | |
116 * Similar to above but applies only the path effect. Path effects take the
original geometry | |
117 * and fill/stroking information and compute a new geometry and residual fil
l/stroking | |
118 * information to be applied. The path effect's output geometry and stroking
will be captured | |
119 * in the returned GrShape. | |
120 */ | |
121 GrShape applyPathEffect() { return GrShape(*this, true); } | |
122 | 110 |
123 bool asRRect(SkRRect* rrect) const { | 111 bool asRRect(SkRRect* rrect) const { |
124 if (Type::kRRect != fType) { | 112 if (Type::kRRect != fType) { |
125 return false; | 113 return false; |
126 } | 114 } |
127 if (rrect) { | 115 if (rrect) { |
128 *rrect = fRRect; | 116 *rrect = fRRect; |
129 } | 117 } |
130 return true; | 118 return true; |
131 } | 119 } |
(...skipping 26 matching lines...) Expand all Loading... |
158 */ | 146 */ |
159 void writeUnstyledKey(uint32_t* key) const; | 147 void writeUnstyledKey(uint32_t* key) const; |
160 | 148 |
161 private: | 149 private: |
162 enum class Type { | 150 enum class Type { |
163 kEmpty, | 151 kEmpty, |
164 kRRect, | 152 kRRect, |
165 kPath, | 153 kPath, |
166 }; | 154 }; |
167 | 155 |
168 /** | |
169 * Computes the key length for a GrStyle. The return will be negative if it
cannot be turned | |
170 * into a key. | |
171 */ | |
172 static int StyleKeySize(const GrStyle& , bool stopAfterPE); | |
173 | |
174 /** | |
175 * Writes a unique key for the style into the provided buffer. This function
assumes the buffer | |
176 * has room for at least StyleKeySize() values. It assumes that StyleKeySize
() returns a | |
177 * positive value for the style and stopAfterPE param. This is written so th
at the key for just | |
178 * dash application followed by the key for the remaining SkStrokeRec is the
same as the | |
179 * key for applying dashing and SkStrokeRec all at once. | |
180 */ | |
181 static void StyleKey(uint32_t*, const GrStyle&, bool stopAfterPE); | |
182 | 156 |
183 /** Constructor used by Apply* functions */ | 157 /** Constructor used by Apply* functions */ |
184 GrShape(const GrShape& parentShape, bool stopAfterPE); | 158 GrShape(const GrShape& parentShape, GrStyle::Apply); |
185 | 159 |
186 /** | 160 /** |
187 * Determines the key we should inherit from the input shape's geometry and
style when | 161 * Determines the key we should inherit from the input shape's geometry and
style when |
188 * we are applying the style to create a new shape. | 162 * we are applying the style to create a new shape. |
189 */ | 163 */ |
190 void setInheritedKey(const GrShape& parentShape, bool stopAfterPE); | 164 void setInheritedKey(const GrShape& parentShape, GrStyle::Apply); |
191 | 165 |
192 void attemptToReduceFromPath() { | 166 void attemptToReduceFromPath() { |
193 SkASSERT(Type::kPath == fType); | 167 SkASSERT(Type::kPath == fType); |
194 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEf
fect(), | 168 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEf
fect(), |
195 fStyle.strokeRec()); | 169 fStyle.strokeRec()); |
196 if (Type::kPath != fType) { | 170 if (Type::kPath != fType) { |
197 fPath.reset(); | 171 fPath.reset(); |
198 fInheritedKey.reset(0); | 172 fInheritedKey.reset(0); |
199 } | 173 } |
200 } | 174 } |
(...skipping 30 matching lines...) Expand all Loading... |
231 return Type::kPath; | 205 return Type::kPath; |
232 } | 206 } |
233 | 207 |
234 Type fType; | 208 Type fType; |
235 SkRRect fRRect; | 209 SkRRect fRRect; |
236 SkTLazy<SkPath> fPath; | 210 SkTLazy<SkPath> fPath; |
237 GrStyle fStyle; | 211 GrStyle fStyle; |
238 SkAutoSTArray<8, uint32_t> fInheritedKey; | 212 SkAutoSTArray<8, uint32_t> fInheritedKey; |
239 }; | 213 }; |
240 #endif | 214 #endif |
OLD | NEW |