Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/gpu/batches/GrAAHairLinePathRenderer.cpp

Issue 1831133004: Revert of Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrBuffer.h"
13 #include "GrCaps.h" 12 #include "GrCaps.h"
14 #include "GrContext.h" 13 #include "GrContext.h"
15 #include "GrDefaultGeoProcFactory.h" 14 #include "GrDefaultGeoProcFactory.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 "SkGeometry.h" 21 #include "SkGeometry.h"
21 #include "SkStroke.h" 22 #include "SkStroke.h"
22 #include "SkTemplates.h" 23 #include "SkTemplates.h"
23 24
24 #include "batches/GrVertexBatch.h" 25 #include "batches/GrVertexBatch.h"
25 26
26 #include "effects/GrBezierEffect.h" 27 #include "effects/GrBezierEffect.h"
27 28
28 #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true> 29 #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true>
29 30
(...skipping 27 matching lines...) Expand all
57 0, 1, 2, 58 0, 1, 2,
58 2, 4, 3, 59 2, 4, 3,
59 1, 4, 2 60 1, 4, 2
60 }; 61 };
61 62
62 static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern); 63 static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern);
63 static const int kQuadNumVertices = 5; 64 static const int kQuadNumVertices = 5;
64 static const int kQuadsNumInIdxBuffer = 256; 65 static const int kQuadsNumInIdxBuffer = 256;
65 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); 66 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
66 67
67 static const GrBuffer* ref_quads_index_buffer(GrResourceProvider* resourceProvid er) { 68 static const GrIndexBuffer* ref_quads_index_buffer(GrResourceProvider* resourceP rovider) {
68 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); 69 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
69 return resourceProvider->findOrCreateInstancedIndexBuffer( 70 return resourceProvider->findOrCreateInstancedIndexBuffer(
70 kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices , 71 kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices ,
71 gQuadsIndexBufferKey); 72 gQuadsIndexBufferKey);
72 } 73 }
73 74
74 75
75 // Each line segment is rendered as two quads and two triangles. 76 // Each line segment is rendered as two quads and two triangles.
76 // p0 and p1 have alpha = 1 while all other points have alpha = 0. 77 // p0 and p1 have alpha = 1 while all other points have alpha = 0.
77 // The four external points are offset 1 pixel perpendicular to the 78 // The four external points are offset 1 pixel perpendicular to the
(...skipping 13 matching lines...) Expand all
91 0, 2, 4, 92 0, 2, 4,
92 1, 5, 3 93 1, 5, 3
93 }; 94 };
94 95
95 static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern); 96 static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern);
96 static const int kLineSegNumVertices = 6; 97 static const int kLineSegNumVertices = 6;
97 static const int kLineSegsNumInIdxBuffer = 256; 98 static const int kLineSegsNumInIdxBuffer = 256;
98 99
99 GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); 100 GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
100 101
101 static const GrBuffer* ref_lines_index_buffer(GrResourceProvider* resourceProvid er) { 102 static const GrIndexBuffer* ref_lines_index_buffer(GrResourceProvider* resourceP rovider) {
102 GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); 103 GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
103 return resourceProvider->findOrCreateInstancedIndexBuffer( 104 return resourceProvider->findOrCreateInstancedIndexBuffer(
104 kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineS egNumVertices, 105 kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineS egNumVertices,
105 gLinesIndexBufferKey); 106 gLinesIndexBufferKey);
106 } 107 }
107 108
108 // Takes 178th time of logf on Z600 / VC2010 109 // Takes 178th time of logf on Z600 / VC2010
109 static int get_float_exp(float x) { 110 static int get_float_exp(float x) {
110 GR_STATIC_ASSERT(sizeof(int) == sizeof(float)); 111 GR_STATIC_ASSERT(sizeof(int) == sizeof(float));
111 #ifdef SK_DEBUG 112 #ifdef SK_DEBUG
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 const Geometry& args = fGeoData[i]; 851 const Geometry& args = fGeoData[i];
851 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f DevClipBounds, 852 quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.f DevClipBounds,
852 &lines, &quads, &conics, &qSubdivs, &cWeights); 853 &lines, &quads, &conics, &qSubdivs, &cWeights);
853 } 854 }
854 855
855 int lineCount = lines.count() / 2; 856 int lineCount = lines.count() / 2;
856 int conicCount = conics.count() / 3; 857 int conicCount = conics.count() / 3;
857 858
858 // do lines first 859 // do lines first
859 if (lineCount) { 860 if (lineCount) {
860 SkAutoTUnref<const GrBuffer> linesIndexBuffer( 861 SkAutoTUnref<const GrIndexBuffer> linesIndexBuffer(
861 ref_lines_index_buffer(target->resourceProvider())); 862 ref_lines_index_buffer(target->resourceProvider()));
862 target->initDraw(lineGP); 863 target->initDraw(lineGP);
863 864
864 const GrBuffer* vertexBuffer; 865 const GrVertexBuffer* vertexBuffer;
865 int firstVertex; 866 int firstVertex;
866 867
867 size_t vertexStride = lineGP->getVertexStride(); 868 size_t vertexStride = lineGP->getVertexStride();
868 int vertexCount = kLineSegNumVertices * lineCount; 869 int vertexCount = kLineSegNumVertices * lineCount;
869 LineVertex* verts = reinterpret_cast<LineVertex*>( 870 LineVertex* verts = reinterpret_cast<LineVertex*>(
870 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f irstVertex)); 871 target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &f irstVertex));
871 872
872 if (!verts|| !linesIndexBuffer) { 873 if (!verts|| !linesIndexBuffer) {
873 SkDebugf("Could not allocate vertices\n"); 874 SkDebugf("Could not allocate vertices\n");
874 return; 875 return;
875 } 876 }
876 877
877 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); 878 SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex));
878 879
879 for (int i = 0; i < lineCount; ++i) { 880 for (int i = 0; i < lineCount; ++i) {
880 add_line(&lines[2*i], toSrc, this->coverage(), &verts); 881 add_line(&lines[2*i], toSrc, this->coverage(), &verts);
881 } 882 }
882 883
883 { 884 {
884 GrMesh mesh; 885 GrMesh mesh;
885 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIn dexBuffer, 886 mesh.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIn dexBuffer,
886 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg , lineCount, 887 firstVertex, kLineSegNumVertices, kIdxsPerLineSeg , lineCount,
887 kLineSegsNumInIdxBuffer); 888 kLineSegsNumInIdxBuffer);
888 target->draw(mesh); 889 target->draw(mesh);
889 } 890 }
890 } 891 }
891 892
892 if (quadCount || conicCount) { 893 if (quadCount || conicCount) {
893 const GrBuffer* vertexBuffer; 894 const GrVertexBuffer* vertexBuffer;
894 int firstVertex; 895 int firstVertex;
895 896
896 SkAutoTUnref<const GrBuffer> quadsIndexBuffer( 897 SkAutoTUnref<const GrIndexBuffer> quadsIndexBuffer(
897 ref_quads_index_buffer(target->resourceProvider())); 898 ref_quads_index_buffer(target->resourceProvider()));
898 899
899 size_t vertexStride = sizeof(BezierVertex); 900 size_t vertexStride = sizeof(BezierVertex);
900 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni cCount; 901 int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * coni cCount;
901 void *vertices = target->makeVertexSpace(vertexStride, vertexCount, 902 void *vertices = target->makeVertexSpace(vertexStride, vertexCount,
902 &vertexBuffer, &firstVertex); 903 &vertexBuffer, &firstVertex);
903 904
904 if (!vertices || !quadsIndexBuffer) { 905 if (!vertices || !quadsIndexBuffer) {
905 SkDebugf("Could not allocate vertices\n"); 906 SkDebugf("Could not allocate vertices\n");
906 return; 907 return;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 GrColor color = GrRandomColor(random); 990 GrColor color = GrRandomColor(random);
990 SkMatrix viewMatrix = GrTest::TestMatrix(random); 991 SkMatrix viewMatrix = GrTest::TestMatrix(random);
991 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); 992 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle);
992 SkPath path = GrTest::TestPath(random); 993 SkPath path = GrTest::TestPath(random);
993 SkIRect devClipBounds; 994 SkIRect devClipBounds;
994 devClipBounds.setEmpty(); 995 devClipBounds.setEmpty();
995 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds) ; 996 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds) ;
996 } 997 }
997 998
998 #endif 999 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAAFillRectBatch.cpp ('k') | src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698