reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrPathIter_DEFINED |
| 19 | #define GrPathIter_DEFINED |
| 20 | |
| 21 | #include "GrTypes.h" |
| 22 | |
| 23 | struct GrPoint; |
| 24 | |
| 25 | /** |
| 26 | 2D Path iterator. Porting layer creates a subclass of this. It allows Ganesh to |
| 27 | parse the top-level API's 2D paths. Supports lines, quadratics, and cubic |
| 28 | pieces and moves (multi-part paths). |
| 29 | */ |
| 30 | class GrPathIter { |
| 31 | public: |
| 32 | /** |
| 33 | Returned by next(). Indicates the next piece of the path. |
| 34 | */ |
| 35 | enum Command { |
| 36 | kMove_Command, //!< next() returns 1 pt |
| 37 | // Starts a new subpath at |
| 38 | // at the returned point |
| 39 | kLine_Command, //!< next() returns 2 pts |
| 40 | // Adds a line segment |
| 41 | kQuadratic_Command, //!< next() returns 3 pts |
| 42 | // Adds a quadratic segment |
| 43 | kCubic_Command, //!< next() returns 4 pts |
| 44 | // Adds a cubic segment |
| 45 | kClose_Command, //!< next() returns 0 pts |
| 46 | kEnd_Command //!< next() returns 0 pts |
| 47 | // Implictly closes the last |
| 48 | // point |
| 49 | }; |
| 50 | |
| 51 | enum ConvexHint { |
| 52 | kNone_ConvexHint, //<! No hint about convexity |
| 53 | // of the path |
| 54 | kConvex_ConvexHint, //<! Path is one convex piece |
| 55 | kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces, |
| 56 | // pieces are known to be |
| 57 | // disjoint |
| 58 | kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces, |
| 59 | // may or may not intersect, |
| 60 | // either all wind cw or all |
| 61 | // wind ccw. |
| 62 | kConcave_ConvexHint //<! Path is known to be |
| 63 | // concave |
| 64 | }; |
| 65 | |
| 66 | static int NumCommandPoints(Command cmd) { |
| 67 | static const int numPoints[] = { |
| 68 | 1, 2, 3, 4, 0, 0 |
| 69 | }; |
| 70 | return numPoints[cmd]; |
| 71 | } |
| 72 | |
| 73 | virtual ~GrPathIter() {}; |
| 74 | |
| 75 | /** |
| 76 | Iterates through the path. Should not be called after |
| 77 | kEnd_Command has been returned once. This version retrieves the |
| 78 | points for the command. |
| 79 | @param points The points relevant to returned commend. See Command |
| 80 | enum for number of points valid for each command. |
| 81 | @return The next command of the path. |
| 82 | */ |
| 83 | virtual Command next(GrPoint points[4]) = 0; |
| 84 | |
| 85 | /** |
| 86 | * If the host API has knowledge of the convexity of the path |
| 87 | * it can be communicated by this hint. Ganesh can make these |
| 88 | * determinations itself. So it is not necessary to compute |
| 89 | * convexity status if it isn't already determined. |
| 90 | * |
| 91 | * @return a hint about the convexity of the path. |
| 92 | */ |
| 93 | virtual ConvexHint hint() const { return kNone_ConvexHint; } |
| 94 | |
| 95 | /** |
| 96 | Iterates through the path. Should not be called after |
| 97 | kEnd_Command has been returned once. This version does not retrieve the |
| 98 | points for the command. |
| 99 | @return The next command of the path. |
| 100 | */ |
| 101 | virtual Command next() = 0; |
| 102 | |
| 103 | /** |
| 104 | Restarts iteration from the beginning. |
| 105 | */ |
| 106 | virtual void rewind() = 0; |
| 107 | |
| 108 | }; |
| 109 | |
| 110 | #endif |