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

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

Issue 2104383003: Hide GrDrawVerticesBatch::Geometry and rename to Mesh (Closed) Base URL: https://chromium.googlesource.com/skia.git@moremore
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/gpu/batches/GrDrawVerticesBatch.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "GrDrawVerticesBatch.h" 8 #include "GrDrawVerticesBatch.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 13 matching lines...) Expand all
24 LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type : 24 LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type :
25 LocalCoords::kUsePosition_Type); 25 LocalCoords::kUsePosition_Type);
26 *colorOffset = sizeof(SkPoint); 26 *colorOffset = sizeof(SkPoint);
27 if (hasLocalCoords) { 27 if (hasLocalCoords) {
28 *texOffset = sizeof(SkPoint) + sizeof(GrColor); 28 *texOffset = sizeof(SkPoint) + sizeof(GrColor);
29 } 29 }
30 return GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type), 30 return GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type),
31 coverage, localCoords, viewMatrix); 31 coverage, localCoords, viewMatrix);
32 } 32 }
33 33
34 GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy pe primitiveType, 34 GrDrawVerticesBatch::GrDrawVerticesBatch(GrColor color, GrPrimitiveType primitiv eType,
35 const SkMatrix& viewMatrix, 35 const SkMatrix& viewMatrix,
36 const SkPoint* positions, int vertexCou nt, 36 const SkPoint* positions, int vertexCou nt,
37 const uint16_t* indices, int indexCount , 37 const uint16_t* indices, int indexCount ,
38 const GrColor* colors, const SkPoint* l ocalCoords, 38 const GrColor* colors, const SkPoint* l ocalCoords,
39 const SkRect& bounds) 39 const SkRect& bounds)
40 : INHERITED(ClassID()) { 40 : INHERITED(ClassID()) {
41 SkASSERT(positions); 41 SkASSERT(positions);
42 42
43 fViewMatrix = viewMatrix; 43 fViewMatrix = viewMatrix;
44 Geometry& installedGeo = fGeoData.push_back(geometry); 44 Mesh& mesh = fMeshes.push_back();
45 mesh.fColor = color;
45 46
46 installedGeo.fPositions.append(vertexCount, positions); 47 mesh.fPositions.append(vertexCount, positions);
47 if (indices) { 48 if (indices) {
48 installedGeo.fIndices.append(indexCount, indices); 49 mesh.fIndices.append(indexCount, indices);
49 } 50 }
50 51
51 if (colors) { 52 if (colors) {
52 fVariableColor = true; 53 fVariableColor = true;
53 installedGeo.fColors.append(vertexCount, colors); 54 mesh.fColors.append(vertexCount, colors);
54 } else { 55 } else {
55 fVariableColor = false; 56 fVariableColor = false;
56 } 57 }
57 58
58 if (localCoords) { 59 if (localCoords) {
59 installedGeo.fLocalCoords.append(vertexCount, localCoords); 60 mesh.fLocalCoords.append(vertexCount, localCoords);
60 } 61 }
61 fVertexCount = vertexCount; 62 fVertexCount = vertexCount;
62 fIndexCount = indexCount; 63 fIndexCount = indexCount;
63 fPrimitiveType = primitiveType; 64 fPrimitiveType = primitiveType;
64 65
65 this->setBounds(bounds); 66 this->setBounds(bounds);
66 } 67 }
67 68
68 void GrDrawVerticesBatch::computePipelineOptimizations(GrInitInvariantOutput* co lor, 69 void GrDrawVerticesBatch::computePipelineOptimizations(GrInitInvariantOutput* co lor,
69 GrInitInvariantOutput* co verage, 70 GrInitInvariantOutput* co verage,
70 GrBatchToXPOverrides* ove rrides) const { 71 GrBatchToXPOverrides* ove rrides) const {
71 // When this is called on a batch, there is only one geometry bundle 72 // When this is called on a batch, there is only one mesh
72 if (fVariableColor) { 73 if (fVariableColor) {
73 color->setUnknownFourComponents(); 74 color->setUnknownFourComponents();
74 } else { 75 } else {
75 color->setKnownFourComponents(fGeoData[0].fColor); 76 color->setKnownFourComponents(fMeshes[0].fColor);
76 } 77 }
77 coverage->setKnownSingleComponent(0xff); 78 coverage->setKnownSingleComponent(0xff);
78 } 79 }
79 80
80 void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& override s) { 81 void GrDrawVerticesBatch::initBatchTracker(const GrXPOverridesForBatch& override s) {
81 SkASSERT(fGeoData.count() == 1); 82 SkASSERT(fMeshes.count() == 1);
82 GrColor overrideColor; 83 GrColor overrideColor;
83 if (overrides.getOverrideColorIfSet(&overrideColor)) { 84 if (overrides.getOverrideColorIfSet(&overrideColor)) {
84 fGeoData[0].fColor = overrideColor; 85 fMeshes[0].fColor = overrideColor;
85 fGeoData[0].fColors.reset(); 86 fMeshes[0].fColors.reset();
86 fVariableColor = false; 87 fVariableColor = false;
87 } 88 }
88 fCoverageIgnored = !overrides.readsCoverage(); 89 fCoverageIgnored = !overrides.readsCoverage();
89 if (!overrides.readsLocalCoords()) { 90 if (!overrides.readsLocalCoords()) {
90 fGeoData[0].fLocalCoords.reset(); 91 fMeshes[0].fLocalCoords.reset();
91 } 92 }
92 } 93 }
93 94
94 void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { 95 void GrDrawVerticesBatch::onPrepareDraws(Target* target) const {
95 bool hasLocalCoords = !fGeoData[0].fLocalCoords.isEmpty(); 96 bool hasLocalCoords = !fMeshes[0].fLocalCoords.isEmpty();
96 int colorOffset = -1, texOffset = -1; 97 int colorOffset = -1, texOffset = -1;
97 sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOf fset, &texOffset, 98 sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOf fset, &texOffset,
98 fViewMatrix, fCoverageIg nored)); 99 fViewMatrix, fCoverageIg nored));
99 size_t vertexStride = gp->getVertexStride(); 100 size_t vertexStride = gp->getVertexStride();
100 101
101 SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0) 102 SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint) : 0)
102 + sizeof(GrColor)); 103 + sizeof(GrColor));
103 104
104 int instanceCount = fGeoData.count(); 105 int instanceCount = fMeshes.count();
105 106
106 const GrBuffer* vertexBuffer; 107 const GrBuffer* vertexBuffer;
107 int firstVertex; 108 int firstVertex;
108 109
109 void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuf fer, &firstVertex); 110 void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuf fer, &firstVertex);
110 111
111 if (!verts) { 112 if (!verts) {
112 SkDebugf("Could not allocate vertices\n"); 113 SkDebugf("Could not allocate vertices\n");
113 return; 114 return;
114 } 115 }
115 116
116 const GrBuffer* indexBuffer = nullptr; 117 const GrBuffer* indexBuffer = nullptr;
117 int firstIndex = 0; 118 int firstIndex = 0;
118 119
119 uint16_t* indices = nullptr; 120 uint16_t* indices = nullptr;
120 if (!fGeoData[0].fIndices.isEmpty()) { 121 if (!fMeshes[0].fIndices.isEmpty()) {
121 indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex) ; 122 indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex) ;
122 123
123 if (!indices) { 124 if (!indices) {
124 SkDebugf("Could not allocate indices\n"); 125 SkDebugf("Could not allocate indices\n");
125 return; 126 return;
126 } 127 }
127 } 128 }
128 129
129 int indexOffset = 0; 130 int indexOffset = 0;
130 int vertexOffset = 0; 131 int vertexOffset = 0;
131 for (int i = 0; i < instanceCount; i++) { 132 for (int i = 0; i < instanceCount; i++) {
132 const Geometry& args = fGeoData[i]; 133 const Mesh& mesh = fMeshes[i];
133 134
134 // TODO we can actually cache this interleaved and then just memcopy 135 // TODO we can actually cache this interleaved and then just memcopy
135 if (indices) { 136 if (indices) {
136 for (int j = 0; j < args.fIndices.count(); ++j, ++indexOffset) { 137 for (int j = 0; j < mesh.fIndices.count(); ++j, ++indexOffset) {
137 *(indices + indexOffset) = args.fIndices[j] + vertexOffset; 138 *(indices + indexOffset) = mesh.fIndices[j] + vertexOffset;
138 } 139 }
139 } 140 }
140 141
141 for (int j = 0; j < args.fPositions.count(); ++j) { 142 for (int j = 0; j < mesh.fPositions.count(); ++j) {
142 *((SkPoint*)verts) = args.fPositions[j]; 143 *((SkPoint*)verts) = mesh.fPositions[j];
143 if (args.fColors.isEmpty()) { 144 if (mesh.fColors.isEmpty()) {
144 *(GrColor*)((intptr_t)verts + colorOffset) = args.fColor; 145 *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColor;
145 } else { 146 } else {
146 *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j]; 147 *(GrColor*)((intptr_t)verts + colorOffset) = mesh.fColors[j];
147 } 148 }
148 if (hasLocalCoords) { 149 if (hasLocalCoords) {
149 *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords[j]; 150 *(SkPoint*)((intptr_t)verts + texOffset) = mesh.fLocalCoords[j];
150 } 151 }
151 verts = (void*)((intptr_t)verts + vertexStride); 152 verts = (void*)((intptr_t)verts + vertexStride);
152 vertexOffset++; 153 vertexOffset++;
153 } 154 }
154 } 155 }
155 156
156 GrMesh mesh; 157 GrMesh mesh;
157 if (indices) { 158 if (indices) {
158 mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, first Vertex, 159 mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, first Vertex,
159 firstIndex, fVertexCount, fIndexCount); 160 firstIndex, fVertexCount, fIndexCount);
(...skipping 14 matching lines...) Expand all
174 175
175 if (!this->batchablePrimitiveType() || this->primitiveType() != that->primit iveType()) { 176 if (!this->batchablePrimitiveType() || this->primitiveType() != that->primit iveType()) {
176 return false; 177 return false;
177 } 178 }
178 179
179 // We currently use a uniform viewmatrix for this batch 180 // We currently use a uniform viewmatrix for this batch
180 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { 181 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) {
181 return false; 182 return false;
182 } 183 }
183 184
184 if (fGeoData[0].fIndices.isEmpty() != that->fGeoData[0].fIndices.isEmpty()) { 185 if (fMeshes[0].fIndices.isEmpty() != that->fMeshes[0].fIndices.isEmpty()) {
185 return false; 186 return false;
186 } 187 }
187 188
188 if (fGeoData[0].fLocalCoords.isEmpty() != that->fGeoData[0].fLocalCoords.isE mpty()) { 189 if (fMeshes[0].fLocalCoords.isEmpty() != that->fMeshes[0].fLocalCoords.isEmp ty()) {
189 return false; 190 return false;
190 } 191 }
191 192
192 if (!fVariableColor) { 193 if (!fVariableColor) {
193 if (that->fVariableColor || that->fGeoData[0].fColor != fGeoData[0].fCol or) { 194 if (that->fVariableColor || that->fMeshes[0].fColor != fMeshes[0].fColor ) {
194 fVariableColor = true; 195 fVariableColor = true;
195 } 196 }
196 } 197 }
197 198
198 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); 199 fMeshes.push_back_n(that->fMeshes.count(), that->fMeshes.begin());
199 fVertexCount += that->fVertexCount; 200 fVertexCount += that->fVertexCount;
200 fIndexCount += that->fIndexCount; 201 fIndexCount += that->fIndexCount;
201 202
202 this->joinBounds(that->bounds()); 203 this->joinBounds(that->bounds());
203 return true; 204 return true;
204 } 205 }
205 206
206 //////////////////////////////////////////////////////////////////////////////// /////////////////// 207 //////////////////////////////////////////////////////////////////////////////// ///////////////////
207 208
208 #ifdef GR_TEST_UTILS 209 #ifdef GR_TEST_UTILS
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 &indices, hasIndices); 304 &indices, hasIndices);
304 } 305 }
305 306
306 SkMatrix viewMatrix = GrTest::TestMatrix(random); 307 SkMatrix viewMatrix = GrTest::TestMatrix(random);
307 SkRect bounds; 308 SkRect bounds;
308 SkDEBUGCODE(bool result = ) bounds.setBoundsCheck(positions.begin(), vertexC ount); 309 SkDEBUGCODE(bool result = ) bounds.setBoundsCheck(positions.begin(), vertexC ount);
309 SkASSERT(result); 310 SkASSERT(result);
310 311
311 viewMatrix.mapRect(&bounds); 312 viewMatrix.mapRect(&bounds);
312 313
313 GrDrawVerticesBatch::Geometry geometry; 314 GrColor color = GrRandomColor(random);
314 geometry.fColor = GrRandomColor(random); 315 return new GrDrawVerticesBatch(color, type, viewMatrix, positions.begin(), v ertexCount,
315 return GrDrawVerticesBatch::Create(geometry, type, viewMatrix, 316 indices.begin(), hasIndices ? vertexCount : 0 ,
316 positions.begin(), vertexCount, 317 colors.begin(), texCoords.begin(), bounds);
317 indices.begin(), hasIndices ? vertexCount : 0,
318 colors.begin(),
319 texCoords.begin(),
320 bounds);
321 } 318 }
322 319
323 #endif 320 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrDrawVerticesBatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698