| 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 GrPath_DEFINED |
| 19 | #define GrPath_DEFINED |
| 20 | |
| 21 | #include "GrPathSink.h" |
| 22 | #include "GrPathIter.h" |
| 23 | #include "GrTDArray.h" |
| 24 | #include "GrPoint.h" |
| bsalomon@google.com | 06e1795 | 2011-04-27 21:13:04 +0000 | [diff] [blame^] | 25 | #include "GrRect.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
| 27 | class GrPath : public GrPathSink { |
| 28 | public: |
| 29 | GrPath(); |
| 30 | GrPath(const GrPath&); |
| 31 | explicit GrPath(GrPathIter&); |
| 32 | virtual ~GrPath(); |
| 33 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 34 | GrConvexHint getConvexHint() const { return fConvexHint; } |
| 35 | void setConvexHint(GrConvexHint hint) { fConvexHint = hint; } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | |
| bsalomon@google.com | 06e1795 | 2011-04-27 21:13:04 +0000 | [diff] [blame^] | 37 | const GrRect& getConservativeBounds() const { return fConservativeBounds; } |
| 38 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | void resetFromIter(GrPathIter*); |
| 40 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 41 | bool operator ==(const GrPath& path) const; |
| 42 | bool operator !=(const GrPath& path) const { return !(*this == path); } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | // overrides from GrPathSink |
| 44 | |
| 45 | virtual void moveTo(GrScalar x, GrScalar y); |
| 46 | virtual void lineTo(GrScalar x, GrScalar y); |
| 47 | virtual void quadTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1); |
| 48 | virtual void cubicTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1, |
| 49 | GrScalar x2, GrScalar y2); |
| 50 | virtual void close(); |
| 51 | |
| reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Offset the path by (tx, ty), adding tx to the horizontal position |
| 54 | * and adds ty to the vertical position of every point. |
| 55 | */ |
| 56 | void offset(GrScalar tx, GrScalar ty); |
| 57 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | class Iter : public GrPathIter { |
| 59 | public: |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Creates an uninitialized iterator |
| 62 | */ |
| 63 | Iter(); |
| 64 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | Iter(const GrPath& path); |
| 66 | |
| 67 | // overrides from GrPathIter |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 68 | virtual GrPathCmd next(GrPoint points[]); |
| 69 | virtual GrConvexHint convexHint() const; |
| 70 | virtual GrPathCmd next(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 71 | virtual void rewind(); |
| bsalomon@google.com | 06e1795 | 2011-04-27 21:13:04 +0000 | [diff] [blame^] | 72 | virtual bool getConservativeBounds(GrRect* rect) const; |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Sets iterator to begining of path |
| 76 | */ |
| 77 | void reset(const GrPath& path); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 78 | private: |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 79 | const GrPath* fPath; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | GrPoint fLastPt; |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 81 | int fCmdIndex; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | int fPtIndex; |
| 83 | }; |
| 84 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 85 | static void ConvexUnitTest(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 87 | private: |
| 88 | |
| 89 | GrTDArray<GrPathCmd> fCmds; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | GrTDArray<GrPoint> fPts; |
| bsalomon@google.com | 06e1795 | 2011-04-27 21:13:04 +0000 | [diff] [blame^] | 91 | GrConvexHint fConvexHint; |
| 92 | GrRect fConservativeBounds; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 93 | |
| 94 | // this ensures we have a moveTo at the start of each contour |
| 95 | inline void ensureMoveTo(); |
| 96 | |
| bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 97 | bool wasLastVerb(GrPathCmd cmd) const { |
| 98 | int count = fCmds.count(); |
| 99 | return count > 0 && cmd == fCmds[count - 1]; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | friend class Iter; |
| reed@google.com | c921843 | 2011-01-25 19:05:12 +0000 | [diff] [blame] | 103 | |
| 104 | typedef GrPathSink INHERITED; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #endif |
| 108 | |