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

Side by Side Diff: src/gpu/GrClipMaskManager.cpp

Issue 678683005: Scissor rect on drawinfo (Closed) Base URL: https://skia.googlesource.com/skia.git@clip_to_target
Patch Set: rebase on master Created 6 years, 1 month 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 | « src/gpu/GrClipMaskManager.h ('k') | src/gpu/GrDrawTarget.h » ('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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrClipMaskManager.h" 9 #include "GrClipMaskManager.h"
10 #include "GrAAConvexPathRenderer.h" 10 #include "GrAAConvexPathRenderer.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 are->set(NULL); 204 are->set(NULL);
205 } 205 }
206 206
207 return !failed; 207 return !failed;
208 } 208 }
209 209
210 //////////////////////////////////////////////////////////////////////////////// 210 ////////////////////////////////////////////////////////////////////////////////
211 // sort out what kind of clip mask needs to be created: alpha, stencil, 211 // sort out what kind of clip mask needs to be created: alpha, stencil,
212 // scissor, or entirely software 212 // scissor, or entirely software
213 bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn, 213 bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn,
214 const SkRect* devBounds,
214 GrDrawState::AutoRestoreEffects* are, 215 GrDrawState::AutoRestoreEffects* are,
215 GrDrawState::AutoRestoreStencil* asr, 216 GrDrawState::AutoRestoreStencil* ars,
216 const SkRect* devBounds) { 217 GrDrawTarget::ScissorState* scissorState) {
217 fCurrClipMaskType = kNone_ClipMaskType; 218 fCurrClipMaskType = kNone_ClipMaskType;
218 219
219 GrReducedClip::ElementList elements(16); 220 GrReducedClip::ElementList elements(16);
220 int32_t genID; 221 int32_t genID;
221 GrReducedClip::InitialState initialState; 222 GrReducedClip::InitialState initialState;
222 SkIRect clipSpaceIBounds; 223 SkIRect clipSpaceIBounds;
223 bool requiresAA; 224 bool requiresAA;
224 225
225 GrDrawState* drawState = fGpu->drawState(); 226 GrDrawState* drawState = fGpu->drawState();
226 227
(...skipping 15 matching lines...) Expand all
242 if (elements.isEmpty()) { 243 if (elements.isEmpty()) {
243 if (GrReducedClip::kAllIn_InitialState == initialState) { 244 if (GrReducedClip::kAllIn_InitialState == initialState) {
244 ignoreClip = clipSpaceIBounds == clipSpaceRTIBounds; 245 ignoreClip = clipSpaceIBounds == clipSpaceRTIBounds;
245 } else { 246 } else {
246 return false; 247 return false;
247 } 248 }
248 } 249 }
249 } 250 }
250 251
251 if (ignoreClip) { 252 if (ignoreClip) {
252 fGpu->disableScissor(); 253 this->setDrawStateStencil(ars);
253 this->setDrawStateStencil(asr);
254 return true; 254 return true;
255 } 255 }
256 256
257 // An element count of 4 was chosen because of the common pattern in Blink o f: 257 // An element count of 4 was chosen because of the common pattern in Blink o f:
258 // isect RR 258 // isect RR
259 // diff RR 259 // diff RR
260 // isect convex_poly 260 // isect convex_poly
261 // isect convex_poly 261 // isect convex_poly
262 // when drawing rounded div borders. This could probably be tuned based on a 262 // when drawing rounded div borders. This could probably be tuned based on a
263 // configuration's relative costs of switching RTs to generate a mask vs 263 // configuration's relative costs of switching RTs to generate a mask vs
264 // longer shaders. 264 // longer shaders.
265 if (elements.count() <= 4) { 265 if (elements.count() <= 4) {
266 SkVector clipToRTOffset = { SkIntToScalar(-clipDataIn->fOrigin.fX), 266 SkVector clipToRTOffset = { SkIntToScalar(-clipDataIn->fOrigin.fX),
267 SkIntToScalar(-clipDataIn->fOrigin.fY) }; 267 SkIntToScalar(-clipDataIn->fOrigin.fY) };
268 if (elements.isEmpty() || 268 if (elements.isEmpty() ||
269 (requiresAA && this->installClipEffects(elements, are, clipToRTOffse t, devBounds))) { 269 (requiresAA && this->installClipEffects(elements, are, clipToRTOffse t, devBounds))) {
270 SkIRect scissorSpaceIBounds(clipSpaceIBounds); 270 SkIRect scissorSpaceIBounds(clipSpaceIBounds);
271 scissorSpaceIBounds.offset(-clipDataIn->fOrigin); 271 scissorSpaceIBounds.offset(-clipDataIn->fOrigin);
272 if (NULL == devBounds || 272 if (NULL == devBounds ||
273 !SkRect::Make(scissorSpaceIBounds).contains(*devBounds)) { 273 !SkRect::Make(scissorSpaceIBounds).contains(*devBounds)) {
274 fGpu->enableScissor(scissorSpaceIBounds); 274 scissorState->set(scissorSpaceIBounds);
275 } else {
276 fGpu->disableScissor();
277 } 275 }
278 this->setDrawStateStencil(asr); 276 this->setDrawStateStencil(ars);
279 return true; 277 return true;
280 } 278 }
281 } 279 }
282 280
283 #if GR_AA_CLIP 281 #if GR_AA_CLIP
284 // If MSAA is enabled we can do everything in the stencil buffer. 282 // If MSAA is enabled we can do everything in the stencil buffer.
285 if (0 == rt->numSamples() && requiresAA) { 283 if (0 == rt->numSamples() && requiresAA) {
286 GrTexture* result = NULL; 284 GrTexture* result = NULL;
287 285
288 if (this->useSWOnlyPath(elements)) { 286 if (this->useSWOnlyPath(elements)) {
(...skipping 10 matching lines...) Expand all
299 clipSpaceIBounds); 297 clipSpaceIBounds);
300 } 298 }
301 299
302 if (result) { 300 if (result) {
303 // The mask's top left coord should be pinned to the rounded-out top left corner of 301 // The mask's top left coord should be pinned to the rounded-out top left corner of
304 // clipSpace bounds. We determine the mask's position WRT to the ren der target here. 302 // clipSpace bounds. We determine the mask's position WRT to the ren der target here.
305 SkIRect rtSpaceMaskBounds = clipSpaceIBounds; 303 SkIRect rtSpaceMaskBounds = clipSpaceIBounds;
306 rtSpaceMaskBounds.offset(-clipDataIn->fOrigin); 304 rtSpaceMaskBounds.offset(-clipDataIn->fOrigin);
307 are->set(fGpu->drawState()); 305 are->set(fGpu->drawState());
308 setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds); 306 setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds);
309 fGpu->disableScissor(); 307 this->setDrawStateStencil(ars);
310 this->setDrawStateStencil(asr);
311 return true; 308 return true;
312 } 309 }
313 // if alpha clip mask creation fails fall through to the non-AA code pat hs 310 // if alpha clip mask creation fails fall through to the non-AA code pat hs
314 } 311 }
315 #endif // GR_AA_CLIP 312 #endif // GR_AA_CLIP
316 313
317 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a liased clip couldn't 314 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a liased clip couldn't
318 // be created. In either case, free up the texture in the anti-aliased mask cache. 315 // be created. In either case, free up the texture in the anti-aliased mask cache.
319 // TODO: this may require more investigation. Ganesh performs a lot of utili ty draws (e.g., 316 // TODO: this may require more investigation. Ganesh performs a lot of utili ty draws (e.g.,
320 // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. Th ese may be 317 // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. Th ese may be
321 // "incorrectly" clearing the AA cache. 318 // "incorrectly" clearing the AA cache.
322 fAACache.reset(); 319 fAACache.reset();
323 320
324 // use the stencil clip if we can't represent the clip as a rectangle. 321 // use the stencil clip if we can't represent the clip as a rectangle.
325 SkIPoint clipSpaceToStencilSpaceOffset = -clipDataIn->fOrigin; 322 SkIPoint clipSpaceToStencilSpaceOffset = -clipDataIn->fOrigin;
326 this->createStencilClipMask(genID, 323 this->createStencilClipMask(genID,
327 initialState, 324 initialState,
328 elements, 325 elements,
329 clipSpaceIBounds, 326 clipSpaceIBounds,
330 clipSpaceToStencilSpaceOffset); 327 clipSpaceToStencilSpaceOffset);
331 328
332 // This must occur after createStencilClipMask. That function may change the scissor. Also, it 329 // This must occur after createStencilClipMask. That function may change the scissor. Also, it
333 // only guarantees that the stencil mask is correct within the bounds it was passed, so we must 330 // only guarantees that the stencil mask is correct within the bounds it was passed, so we must
334 // use both stencil and scissor test to the bounds for the final draw. 331 // use both stencil and scissor test to the bounds for the final draw.
335 SkIRect scissorSpaceIBounds(clipSpaceIBounds); 332 SkIRect scissorSpaceIBounds(clipSpaceIBounds);
336 scissorSpaceIBounds.offset(clipSpaceToStencilSpaceOffset); 333 scissorSpaceIBounds.offset(clipSpaceToStencilSpaceOffset);
337 fGpu->enableScissor(scissorSpaceIBounds); 334 scissorState->set(scissorSpaceIBounds);
338 this->setDrawStateStencil(asr); 335 this->setDrawStateStencil(ars);
339 return true; 336 return true;
340 } 337 }
341 338
342 #define VISUALIZE_COMPLEX_CLIP 0 339 #define VISUALIZE_COMPLEX_CLIP 0
343 340
344 #if VISUALIZE_COMPLEX_CLIP 341 #if VISUALIZE_COMPLEX_CLIP
345 #include "SkRandom.h" 342 #include "SkRandom.h"
346 SkRandom gRandom; 343 SkRandom gRandom;
347 #define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU()); 344 #define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU());
348 #else 345 #else
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 1131
1135 // TODO: dynamically attach a stencil buffer 1132 // TODO: dynamically attach a stencil buffer
1136 int stencilBits = 0; 1133 int stencilBits = 0;
1137 GrStencilBuffer* stencilBuffer = 1134 GrStencilBuffer* stencilBuffer =
1138 drawState.getRenderTarget()->getStencilBuffer(); 1135 drawState.getRenderTarget()->getStencilBuffer();
1139 if (stencilBuffer) { 1136 if (stencilBuffer) {
1140 stencilBits = stencilBuffer->bits(); 1137 stencilBits = stencilBuffer->bits();
1141 this->adjustStencilParams(settings, clipMode, stencilBits); 1138 this->adjustStencilParams(settings, clipMode, stencilBits);
1142 } 1139 }
1143 } 1140 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698