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

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: dm cleaned up 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
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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 471 }
472 } 472 }
473 473
474 void GrDrawTarget::drawIndexed(GrPrimitiveType type, 474 void GrDrawTarget::drawIndexed(GrPrimitiveType type,
475 int startVertex, 475 int startVertex,
476 int startIndex, 476 int startIndex,
477 int vertexCount, 477 int vertexCount,
478 int indexCount, 478 int indexCount,
479 const SkRect* devBounds) { 479 const SkRect* devBounds) {
480 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC ount, indexCount)) { 480 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexC ount, indexCount)) {
481 // Setup clip
482 GrClipMaskManager::ScissorState scissorState;
483 GrDrawState::AutoRestoreEffects are;
484 GrDrawState::AutoRestoreStencil ars;
485 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
486 return;
487 }
488
481 DrawInfo info; 489 DrawInfo info;
482 info.fPrimitiveType = type; 490 info.fPrimitiveType = type;
483 info.fStartVertex = startVertex; 491 info.fStartVertex = startVertex;
484 info.fStartIndex = startIndex; 492 info.fStartIndex = startIndex;
485 info.fVertexCount = vertexCount; 493 info.fVertexCount = vertexCount;
486 info.fIndexCount = indexCount; 494 info.fIndexCount = indexCount;
487 495
488 info.fInstanceCount = 0; 496 info.fInstanceCount = 0;
489 info.fVerticesPerInstance = 0; 497 info.fVerticesPerInstance = 0;
490 info.fIndicesPerInstance = 0; 498 info.fIndicesPerInstance = 0;
491 499
492 if (devBounds) { 500 if (devBounds) {
493 info.setDevBounds(*devBounds); 501 info.setDevBounds(*devBounds);
494 } 502 }
495 // TODO: We should continue with incorrect blending. 503 // TODO: We should continue with incorrect blending.
496 if (!this->setupDstReadIfNecessary(&info)) { 504 if (!this->setupDstReadIfNecessary(&info)) {
497 return; 505 return;
498 } 506 }
499 this->onDraw(info); 507 this->onDraw(info, scissorState);
500 } 508 }
501 } 509 }
502 510
503 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, 511 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
504 int startVertex, 512 int startVertex,
505 int vertexCount, 513 int vertexCount,
506 const SkRect* devBounds) { 514 const SkRect* devBounds) {
507 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, - 1)) { 515 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, - 1)) {
516 // Setup clip
517 GrClipMaskManager::ScissorState scissorState;
518 GrDrawState::AutoRestoreEffects are;
519 GrDrawState::AutoRestoreStencil ars;
520 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
521 return;
522 }
523
508 DrawInfo info; 524 DrawInfo info;
509 info.fPrimitiveType = type; 525 info.fPrimitiveType = type;
510 info.fStartVertex = startVertex; 526 info.fStartVertex = startVertex;
511 info.fStartIndex = 0; 527 info.fStartIndex = 0;
512 info.fVertexCount = vertexCount; 528 info.fVertexCount = vertexCount;
513 info.fIndexCount = 0; 529 info.fIndexCount = 0;
514 530
515 info.fInstanceCount = 0; 531 info.fInstanceCount = 0;
516 info.fVerticesPerInstance = 0; 532 info.fVerticesPerInstance = 0;
517 info.fIndicesPerInstance = 0; 533 info.fIndicesPerInstance = 0;
518 534
519 if (devBounds) { 535 if (devBounds) {
520 info.setDevBounds(*devBounds); 536 info.setDevBounds(*devBounds);
521 } 537 }
538
522 // TODO: We should continue with incorrect blending. 539 // TODO: We should continue with incorrect blending.
523 if (!this->setupDstReadIfNecessary(&info)) { 540 if (!this->setupDstReadIfNecessary(&info)) {
524 return; 541 return;
525 } 542 }
526 this->onDraw(info); 543 this->onDraw(info, scissorState);
527 } 544 }
528 } 545 }
529 546
547 static const GrStencilSettings& winding_path_stencil_settings() {
548 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
549 kIncClamp_StencilOp,
550 kIncClamp_StencilOp,
551 kAlwaysIfInClip_StencilFunc,
552 0xFFFF, 0xFFFF, 0xFFFF);
553 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
554 }
555
556 static const GrStencilSettings& even_odd_path_stencil_settings() {
557 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
558 kInvert_StencilOp,
559 kInvert_StencilOp,
560 kAlwaysIfInClip_StencilFunc,
561 0xFFFF, 0xFFFF, 0xFFFF);
562 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
563 }
564
565 void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType f ill,
566 GrStencilSettings* outStenc ilSettings) {
567
568 switch (fill) {
569 default:
570 SkFAIL("Unexpected path fill.");
571 case GrPathRendering::kWinding_FillType:
572 *outStencilSettings = winding_path_stencil_settings();
573 break;
574 case GrPathRendering::kEvenOdd_FillType:
575 *outStencilSettings = even_odd_path_stencil_settings();
576 break;
577 }
578 this->clipMaskManager()->adjustPathStencilParams(outStencilSettings);
579 }
580
530 void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fil l) { 581 void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fil l) {
531 // TODO: extract portions of checkDraw that are relevant to path stenciling. 582 // TODO: extract portions of checkDraw that are relevant to path stenciling.
532 SkASSERT(path); 583 SkASSERT(path);
533 SkASSERT(this->caps()->pathRenderingSupport()); 584 SkASSERT(this->caps()->pathRenderingSupport());
534 this->onStencilPath(path, fill); 585
586 // Setup clip
587 GrClipMaskManager::ScissorState scissorState;
588 GrDrawState::AutoRestoreEffects are;
589 GrDrawState::AutoRestoreStencil ars;
590 if (!this->setupClip(NULL, &are, &ars, &scissorState)) {
591 return;
592 }
593
594 // set stencil settings for path
595 GrStencilSettings stencilSettings;
596 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
597
598 this->onStencilPath(path, scissorState, stencilSettings);
535 } 599 }
536 600
537 void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) { 601 void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) {
538 // TODO: extract portions of checkDraw that are relevant to path rendering. 602 // TODO: extract portions of checkDraw that are relevant to path rendering.
539 SkASSERT(path); 603 SkASSERT(path);
540 SkASSERT(this->caps()->pathRenderingSupport()); 604 SkASSERT(this->caps()->pathRenderingSupport());
541 605
542 SkRect devBounds = path->getBounds(); 606 SkRect devBounds = path->getBounds();
543 SkMatrix viewM = this->drawState()->getViewMatrix(); 607 SkMatrix viewM = this->drawState()->getViewMatrix();
544 viewM.mapRect(&devBounds); 608 viewM.mapRect(&devBounds);
545 609
610 // Setup clip
611 GrClipMaskManager::ScissorState scissorState;
612 GrDrawState::AutoRestoreEffects are;
613 GrDrawState::AutoRestoreStencil ars;
614 if (!this->setupClip(&devBounds, &are, &ars, &scissorState)) {
615 return;
616 }
617
618 // set stencil settings for path
619 GrStencilSettings stencilSettings;
620 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
621
546 GrDeviceCoordTexture dstCopy; 622 GrDeviceCoordTexture dstCopy;
547 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { 623 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
548 return; 624 return;
549 } 625 }
550 626
551 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); 627 this->onDrawPath(path, scissorState, stencilSettings, dstCopy.texture() ? &d stCopy : NULL);
552 } 628 }
553 629
554 void GrDrawTarget::drawPaths(const GrPathRange* pathRange, 630 void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
555 const uint32_t indices[], int count, 631 const uint32_t indices[], int count,
556 const float transforms[], PathTransformType transfo rmsType, 632 const float transforms[], PathTransformType transfo rmsType,
557 GrPathRendering::FillType fill) { 633 GrPathRendering::FillType fill) {
558 SkASSERT(this->caps()->pathRenderingSupport()); 634 SkASSERT(this->caps()->pathRenderingSupport());
559 SkASSERT(pathRange); 635 SkASSERT(pathRange);
560 SkASSERT(indices); 636 SkASSERT(indices);
561 SkASSERT(transforms); 637 SkASSERT(transforms);
562 638
639 // Setup clip
640 GrClipMaskManager::ScissorState scissorState;
641 GrDrawState::AutoRestoreEffects are;
642 GrDrawState::AutoRestoreStencil ars;
643
644 if (!this->setupClip(NULL, &are, &ars, &scissorState)) {
645 return;
646 }
647
648 // set stencil settings for path
649 GrStencilSettings stencilSettings;
650 this->getPathStencilSettingsForFilltype(fill, &stencilSettings);
651
563 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt 652 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
564 // instead for it to just copy the entire dst. Realistically this is a moot 653 // instead for it to just copy the entire dst. Realistically this is a moot
565 // point, because any context that supports NV_path_rendering will also 654 // point, because any context that supports NV_path_rendering will also
566 // support NV_blend_equation_advanced. 655 // support NV_blend_equation_advanced.
567 GrDeviceCoordTexture dstCopy; 656 GrDeviceCoordTexture dstCopy;
568 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { 657 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
569 return; 658 return;
570 } 659 }
571 660
572 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fil l, 661 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, sci ssorState,
573 dstCopy.texture() ? &dstCopy : NULL); 662 stencilSettings, dstCopy.texture() ? &dstCopy : NULL);
574 } 663 }
575 664
576 typedef GrTraceMarkerSet::Iter TMIter; 665 typedef GrTraceMarkerSet::Iter TMIter;
577 void GrDrawTarget::saveActiveTraceMarkers() { 666 void GrDrawTarget::saveActiveTraceMarkers() {
578 if (this->caps()->gpuTracingSupport()) { 667 if (this->caps()->gpuTracingSupport()) {
579 SkASSERT(0 == fStoredTraceMarkers.count()); 668 SkASSERT(0 == fStoredTraceMarkers.count());
580 fStoredTraceMarkers.addSet(fActiveTraceMarkers); 669 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
581 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMark ers.end(); ++iter) { 670 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMark ers.end(); ++iter) {
582 this->removeGpuTraceMarker(&(*iter)); 671 this->removeGpuTraceMarker(&(*iter));
583 } 672 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 const SkRect* devBounds) { 712 const SkRect* devBounds) {
624 if (!verticesPerInstance || !indicesPerInstance) { 713 if (!verticesPerInstance || !indicesPerInstance) {
625 return; 714 return;
626 } 715 }
627 716
628 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance; 717 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst ance;
629 if (!maxInstancesPerDraw) { 718 if (!maxInstancesPerDraw) {
630 return; 719 return;
631 } 720 }
632 721
722 // Setup clip
723 GrClipMaskManager::ScissorState scissorState;
724 GrDrawState::AutoRestoreEffects are;
725 GrDrawState::AutoRestoreStencil ars;
726 if (!this->setupClip(devBounds, &are, &ars, &scissorState)) {
727 return;
728 }
729
633 DrawInfo info; 730 DrawInfo info;
634 info.fPrimitiveType = type; 731 info.fPrimitiveType = type;
635 info.fStartIndex = 0; 732 info.fStartIndex = 0;
636 info.fStartVertex = 0; 733 info.fStartVertex = 0;
637 info.fIndicesPerInstance = indicesPerInstance; 734 info.fIndicesPerInstance = indicesPerInstance;
638 info.fVerticesPerInstance = verticesPerInstance; 735 info.fVerticesPerInstance = verticesPerInstance;
639 736
640 // Set the same bounds for all the draws. 737 // Set the same bounds for all the draws.
641 if (devBounds) { 738 if (devBounds) {
642 info.setDevBounds(*devBounds); 739 info.setDevBounds(*devBounds);
643 } 740 }
644 // TODO: We should continue with incorrect blending. 741 // TODO: We should continue with incorrect blending.
645 if (!this->setupDstReadIfNecessary(&info)) { 742 if (!this->setupDstReadIfNecessary(&info)) {
646 return; 743 return;
647 } 744 }
648 745
649 while (instanceCount) { 746 while (instanceCount) {
650 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); 747 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
651 info.fVertexCount = info.fInstanceCount * verticesPerInstance; 748 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
652 info.fIndexCount = info.fInstanceCount * indicesPerInstance; 749 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
653 750
654 if (this->checkDraw(type, 751 if (this->checkDraw(type,
655 info.fStartVertex, 752 info.fStartVertex,
656 info.fStartIndex, 753 info.fStartIndex,
657 info.fVertexCount, 754 info.fVertexCount,
658 info.fIndexCount)) { 755 info.fIndexCount)) {
659 this->onDraw(info); 756 this->onDraw(info, scissorState);
660 } 757 }
661 info.fStartVertex += info.fVertexCount; 758 info.fStartVertex += info.fVertexCount;
662 instanceCount -= info.fInstanceCount; 759 instanceCount -= info.fInstanceCount;
663 } 760 }
664 } 761 }
665 762
666 //////////////////////////////////////////////////////////////////////////////// 763 ////////////////////////////////////////////////////////////////////////////////
667 764
668 namespace { 765 namespace {
669 766
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1225
1129 uint32_t GrDrawTargetCaps::CreateUniqueID() { 1226 uint32_t GrDrawTargetCaps::CreateUniqueID() {
1130 static int32_t gUniqueID = SK_InvalidUniqueID; 1227 static int32_t gUniqueID = SK_InvalidUniqueID;
1131 uint32_t id; 1228 uint32_t id;
1132 do { 1229 do {
1133 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 1230 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1134 } while (id == SK_InvalidUniqueID); 1231 } while (id == SK_InvalidUniqueID);
1135 return id; 1232 return id;
1136 } 1233 }
1137 1234
1235 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1236
1237 bool GrClipTarget::setupClip(const SkRect* devBounds,
1238 GrDrawState::AutoRestoreEffects* are,
1239 GrDrawState::AutoRestoreStencil* ars,
1240 GrClipMaskManager::ScissorState* scissorState) {
1241 return fClipMaskManager.setupClipping(this->getClip(),
1242 devBounds,
1243 are,
1244 ars,
1245 scissorState);
1246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698