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

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

Issue 732693002: Drawstate on stack (Closed) Base URL: https://skia.googlesource.com/skia.git@real_def_gp
Patch Set: tiny fix 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/GrAAConvexPathRenderer.h ('k') | src/gpu/GrAADistanceFieldPathRenderer.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 "GrAAConvexPathRenderer.h" 9 #include "GrAAConvexPathRenderer.h"
10 10
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, 603 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random,
604 GrContext*, 604 GrContext*,
605 const GrDrawTargetCaps& caps, 605 const GrDrawTargetCaps& caps,
606 GrTexture*[]) { 606 GrTexture*[]) {
607 // Doesn't work without derivative instructions. 607 // Doesn't work without derivative instructions.
608 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; 608 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL;
609 } 609 }
610 610
611 /////////////////////////////////////////////////////////////////////////////// 611 ///////////////////////////////////////////////////////////////////////////////
612 612
613 bool GrAAConvexPathRenderer::canDrawPath(const SkPath& path, 613 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target,
614 const GrDrawState*,
615 const SkPath& path,
614 const SkStrokeRec& stroke, 616 const SkStrokeRec& stroke,
615 const GrDrawTarget* target,
616 bool antiAlias) const { 617 bool antiAlias) const {
617 return (target->caps()->shaderDerivativeSupport() && antiAlias && 618 return (target->caps()->shaderDerivativeSupport() && antiAlias &&
618 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex() ); 619 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex() );
619 } 620 }
620 621
621 namespace { 622 namespace {
622 623
623 // position + edge 624 // position + edge
624 extern const GrVertexAttrib gPathAttribs[] = { 625 extern const GrVertexAttrib gPathAttribs[] = {
625 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, 626 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
626 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr ibBinding} 627 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr ibBinding}
627 }; 628 };
628 629
629 }; 630 };
630 631
631 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, 632 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target,
633 GrDrawState* drawState,
634 const SkPath& origPath,
632 const SkStrokeRec&, 635 const SkStrokeRec&,
633 GrDrawTarget* target,
634 bool antiAlias) { 636 bool antiAlias) {
635 637
636 const SkPath* path = &origPath; 638 const SkPath* path = &origPath;
637 if (path->isEmpty()) { 639 if (path->isEmpty()) {
638 return true; 640 return true;
639 } 641 }
640 642
641 SkMatrix viewMatrix = target->getDrawState().getViewMatrix(); 643 SkMatrix viewMatrix = drawState->getViewMatrix();
642 GrDrawTarget::AutoStateRestore asr; 644 GrDrawState::AutoViewMatrixRestore avmr;
643 if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { 645 if (!avmr.setIdentity(drawState)) {
644 return false; 646 return false;
645 } 647 }
646 GrDrawState* drawState = target->drawState();
647 648
648 // We use the fact that SkPath::transform path does subdivision based on 649 // We use the fact that SkPath::transform path does subdivision based on
649 // perspective. Otherwise, we apply the view matrix when copying to the 650 // perspective. Otherwise, we apply the view matrix when copying to the
650 // segment representation. 651 // segment representation.
651 SkPath tmpPath; 652 SkPath tmpPath;
652 if (viewMatrix.hasPerspective()) { 653 if (viewMatrix.hasPerspective()) {
653 origPath.transform(viewMatrix, &tmpPath); 654 origPath.transform(viewMatrix, &tmpPath);
654 path = &tmpPath; 655 path = &tmpPath;
655 viewMatrix = SkMatrix::I(); 656 viewMatrix = SkMatrix::I();
656 } 657 }
(...skipping 18 matching lines...) Expand all
675 } 676 }
676 677
677 // Our computed verts should all be within one pixel of the segment control points. 678 // Our computed verts should all be within one pixel of the segment control points.
678 devBounds.outset(SK_Scalar1, SK_Scalar1); 679 devBounds.outset(SK_Scalar1, SK_Scalar1);
679 680
680 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size of(QuadVertex)); 681 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size of(QuadVertex));
681 682
682 GrGeometryProcessor* quadProcessor = QuadEdgeEffect::Create(); 683 GrGeometryProcessor* quadProcessor = QuadEdgeEffect::Create();
683 drawState->setGeometryProcessor(quadProcessor)->unref(); 684 drawState->setGeometryProcessor(quadProcessor)->unref();
684 685
685 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); 686 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, drawState->getVertexSt ride(), iCount);
686 if (!arg.succeeded()) { 687 if (!arg.succeeded()) {
687 return false; 688 return false;
688 } 689 }
689 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); 690 verts = reinterpret_cast<QuadVertex*>(arg.vertices());
690 idxs = reinterpret_cast<uint16_t*>(arg.indices()); 691 idxs = reinterpret_cast<uint16_t*>(arg.indices());
691 692
692 SkSTArray<kPreallocDrawCnt, Draw, true> draws; 693 SkSTArray<kPreallocDrawCnt, Draw, true> draws;
693 create_vertices(segments, fanPt, &draws, verts, idxs); 694 create_vertices(segments, fanPt, &draws, verts, idxs);
694 695
695 // Check devBounds 696 // Check devBounds
696 #ifdef SK_DEBUG 697 #ifdef SK_DEBUG
697 SkRect tolDevBounds = devBounds; 698 SkRect tolDevBounds = devBounds;
698 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); 699 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000);
699 SkRect actualBounds; 700 SkRect actualBounds;
700 actualBounds.set(verts[0].fPos, verts[1].fPos); 701 actualBounds.set(verts[0].fPos, verts[1].fPos);
701 for (int i = 2; i < vCount; ++i) { 702 for (int i = 2; i < vCount; ++i) {
702 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY); 703 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY);
703 } 704 }
704 SkASSERT(tolDevBounds.contains(actualBounds)); 705 SkASSERT(tolDevBounds.contains(actualBounds));
705 #endif 706 #endif
706 707
707 int vOffset = 0; 708 int vOffset = 0;
708 for (int i = 0; i < draws.count(); ++i) { 709 for (int i = 0; i < draws.count(); ++i) {
709 const Draw& draw = draws[i]; 710 const Draw& draw = draws[i];
710 target->drawIndexed(kTriangles_GrPrimitiveType, 711 target->drawIndexed(drawState,
712 kTriangles_GrPrimitiveType,
711 vOffset, // start vertex 713 vOffset, // start vertex
712 0, // start index 714 0, // start index
713 draw.fVertexCnt, 715 draw.fVertexCnt,
714 draw.fIndexCnt, 716 draw.fIndexCnt,
715 &devBounds); 717 &devBounds);
716 vOffset += draw.fVertexCnt; 718 vOffset += draw.fVertexCnt;
717 } 719 }
718 720
719 return true; 721 return true;
720 } 722 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.h ('k') | src/gpu/GrAADistanceFieldPathRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698