blob: cf7b97f2d8e0049710a748ecd3960d00bf14ad75 [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 GrPath_DEFINED
19#define GrPath_DEFINED
20
21#include "GrPathSink.h"
22#include "GrPathIter.h"
23#include "GrTDArray.h"
24#include "GrPoint.h"
25
26class GrPath : public GrPathSink {
27public:
28 GrPath();
29 GrPath(const GrPath&);
30 explicit GrPath(GrPathIter&);
31 virtual ~GrPath();
32
33 GrPathIter::ConvexHint getConvexHint() const { return fConvexHint; }
34 void setConvexHint(GrPathIter::ConvexHint hint) { fConvexHint = hint; }
35
36 void resetFromIter(GrPathIter*);
37
38 // overrides from GrPathSink
39
40 virtual void moveTo(GrScalar x, GrScalar y);
41 virtual void lineTo(GrScalar x, GrScalar y);
42 virtual void quadTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1);
43 virtual void cubicTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1,
44 GrScalar x2, GrScalar y2);
45 virtual void close();
46
47 class Iter : public GrPathIter {
48 public:
49 Iter(const GrPath& path);
50
51 // overrides from GrPathIter
52 virtual Command next(GrPoint points[]);
53 virtual ConvexHint hint() const;
54 virtual Command next();
55 virtual void rewind();
56 private:
57 const GrPath& fPath;
58 GrPoint fLastPt;
59 int fVerbIndex;
60 int fPtIndex;
61 };
62
63private:
64 enum Verb {
65 kMove, kLine, kQuad, kCubic, kClose
66 };
67
68 GrTDArray<uint8_t> fVerbs;
69 GrTDArray<GrPoint> fPts;
70 GrPathIter::ConvexHint fConvexHint;
71
72 // this ensures we have a moveTo at the start of each contour
73 inline void ensureMoveTo();
74
75 bool wasLastVerb(Verb verb) const {
76 int count = fVerbs.count();
77 return count > 0 && verb == fVerbs[count - 1];
78 }
79
80 friend class Iter;
reed@google.comc9218432011-01-25 19:05:12 +000081
82 typedef GrPathSink INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000083};
84
85#endif
86