OLD | NEW |
---|---|
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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 | 770 |
771 // setup batch properties | 771 // setup batch properties |
772 fBatch.fColorIgnored = !opt.readsColor(); | 772 fBatch.fColorIgnored = !opt.readsColor(); |
773 fBatch.fColor = fGeoData[0].fColor; | 773 fBatch.fColor = fGeoData[0].fColor; |
774 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 774 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
775 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 775 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
776 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); | 776 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); |
777 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); | 777 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); |
778 } | 778 } |
779 | 779 |
780 void prepareLinesOnlyDraws(Target* target) { | 780 void prepareLinesOnlyDraws(Target* target) const { |
781 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 781 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
782 | 782 |
783 // Setup GrGeometryProcessor | 783 // Setup GrGeometryProcessor |
784 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, | 784 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, |
785 this->viewMatr ix(), | 785 this->viewMatr ix(), |
786 this->usesLoca lCoords(), | 786 this->usesLoca lCoords(), |
787 this->coverage Ignored())); | 787 this->coverage Ignored())); |
788 if (!gp) { | 788 if (!gp) { |
789 SkDebugf("Could not create GrGeometryProcessor\n"); | 789 SkDebugf("Could not create GrGeometryProcessor\n"); |
790 return; | 790 return; |
791 } | 791 } |
792 | 792 |
793 target->initDraw(gp, this->pipeline()); | 793 target->initDraw(gp, this->pipeline()); |
794 | 794 |
795 size_t vertexStride = gp->getVertexStride(); | 795 size_t vertexStride = gp->getVertexStride(); |
796 | 796 |
797 SkASSERT(canTweakAlphaForCoverage ? | 797 SkASSERT(canTweakAlphaForCoverage ? |
798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : | 798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : |
799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); | 799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); |
800 | 800 |
801 GrAAConvexTessellator tess; | 801 GrAAConvexTessellator tess; |
802 | 802 |
803 int instanceCount = fGeoData.count(); | 803 int instanceCount = fGeoData.count(); |
804 | 804 |
805 for (int i = 0; i < instanceCount; i++) { | 805 for (int i = 0; i < instanceCount; i++) { |
806 tess.rewind(); | 806 tess.rewind(); |
807 | 807 |
808 Geometry& args = fGeoData[i]; | 808 const Geometry& args = fGeoData[i]; |
809 | 809 |
810 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { | 810 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
811 continue; | 811 continue; |
812 } | 812 } |
813 | 813 |
814 const GrVertexBuffer* vertexBuffer; | 814 const GrVertexBuffer* vertexBuffer; |
815 int firstVertex; | 815 int firstVertex; |
816 | 816 |
817 void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), & vertexBuffer, | 817 void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), & vertexBuffer, |
818 &firstVertex); | 818 &firstVertex); |
(...skipping 15 matching lines...) Expand all Loading... | |
834 | 834 |
835 GrVertices info; | 835 GrVertices info; |
836 info.initIndexed(kTriangles_GrPrimitiveType, | 836 info.initIndexed(kTriangles_GrPrimitiveType, |
837 vertexBuffer, indexBuffer, | 837 vertexBuffer, indexBuffer, |
838 firstVertex, firstIndex, | 838 firstVertex, firstIndex, |
839 tess.numPts(), tess.numIndices()); | 839 tess.numPts(), tess.numIndices()); |
840 target->draw(info); | 840 target->draw(info); |
841 } | 841 } |
842 } | 842 } |
843 | 843 |
844 void onPrepareDraws(Target* target) override { | 844 void onPrepareDraws(Target* target) const override { |
845 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS | 845 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS |
846 if (this->linesOnly()) { | 846 if (this->linesOnly()) { |
847 this->prepareLinesOnlyDraws(target); | 847 this->prepareLinesOnlyDraws(target); |
848 return; | 848 return; |
849 } | 849 } |
850 #endif | 850 #endif |
851 | 851 |
852 int instanceCount = fGeoData.count(); | 852 int instanceCount = fGeoData.count(); |
853 | 853 |
854 SkMatrix invert; | 854 SkMatrix invert; |
855 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 855 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
856 SkDebugf("Could not invert viewmatrix\n"); | 856 SkDebugf("Could not invert viewmatrix\n"); |
857 return; | 857 return; |
858 } | 858 } |
859 | 859 |
860 // Setup GrGeometryProcessor | 860 // Setup GrGeometryProcessor |
861 SkAutoTUnref<GrGeometryProcessor> quadProcessor( | 861 SkAutoTUnref<GrGeometryProcessor> quadProcessor( |
862 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds())); | 862 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds())); |
863 | 863 |
864 target->initDraw(quadProcessor, this->pipeline()); | 864 target->initDraw(quadProcessor, this->pipeline()); |
865 | 865 |
866 // TODO generate all segments for all paths and use one vertex buffer | 866 // TODO generate all segments for all paths and use one vertex buffer |
867 for (int i = 0; i < instanceCount; i++) { | 867 for (int i = 0; i < instanceCount; i++) { |
868 Geometry& args = fGeoData[i]; | 868 const Geometry& args = fGeoData[i]; |
869 | 869 |
870 // We use the fact that SkPath::transform path does subdivision base d on | 870 // We use the fact that SkPath::transform path does subdivision base d on |
871 // perspective. Otherwise, we apply the view matrix when copying to the | 871 // perspective. Otherwise, we apply the view matrix when copying to the |
872 // segment representation. | 872 // segment representation. |
873 const SkMatrix* viewMatrix = &args.fViewMatrix; | 873 const SkMatrix* viewMatrix = &args.fViewMatrix; |
874 | |
875 // We avoid initializing the path unless we have to | |
876 const SkPath* pathPtr = &args.fPath; | |
877 SkTLazy<SkPath> tmpPath; | |
874 if (viewMatrix->hasPerspective()) { | 878 if (viewMatrix->hasPerspective()) { |
875 args.fPath.transform(*viewMatrix); | 879 SkPath* tmpPathPtr = tmpPath.init(*pathPtr); |
robertphillips
2015/11/30 19:52:40
Should we set the volatile bit on the new path ?
| |
880 tmpPathPtr->transform(*viewMatrix); | |
876 viewMatrix = &SkMatrix::I(); | 881 viewMatrix = &SkMatrix::I(); |
882 pathPtr = tmpPathPtr; | |
877 } | 883 } |
878 | 884 |
879 int vertexCount; | 885 int vertexCount; |
880 int indexCount; | 886 int indexCount; |
881 enum { | 887 enum { |
882 kPreallocSegmentCnt = 512 / sizeof(Segment), | 888 kPreallocSegmentCnt = 512 / sizeof(Segment), |
883 kPreallocDrawCnt = 4, | 889 kPreallocDrawCnt = 4, |
884 }; | 890 }; |
885 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; | 891 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
886 SkPoint fanPt; | 892 SkPoint fanPt; |
887 | 893 |
888 if (!get_segments(args.fPath, *viewMatrix, &segments, &fanPt, &verte xCount, | 894 if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexC ount, |
889 &indexCount)) { | 895 &indexCount)) { |
890 continue; | 896 continue; |
891 } | 897 } |
892 | 898 |
893 const GrVertexBuffer* vertexBuffer; | 899 const GrVertexBuffer* vertexBuffer; |
894 int firstVertex; | 900 int firstVertex; |
895 | 901 |
896 size_t vertexStride = quadProcessor->getVertexStride(); | 902 size_t vertexStride = quadProcessor->getVertexStride(); |
897 QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertex Space( | 903 QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertex Space( |
898 vertexStride, vertexCount, &vertexBuffer, &firstVertex)); | 904 vertexStride, vertexCount, &vertexBuffer, &firstVertex)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { | 1020 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { |
1015 AAConvexPathBatch::Geometry geometry; | 1021 AAConvexPathBatch::Geometry geometry; |
1016 geometry.fColor = GrRandomColor(random); | 1022 geometry.fColor = GrRandomColor(random); |
1017 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 1023 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
1018 geometry.fPath = GrTest::TestPathConvex(random); | 1024 geometry.fPath = GrTest::TestPathConvex(random); |
1019 | 1025 |
1020 return AAConvexPathBatch::Create(geometry); | 1026 return AAConvexPathBatch::Create(geometry); |
1021 } | 1027 } |
1022 | 1028 |
1023 #endif | 1029 #endif |
OLD | NEW |