| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrClip_DEFINED |
| 12 | #define GrClip_DEFINED |
| 13 | |
| 14 | #include "GrClipIterator.h" |
| 15 | #include "GrRect.h" |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 16 | |
| bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 17 | #include "SkPath.h" |
| bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 18 | #include "SkTArray.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
| 20 | class GrClip { |
| 21 | public: |
| 22 | GrClip(); |
| 23 | GrClip(const GrClip& src); |
| reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 24 | /** |
| robertphillips@google.com | 3e11c0b | 2012-07-11 18:20:35 +0000 | [diff] [blame] | 25 | * The conservativeBounds parameter already takes (tx,ty) into account. |
| reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 26 | */ |
| 27 | GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty, |
| robertphillips@google.com | 3e11c0b | 2012-07-11 18:20:35 +0000 | [diff] [blame] | 28 | const GrRect& conservativeBounds); |
| 29 | explicit GrClip(const GrIRect& rect); |
| 30 | explicit GrClip(const GrRect& rect); |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 31 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | ~GrClip(); |
| 33 | |
| 34 | GrClip& operator=(const GrClip& src); |
| 35 | |
| robertphillips@google.com | 3e11c0b | 2012-07-11 18:20:35 +0000 | [diff] [blame] | 36 | const GrRect& getConservativeBounds() const { |
| 37 | GrAssert(fConservativeBoundsValid); |
| 38 | return fConservativeBounds; |
| 39 | } |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 40 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 41 | bool requiresAA() const { return fRequiresAA; } |
| 42 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 43 | int getElementCount() const { return fList.count(); } |
| 44 | |
| 45 | GrClipType getElementType(int i) const { return fList[i].fType; } |
| 46 | |
| bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 47 | const SkPath& getPath(int i) const { |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 48 | GrAssert(kPath_ClipType == fList[i].fType); |
| 49 | return fList[i].fPath; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 51 | |
| 52 | GrPathFill getPathFill(int i) const { |
| 53 | GrAssert(kPath_ClipType == fList[i].fType); |
| 54 | return fList[i].fPathFill; |
| 55 | } |
| 56 | |
| 57 | const GrRect& getRect(int i) const { |
| 58 | GrAssert(kRect_ClipType == fList[i].fType); |
| 59 | return fList[i].fRect; |
| 60 | } |
| 61 | |
| robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 62 | SkRegion::Op getOp(int i) const { return fList[i].fOp; } |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 63 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 64 | bool getDoAA(int i) const { return fList[i].fDoAA; } |
| 65 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 66 | bool isRect() const { |
| bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 67 | if (1 == fList.count() && kRect_ClipType == fList[0].fType && |
| robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 68 | (SkRegion::kIntersect_Op == fList[0].fOp || |
| 69 | SkRegion::kReplace_Op == fList[0].fOp)) { |
| bsalomon@google.com | 0b50b2e | 2011-03-08 21:07:21 +0000 | [diff] [blame] | 70 | // if we determined that the clip is a single rect |
| 71 | // we ought to have also used that rect as the bounds. |
| 72 | GrAssert(fConservativeBoundsValid); |
| 73 | GrAssert(fConservativeBounds == fList[0].fRect); |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 74 | return true; |
| 75 | } else { |
| 76 | return false; |
| 77 | } |
| 78 | } |
| 79 | |
| bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 80 | // FIXME: This word "empty" is confusing. It means that the clip has no |
| 81 | // elements (it is the infinite plane) not that it has no area. |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 82 | bool isEmpty() const { return 0 == fList.count(); } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | |
| 84 | /** |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 85 | * Resets this clip to be empty |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 86 | */ |
| 87 | void setEmpty(); |
| reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * If specified, the bounds parameter already takes (tx,ty) into account. |
| 91 | */ |
| 92 | void setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty, |
| robertphillips@google.com | 3e11c0b | 2012-07-11 18:20:35 +0000 | [diff] [blame] | 93 | const GrRect& conservativeBounds); |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 94 | void setFromRect(const GrRect& rect); |
| 95 | void setFromIRect(const GrIRect& rect); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | |
| 97 | friend bool operator==(const GrClip& a, const GrClip& b) { |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 98 | if (a.fList.count() != b.fList.count()) { |
| 99 | return false; |
| 100 | } |
| 101 | int count = a.fList.count(); |
| 102 | for (int i = 0; i < count; ++i) { |
| 103 | if (a.fList[i] != b.fList[i]) { |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | return true; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 108 | } |
| 109 | friend bool operator!=(const GrClip& a, const GrClip& b) { |
| 110 | return !(a == b); |
| 111 | } |
| 112 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 113 | private: |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 114 | struct Element { |
| robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 115 | GrClipType fType; |
| 116 | GrRect fRect; |
| bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 117 | SkPath fPath; |
| robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 118 | GrPathFill fPathFill; |
| 119 | SkRegion::Op fOp; |
| 120 | bool fDoAA; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 121 | bool operator ==(const Element& e) const { |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 122 | if (e.fType != fType || e.fOp != fOp || e.fDoAA != fDoAA) { |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 123 | return false; |
| 124 | } |
| 125 | switch (fType) { |
| 126 | case kRect_ClipType: |
| 127 | return fRect == e.fRect; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 128 | case kPath_ClipType: |
| 129 | return fPath == e.fPath; |
| 130 | default: |
| 131 | GrCrash("Unknown clip element type."); |
| 132 | return false; // suppress warning |
| 133 | } |
| 134 | } |
| 135 | bool operator !=(const Element& e) const { return !(*this == e); } |
| 136 | }; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 137 | |
| bsalomon@google.com | 0b50b2e | 2011-03-08 21:07:21 +0000 | [diff] [blame] | 138 | GrRect fConservativeBounds; |
| 139 | bool fConservativeBoundsValid; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 140 | |
| robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 141 | bool fRequiresAA; |
| 142 | |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 143 | enum { |
| 144 | kPreAllocElements = 4, |
| 145 | }; |
| bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 146 | SkSTArray<kPreAllocElements, Element> fList; |
| bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 147 | }; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | #endif |
| 149 | |