blob: 140cbcba56a1fe11ebdea2b78ab9915d9bae8449 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
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
23struct 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 */
30class GrPathIter {
31public:
32 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +000033 Returned by next(). Indicates the next piece of the path.
reed@google.comac10a2d2010-12-22 21:39:39 +000034 */
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
bsalomon@google.comd302f142011-03-03 13:54:13 +000047 // Implictly closes the last
reed@google.comac10a2d2010-12-22 21:39:39 +000048 // point
49 };
bsalomon@google.comd302f142011-03-03 13:54:13 +000050
reed@google.comac10a2d2010-12-22 21:39:39 +000051 enum ConvexHint {
bsalomon@google.comd302f142011-03-03 13:54:13 +000052 kNone_ConvexHint, //<! No hint about convexity
reed@google.comac10a2d2010-12-22 21:39:39 +000053 // of the path
54 kConvex_ConvexHint, //<! Path is one convex piece
bsalomon@google.comd302f142011-03-03 13:54:13 +000055 kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces,
reed@google.comac10a2d2010-12-22 21:39:39 +000056 // pieces are known to be
57 // disjoint
bsalomon@google.comd302f142011-03-03 13:54:13 +000058 kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces,
reed@google.comac10a2d2010-12-22 21:39:39 +000059 // may or may not intersect,
bsalomon@google.comd302f142011-03-03 13:54:13 +000060 // either all wind cw or all
reed@google.comac10a2d2010-12-22 21:39:39 +000061 // wind ccw.
bsalomon@google.comd302f142011-03-03 13:54:13 +000062 kConcave_ConvexHint //<! Path is known to be
reed@google.comac10a2d2010-12-22 21:39:39 +000063 // concave
64 };
bsalomon@google.comd302f142011-03-03 13:54:13 +000065
reed@google.comac10a2d2010-12-22 21:39:39 +000066 static int NumCommandPoints(Command cmd) {
67 static const int numPoints[] = {
68 1, 2, 3, 4, 0, 0
69 };
70 return numPoints[cmd];
71 }
bsalomon@google.comd302f142011-03-03 13:54:13 +000072
reed@google.comac10a2d2010-12-22 21:39:39 +000073 virtual ~GrPathIter() {};
74
bsalomon@google.comd302f142011-03-03 13:54:13 +000075 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000076 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
bsalomon@google.comd302f142011-03-03 13:54:13 +000088 * determinations itself. So it is not necessary to compute
reed@google.comac10a2d2010-12-22 21:39:39 +000089 * convexity status if it isn't already determined.
90 *
91 * @return a hint about the convexity of the path.
bsalomon@google.comd302f142011-03-03 13:54:13 +000092 */
93 virtual ConvexHint convexHint() const { return kNone_ConvexHint; }
reed@google.comac10a2d2010-12-22 21:39:39 +000094
bsalomon@google.comd302f142011-03-03 13:54:13 +000095 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000096 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