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

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

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