Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/gpu/GrShape.h

Issue 2070643002: Add some more getters to GrShape. (Closed) Base URL: https://chromium.googlesource.com/skia.git@moreshapestuf
Patch Set: rm extra space Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/GrShapeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 } 138 }
139 139
140 const GrStyle& style() const { return fStyle; } 140 const GrStyle& style() const { return fStyle; }
141 141
142 /** 142 /**
143 * Returns a shape that has either applied the path effect or path effect an d stroking 143 * Returns a shape that has either applied the path effect or path effect an d stroking
144 * information from this shape's style to its geometry. Scale is used when a pproximating the 144 * information from this shape's style to its geometry. Scale is used when a pproximating the
145 * output geometry and typically is computed from the view matrix 145 * output geometry and typically is computed from the view matrix
146 */ 146 */
147 GrShape applyStyle(GrStyle::Apply apply, SkScalar scale) { 147 GrShape applyStyle(GrStyle::Apply apply, SkScalar scale) const {
148 return GrShape(*this, apply, scale); 148 return GrShape(*this, apply, scale);
149 } 149 }
150 150
151 /** Returns the unstyled geometry as a rrect if possible. */ 151 /** Returns the unstyled geometry as a rrect if possible. */
152 bool asRRect(SkRRect* rrect, SkPath::Direction* dir, unsigned* start, bool* inverted) const { 152 bool asRRect(SkRRect* rrect, SkPath::Direction* dir, unsigned* start, bool* inverted) const {
153 if (Type::kRRect != fType) { 153 if (Type::kRRect != fType) {
154 return false; 154 return false;
155 } 155 }
156 if (rrect) { 156 if (rrect) {
157 *rrect = fRRect; 157 *rrect = fRRect;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 */ 213 */
214 const SkRect& bounds() const; 214 const SkRect& bounds() const;
215 215
216 /** 216 /**
217 * Gets the bounds of the geometry reflecting the shape's styling (ignoring inverse fill 217 * Gets the bounds of the geometry reflecting the shape's styling (ignoring inverse fill
218 * status). 218 * status).
219 */ 219 */
220 void styledBounds(SkRect* bounds) const; 220 void styledBounds(SkRect* bounds) const;
221 221
222 /** 222 /**
223 * Is this shape known to be convex, before styling is applied. An unclosed but otherwise
224 * convex path is considered to be closed if they styling reflects a fill an d not otherwise.
225 * This is because filling closes all contours in the path.
226 */
227 bool knownToBeConvex() const {
228 switch (fType) {
229 case Type::kEmpty:
230 return true;
231 case Type::kRRect:
232 return true;
233 case Type::kPath:
234 // SkPath.isConvex() really means "is this path convex were it t o be closed" and
235 // thus doesn't give the correct answer for stroked paths, hence we also check
236 // whether the path is either filled or closed. Convex paths may only have one
237 // contour hence isLastContourClosed() is a sufficient for a con vex path.
238 return (this->style().isSimpleFill() || fPath.get()->isLastConto urClosed()) &&
239 fPath.get()->isConvex();
240 }
241 return false;
242 }
243
244 /** Is the pre-styled geometry inverse filled? */
245 bool inverseFilled() const {
246 bool ret = false;
247 switch (fType) {
248 case Type::kEmpty:
249 ret = false;
250 break;
251 case Type::kRRect:
252 ret = fRRectIsInverted;
253 break;
254 case Type::kPath:
255 ret = this->fPath.get()->isInverseFillType();
256 break;
257 }
258 // Dashing ignores inverseness. We should have caught this earlier. skbu g.com/5421
259 SkASSERT(!(ret && this->style().isDashed()));
260 return ret;
261 }
262
263 /**
264 * Might applying the styling to the geometry produce an inverse fill. The " may" part comes in
265 * because an arbitrary path effect could produce an inverse filled path. In other cases this
266 * can be thought of as "inverseFilledAfterStyling()".
267 */
268 bool mayBeInverseFilledAfterStyling() const {
269 // An arbitrary path effect can produce an arbitrary output path, which may be inverse
270 // filled.
271 if (this->style().hasNonDashPathEffect()) {
272 return true;
273 }
274 return this->inverseFilled();
275 }
276
277 /**
223 * Is it known that the unstyled geometry has no unclosed contours. This mea ns that it will 278 * Is it known that the unstyled geometry has no unclosed contours. This mea ns that it will
224 * not have any caps if stroked (modulo the effect of any path effect). 279 * not have any caps if stroked (modulo the effect of any path effect).
225 */ 280 */
226 bool knownToBeClosed() const { 281 bool knownToBeClosed() const {
227 switch (fType) { 282 switch (fType) {
228 case Type::kEmpty: 283 case Type::kEmpty:
229 return true; 284 return true;
230 case Type::kRRect: 285 case Type::kRRect:
231 return true; 286 return true;
232 case Type::kPath: 287 case Type::kPath:
233 return false; 288 // SkPath doesn't keep track of the closed status of each contou r.
289 return SkPathPriv::IsClosedSingleContour(*fPath.get());
234 } 290 }
235 return false; 291 return false;
236 } 292 }
237 293
238 uint32_t segmentMask() const { 294 uint32_t segmentMask() const {
239 switch (fType) { 295 switch (fType) {
240 case Type::kEmpty: 296 case Type::kEmpty:
241 return 0; 297 return 0;
242 case Type::kRRect: 298 case Type::kRRect:
243 if (fRRect.getType() == SkRRect::kOval_Type) { 299 if (fRRect.getType() == SkRRect::kOval_Type) {
244 return SkPath::kConic_SegmentMask; 300 return SkPath::kConic_SegmentMask;
245 } else if (fRRect.getType() == SkRRect::kRect_Type) { 301 } else if (fRRect.getType() == SkRRect::kRect_Type) {
246 return SkPath::kLine_SegmentMask; 302 return SkPath::kLine_SegmentMask;
247 } 303 }
248 return SkPath::kLine_SegmentMask | SkPath::kConic_SegmentMask; 304 return SkPath::kLine_SegmentMask | SkPath::kConic_SegmentMask;
249 case Type::kPath: 305 case Type::kPath:
250 return fPath.get()->getSegmentMasks(); 306 return fPath.get()->getSegmentMasks();
251 } 307 }
252 return 0; 308 return 0;
253 } 309 }
254 310
255 /** 311 /**
256 * Gets the size of the key for the shape represented by this GrShape (ignor ing its styling). 312 * Gets the size of the key for the shape represented by this GrShape (ignor ing its styling).
257 * A negative value is returned if the shape has no key (shouldn't be cached ). 313 * A negative value is returned if the shape has no key (shouldn't be cached ).
258 */ 314 */
259 int unstyledKeySize() const; 315 int unstyledKeySize() const;
260 316
317 bool hasUnstyledKey() const { return this->unstyledKeySize() >= 0; }
318
261 /** 319 /**
262 * Writes unstyledKeySize() bytes into the provided pointer. Assumes that th ere is enough 320 * Writes unstyledKeySize() bytes into the provided pointer. Assumes that th ere is enough
263 * space allocated for the key and that unstyledKeySize() does not return a negative value 321 * space allocated for the key and that unstyledKeySize() does not return a negative value
264 * for this shape. 322 * for this shape.
265 */ 323 */
266 void writeUnstyledKey(uint32_t* key) const; 324 void writeUnstyledKey(uint32_t* key) const;
267 325
268 private: 326 private:
269 enum class Type { 327 enum class Type {
270 kEmpty, 328 kEmpty,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 SkPath::Direction fRRectDir; 397 SkPath::Direction fRRectDir;
340 unsigned fRRectStart; 398 unsigned fRRectStart;
341 bool fRRectIsInverted; 399 bool fRRectIsInverted;
342 SkTLazy<SkPath> fPath; 400 SkTLazy<SkPath> fPath;
343 // Gen ID of the original path (fPath may be modified) 401 // Gen ID of the original path (fPath may be modified)
344 int32_t fPathGenID = 0; 402 int32_t fPathGenID = 0;
345 GrStyle fStyle; 403 GrStyle fStyle;
346 SkAutoSTArray<8, uint32_t> fInheritedKey; 404 SkAutoSTArray<8, uint32_t> fInheritedKey;
347 }; 405 };
348 #endif 406 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/GrShapeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698