| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrClip_DEFINED | 8 #ifndef GrClip_DEFINED |
| 9 #define GrClip_DEFINED | 9 #define GrClip_DEFINED |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 GrClip() : fClipType(kWideOpen_ClipType) { | 28 GrClip() : fClipType(kWideOpen_ClipType) { |
| 29 fOrigin.setZero(); | 29 fOrigin.setZero(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { | 32 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { |
| 33 fOrigin.setZero(); | 33 fOrigin.setZero(); |
| 34 fClip.fIRect = rect; | 34 fClip.fIRect = rect; |
| 35 } | 35 } |
| 36 | 36 |
| 37 GrClip(const SkRect& rect) : fClipType(kRect_ClipType) { | 37 GrClip(const SkRect& rect) : fClipType(kIRect_ClipType) { |
| 38 fOrigin.setZero(); | 38 fOrigin.setZero(); |
| 39 fClip.fRect = rect; | 39 fClip.fIRect.fLeft = SkScalarRoundToInt(rect.fLeft); |
| 40 fClip.fIRect.fTop = SkScalarRoundToInt(rect.fTop); |
| 41 fClip.fIRect.fRight = SkScalarRoundToInt(rect.fRight); |
| 42 fClip.fIRect.fBottom = SkScalarRoundToInt(rect.fBottom); |
| 40 } | 43 } |
| 41 | 44 |
| 42 ~GrClip() { this->reset(); } | 45 ~GrClip() { this->reset(); } |
| 43 | 46 |
| 44 const GrClip& operator=(const GrClip& other) { | 47 const GrClip& operator=(const GrClip& other) { |
| 45 this->reset(); | 48 this->reset(); |
| 46 fClipType = other.fClipType; | 49 fClipType = other.fClipType; |
| 47 switch (other.fClipType) { | 50 switch (other.fClipType) { |
| 48 case kWideOpen_ClipType: | 51 case kWideOpen_ClipType: |
| 49 fOrigin.setZero(); | 52 fOrigin.setZero(); |
| 50 break; | 53 break; |
| 51 case kClipStack_ClipType: | 54 case kClipStack_ClipType: |
| 52 fClip.fStack = SkRef(other.clipStack()); | 55 fClip.fStack = SkRef(other.clipStack()); |
| 53 fOrigin = other.origin(); | 56 fOrigin = other.origin(); |
| 54 break; | 57 break; |
| 55 case kIRect_ClipType: | 58 case kIRect_ClipType: |
| 56 fClip.fIRect = other.irect(); | 59 fClip.fIRect = other.irect(); |
| 57 fOrigin.setZero(); | 60 fOrigin.setZero(); |
| 58 break; | 61 break; |
| 59 case kRect_ClipType: | |
| 60 fClip.fRect = other.rect(); | |
| 61 fOrigin.setZero(); | |
| 62 break; | |
| 63 } | 62 } |
| 64 return *this; | 63 return *this; |
| 65 } | 64 } |
| 66 | 65 |
| 67 bool operator==(const GrClip& other) const { | 66 bool operator==(const GrClip& other) const { |
| 68 if (this->clipType() != other.clipType()) { | 67 if (this->clipType() != other.clipType()) { |
| 69 return false; | 68 return false; |
| 70 } | 69 } |
| 71 | 70 |
| 72 switch (fClipType) { | 71 switch (fClipType) { |
| 73 case kWideOpen_ClipType: | 72 case kWideOpen_ClipType: |
| 74 return true; | 73 return true; |
| 75 case kClipStack_ClipType: | 74 case kClipStack_ClipType: |
| 76 if (this->origin() != other.origin()) { | 75 if (this->origin() != other.origin()) { |
| 77 return false; | 76 return false; |
| 78 } | 77 } |
| 79 | 78 |
| 80 if (this->clipStack() && other.clipStack()) { | 79 if (this->clipStack() && other.clipStack()) { |
| 81 return *this->clipStack() == *other.clipStack(); | 80 return *this->clipStack() == *other.clipStack(); |
| 82 } else { | 81 } else { |
| 83 return this->clipStack() == other.clipStack(); | 82 return this->clipStack() == other.clipStack(); |
| 84 } | 83 } |
| 85 break; | 84 break; |
| 86 case kIRect_ClipType: | 85 case kIRect_ClipType: |
| 87 return this->irect() == other.irect(); | 86 return this->irect() == other.irect(); |
| 88 break; | 87 break; |
| 89 case kRect_ClipType: | |
| 90 return this->rect() == other.rect(); | |
| 91 break; | |
| 92 } | 88 } |
| 93 } | 89 } |
| 94 | 90 |
| 95 bool operator!=(const GrClip& other) const { | 91 bool operator!=(const GrClip& other) const { |
| 96 return !(*this == other); | 92 return !(*this == other); |
| 97 } | 93 } |
| 98 | 94 |
| 99 const SkClipStack* clipStack() const { | 95 const SkClipStack* clipStack() const { |
| 100 SkASSERT(kClipStack_ClipType == fClipType); | 96 SkASSERT(kClipStack_ClipType == fClipType); |
| 101 return fClip.fStack; | 97 return fClip.fStack; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 fOrigin.setZero(); | 111 fOrigin.setZero(); |
| 116 } | 112 } |
| 117 } | 113 } |
| 118 } | 114 } |
| 119 | 115 |
| 120 const SkIRect& irect() const { | 116 const SkIRect& irect() const { |
| 121 SkASSERT(kIRect_ClipType == fClipType); | 117 SkASSERT(kIRect_ClipType == fClipType); |
| 122 return fClip.fIRect; | 118 return fClip.fIRect; |
| 123 } | 119 } |
| 124 | 120 |
| 125 const SkRect& rect() const { | |
| 126 SkASSERT(kRect_ClipType == fClipType); | |
| 127 return fClip.fRect; | |
| 128 } | |
| 129 | |
| 130 void reset() { | 121 void reset() { |
| 131 if (kClipStack_ClipType == fClipType) { | 122 if (kClipStack_ClipType == fClipType) { |
| 132 fClip.fStack->unref(); | 123 fClip.fStack->unref(); |
| 133 fClip.fStack = NULL; | 124 fClip.fStack = NULL; |
| 134 } | 125 } |
| 135 fClipType = kWideOpen_ClipType; | 126 fClipType = kWideOpen_ClipType; |
| 136 fOrigin.setZero(); | 127 fOrigin.setZero(); |
| 137 } | 128 } |
| 138 | 129 |
| 139 // We support this for all cliptypes to simplify the logic a bit in clip mas
k manager. | 130 // We support this for all cliptypes to simplify the logic a bit in clip mas
k manager. |
| 140 // non clipstack clip types MUST have a (0,0) origin | 131 // non clipstack clip types MUST have a (0,0) origin |
| 141 const SkIPoint& origin() const { | 132 const SkIPoint& origin() const { |
| 142 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin
.fY == 0)); | 133 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin
.fY == 0)); |
| 143 return fOrigin; | 134 return fOrigin; |
| 144 } | 135 } |
| 145 | 136 |
| 146 bool isWideOpen(const SkRect& rect) const { | 137 bool isWideOpen(const SkRect& rect) const { |
| 147 return (kWideOpen_ClipType == fClipType) || | 138 return (kWideOpen_ClipType == fClipType) || |
| 148 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || | 139 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || |
| 149 (kIRect_ClipType == fClipType && this->irect().contains(rect)) || | 140 (kIRect_ClipType == fClipType && this->irect().contains(rect)); |
| 150 (kRect_ClipType == fClipType && this->rect().contains(rect)); | |
| 151 } | 141 } |
| 152 | 142 |
| 153 bool isWideOpen(const SkIRect& rect) const { | 143 bool isWideOpen(const SkIRect& rect) const { |
| 154 return (kWideOpen_ClipType == fClipType) || | 144 return (kWideOpen_ClipType == fClipType) || |
| 155 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || | 145 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || |
| 156 (kIRect_ClipType == fClipType && this->irect().contains(rect)) || | 146 (kIRect_ClipType == fClipType && this->irect().contains(rect)); |
| 157 (kRect_ClipType == fClipType && this->rect().contains(rect)); | |
| 158 } | 147 } |
| 159 | 148 |
| 160 bool isWideOpen() const { | 149 bool isWideOpen() const { |
| 161 return (kWideOpen_ClipType == fClipType) || | 150 return (kWideOpen_ClipType == fClipType) || |
| 162 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()); | 151 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()); |
| 163 } | 152 } |
| 164 | 153 |
| 165 bool quickContains(const SkRect& rect) const { | 154 bool quickContains(const SkRect& rect) const { |
| 166 return (kWideOpen_ClipType == fClipType) || | 155 return (kWideOpen_ClipType == fClipType) || |
| 167 (kClipStack_ClipType == fClipType && this->clipStack()->quickCont
ains(rect)) || | 156 (kClipStack_ClipType == fClipType && this->clipStack()->quickCont
ains(rect)) || |
| 168 (kIRect_ClipType == fClipType && this->irect().contains(rect)) || | 157 (kIRect_ClipType == fClipType && this->irect().contains(rect)); |
| 169 (kRect_ClipType == fClipType && this->rect().contains(rect)); | |
| 170 } | 158 } |
| 171 | 159 |
| 172 void getConservativeBounds(const GrSurface* surface, | 160 void getConservativeBounds(const GrSurface* surface, |
| 173 SkIRect* devResult, | 161 SkIRect* devResult, |
| 174 bool* isIntersectionOfRects = NULL) const { | 162 bool* isIntersectionOfRects = NULL) const { |
| 175 this->getConservativeBounds(surface->width(), surface->height(), | 163 this->getConservativeBounds(surface->width(), surface->height(), |
| 176 devResult, isIntersectionOfRects); | 164 devResult, isIntersectionOfRects); |
| 177 } | 165 } |
| 178 | 166 |
| 179 void getConservativeBounds(int width, int height, | 167 void getConservativeBounds(int width, int height, |
| 180 SkIRect* devResult, | 168 SkIRect* devResult, |
| 181 bool* isIntersectionOfRects = NULL) const; | 169 bool* isIntersectionOfRects = NULL) const; |
| 182 | 170 |
| 183 static const GrClip& WideOpen(); | 171 static const GrClip& WideOpen(); |
| 184 | 172 |
| 185 enum ClipType { | 173 enum ClipType { |
| 186 kClipStack_ClipType, | 174 kClipStack_ClipType, |
| 187 kWideOpen_ClipType, | 175 kWideOpen_ClipType, |
| 188 kIRect_ClipType, | 176 kIRect_ClipType, |
| 189 kRect_ClipType, | |
| 190 }; | 177 }; |
| 191 | 178 |
| 192 ClipType clipType() const { return fClipType; } | 179 ClipType clipType() const { return fClipType; } |
| 193 | 180 |
| 194 private: | 181 private: |
| 195 union Clip { | 182 union Clip { |
| 196 const SkClipStack* fStack; | 183 const SkClipStack* fStack; |
| 197 SkRect fRect; | |
| 198 SkIRect fIRect; | 184 SkIRect fIRect; |
| 199 } fClip; | 185 } fClip; |
| 200 | 186 |
| 201 SkIPoint fOrigin; | 187 SkIPoint fOrigin; |
| 202 ClipType fClipType; | 188 ClipType fClipType; |
| 203 }; | 189 }; |
| 204 | 190 |
| 205 #endif | 191 #endif |
| OLD | NEW |