| 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 "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 767 |
| 768 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 768 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 769 this->joinBounds(that->bounds()); | 769 this->joinBounds(that->bounds()); |
| 770 return true; | 770 return true; |
| 771 } | 771 } |
| 772 | 772 |
| 773 GrColor color() const { return fBatch.fColor; } | 773 GrColor color() const { return fBatch.fColor; } |
| 774 uint8_t coverage() const { return fBatch.fCoverage; } | 774 uint8_t coverage() const { return fBatch.fCoverage; } |
| 775 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 775 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 776 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 776 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 777 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 778 | 777 |
| 779 struct BatchTracker { | 778 struct BatchTracker { |
| 780 GrColor fColor; | 779 GrColor fColor; |
| 781 uint8_t fCoverage; | 780 uint8_t fCoverage; |
| 782 SkRect fDevBounds; | 781 SkRect fDevBounds; |
| 783 bool fUsesLocalCoords; | 782 bool fUsesLocalCoords; |
| 784 bool fColorIgnored; | 783 bool fColorIgnored; |
| 785 bool fCoverageIgnored; | 784 bool fCoverageIgnored; |
| 786 }; | 785 }; |
| 787 | 786 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 809 toSrc = &invert; | 808 toSrc = &invert; |
| 810 } | 809 } |
| 811 | 810 |
| 812 // Setup geometry processors for worst case | 811 // Setup geometry processors for worst case |
| 813 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | | 812 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 814 GrDefaultGeoProcFactory::kCoverage_GPType; | 813 GrDefaultGeoProcFactory::kCoverage_GPType; |
| 815 | 814 |
| 816 SkAutoTUnref<const GrGeometryProcessor> lineGP( | 815 SkAutoTUnref<const GrGeometryProcessor> lineGP( |
| 817 GrDefaultGeoProcFactory::Create(gpFlags, | 816 GrDefaultGeoProcFactory::Create(gpFlags, |
| 818 this->color(), | 817 this->color(), |
| 819 this->usesLocalCoords(), | |
| 820 this->coverageIgnored(), | |
| 821 *geometryProcessorViewM, | 818 *geometryProcessorViewM, |
| 822 *geometryProcessorLocalM, | 819 *geometryProcessorLocalM, |
| 823 this->coverage())); | 820 this->coverage())); |
| 824 | 821 |
| 825 SkAutoTUnref<const GrGeometryProcessor> quadGP( | 822 SkAutoTUnref<const GrGeometryProcessor> quadGP( |
| 826 GrQuadEffect::Create(this->color(), | 823 GrQuadEffect::Create(this->color(), |
| 827 *geometryProcessorViewM, | 824 *geometryProcessorViewM, |
| 828 kHairlineAA_GrProcessorEdgeType, | 825 kHairlineAA_GrProcessorEdgeType, |
| 829 batchTarget->caps(), | 826 batchTarget->caps(), |
| 830 *geometryProcessorLocalM, | 827 *geometryProcessorLocalM, |
| 831 this->usesLocalCoords(), | |
| 832 this->coverage())); | 828 this->coverage())); |
| 833 | 829 |
| 834 SkAutoTUnref<const GrGeometryProcessor> conicGP( | 830 SkAutoTUnref<const GrGeometryProcessor> conicGP( |
| 835 GrConicEffect::Create(this->color(), | 831 GrConicEffect::Create(this->color(), |
| 836 *geometryProcessorViewM, | 832 *geometryProcessorViewM, |
| 837 kHairlineAA_GrProcessorEdgeType, | 833 kHairlineAA_GrProcessorEdgeType, |
| 838 batchTarget->caps(), | 834 batchTarget->caps(), |
| 839 *geometryProcessorLocalM, | 835 *geometryProcessorLocalM, |
| 840 this->usesLocalCoords(), | |
| 841 this->coverage())); | 836 this->coverage())); |
| 842 | 837 |
| 843 // This is hand inlined for maximum performance. | 838 // This is hand inlined for maximum performance. |
| 844 PREALLOC_PTARRAY(128) lines; | 839 PREALLOC_PTARRAY(128) lines; |
| 845 PREALLOC_PTARRAY(128) quads; | 840 PREALLOC_PTARRAY(128) quads; |
| 846 PREALLOC_PTARRAY(128) conics; | 841 PREALLOC_PTARRAY(128) conics; |
| 847 IntArray qSubdivs; | 842 IntArray qSubdivs; |
| 848 FloatArray cWeights; | 843 FloatArray cWeights; |
| 849 int quadCount = 0; | 844 int quadCount = 0; |
| 850 | 845 |
| 851 int instanceCount = fGeoData.count(); | 846 int instanceCount = fGeoData.count(); |
| 852 for (int i = 0; i < instanceCount; i++) { | 847 for (int i = 0; i < instanceCount; i++) { |
| 853 const Geometry& args = fGeoData[i]; | 848 const Geometry& args = fGeoData[i]; |
| 854 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, | 849 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f
DevClipBounds, |
| 855 &lines, &quads, &conics, &qSubdivs,
&cWeights); | 850 &lines, &quads, &conics, &qSubdivs,
&cWeights); |
| 856 } | 851 } |
| 857 | 852 |
| 858 int lineCount = lines.count() / 2; | 853 int lineCount = lines.count() / 2; |
| 859 int conicCount = conics.count() / 3; | 854 int conicCount = conics.count() / 3; |
| 860 | 855 |
| 861 // do lines first | 856 // do lines first |
| 862 if (lineCount) { | 857 if (lineCount) { |
| 863 SkAutoTUnref<const GrIndexBuffer> linesIndexBuffer( | 858 SkAutoTUnref<const GrIndexBuffer> linesIndexBuffer( |
| 864 ref_lines_index_buffer(batchTarget->resourceProvider())); | 859 ref_lines_index_buffer(batchTarget->resourceProvider())); |
| 865 batchTarget->initDraw(lineGP, pipeline); | 860 batchTarget->initDraw(lineGP, pipeline); |
| 866 | 861 |
| 862 // TODO remove this when batch is everywhere |
| 863 GrPipelineInfo init; |
| 864 init.fColorIgnored = fBatch.fColorIgnored; |
| 865 init.fOverrideColor = GrColor_ILLEGAL; |
| 866 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 867 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 868 lineGP->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 869 |
| 867 const GrVertexBuffer* vertexBuffer; | 870 const GrVertexBuffer* vertexBuffer; |
| 868 int firstVertex; | 871 int firstVertex; |
| 869 | 872 |
| 870 size_t vertexStride = lineGP->getVertexStride(); | 873 size_t vertexStride = lineGP->getVertexStride(); |
| 871 int vertexCount = kLineSegNumVertices * lineCount; | 874 int vertexCount = kLineSegNumVertices * lineCount; |
| 872 LineVertex* verts = reinterpret_cast<LineVertex*>( | 875 LineVertex* verts = reinterpret_cast<LineVertex*>( |
| 873 batchTarget->makeVertSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex)); | 876 batchTarget->makeVertSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex)); |
| 874 | 877 |
| 875 if (!verts|| !linesIndexBuffer) { | 878 if (!verts|| !linesIndexBuffer) { |
| 876 SkDebugf("Could not allocate vertices\n"); | 879 SkDebugf("Could not allocate vertices\n"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 } | 922 } |
| 920 | 923 |
| 921 // Start Conics | 924 // Start Conics |
| 922 for (int i = 0; i < conicCount; ++i) { | 925 for (int i = 0; i < conicCount; ++i) { |
| 923 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts); | 926 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts); |
| 924 } | 927 } |
| 925 | 928 |
| 926 if (quadCount > 0) { | 929 if (quadCount > 0) { |
| 927 batchTarget->initDraw(quadGP, pipeline); | 930 batchTarget->initDraw(quadGP, pipeline); |
| 928 | 931 |
| 932 // TODO remove this when batch is everywhere |
| 933 GrPipelineInfo init; |
| 934 init.fColorIgnored = fBatch.fColorIgnored; |
| 935 init.fOverrideColor = GrColor_ILLEGAL; |
| 936 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 937 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 938 quadGP->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 939 |
| 929 { | 940 { |
| 930 GrVertices verts; | 941 GrVertices verts; |
| 931 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, | 942 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, |
| 932 firstVertex, kQuadNumVertices, kIdxsPerQuad,
quadCount, | 943 firstVertex, kQuadNumVertices, kIdxsPerQuad,
quadCount, |
| 933 kQuadsNumInIdxBuffer); | 944 kQuadsNumInIdxBuffer); |
| 934 batchTarget->draw(verts); | 945 batchTarget->draw(verts); |
| 935 firstVertex += quadCount * kQuadNumVertices; | 946 firstVertex += quadCount * kQuadNumVertices; |
| 936 } | 947 } |
| 937 } | 948 } |
| 938 | 949 |
| 939 if (conicCount > 0) { | 950 if (conicCount > 0) { |
| 940 batchTarget->initDraw(conicGP, pipeline); | 951 batchTarget->initDraw(conicGP, pipeline); |
| 941 | 952 |
| 953 // TODO remove this when batch is everywhere |
| 954 GrPipelineInfo init; |
| 955 init.fColorIgnored = fBatch.fColorIgnored; |
| 956 init.fOverrideColor = GrColor_ILLEGAL; |
| 957 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 958 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 959 conicGP->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 960 |
| 942 { | 961 { |
| 943 GrVertices verts; | 962 GrVertices verts; |
| 944 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, | 963 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, |
| 945 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, | 964 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, |
| 946 kQuadsNumInIdxBuffer); | 965 kQuadsNumInIdxBuffer); |
| 947 batchTarget->draw(verts); | 966 batchTarget->draw(verts); |
| 948 } | 967 } |
| 949 } | 968 } |
| 950 } | 969 } |
| 951 } | 970 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 GrColor color = GrRandomColor(random); | 1016 GrColor color = GrRandomColor(random); |
| 998 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 1017 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 999 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); | 1018 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
| 1000 SkPath path = GrTest::TestPath(random); | 1019 SkPath path = GrTest::TestPath(random); |
| 1001 SkIRect devClipBounds; | 1020 SkIRect devClipBounds; |
| 1002 devClipBounds.setEmpty(); | 1021 devClipBounds.setEmpty(); |
| 1003 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; | 1022 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; |
| 1004 } | 1023 } |
| 1005 | 1024 |
| 1006 #endif | 1025 #endif |
| OLD | NEW |