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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 const Geometry& args = fGeoData[i]; | 824 const Geometry& args = fGeoData[i]; |
825 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, | 825 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, |
826 &lines, &quads, &conics, &qSubdivs,
&cWeights); | 826 &lines, &quads, &conics, &qSubdivs,
&cWeights); |
827 } | 827 } |
828 | 828 |
829 int lineCount = lines.count() / 2; | 829 int lineCount = lines.count() / 2; |
830 int conicCount = conics.count() / 3; | 830 int conicCount = conics.count() / 3; |
831 | 831 |
832 // do lines first | 832 // do lines first |
833 if (lineCount) { | 833 if (lineCount) { |
834 SkAutoTUnref<const GrGeometryProcessor> lineGP; | 834 sk_sp<GrGeometryProcessor> lineGP; |
835 { | 835 { |
836 using namespace GrDefaultGeoProcFactory; | 836 using namespace GrDefaultGeoProcFactory; |
837 | 837 |
838 Color color(this->color()); | 838 Color color(this->color()); |
839 Coverage coverage(Coverage::kAttribute_Type); | 839 Coverage coverage(Coverage::kAttribute_Type); |
840 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : | 840 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : |
841 LocalCoords::kUnused_Type); | 841 LocalCoords::kUnused_Type); |
842 localCoords.fMatrix = geometryProcessorLocalM; | 842 localCoords.fMatrix = geometryProcessorLocalM; |
843 lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localC
oords, | 843 lineGP = GrDefaultGeoProcFactory::Make(color, coverage, localCoords, |
844 *geometryProcessorViewM
)); | 844 *geometryProcessorViewM); |
845 } | 845 } |
846 | 846 |
847 SkAutoTUnref<const GrBuffer> linesIndexBuffer( | 847 SkAutoTUnref<const GrBuffer> linesIndexBuffer( |
848 ref_lines_index_buffer(target->resourceProvider())); | 848 ref_lines_index_buffer(target->resourceProvider())); |
849 | 849 |
850 const GrBuffer* vertexBuffer; | 850 const GrBuffer* vertexBuffer; |
851 int firstVertex; | 851 int firstVertex; |
852 | 852 |
853 size_t vertexStride = lineGP->getVertexStride(); | 853 size_t vertexStride = lineGP->getVertexStride(); |
854 int vertexCount = kLineSegNumVertices * lineCount; | 854 int vertexCount = kLineSegNumVertices * lineCount; |
855 LineVertex* verts = reinterpret_cast<LineVertex*>( | 855 LineVertex* verts = reinterpret_cast<LineVertex*>( |
856 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f
irstVertex)); | 856 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f
irstVertex)); |
857 | 857 |
858 if (!verts|| !linesIndexBuffer) { | 858 if (!verts|| !linesIndexBuffer) { |
859 SkDebugf("Could not allocate vertices\n"); | 859 SkDebugf("Could not allocate vertices\n"); |
860 return; | 860 return; |
861 } | 861 } |
862 | 862 |
863 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); | 863 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); |
864 | 864 |
865 for (int i = 0; i < lineCount; ++i) { | 865 for (int i = 0; i < lineCount; ++i) { |
866 add_line(&lines[2*i], toSrc, this->coverage(), &verts); | 866 add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
867 } | 867 } |
868 | 868 |
869 GrMesh mesh; | 869 GrMesh mesh; |
870 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIndexB
uffer, | 870 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIndexB
uffer, |
871 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg, li
neCount, | 871 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg, li
neCount, |
872 kLineSegsNumInIdxBuffer); | 872 kLineSegsNumInIdxBuffer); |
873 target->draw(lineGP, mesh); | 873 target->draw(lineGP.get(), mesh); |
874 } | 874 } |
875 | 875 |
876 if (quadCount || conicCount) { | 876 if (quadCount || conicCount) { |
877 SkAutoTUnref<const GrGeometryProcessor> quadGP( | 877 sk_sp<GrGeometryProcessor> quadGP( |
878 GrQuadEffect::Create(this->color(), | 878 GrQuadEffect::Make(this->color(), |
879 *geometryProcessorViewM, | 879 *geometryProcessorViewM, |
880 kHairlineAA_GrProcessorEdgeType, | 880 kHairlineAA_GrProcessorEdgeType, |
881 target->caps(), | 881 target->caps(), |
882 *geometryProcessorLocalM, | 882 *geometryProcessorLocalM, |
883 this->usesLocalCoords(), | 883 this->usesLocalCoords(), |
884 this->coverage())); | 884 this->coverage())); |
885 | 885 |
886 SkAutoTUnref<const GrGeometryProcessor> conicGP( | 886 sk_sp<GrGeometryProcessor> conicGP( |
887 GrConicEffect::Create(this->color(), | 887 GrConicEffect::Make(this->color(), |
888 *geometryProcessorViewM, | 888 *geometryProcessorViewM, |
889 kHairlineAA_GrProcessorEdgeType, | 889 kHairlineAA_GrProcessorEdgeType, |
890 target->caps(), | 890 target->caps(), |
891 *geometryProcessorLocalM, | 891 *geometryProcessorLocalM, |
892 this->usesLocalCoords(), | 892 this->usesLocalCoords(), |
893 this->coverage())); | 893 this->coverage())); |
894 | 894 |
895 const GrBuffer* vertexBuffer; | 895 const GrBuffer* vertexBuffer; |
896 int firstVertex; | 896 int firstVertex; |
897 | 897 |
898 SkAutoTUnref<const GrBuffer> quadsIndexBuffer( | 898 SkAutoTUnref<const GrBuffer> quadsIndexBuffer( |
899 ref_quads_index_buffer(target->resourceProvider())); | 899 ref_quads_index_buffer(target->resourceProvider())); |
900 | 900 |
901 size_t vertexStride = sizeof(BezierVertex); | 901 size_t vertexStride = sizeof(BezierVertex); |
902 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; | 902 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; |
903 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, | 903 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, |
(...skipping 16 matching lines...) Expand all Loading... |
920 // Start Conics | 920 // Start Conics |
921 for (int i = 0; i < conicCount; ++i) { | 921 for (int i = 0; i < conicCount; ++i) { |
922 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); | 922 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); |
923 } | 923 } |
924 | 924 |
925 if (quadCount > 0) { | 925 if (quadCount > 0) { |
926 GrMesh mesh; | 926 GrMesh mesh; |
927 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, | 927 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, |
928 firstVertex, kQuadNumVertices, kIdxsPerQuad, quad
Count, | 928 firstVertex, kQuadNumVertices, kIdxsPerQuad, quad
Count, |
929 kQuadsNumInIdxBuffer); | 929 kQuadsNumInIdxBuffer); |
930 target->draw(quadGP, mesh); | 930 target->draw(quadGP.get(), mesh); |
931 firstVertex += quadCount * kQuadNumVertices; | 931 firstVertex += quadCount * kQuadNumVertices; |
932 } | 932 } |
933 | 933 |
934 if (conicCount > 0) { | 934 if (conicCount > 0) { |
935 GrMesh mesh; | 935 GrMesh mesh; |
936 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, | 936 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, |
937 firstVertex, kQuadNumVertices, kIdxsPerQuad, coni
cCount, | 937 firstVertex, kQuadNumVertices, kIdxsPerQuad, coni
cCount, |
938 kQuadsNumInIdxBuffer); | 938 kQuadsNumInIdxBuffer); |
939 target->draw(conicGP, mesh); | 939 target->draw(conicGP.get(), mesh); |
940 } | 940 } |
941 } | 941 } |
942 } | 942 } |
943 | 943 |
944 static GrDrawBatch* create_hairline_batch(GrColor color, | 944 static GrDrawBatch* create_hairline_batch(GrColor color, |
945 const SkMatrix& viewMatrix, | 945 const SkMatrix& viewMatrix, |
946 const SkPath& path, | 946 const SkPath& path, |
947 const GrStyle& style, | 947 const GrStyle& style, |
948 const SkIRect& devClipBounds) { | 948 const SkIRect& devClipBounds) { |
949 SkScalar hairlineCoverage; | 949 SkScalar hairlineCoverage; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 DRAW_BATCH_TEST_DEFINE(AAHairlineBatch) { | 989 DRAW_BATCH_TEST_DEFINE(AAHairlineBatch) { |
990 GrColor color = GrRandomColor(random); | 990 GrColor color = GrRandomColor(random); |
991 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 991 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
992 SkPath path = GrTest::TestPath(random); | 992 SkPath path = GrTest::TestPath(random); |
993 SkIRect devClipBounds; | 993 SkIRect devClipBounds; |
994 devClipBounds.setEmpty(); | 994 devClipBounds.setEmpty(); |
995 return create_hairline_batch(color, viewMatrix, path, GrStyle::SimpleHairlin
e(), devClipBounds); | 995 return create_hairline_batch(color, viewMatrix, path, GrStyle::SimpleHairlin
e(), devClipBounds); |
996 } | 996 } |
997 | 997 |
998 #endif | 998 #endif |
OLD | NEW |