| 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; | |
| 132 }; | 112 }; |
| 133 | 113 |
| 134 /** | 114 /** |
| 135 * Specialized implementation for no clip. | 115 * Specialized implementation for no clip. |
| 136 */ | 116 */ |
| 137 class GrNoClip final : public GrClip { | 117 class GrNoClip final : public GrClip { |
| 138 private: | 118 private: |
| 139 bool quickContains(const SkRect&) const final { return true; } | 119 bool quickContains(const SkRect&) const final { return true; } |
| 140 void getConservativeBounds(int width, int height, SkIRect* devResult, | 120 void getConservativeBounds(int width, int height, SkIRect* devResult, |
| 141 bool* isIntersectionOfRects) const final; | 121 bool* isIntersectionOfRects) const final; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 bool* isIntersectionOfRects) const final; | 211 bool* isIntersectionOfRects) const final; |
| 232 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, | 212 bool apply(GrContext*, const GrPipelineBuilder&, GrDrawContext*, |
| 233 const SkRect* devBounds, GrAppliedClip*) const final; | 213 const SkRect* devBounds, GrAppliedClip*) const final; |
| 234 | 214 |
| 235 private: | 215 private: |
| 236 SkIPoint fOrigin; | 216 SkIPoint fOrigin; |
| 237 SkAutoTUnref<const SkClipStack> fStack; | 217 SkAutoTUnref<const SkClipStack> fStack; |
| 238 }; | 218 }; |
| 239 | 219 |
| 240 #endif | 220 #endif |
| OLD | NEW |