Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: include/gpu/GrClip.h

Issue 2160093002: Allow GrReducedClip to take non-integer query bounds (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix tests on ubuntu Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrClip.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 kBoundsTolerance = 1e-3f;
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 >= kBoundsToleranc e &&
131 scissorRect.fBottom >= drawBounds.fBottom - fuzz; 134 innerClipBounds.fBottom - innerClipBounds.fTop >= kBoundsToleranc e &&
135 innerClipBounds.fLeft <= queryBounds.fLeft + kBoundsTolerance &&
136 innerClipBounds.fTop <= queryBounds.fTop + kBoundsTolerance &&
137 innerClipBounds.fRight >= queryBounds.fRight - kBoundsTolerance & &
138 innerClipBounds.fBottom >= queryBounds.fBottom - kBoundsTolerance ;
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 < kBoundsTolerance ||
150 outerClipBounds.fBottom - outerClipBounds.fTop < kBoundsTolerance ||
151 outerClipBounds.fLeft > queryBounds.fRight - kBoundsTolerance ||
152 outerClipBounds.fTop > queryBounds.fBottom - kBoundsTolerance ||
153 outerClipBounds.fRight < queryBounds.fLeft + kBoundsTolerance ||
154 outerClipBounds.fBottom < queryBounds.fTop + kBoundsTolerance;
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 + kBoundsTolera nce),
162 SkScalarFloorToInt(bounds.fTop + kBoundsToleran ce),
163 SkScalarCeilToInt(bounds.fRight - kBoundsTolera nce),
164 SkScalarCeilToInt(bounds.fBottom - kBoundsToler ance));
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 + kBoundsTole rance),
172 SkScalarFloorToScalar(bounds.fTop + kBoundsToler ance),
173 SkScalarCeilToScalar(bounds.fRight - kBoundsTole rance),
174 SkScalarCeilToScalar(bounds.fBottom - kBoundsTol erance));
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) <= kB oundsTolerance &&
182 SkScalarAbs(SkScalarRoundToScalar(rect.fTop) - rect.fTop) <= kBou ndsTolerance &&
183 SkScalarAbs(SkScalarRoundToScalar(rect.fRight) - rect.fRight) <= kBoundsTolerance &&
184 SkScalarAbs(SkScalarRoundToScalar(rect.fBottom) - rect.fBottom) < = kBoundsTolerance;
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
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
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrClip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698