| 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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 const SkMatrix* geometryProcessorLocalM = &invert; | 799 const SkMatrix* geometryProcessorLocalM = &invert; |
| 800 const SkMatrix* toDevice = nullptr; | 800 const SkMatrix* toDevice = nullptr; |
| 801 const SkMatrix* toSrc = nullptr; | 801 const SkMatrix* toSrc = nullptr; |
| 802 if (hasPerspective) { | 802 if (hasPerspective) { |
| 803 geometryProcessorViewM = &this->viewMatrix(); | 803 geometryProcessorViewM = &this->viewMatrix(); |
| 804 geometryProcessorLocalM = &SkMatrix::I(); | 804 geometryProcessorLocalM = &SkMatrix::I(); |
| 805 toDevice = &this->viewMatrix(); | 805 toDevice = &this->viewMatrix(); |
| 806 toSrc = &invert; | 806 toSrc = &invert; |
| 807 } | 807 } |
| 808 | 808 |
| 809 SkAutoTUnref<const GrGeometryProcessor> lineGP; | |
| 810 { | |
| 811 using namespace GrDefaultGeoProcFactory; | |
| 812 | |
| 813 Color color(this->color()); | |
| 814 Coverage coverage(Coverage::kAttribute_Type); | |
| 815 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosit
ion_Type : | |
| 816 LocalCoords::kUnused_T
ype); | |
| 817 localCoords.fMatrix = geometryProcessorLocalM; | |
| 818 lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, | |
| 819 *geometryProcessorViewM)); | |
| 820 } | |
| 821 | |
| 822 SkAutoTUnref<const GrGeometryProcessor> quadGP( | |
| 823 GrQuadEffect::Create(this->color(), | |
| 824 *geometryProcessorViewM, | |
| 825 kHairlineAA_GrProcessorEdgeType, | |
| 826 target->caps(), | |
| 827 *geometryProcessorLocalM, | |
| 828 this->usesLocalCoords(), | |
| 829 this->coverage())); | |
| 830 | |
| 831 SkAutoTUnref<const GrGeometryProcessor> conicGP( | |
| 832 GrConicEffect::Create(this->color(), | |
| 833 *geometryProcessorViewM, | |
| 834 kHairlineAA_GrProcessorEdgeType, | |
| 835 target->caps(), | |
| 836 *geometryProcessorLocalM, | |
| 837 this->usesLocalCoords(), | |
| 838 this->coverage())); | |
| 839 | |
| 840 // This is hand inlined for maximum performance. | 809 // This is hand inlined for maximum performance. |
| 841 PREALLOC_PTARRAY(128) lines; | 810 PREALLOC_PTARRAY(128) lines; |
| 842 PREALLOC_PTARRAY(128) quads; | 811 PREALLOC_PTARRAY(128) quads; |
| 843 PREALLOC_PTARRAY(128) conics; | 812 PREALLOC_PTARRAY(128) conics; |
| 844 IntArray qSubdivs; | 813 IntArray qSubdivs; |
| 845 FloatArray cWeights; | 814 FloatArray cWeights; |
| 846 int quadCount = 0; | 815 int quadCount = 0; |
| 847 | 816 |
| 848 int instanceCount = fGeoData.count(); | 817 int instanceCount = fGeoData.count(); |
| 849 for (int i = 0; i < instanceCount; i++) { | 818 for (int i = 0; i < instanceCount; i++) { |
| 850 const Geometry& args = fGeoData[i]; | 819 const Geometry& args = fGeoData[i]; |
| 851 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, | 820 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, |
| 852 &lines, &quads, &conics, &qSubdivs,
&cWeights); | 821 &lines, &quads, &conics, &qSubdivs,
&cWeights); |
| 853 } | 822 } |
| 854 | 823 |
| 855 int lineCount = lines.count() / 2; | 824 int lineCount = lines.count() / 2; |
| 856 int conicCount = conics.count() / 3; | 825 int conicCount = conics.count() / 3; |
| 857 | 826 |
| 858 // do lines first | 827 // do lines first |
| 859 if (lineCount) { | 828 if (lineCount) { |
| 829 SkAutoTUnref<const GrGeometryProcessor> lineGP; |
| 830 { |
| 831 using namespace GrDefaultGeoProcFactory; |
| 832 |
| 833 Color color(this->color()); |
| 834 Coverage coverage(Coverage::kAttribute_Type); |
| 835 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : |
| 836 LocalCoords::kUnused_Type); |
| 837 localCoords.fMatrix = geometryProcessorLocalM; |
| 838 lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localC
oords, |
| 839 *geometryProcessorViewM
)); |
| 840 } |
| 841 |
| 860 SkAutoTUnref<const GrBuffer> linesIndexBuffer( | 842 SkAutoTUnref<const GrBuffer> linesIndexBuffer( |
| 861 ref_lines_index_buffer(target->resourceProvider())); | 843 ref_lines_index_buffer(target->resourceProvider())); |
| 862 target->initDraw(lineGP); | |
| 863 | 844 |
| 864 const GrBuffer* vertexBuffer; | 845 const GrBuffer* vertexBuffer; |
| 865 int firstVertex; | 846 int firstVertex; |
| 866 | 847 |
| 867 size_t vertexStride = lineGP->getVertexStride(); | 848 size_t vertexStride = lineGP->getVertexStride(); |
| 868 int vertexCount = kLineSegNumVertices * lineCount; | 849 int vertexCount = kLineSegNumVertices * lineCount; |
| 869 LineVertex* verts = reinterpret_cast<LineVertex*>( | 850 LineVertex* verts = reinterpret_cast<LineVertex*>( |
| 870 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f
irstVertex)); | 851 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f
irstVertex)); |
| 871 | 852 |
| 872 if (!verts|| !linesIndexBuffer) { | 853 if (!verts|| !linesIndexBuffer) { |
| 873 SkDebugf("Could not allocate vertices\n"); | 854 SkDebugf("Could not allocate vertices\n"); |
| 874 return; | 855 return; |
| 875 } | 856 } |
| 876 | 857 |
| 877 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); | 858 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); |
| 878 | 859 |
| 879 for (int i = 0; i < lineCount; ++i) { | 860 for (int i = 0; i < lineCount; ++i) { |
| 880 add_line(&lines[2*i], toSrc, this->coverage(), &verts); | 861 add_line(&lines[2*i], toSrc, this->coverage(), &verts); |
| 881 } | 862 } |
| 882 | 863 |
| 883 { | 864 GrMesh mesh; |
| 884 GrMesh mesh; | 865 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIndexB
uffer, |
| 885 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIn
dexBuffer, | 866 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg, li
neCount, |
| 886 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg
, lineCount, | 867 kLineSegsNumInIdxBuffer); |
| 887 kLineSegsNumInIdxBuffer); | 868 target->draw(lineGP, mesh); |
| 888 target->draw(mesh); | |
| 889 } | |
| 890 } | 869 } |
| 891 | 870 |
| 892 if (quadCount || conicCount) { | 871 if (quadCount || conicCount) { |
| 872 SkAutoTUnref<const GrGeometryProcessor> quadGP( |
| 873 GrQuadEffect::Create(this->color(), |
| 874 *geometryProcessorViewM, |
| 875 kHairlineAA_GrProcessorEdgeType, |
| 876 target->caps(), |
| 877 *geometryProcessorLocalM, |
| 878 this->usesLocalCoords(), |
| 879 this->coverage())); |
| 880 |
| 881 SkAutoTUnref<const GrGeometryProcessor> conicGP( |
| 882 GrConicEffect::Create(this->color(), |
| 883 *geometryProcessorViewM, |
| 884 kHairlineAA_GrProcessorEdgeType, |
| 885 target->caps(), |
| 886 *geometryProcessorLocalM, |
| 887 this->usesLocalCoords(), |
| 888 this->coverage())); |
| 889 |
| 893 const GrBuffer* vertexBuffer; | 890 const GrBuffer* vertexBuffer; |
| 894 int firstVertex; | 891 int firstVertex; |
| 895 | 892 |
| 896 SkAutoTUnref<const GrBuffer> quadsIndexBuffer( | 893 SkAutoTUnref<const GrBuffer> quadsIndexBuffer( |
| 897 ref_quads_index_buffer(target->resourceProvider())); | 894 ref_quads_index_buffer(target->resourceProvider())); |
| 898 | 895 |
| 899 size_t vertexStride = sizeof(BezierVertex); | 896 size_t vertexStride = sizeof(BezierVertex); |
| 900 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; | 897 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni
cCount; |
| 901 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, | 898 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, |
| 902 &vertexBuffer, &firstVertex); | 899 &vertexBuffer, &firstVertex); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 914 SkASSERT(qSubdivs[i] >= 0); | 911 SkASSERT(qSubdivs[i] >= 0); |
| 915 add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts); | 912 add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts); |
| 916 } | 913 } |
| 917 | 914 |
| 918 // Start Conics | 915 // Start Conics |
| 919 for (int i = 0; i < conicCount; ++i) { | 916 for (int i = 0; i < conicCount; ++i) { |
| 920 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); | 917 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts); |
| 921 } | 918 } |
| 922 | 919 |
| 923 if (quadCount > 0) { | 920 if (quadCount > 0) { |
| 924 target->initDraw(quadGP); | 921 GrMesh mesh; |
| 925 | 922 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, |
| 926 { | 923 firstVertex, kQuadNumVertices, kIdxsPerQuad, quad
Count, |
| 927 GrMesh mesh; | 924 kQuadsNumInIdxBuffer); |
| 928 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qua
dsIndexBuffer, | 925 target->draw(quadGP, mesh); |
| 929 firstVertex, kQuadNumVertices, kIdxsPerQuad,
quadCount, | 926 firstVertex += quadCount * kQuadNumVertices; |
| 930 kQuadsNumInIdxBuffer); | |
| 931 target->draw(mesh); | |
| 932 firstVertex += quadCount * kQuadNumVertices; | |
| 933 } | |
| 934 } | 927 } |
| 935 | 928 |
| 936 if (conicCount > 0) { | 929 if (conicCount > 0) { |
| 937 target->initDraw(conicGP); | 930 GrMesh mesh; |
| 938 | 931 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIn
dexBuffer, |
| 939 { | 932 firstVertex, kQuadNumVertices, kIdxsPerQuad, coni
cCount, |
| 940 GrMesh mesh; | 933 kQuadsNumInIdxBuffer); |
| 941 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qua
dsIndexBuffer, | 934 target->draw(conicGP, mesh); |
| 942 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, | |
| 943 kQuadsNumInIdxBuffer); | |
| 944 target->draw(mesh); | |
| 945 } | |
| 946 } | 935 } |
| 947 } | 936 } |
| 948 } | 937 } |
| 949 | 938 |
| 950 static GrDrawBatch* create_hairline_batch(GrColor color, | 939 static GrDrawBatch* create_hairline_batch(GrColor color, |
| 951 const SkMatrix& viewMatrix, | 940 const SkMatrix& viewMatrix, |
| 952 const SkPath& path, | 941 const SkPath& path, |
| 953 const GrStrokeInfo& stroke, | 942 const GrStrokeInfo& stroke, |
| 954 const SkIRect& devClipBounds) { | 943 const SkIRect& devClipBounds) { |
| 955 SkScalar hairlineCoverage; | 944 SkScalar hairlineCoverage; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 GrColor color = GrRandomColor(random); | 978 GrColor color = GrRandomColor(random); |
| 990 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 979 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 991 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); | 980 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
| 992 SkPath path = GrTest::TestPath(random); | 981 SkPath path = GrTest::TestPath(random); |
| 993 SkIRect devClipBounds; | 982 SkIRect devClipBounds; |
| 994 devClipBounds.setEmpty(); | 983 devClipBounds.setEmpty(); |
| 995 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; | 984 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; |
| 996 } | 985 } |
| 997 | 986 |
| 998 #endif | 987 #endif |
| OLD | NEW |