| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAAConvexPathRenderer.h" | 8 #include "GrAAConvexPathRenderer.h" |
| 9 | 9 |
| 10 #include "GrAAConvexTessellator.h" | 10 #include "GrAAConvexTessellator.h" |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 // Setup GrGeometryProcessor | 785 // Setup GrGeometryProcessor |
| 786 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, | 786 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, |
| 787 this->viewMatr
ix(), | 787 this->viewMatr
ix(), |
| 788 this->usesLoca
lCoords(), | 788 this->usesLoca
lCoords(), |
| 789 this->coverage
Ignored())); | 789 this->coverage
Ignored())); |
| 790 if (!gp) { | 790 if (!gp) { |
| 791 SkDebugf("Could not create GrGeometryProcessor\n"); | 791 SkDebugf("Could not create GrGeometryProcessor\n"); |
| 792 return; | 792 return; |
| 793 } | 793 } |
| 794 | 794 |
| 795 target->initDraw(gp); | |
| 796 | |
| 797 size_t vertexStride = gp->getVertexStride(); | 795 size_t vertexStride = gp->getVertexStride(); |
| 798 | 796 |
| 799 SkASSERT(canTweakAlphaForCoverage ? | 797 SkASSERT(canTweakAlphaForCoverage ? |
| 800 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 801 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 802 | 800 |
| 803 GrAAConvexTessellator tess; | 801 GrAAConvexTessellator tess; |
| 804 | 802 |
| 805 int instanceCount = fGeoData.count(); | 803 int instanceCount = fGeoData.count(); |
| 806 | 804 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 832 return; | 830 return; |
| 833 } | 831 } |
| 834 | 832 |
| 835 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak
AlphaForCoverage); | 833 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak
AlphaForCoverage); |
| 836 | 834 |
| 837 GrMesh mesh; | 835 GrMesh mesh; |
| 838 mesh.initIndexed(kTriangles_GrPrimitiveType, | 836 mesh.initIndexed(kTriangles_GrPrimitiveType, |
| 839 vertexBuffer, indexBuffer, | 837 vertexBuffer, indexBuffer, |
| 840 firstVertex, firstIndex, | 838 firstVertex, firstIndex, |
| 841 tess.numPts(), tess.numIndices()); | 839 tess.numPts(), tess.numIndices()); |
| 842 target->draw(mesh); | 840 target->draw(gp, mesh); |
| 843 } | 841 } |
| 844 } | 842 } |
| 845 | 843 |
| 846 void onPrepareDraws(Target* target) const override { | 844 void onPrepareDraws(Target* target) const override { |
| 847 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS | 845 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS |
| 848 if (this->linesOnly()) { | 846 if (this->linesOnly()) { |
| 849 this->prepareLinesOnlyDraws(target); | 847 this->prepareLinesOnlyDraws(target); |
| 850 return; | 848 return; |
| 851 } | 849 } |
| 852 #endif | 850 #endif |
| 853 | 851 |
| 854 int instanceCount = fGeoData.count(); | 852 int instanceCount = fGeoData.count(); |
| 855 | 853 |
| 856 SkMatrix invert; | 854 SkMatrix invert; |
| 857 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 855 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
| 858 SkDebugf("Could not invert viewmatrix\n"); | 856 SkDebugf("Could not invert viewmatrix\n"); |
| 859 return; | 857 return; |
| 860 } | 858 } |
| 861 | 859 |
| 862 // Setup GrGeometryProcessor | 860 // Setup GrGeometryProcessor |
| 863 SkAutoTUnref<GrGeometryProcessor> quadProcessor( | 861 SkAutoTUnref<GrGeometryProcessor> quadProcessor( |
| 864 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo
rds())); | 862 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo
rds())); |
| 865 | 863 |
| 866 target->initDraw(quadProcessor); | |
| 867 | |
| 868 // TODO generate all segments for all paths and use one vertex buffer | 864 // TODO generate all segments for all paths and use one vertex buffer |
| 869 for (int i = 0; i < instanceCount; i++) { | 865 for (int i = 0; i < instanceCount; i++) { |
| 870 const Geometry& args = fGeoData[i]; | 866 const Geometry& args = fGeoData[i]; |
| 871 | 867 |
| 872 // We use the fact that SkPath::transform path does subdivision base
d on | 868 // We use the fact that SkPath::transform path does subdivision base
d on |
| 873 // perspective. Otherwise, we apply the view matrix when copying to
the | 869 // perspective. Otherwise, we apply the view matrix when copying to
the |
| 874 // segment representation. | 870 // segment representation. |
| 875 const SkMatrix* viewMatrix = &args.fViewMatrix; | 871 const SkMatrix* viewMatrix = &args.fViewMatrix; |
| 876 | 872 |
| 877 // We avoid initializing the path unless we have to | 873 // We avoid initializing the path unless we have to |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 | 918 |
| 923 SkSTArray<kPreallocDrawCnt, Draw, true> draws; | 919 SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
| 924 create_vertices(segments, fanPt, &draws, verts, idxs); | 920 create_vertices(segments, fanPt, &draws, verts, idxs); |
| 925 | 921 |
| 926 GrMesh mesh; | 922 GrMesh mesh; |
| 927 | 923 |
| 928 for (int j = 0; j < draws.count(); ++j) { | 924 for (int j = 0; j < draws.count(); ++j) { |
| 929 const Draw& draw = draws[j]; | 925 const Draw& draw = draws[j]; |
| 930 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, index
Buffer, | 926 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, index
Buffer, |
| 931 firstVertex, firstIndex, draw.fVertexCnt, draw.
fIndexCnt); | 927 firstVertex, firstIndex, draw.fVertexCnt, draw.
fIndexCnt); |
| 932 target->draw(mesh); | 928 target->draw(quadProcessor, mesh); |
| 933 firstVertex += draw.fVertexCnt; | 929 firstVertex += draw.fVertexCnt; |
| 934 firstIndex += draw.fIndexCnt; | 930 firstIndex += draw.fIndexCnt; |
| 935 } | 931 } |
| 936 } | 932 } |
| 937 } | 933 } |
| 938 | 934 |
| 939 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 935 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 940 | 936 |
| 941 AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { | 937 AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { |
| 942 fGeoData.push_back(geometry); | 938 fGeoData.push_back(geometry); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { | 1020 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { |
| 1025 AAConvexPathBatch::Geometry geometry; | 1021 AAConvexPathBatch::Geometry geometry; |
| 1026 geometry.fColor = GrRandomColor(random); | 1022 geometry.fColor = GrRandomColor(random); |
| 1027 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 1023 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
| 1028 geometry.fPath = GrTest::TestPathConvex(random); | 1024 geometry.fPath = GrTest::TestPathConvex(random); |
| 1029 | 1025 |
| 1030 return AAConvexPathBatch::Create(geometry); | 1026 return AAConvexPathBatch::Create(geometry); |
| 1031 } | 1027 } |
| 1032 | 1028 |
| 1033 #endif | 1029 #endif |
| OLD | NEW |