| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 */ | 102 */ |
| 103 class GrClip { | 103 class GrClip { |
| 104 public: | 104 public: |
| 105 virtual bool quickContains(const SkRect&) const = 0; | 105 virtual bool quickContains(const SkRect&) const = 0; |
| 106 virtual void getConservativeBounds(int width, int height, SkIRect* devResult
, | 106 virtual void getConservativeBounds(int width, int height, SkIRect* devResult
, |
| 107 bool* isIntersectionOfRects = nullptr) co
nst = 0; | 107 bool* isIntersectionOfRects = nullptr) co
nst = 0; |
| 108 virtual bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 108 virtual bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 109 const SkRect* devBounds, GrAppliedClip*) const = 0; | 109 const SkRect* devBounds, GrAppliedClip*) const = 0; |
| 110 | 110 |
| 111 virtual ~GrClip() {} | 111 virtual ~GrClip() {} |
| 112 |
| 113 protected: |
| 114 /** |
| 115 * Returns true if a clip can safely disable its scissor test for a particul
ar draw. |
| 116 */ |
| 117 static bool CanIgnoreScissor(const SkIRect& scissorRect, const SkRect& drawB
ounds) { |
| 118 // This is the maximum distance that a draw may extend beyond a clip's s
cissor and still |
| 119 // count as inside. We use a sloppy compare because the draw may have ch
osen its bounds in a |
| 120 // different coord system. The rationale for 1e-3 is that in the coverag
e case (and barring |
| 121 // unexpected rounding), as long as coverage stays below 0.5 * 1/256 we
ought to be OK. |
| 122 constexpr SkScalar fuzz = 1e-3f; |
| 123 SkASSERT(!scissorRect.isEmpty()); |
| 124 SkASSERT(!drawBounds.isEmpty()); |
| 125 return scissorRect.fLeft <= drawBounds.fLeft + fuzz && |
| 126 scissorRect.fTop <= drawBounds.fTop + fuzz && |
| 127 scissorRect.fRight >= drawBounds.fRight - fuzz && |
| 128 scissorRect.fBottom >= drawBounds.fBottom - fuzz; |
| 129 } |
| 130 |
| 131 friend class GrClipMaskManager; |
| 112 }; | 132 }; |
| 113 | 133 |
| 114 /** | 134 /** |
| 115 * Specialized implementation for no clip. | 135 * Specialized implementation for no clip. |
| 116 */ | 136 */ |
| 117 class GrNoClip final : public GrClip { | 137 class GrNoClip final : public GrClip { |
| 118 private: | 138 private: |
| 119 bool quickContains(const SkRect&) const final { return true; } | 139 bool quickContains(const SkRect&) const final { return true; } |
| 120 void getConservativeBounds(int width, int height, SkIRect* devResult, | 140 void getConservativeBounds(int width, int height, SkIRect* devResult, |
| 121 bool* isIntersectionOfRects) const final; | 141 bool* isIntersectionOfRects) const final; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 bool* isIntersectionOfRects) const final; | 231 bool* isIntersectionOfRects) const final; |
| 212 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 232 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 213 const SkRect* devBounds, GrAppliedClip*) const final; | 233 const SkRect* devBounds, GrAppliedClip*) const final; |
| 214 | 234 |
| 215 private: | 235 private: |
| 216 SkIPoint fOrigin; | 236 SkIPoint fOrigin; |
| 217 SkAutoTUnref<const SkClipStack> fStack; | 237 SkAutoTUnref<const SkClipStack> fStack; |
| 218 }; | 238 }; |
| 219 | 239 |
| 220 #endif | 240 #endif |
| OLD | NEW |