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

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

Issue 2246113002: Convert GrAppliedClip interface to builder style (Closed) Base URL: https://skia.googlesource.com/skia.git@fixstencilpath
Patch Set: rebase Created 4 years, 4 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
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 #include "GrDrawTarget.h" 8 #include "GrDrawTarget.h"
9 9
10 #include "GrAuditTrail.h" 10 #include "GrAuditTrail.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 out->fRight = SkTMin(a.fRight, b.fRight); 329 out->fRight = SkTMin(a.fRight, b.fRight);
330 out->fBottom = SkTMin(a.fBottom, b.fBottom); 330 out->fBottom = SkTMin(a.fBottom, b.fBottom);
331 return (out->fLeft <= out->fRight && out->fTop <= out->fBottom); 331 return (out->fLeft <= out->fRight && out->fTop <= out->fBottom);
332 } 332 }
333 333
334 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, 334 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder,
335 GrDrawContext* drawContext, 335 GrDrawContext* drawContext,
336 const GrClip& clip, 336 const GrClip& clip,
337 GrDrawBatch* batch) { 337 GrDrawBatch* batch) {
338 // Setup clip 338 // Setup clip
339 GrAppliedClip appliedClip;
340 SkRect bounds; 339 SkRect bounds;
341 batch_bounds(&bounds, batch); 340 batch_bounds(&bounds, batch);
342 if (!clip.apply(fContext, drawContext, &bounds, 341 GrAppliedClip appliedClip(bounds);
343 pipelineBuilder.isHWAntialias(), pipelineBuilder.hasUserSten cilSettings(), 342 if (!clip.apply(fContext, drawContext, pipelineBuilder.isHWAntialias(),
344 &appliedClip)) { 343 pipelineBuilder.hasUserStencilSettings(), &appliedClip)) {
345 return; 344 return;
346 } 345 }
347 346
348 // TODO: this is the only remaining usage of the AutoRestoreFragmentProcesso rState - remove it 347 // TODO: this is the only remaining usage of the AutoRestoreFragmentProcesso rState - remove it
349 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; 348 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
350 if (appliedClip.getClipCoverageFragmentProcessor()) { 349 if (appliedClip.clipCoverageFragmentProcessor()) {
351 arfps.set(&pipelineBuilder); 350 arfps.set(&pipelineBuilder);
352 arfps.addCoverageFragmentProcessor(sk_ref_sp(appliedClip.getClipCoverage FragmentProcessor())); 351 arfps.addCoverageFragmentProcessor(sk_ref_sp(appliedClip.clipCoverageFra gmentProcessor()));
352 }
353
354 if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip() ) {
355 if (!fResourceProvider->attachStencilAttachment(drawContext->accessRende rTarget())) {
356 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
357 return;
358 }
353 } 359 }
354 360
355 GrPipeline::CreateArgs args; 361 GrPipeline::CreateArgs args;
356 args.fPipelineBuilder = &pipelineBuilder; 362 args.fPipelineBuilder = &pipelineBuilder;
357 args.fDrawContext = drawContext; 363 args.fDrawContext = drawContext;
358 args.fCaps = this->caps(); 364 args.fCaps = this->caps();
359 args.fScissor = &appliedClip.scissorState();
360 args.fHasStencilClip = appliedClip.hasStencilClip();
361 if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip() ) {
362 if (!fResourceProvider->attachStencilAttachment(drawContext->accessRende rTarget())) {
363 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
364 return;
365 }
366 }
367 batch->getPipelineOptimizations(&args.fOpts); 365 batch->getPipelineOptimizations(&args.fOpts);
368 GrScissorState finalScissor;
369 if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { 366 if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) {
370 GrGLIRect viewport; 367 GrGLIRect viewport;
371 viewport.fLeft = 0; 368 viewport.fLeft = 0;
372 viewport.fBottom = 0; 369 viewport.fBottom = 0;
373 viewport.fWidth = drawContext->width(); 370 viewport.fWidth = drawContext->width();
374 viewport.fHeight = drawContext->height(); 371 viewport.fHeight = drawContext->height();
375 SkIRect ibounds; 372 SkIRect ibounds;
376 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft, 373 ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewpo rt.fLeft,
377 viewport.fWidth); 374 viewport.fWidth);
378 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom, 375 ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport .fBottom,
379 viewport.fHeight); 376 viewport.fHeight);
380 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft, 377 ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewp ort.fLeft,
381 viewport.fWidth); 378 viewport.fWidth);
382 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom, 379 ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), vie wport.fBottom,
383 viewport.fHeight); 380 viewport.fHeight);
384 if (appliedClip.scissorState().enabled()) { 381 if (!appliedClip.addScissor(ibounds)) {
385 const SkIRect& scissorRect = appliedClip.scissorState().rect(); 382 return;
386 if (!ibounds.intersect(scissorRect)) {
387 return;
388 }
389 } 383 }
390 finalScissor.set(ibounds);
391 args.fScissor = &finalScissor;
392 } 384 }
393 args.fOpts.fColorPOI.completeCalculations( 385 args.fOpts.fColorPOI.completeCalculations(
394 sk_sp_address_as_pointer_address(pipelineBuilder.fColorFragmentProcessor s.begin()), 386 sk_sp_address_as_pointer_address(pipelineBuilder.fColorFragmentProcessor s.begin()),
395 pipelineBuilder.numColorFragmentProcessors()); 387 pipelineBuilder.numColorFragmentProcessors());
396 args.fOpts.fCoveragePOI.completeCalculations( 388 args.fOpts.fCoveragePOI.completeCalculations(
397 sk_sp_address_as_pointer_address(pipelineBuilder.fCoverageFragmentProces sors.begin()), 389 sk_sp_address_as_pointer_address(pipelineBuilder.fCoverageFragmentProces sors.begin()),
398 pipelineBuilder.numCoverageFragmentProcessors()); 390 pipelineBuilder.numCoverageFragmentProcessors());
391 args.fScissor = &appliedClip.scissorState();
392 args.fHasStencilClip = appliedClip.hasStencilClip();
399 if (!this->setupDstReadIfNecessary(pipelineBuilder, drawContext->accessRende rTarget(), 393 if (!this->setupDstReadIfNecessary(pipelineBuilder, drawContext->accessRende rTarget(),
400 clip, args.fOpts, 394 clip, args.fOpts,
401 &args.fDstTexture, batch->bounds())) { 395 &args.fDstTexture, batch->bounds())) {
402 return; 396 return;
403 } 397 }
404 398
405 if (!batch->installPipeline(args)) { 399 if (!batch->installPipeline(args)) {
406 return; 400 return;
407 } 401 }
408 402
409 #ifdef ENABLE_MDB 403 #ifdef ENABLE_MDB
410 SkASSERT(fRenderTarget); 404 SkASSERT(fRenderTarget);
411 batch->pipeline()->addDependenciesTo(fRenderTarget); 405 batch->pipeline()->addDependenciesTo(fRenderTarget);
412 #endif 406 #endif
413 SkRect clippedBounds; 407 SkRect clippedBounds;
414 SkAssertResult(intersect(&clippedBounds, bounds, appliedClip.deviceBounds()) ); 408 SkAssertResult(intersect(&clippedBounds, bounds, appliedClip.deviceBounds()) );
415 this->recordBatch(batch, clippedBounds); 409 this->recordBatch(batch, clippedBounds);
416 } 410 }
417 411
418 void GrDrawTarget::stencilPath(GrDrawContext* drawContext, 412 void GrDrawTarget::stencilPath(GrDrawContext* drawContext,
419 const GrClip& clip, 413 const GrClip& clip,
420 bool useHWAA, 414 bool useHWAA,
421 const SkMatrix& viewMatrix, 415 const SkMatrix& viewMatrix,
422 const GrPath* path) { 416 const GrPath* path) {
423 // TODO: extract portions of checkDraw that are relevant to path stenciling. 417 // TODO: extract portions of checkDraw that are relevant to path stenciling.
424 SkASSERT(path); 418 SkASSERT(path);
425 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); 419 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
426 420
421 // FIXME: Use path bounds instead of this WAR once
422 // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved.
423 SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext->height()) ;
424
427 // Setup clip 425 // Setup clip
428 GrAppliedClip appliedClip; 426 GrAppliedClip appliedClip(bounds);
429 if (!clip.apply(fContext, drawContext, nullptr, useHWAA, true, &appliedClip) ) { 427 if (!clip.apply(fContext, drawContext, useHWAA, true, &appliedClip)) {
430 return; 428 return;
431 } 429 }
432 // TODO: respect fClipBatchToBounds if we ever start computing bounds here. 430 // TODO: respect fClipBatchToBounds if we ever start computing bounds here.
433 431
434 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never 432 // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never
435 // attempt this in a situation that would require coverage AA. 433 // attempt this in a situation that would require coverage AA.
436 SkASSERT(!appliedClip.getClipCoverageFragmentProcessor()); 434 SkASSERT(!appliedClip.clipCoverageFragmentProcessor());
437 435
438 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment( 436 GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAtt achment(
439 drawContext->accessRenderTarget( )); 437 drawContext->accessRenderTarget( ));
440 if (!stencilAttachment) { 438 if (!stencilAttachment) {
441 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); 439 SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
442 return; 440 return;
443 } 441 }
444 442
445 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, 443 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix,
446 useHWAA, 444 useHWAA,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 623 }
626 } 624 }
627 625
628 /////////////////////////////////////////////////////////////////////////////// 626 ///////////////////////////////////////////////////////////////////////////////
629 627
630 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { 628 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) {
631 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); 629 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt);
632 this->recordBatch(batch, batch->bounds()); 630 this->recordBatch(batch, batch->bounds());
633 batch->unref(); 631 batch->unref();
634 } 632 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698