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

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

Issue 685883003: Clip in grdrawtarget (Closed) Base URL: https://skia.googlesource.com/skia.git@drawtarget_on_clip_manager
Patch Set: add ccclip to ignore 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/GrDrawTarget.h ('k') | src/gpu/GrGpu.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 2010 Google Inc. 3 * Copyright 2010 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 9
10 10
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 444 }
445 } 445 }
446 446
447 void GrDrawTarget::drawIndexed(GrPrimitiveType type, 447 void GrDrawTarget::drawIndexed(GrPrimitiveType type,
448 int startVertex, 448 int startVertex,
449 int startIndex, 449 int startIndex,
450 int vertexCount, 450 int vertexCount,
451 int indexCount, 451 int indexCount,
452 const SkRect* devBounds) { 452 const SkRect* devBounds) {
453 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC ount, indexCount)) { 453 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC ount, indexCount)) {
454 // Setup clip
455 GrClipMaskManager::ScissorState scissorState;
456 GrDrawState::AutoRestoreEffects are;
457 GrDrawState::AutoRestoreStencil ars;
458 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
459 return;
460 }
461
454 DrawInfo info; 462 DrawInfo info;
455 info.fPrimitiveType = type; 463 info.fPrimitiveType = type;
456 info.fStartVertex = startVertex; 464 info.fStartVertex = startVertex;
457 info.fStartIndex = startIndex; 465 info.fStartIndex = startIndex;
458 info.fVertexCount = vertexCount; 466 info.fVertexCount = vertexCount;
459 info.fIndexCount = indexCount; 467 info.fIndexCount = indexCount;
460 468
461 info.fInstanceCount = 0; 469 info.fInstanceCount = 0;
462 info.fVerticesPerInstance = 0; 470 info.fVerticesPerInstance = 0;
463 info.fIndicesPerInstance = 0; 471 info.fIndicesPerInstance = 0;
464 472
465 if (devBounds) { 473 if (devBounds) {
466 info.setDevBounds(*devBounds); 474 info.setDevBounds(*devBounds);
467 } 475 }
468 // TODO: We should continue with incorrect blending. 476 // TODO: We should continue with incorrect blending.
469 if (!this->setupDstReadIfNecessary(&info)) { 477 if (!this->setupDstReadIfNecessary(&info)) {
470 return; 478 return;
471 } 479 }
472 this->onDraw(info); 480 this->onDraw(info, scissorState);
473 } 481 }
474 } 482 }
475 483
476 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, 484 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
477 int startVertex, 485 int startVertex,
478 int vertexCount, 486 int vertexCount,
479 const SkRect* devBounds) { 487 const SkRect* devBounds) {
480 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, - 1)) { 488 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, - 1)) {
489 // Setup clip
490 GrClipMaskManager::ScissorState scissorState;
491 GrDrawState::AutoRestoreEffects are;
492 GrDrawState::AutoRestoreStencil ars;
493 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
494 return;
495 }
496
481 DrawInfo info; 497 DrawInfo info;
482 info.fPrimitiveType = type; 498 info.fPrimitiveType = type;
483 info.fStartVertex = startVertex; 499 info.fStartVertex = startVertex;
484 info.fStartIndex = 0; 500 info.fStartIndex = 0;
485 info.fVertexCount = vertexCount; 501 info.fVertexCount = vertexCount;
486 info.fIndexCount = 0; 502 info.fIndexCount = 0;
487 503
488 info.fInstanceCount = 0; 504 info.fInstanceCount = 0;
489 info.fVerticesPerInstance = 0; 505 info.fVerticesPerInstance = 0;
490 info.fIndicesPerInstance = 0; 506 info.fIndicesPerInstance = 0;
491 507
492 if (devBounds) { 508 if (devBounds) {
493 info.setDevBounds(*devBounds); 509 info.setDevBounds(*devBounds);
494 } 510 }
511
495 // TODO: We should continue with incorrect blending. 512 // TODO: We should continue with incorrect blending.
496 if (!this->setupDstReadIfNecessary(&info)) { 513 if (!this->setupDstReadIfNecessary(&info)) {
497 return; 514 return;
498 } 515 }
499 this->onDraw(info); 516 this->onDraw(info, scissorState);
500 } 517 }
501 } 518 }
502 519
520 static const GrStencilSettings& winding_path_stencil_settings() {
521 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
522 kIncClamp_StencilOp,
523 kIncClamp_StencilOp,
524 kAlwaysIfInClip_StencilFunc,
525 0xFFFF, 0xFFFF, 0xFFFF);
526 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
527 }
528
529 static const GrStencilSettings& even_odd_path_stencil_settings() {
530 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
531 kInvert_StencilOp,
532 kInvert_StencilOp,
533 kAlwaysIfInClip_StencilFunc,
534 0xFFFF, 0xFFFF, 0xFFFF);
535 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
536 }
537
538 void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType f ill,
539 GrStencilSettings* outStenc ilSettings) {
540
541 switch (fill) {
542 default:
543 SkFAIL("Unexpected path fill.");
544 case GrPathRendering::kWinding_FillType:
545 *outStencilSettings = winding_path_stencil_settings();
546 break;
547 case GrPathRendering::kEvenOdd_FillType:
548 *outStencilSettings = even_odd_path_stencil_settings();
549 break;
550 }
551 this->clipMaskManager()->adjustPathStencilParams(outStencilSettings);
552 }
553
503 void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fil l) { 554 void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fil l) {
504 // TODO: extract portions of checkDraw that are relevant to path stenciling. 555 // TODO: extract portions of checkDraw that are relevant to path stenciling.
505 SkASSERT(path); 556 SkASSERT(path);
506 SkASSERT(this->caps()->pathRenderingSupport()); 557 SkASSERT(this->caps()->pathRenderingSupport());
507 this->onStencilPath(path, fill); 558
559 // Setup clip
560 GrClipMaskManager::ScissorState scissorState;
561 GrDrawState::AutoRestoreEffects are;
562 GrDrawState::AutoRestoreStencil ars;
563 if (!this->setupClip(NULL, &are, &ars, &scissorState)) {
564 return;
565 }
566
567 // set stencil settings for path
568 GrStencilSettings stencilSettings;
569 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
570
571 this->onStencilPath(path, scissorState, stencilSettings);
508 } 572 }
509 573
510 void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) { 574 void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) {
511 // TODO: extract portions of checkDraw that are relevant to path rendering. 575 // TODO: extract portions of checkDraw that are relevant to path rendering.
512 SkASSERT(path); 576 SkASSERT(path);
513 SkASSERT(this->caps()->pathRenderingSupport()); 577 SkASSERT(this->caps()->pathRenderingSupport());
514 578
515 SkRect devBounds = path->getBounds(); 579 SkRect devBounds = path->getBounds();
516 SkMatrix viewM = this->drawState()->getViewMatrix(); 580 SkMatrix viewM = this->drawState()->getViewMatrix();
517 viewM.mapRect(&devBounds); 581 viewM.mapRect(&devBounds);
518 582
583 // Setup clip
584 GrClipMaskManager::ScissorState scissorState;
585 GrDrawState::AutoRestoreEffects are;
586 GrDrawState::AutoRestoreStencil ars;
587 if (!this->setupClip(&devBounds, &are, &ars, &scissorState)) {
588 return;
589 }
590
591 // set stencil settings for path
592 GrStencilSettings stencilSettings;
593 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
594
519 GrDeviceCoordTexture dstCopy; 595 GrDeviceCoordTexture dstCopy;
520 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { 596 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
521 return; 597 return;
522 } 598 }
523 599
524 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); 600 this->onDrawPath(path, scissorState, stencilSettings, dstCopy.texture() ? &d stCopy : NULL);
525 } 601 }
526 602
527 void GrDrawTarget::drawPaths(const GrPathRange* pathRange, 603 void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
528 const uint32_t indices[], int count, 604 const uint32_t indices[], int count,
529 const float transforms[], PathTransformType transfo rmsType, 605 const float transforms[], PathTransformType transfo rmsType,
530 GrPathRendering::FillType fill) { 606 GrPathRendering::FillType fill) {
531 SkASSERT(this->caps()->pathRenderingSupport()); 607 SkASSERT(this->caps()->pathRenderingSupport());
532 SkASSERT(pathRange); 608 SkASSERT(pathRange);
533 SkASSERT(indices); 609 SkASSERT(indices);
534 SkASSERT(transforms); 610 SkASSERT(transforms);
535 611
612 // Setup clip
613 GrClipMaskManager::ScissorState scissorState;
614 GrDrawState::AutoRestoreEffects are;
615 GrDrawState::AutoRestoreStencil ars;
616
617 if (!this->setupClip(NULL, &are, &ars, &scissorState)) {
618 return;
619 }
620
621 // set stencil settings for path
622 GrStencilSettings stencilSettings;
623 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
624
536 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt 625 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
537 // instead for it to just copy the entire dst. Realistically this is a moot 626 // instead for it to just copy the entire dst. Realistically this is a moot
538 // point, because any context that supports NV_path_rendering will also 627 // point, because any context that supports NV_path_rendering will also
539 // support NV_blend_equation_advanced. 628 // support NV_blend_equation_advanced.
540 GrDeviceCoordTexture dstCopy; 629 GrDeviceCoordTexture dstCopy;
541 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { 630 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
542 return; 631 return;
543 } 632 }
544 633
545 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fil l, 634 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, sci ssorState,
546 dstCopy.texture() ? &dstCopy : NULL); 635 stencilSettings, dstCopy.texture() ? &dstCopy : NULL);
547 } 636 }
548 637
549 void GrDrawTarget::clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, 638 void GrDrawTarget::clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
550 GrRenderTarget* renderTarget) { 639 GrRenderTarget* renderTarget) {
551 if (fCaps->useDrawInsteadOfClear()) { 640 if (fCaps->useDrawInsteadOfClear()) {
552 // This works around a driver bug with clear by drawing a rect instead. 641 // This works around a driver bug with clear by drawing a rect instead.
553 // The driver will ignore a clear if it is the only thing rendered to a 642 // The driver will ignore a clear if it is the only thing rendered to a
554 // target before the target is read. 643 // target before the target is read.
555 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he ight()); 644 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he ight());
556 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { 645 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 const SkRect* devBounds) { 710 const SkRect* devBounds) {
622 if (!verticesPerInstance || !indicesPerInstance) { 711 if (!verticesPerInstance || !indicesPerInstance) {
623 return; 712 return;
624 } 713 }
625 714
626 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance; 715 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance;
627 if (!maxInstancesPerDraw) { 716 if (!maxInstancesPerDraw) {
628 return; 717 return;
629 } 718 }
630 719
720 // Setup clip
721 GrClipMaskManager::ScissorState scissorState;
722 GrDrawState::AutoRestoreEffects are;
723 GrDrawState::AutoRestoreStencil ars;
724 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
725 return;
726 }
727
631 DrawInfo info; 728 DrawInfo info;
632 info.fPrimitiveType = type; 729 info.fPrimitiveType = type;
633 info.fStartIndex = 0; 730 info.fStartIndex = 0;
634 info.fStartVertex = 0; 731 info.fStartVertex = 0;
635 info.fIndicesPerInstance = indicesPerInstance; 732 info.fIndicesPerInstance = indicesPerInstance;
636 info.fVerticesPerInstance = verticesPerInstance; 733 info.fVerticesPerInstance = verticesPerInstance;
637 734
638 // Set the same bounds for all the draws. 735 // Set the same bounds for all the draws.
639 if (devBounds) { 736 if (devBounds) {
640 info.setDevBounds(*devBounds); 737 info.setDevBounds(*devBounds);
641 } 738 }
642 // TODO: We should continue with incorrect blending. 739 // TODO: We should continue with incorrect blending.
643 if (!this->setupDstReadIfNecessary(&info)) { 740 if (!this->setupDstReadIfNecessary(&info)) {
644 return; 741 return;
645 } 742 }
646 743
647 while (instanceCount) { 744 while (instanceCount) {
648 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); 745 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
649 info.fVertexCount = info.fInstanceCount * verticesPerInstance; 746 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
650 info.fIndexCount = info.fInstanceCount * indicesPerInstance; 747 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
651 748
652 if (this->checkDraw(type, 749 if (this->checkDraw(type,
653 info.fStartVertex, 750 info.fStartVertex,
654 info.fStartIndex, 751 info.fStartIndex,
655 info.fVertexCount, 752 info.fVertexCount,
656 info.fIndexCount)) { 753 info.fIndexCount)) {
657 this->onDraw(info); 754 this->onDraw(info, scissorState);
658 } 755 }
659 info.fStartVertex += info.fVertexCount; 756 info.fStartVertex += info.fVertexCount;
660 instanceCount -= info.fInstanceCount; 757 instanceCount -= info.fInstanceCount;
661 } 758 }
662 } 759 }
663 760
664 //////////////////////////////////////////////////////////////////////////////// 761 ////////////////////////////////////////////////////////////////////////////////
665 762
666 namespace { 763 namespace {
667 764
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 1231
1135 uint32_t GrDrawTargetCaps::CreateUniqueID() { 1232 uint32_t GrDrawTargetCaps::CreateUniqueID() {
1136 static int32_t gUniqueID = SK_InvalidUniqueID; 1233 static int32_t gUniqueID = SK_InvalidUniqueID;
1137 uint32_t id; 1234 uint32_t id;
1138 do { 1235 do {
1139 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 1236 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1140 } while (id == SK_InvalidUniqueID); 1237 } while (id == SK_InvalidUniqueID);
1141 return id; 1238 return id;
1142 } 1239 }
1143 1240
1241 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1242
1243 bool GrClipTarget::setupClip(const SkRect* devBounds,
1244 GrDrawState::AutoRestoreEffects* are,
1245 GrDrawState::AutoRestoreStencil* ars,
1246 GrClipMaskManager::ScissorState* scissorState) {
1247 return fClipMaskManager.setupClipping(this->getClip(),
1248 devBounds,
1249 are,
1250 ars,
1251 scissorState);
1252 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698