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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 bool* isIntersectionOfRects = nullptr) co nst = 0; | 106 bool* isIntersectionOfRects = nullptr) co nst = 0; |
107 virtual bool apply(GrContext*, | 107 virtual bool apply(GrContext*, |
108 GrDrawContext*, | 108 GrDrawContext*, |
109 const SkRect* devBounds, | 109 const SkRect* devBounds, |
110 bool useHWAA, | 110 bool useHWAA, |
111 bool hasUserStencilSettings, | 111 bool hasUserStencilSettings, |
112 GrAppliedClip* out) const = 0; | 112 GrAppliedClip* out) const = 0; |
113 | 113 |
114 virtual ~GrClip() {} | 114 virtual ~GrClip() {} |
115 | 115 |
116 protected: | |
117 /** | 116 /** |
118 * Returns true if a clip can safely disable its scissor test for a particul ar draw. | 117 * This is the maximum distance that a draw may extend beyond a clip's bound ary and still count |
118 * count as "on the other side". We leave some slack because floating point rounding error is | |
119 * likely to blame. The rationale for 1e-3 is that in the coverage case (and barring unexpected | |
120 * rounding), as long as coverage stays within 0.5 * 1/256 of its intended v alue it shouldn't | |
121 * have any effect on the final pixel values. | |
119 */ | 122 */ |
120 static bool CanIgnoreScissor(const SkIRect& scissorRect, const SkRect& drawB ounds) { | 123 constexpr static SkScalar kClipBoundsFuzz = 1e-3f; |
bsalomon
2016/07/19 13:33:12
Can we call this tolerance or "tol" rather than fu
csmartdalton
2016/07/19 15:59:00
Done.
| |
121 // This is the maximum distance that a draw may extend beyond a clip's s cissor and still | 124 |
122 // count as inside. We use a sloppy compare because the draw may have ch osen its bounds in a | 125 /** |
123 // different coord system. The rationale for 1e-3 is that in the coverag e case (and barring | 126 * Returns true if the given query bounds count as entirely inside the clip. |
124 // unexpected rounding), as long as coverage stays below 0.5 * 1/256 we ought to be OK. | 127 * |
125 constexpr SkScalar fuzz = 1e-3f; | 128 * @param innerClipBounds device-space rect contained by the clip (SkRect or SkIRect). |
126 SkASSERT(!scissorRect.isEmpty()); | 129 * @param queryBounds device-space bounds of the query region. |
127 SkASSERT(!drawBounds.isEmpty()); | 130 */ |
128 return scissorRect.fLeft <= drawBounds.fLeft + fuzz && | 131 template<typename TRect> constexpr static bool IsInsideClip(const TRect& inn erClipBounds, |
129 scissorRect.fTop <= drawBounds.fTop + fuzz && | 132 const SkRect& qu eryBounds) { |
130 scissorRect.fRight >= drawBounds.fRight - fuzz && | 133 return innerClipBounds.fRight - innerClipBounds.fLeft >= kClipBoundsFuzz && |
131 scissorRect.fBottom >= drawBounds.fBottom - fuzz; | 134 innerClipBounds.fBottom - innerClipBounds.fTop >= kClipBoundsFuzz && |
135 innerClipBounds.fLeft <= queryBounds.fLeft + kClipBoundsFuzz && | |
136 innerClipBounds.fTop <= queryBounds.fTop + kClipBoundsFuzz && | |
137 innerClipBounds.fRight >= queryBounds.fRight - kClipBoundsFuzz && | |
138 innerClipBounds.fBottom >= queryBounds.fBottom - kClipBoundsFuzz; | |
132 } | 139 } |
133 | 140 |
134 friend class GrClipMaskManager; | 141 /** |
142 * Returns true if the given query bounds count as entirely outside the clip . | |
143 * | |
144 * @param outerClipBounds device-space rect that contains the clip (SkRect or SkIRect). | |
145 * @param queryBounds device-space bounds of the query region. | |
146 */ | |
147 template<typename TRect> constexpr static bool IsOutsideClip(const TRect& ou terClipBounds, | |
148 const SkRect& q ueryBounds) { | |
149 return outerClipBounds.fRight - outerClipBounds.fLeft < kClipBoundsFuzz || | |
150 outerClipBounds.fBottom - outerClipBounds.fTop < kClipBoundsFuzz || | |
151 outerClipBounds.fLeft > queryBounds.fRight - kClipBoundsFuzz || | |
152 outerClipBounds.fTop > queryBounds.fBottom - kClipBoundsFuzz || | |
153 outerClipBounds.fRight < queryBounds.fLeft + kClipBoundsFuzz || | |
154 outerClipBounds.fBottom < queryBounds.fTop + kClipBoundsFuzz; | |
155 } | |
156 | |
157 /** | |
158 * Returns the minimal integer rect that counts as containing a given set of bounds. | |
159 */ | |
160 static SkIRect GetPixelIBounds(const SkRect& bounds) { | |
161 return SkIRect::MakeLTRB(SkScalarFloorToInt(bounds.fLeft + kClipBoundsFu zz), | |
162 SkScalarFloorToInt(bounds.fTop + kClipBoundsFuz z), | |
163 SkScalarCeilToInt(bounds.fRight - kClipBoundsFu zz), | |
164 SkScalarCeilToInt(bounds.fBottom - kClipBoundsF uzz)); | |
165 } | |
166 | |
167 /** | |
168 * Returns the minimal pixel-aligned rect that counts as containing a given set of bounds. | |
169 */ | |
170 static SkRect GetPixelBounds(const SkRect& bounds) { | |
171 return SkRect::MakeLTRB(SkScalarFloorToScalar(bounds.fLeft + kClipBounds Fuzz), | |
172 SkScalarFloorToScalar(bounds.fTop + kClipBoundsF uzz), | |
173 SkScalarCeilToScalar(bounds.fRight - kClipBounds Fuzz), | |
174 SkScalarCeilToScalar(bounds.fBottom - kClipBound sFuzz)); | |
175 } | |
176 | |
177 /** | |
178 * Returns true if the given rect counts as aligned with pixel boundaries. | |
179 */ | |
180 static bool IsPixelAligned(const SkRect& rect) { | |
181 return SkScalarAbs(SkScalarRoundToScalar(rect.fLeft) - rect.fLeft) <= kC lipBoundsFuzz && | |
182 SkScalarAbs(SkScalarRoundToScalar(rect.fTop) - rect.fTop) <= kCli pBoundsFuzz && | |
183 SkScalarAbs(SkScalarRoundToScalar(rect.fRight) - rect.fRight) <= kClipBoundsFuzz && | |
184 SkScalarAbs(SkScalarRoundToScalar(rect.fBottom) - rect.fBottom) < = kClipBoundsFuzz; | |
185 } | |
135 }; | 186 }; |
136 | 187 |
137 /** | 188 /** |
138 * Specialized implementation for no clip. | 189 * Specialized implementation for no clip. |
139 */ | 190 */ |
140 class GrNoClip final : public GrClip { | 191 class GrNoClip final : public GrClip { |
141 private: | 192 private: |
142 bool quickContains(const SkRect&) const final { return true; } | 193 bool quickContains(const SkRect&) const final { return true; } |
143 void getConservativeBounds(int width, int height, SkIRect* devResult, | 194 void getConservativeBounds(int width, int height, SkIRect* devResult, |
144 bool* isIntersectionOfRects) const final; | 195 bool* isIntersectionOfRects) const final; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 bool useHWAA, | 297 bool useHWAA, |
247 bool hasUserStencilSettings, | 298 bool hasUserStencilSettings, |
248 GrAppliedClip* out) const final; | 299 GrAppliedClip* out) const final; |
249 | 300 |
250 private: | 301 private: |
251 SkIPoint fOrigin; | 302 SkIPoint fOrigin; |
252 SkAutoTUnref<const SkClipStack> fStack; | 303 SkAutoTUnref<const SkClipStack> fStack; |
253 }; | 304 }; |
254 | 305 |
255 #endif | 306 #endif |
OLD | NEW |