OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
9 | 9 |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchFlushState.h" |
11 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrDefaultGeoProcFactory.h" | 14 #include "GrDefaultGeoProcFactory.h" |
15 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
16 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
17 #include "GrPipelineBuilder.h" | 17 #include "GrPipelineBuilder.h" |
18 #include "GrProcessor.h" | 18 #include "GrProcessor.h" |
19 #include "GrResourceProvider.h" | 19 #include "GrResourceProvider.h" |
20 #include "GrVertexBuffer.h" | 20 #include "GrVertexBuffer.h" |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 702 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
703 | 703 |
704 // setup batch properties | 704 // setup batch properties |
705 fBatch.fColorIgnored = !opt.readsColor(); | 705 fBatch.fColorIgnored = !opt.readsColor(); |
706 fBatch.fColor = fGeoData[0].fColor; | 706 fBatch.fColor = fGeoData[0].fColor; |
707 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 707 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
708 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 708 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
709 fBatch.fCoverage = fGeoData[0].fCoverage; | 709 fBatch.fCoverage = fGeoData[0].fCoverage; |
710 } | 710 } |
711 | 711 |
712 void generateGeometry(GrBatchTarget* batchTarget) override; | |
713 | |
714 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 712 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
715 | 713 |
716 private: | 714 private: |
| 715 void onPrepareDraws(Target*) override; |
| 716 |
717 typedef SkTArray<SkPoint, true> PtArray; | 717 typedef SkTArray<SkPoint, true> PtArray; |
718 typedef SkTArray<int, true> IntArray; | 718 typedef SkTArray<int, true> IntArray; |
719 typedef SkTArray<float, true> FloatArray; | 719 typedef SkTArray<float, true> FloatArray; |
720 | 720 |
721 AAHairlineBatch(const Geometry& geometry) { | 721 AAHairlineBatch(const Geometry& geometry) { |
722 this->initClassID<AAHairlineBatch>(); | 722 this->initClassID<AAHairlineBatch>(); |
723 fGeoData.push_back(geometry); | 723 fGeoData.push_back(geometry); |
724 | 724 |
725 // compute bounds | 725 // compute bounds |
726 fBounds = geometry.fPath.getBounds(); | 726 fBounds = geometry.fPath.getBounds(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 SkRect fDevBounds; | 782 SkRect fDevBounds; |
783 bool fUsesLocalCoords; | 783 bool fUsesLocalCoords; |
784 bool fColorIgnored; | 784 bool fColorIgnored; |
785 bool fCoverageIgnored; | 785 bool fCoverageIgnored; |
786 }; | 786 }; |
787 | 787 |
788 BatchTracker fBatch; | 788 BatchTracker fBatch; |
789 SkSTArray<1, Geometry, true> fGeoData; | 789 SkSTArray<1, Geometry, true> fGeoData; |
790 }; | 790 }; |
791 | 791 |
792 void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget) { | 792 void AAHairlineBatch::onPrepareDraws(Target* target) { |
793 // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. | 793 // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. |
794 SkMatrix invert; | 794 SkMatrix invert; |
795 if (!this->viewMatrix().invert(&invert)) { | 795 if (!this->viewMatrix().invert(&invert)) { |
796 return; | 796 return; |
797 } | 797 } |
798 | 798 |
799 // we will transform to identity space if the viewmatrix does not have persp
ective | 799 // we will transform to identity space if the viewmatrix does not have persp
ective |
800 bool hasPerspective = this->viewMatrix().hasPerspective(); | 800 bool hasPerspective = this->viewMatrix().hasPerspective(); |
801 const SkMatrix* geometryProcessorViewM = &SkMatrix::I(); | 801 const SkMatrix* geometryProcessorViewM = &SkMatrix::I(); |
802 const SkMatrix* geometryProcessorLocalM = &invert; | 802 const SkMatrix* geometryProcessorLocalM = &invert; |
(...skipping 16 matching lines...) Expand all Loading... |
819 LocalCoords::kUnused_T
ype); | 819 LocalCoords::kUnused_T
ype); |
820 localCoords.fMatrix = geometryProcessorLocalM; | 820 localCoords.fMatrix = geometryProcessorLocalM; |
821 lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, | 821 lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, |
822 *geometryProcessorViewM)); | 822 *geometryProcessorViewM)); |
823 } | 823 } |
824 | 824 |
825 SkAutoTUnref<const GrGeometryProcessor> quadGP( | 825 SkAutoTUnref<const GrGeometryProcessor> quadGP( |
826 GrQuadEffect::Create(this->color(), | 826 GrQuadEffect::Create(this->color(), |
827 *geometryProcessorViewM, | 827 *geometryProcessorViewM, |
828 kHairlineAA_GrProcessorEdgeType, | 828 kHairlineAA_GrProcessorEdgeType, |
829 batchTarget->caps(), | 829 target->caps(), |
830 *geometryProcessorLocalM, | 830 *geometryProcessorLocalM, |
831 this->usesLocalCoords(), | 831 this->usesLocalCoords(), |
832 this->coverage())); | 832 this->coverage())); |
833 | 833 |
834 SkAutoTUnref<const GrGeometryProcessor> conicGP( | 834 SkAutoTUnref<const GrGeometryProcessor> conicGP( |
835 GrConicEffect::Create(this->color(), | 835 GrConicEffect::Create(this->color(), |
836 *geometryProcessorViewM, | 836 *geometryProcessorViewM, |
837 kHairlineAA_GrProcessorEdgeType, | 837 kHairlineAA_GrProcessorEdgeType, |
838 batchTarget->caps(), | 838 target->caps(), |
839 *geometryProcessorLocalM, | 839 *geometryProcessorLocalM, |
840 this->usesLocalCoords(), | 840 this->usesLocalCoords(), |
841 this->coverage())); | 841 this->coverage())); |
842 | 842 |
843 // This is hand inlined for maximum performance. | 843 // This is hand inlined for maximum performance. |
844 PREALLOC_PTARRAY(128) lines; | 844 PREALLOC_PTARRAY(128) lines; |
845 PREALLOC_PTARRAY(128) quads; | 845 PREALLOC_PTARRAY(128) quads; |
846 PREALLOC_PTARRAY(128) conics; | 846 PREALLOC_PTARRAY(128) conics; |
847 IntArray qSubdivs; | 847 IntArray qSubdivs; |
848 FloatArray cWeights; | 848 FloatArray cWeights; |
849 int quadCount = 0; | 849 int quadCount = 0; |
850 | 850 |
851 int instanceCount = fGeoData.count(); | 851 int instanceCount = fGeoData.count(); |
852 for (int i = 0; i < instanceCount; i++) { | 852 for (int i = 0; i < instanceCount; i++) { |
853 const Geometry& args = fGeoData[i]; | 853 const Geometry& args = fGeoData[i]; |
854 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, | 854 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, |
855 &lines, &quads, &conics, &qSubdivs,
&cWeights); | 855 &lines, &quads, &conics, &qSubdivs,
&cWeights); |
856 } | 856 } |
857 | 857 |
858 int lineCount = lines.count() / 2; | 858 int lineCount = lines.count() / 2; |
859 int conicCount = conics.count() / 3; | 859 int conicCount = conics.count() / 3; |
860 | 860 |
861 // do lines first | 861 // do lines first |
862 if (lineCount) { | 862 if (lineCount) { |
863 SkAutoTUnref<const GrIndexBuffer> linesIndexBuffer( | 863 SkAutoTUnref<const GrIndexBuffer> linesIndexBuffer( |
864 ref_lines_index_buffer(batchTarget->resourceProvider())); | 864 ref_lines_index_buffer(target->resourceProvider())); |
865 batchTarget->initDraw(lineGP, this->pipeline()); | 865 target->initDraw(lineGP, this->pipeline()); |
866 | 866 |
867 const GrVertexBuffer* vertexBuffer; | 867 const GrVertexBuffer* vertexBuffer; |
868 int firstVertex; | 868 int firstVertex; |
869 | 869 |
870 size_t vertexStride = lineGP->getVertexStride(); | 870 size_t vertexStride = lineGP->getVertexStride(); |
871 int vertexCount = kLineSegNumVertices * lineCount; | 871 int vertexCount = kLineSegNumVertices * lineCount; |
872 LineVertex* verts = reinterpret_cast<LineVertex*>( | 872 LineVertex* verts = reinterpret_cast<LineVertex*>( |
873 batchTarget->makeVertSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex)); | 873 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f
irstVertex)); |
874 | 874 |
875 if (!verts|| !linesIndexBuffer) { | 875 if (!verts|| !linesIndexBuffer) { |
876 SkDebugf("Could not allocate vertices\n"); | 876 SkDebugf("Could not allocate vertices\n"); |
877 return; | 877 return; |
878 } | 878 } |
879 | 879 |
880 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); | 880 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); |
881 | 881 |
882 for (int i = 0; i < lineCount; ++i) { | 882 for (int i = 0; i < lineCount; ++i) { |
883 add_line(&lines[2*i], toSrc, this->coverage(), &verts); | 883 add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
884 } | 884 } |
885 | 885 |
886 { | 886 { |
887 GrVertices vertices; | 887 GrVertices vertices; |
888 vertices.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, lin
esIndexBuffer, | 888 vertices.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, lin
esIndexBuffer, |
889 firstVertex, kLineSegNumVertices, kIdxsPerLin
eSeg, lineCount, | 889 firstVertex, kLineSegNumVertices, kIdxsPerLin
eSeg, lineCount, |
890 kLineSegsNumInIdxBuffer); | 890 kLineSegsNumInIdxBuffer); |
891 batchTarget->draw(vertices); | 891 target->draw(vertices); |
892 } | 892 } |
893 } | 893 } |
894 | 894 |
895 if (quadCount || conicCount) { | 895 if (quadCount || conicCount) { |
896 const GrVertexBuffer* vertexBuffer; | 896 const GrVertexBuffer* vertexBuffer; |
897 int firstVertex; | 897 int firstVertex; |
898 | 898 |
899 SkAutoTUnref<const GrIndexBuffer> quadsIndexBuffer( | 899 SkAutoTUnref<const GrIndexBuffer> quadsIndexBuffer( |
900 ref_quads_index_buffer(batchTarget->resourceProvider())); | 900 ref_quads_index_buffer(target->resourceProvider())); |
901 | 901 |
902 size_t vertexStride = sizeof(BezierVertex); | 902 size_t vertexStride = sizeof(BezierVertex); |
903 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; | 903 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; |
904 void *vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, | 904 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, |
905 &vertexBuffer, &firstVertex)
; | 905 &vertexBuffer, &firstVertex); |
906 | 906 |
907 if (!vertices || !quadsIndexBuffer) { | 907 if (!vertices || !quadsIndexBuffer) { |
908 SkDebugf("Could not allocate vertices\n"); | 908 SkDebugf("Could not allocate vertices\n"); |
909 return; | 909 return; |
910 } | 910 } |
911 | 911 |
912 // Setup vertices | 912 // Setup vertices |
913 BezierVertex* verts = reinterpret_cast<BezierVertex*>(vertices); | 913 BezierVertex* verts = reinterpret_cast<BezierVertex*>(vertices); |
914 | 914 |
915 int unsubdivQuadCnt = quads.count() / 3; | 915 int unsubdivQuadCnt = quads.count() / 3; |
916 for (int i = 0; i < unsubdivQuadCnt; ++i) { | 916 for (int i = 0; i < unsubdivQuadCnt; ++i) { |
917 SkASSERT(qSubdivs[i] >= 0); | 917 SkASSERT(qSubdivs[i] >= 0); |
918 add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts); | 918 add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts); |
919 } | 919 } |
920 | 920 |
921 // Start Conics | 921 // Start Conics |
922 for (int i = 0; i < conicCount; ++i) { | 922 for (int i = 0; i < conicCount; ++i) { |
923 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts); | 923 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts); |
924 } | 924 } |
925 | 925 |
926 if (quadCount > 0) { | 926 if (quadCount > 0) { |
927 batchTarget->initDraw(quadGP, this->pipeline()); | 927 target->initDraw(quadGP, this->pipeline()); |
928 | 928 |
929 { | 929 { |
930 GrVertices verts; | 930 GrVertices verts; |
931 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, | 931 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, |
932 firstVertex, kQuadNumVertices, kIdxsPerQuad,
quadCount, | 932 firstVertex, kQuadNumVertices, kIdxsPerQuad,
quadCount, |
933 kQuadsNumInIdxBuffer); | 933 kQuadsNumInIdxBuffer); |
934 batchTarget->draw(verts); | 934 target->draw(verts); |
935 firstVertex += quadCount * kQuadNumVertices; | 935 firstVertex += quadCount * kQuadNumVertices; |
936 } | 936 } |
937 } | 937 } |
938 | 938 |
939 if (conicCount > 0) { | 939 if (conicCount > 0) { |
940 batchTarget->initDraw(conicGP, this->pipeline()); | 940 target->initDraw(conicGP, this->pipeline()); |
941 | 941 |
942 { | 942 { |
943 GrVertices verts; | 943 GrVertices verts; |
944 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, | 944 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, |
945 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, | 945 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, |
946 kQuadsNumInIdxBuffer); | 946 kQuadsNumInIdxBuffer); |
947 batchTarget->draw(verts); | 947 target->draw(verts); |
948 } | 948 } |
949 } | 949 } |
950 } | 950 } |
951 } | 951 } |
952 | 952 |
953 static GrDrawBatch* create_hairline_batch(GrColor color, | 953 static GrDrawBatch* create_hairline_batch(GrColor color, |
954 const SkMatrix& viewMatrix, | 954 const SkMatrix& viewMatrix, |
955 const SkPath& path, | 955 const SkPath& path, |
956 const GrStrokeInfo& stroke, | 956 const GrStrokeInfo& stroke, |
957 const SkIRect& devClipBounds) { | 957 const SkIRect& devClipBounds) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 GrColor color = GrRandomColor(random); | 991 GrColor color = GrRandomColor(random); |
992 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 992 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
993 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); | 993 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
994 SkPath path = GrTest::TestPath(random); | 994 SkPath path = GrTest::TestPath(random); |
995 SkIRect devClipBounds; | 995 SkIRect devClipBounds; |
996 devClipBounds.setEmpty(); | 996 devClipBounds.setEmpty(); |
997 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; | 997 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; |
998 } | 998 } |
999 | 999 |
1000 #endif | 1000 #endif |
OLD | NEW |