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

Side by Side Diff: src/gpu/GrInOrderDrawBuffer.cpp

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase and small cleanup Created 6 years 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 "GrInOrderDrawBuffer.h" 8 #include "GrInOrderDrawBuffer.h"
9 9
10 #include "GrBufferAllocPool.h" 10 #include "GrBufferAllocPool.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 The color param is used to determine whether the opaque hint can be set on t he draw state. 82 The color param is used to determine whether the opaque hint can be set on t he draw state.
83 The caller must populate the vertex colors itself. 83 The caller must populate the vertex colors itself.
84 84
85 The vertex attrib order is always pos, color, [local coords]. 85 The vertex attrib order is always pos, color, [local coords].
86 */ 86 */
87 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G rColor color) { 87 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G rColor color) {
88 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | 88 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
89 GrDefaultGeoProcFactory::kColor_GPType; 89 GrDefaultGeoProcFactory::kColor_GPType;
90 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; 90 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0;
91 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs (drawState, 91 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unr ef();
92 flags))->unref();
93 if (0xFF == GrColorUnpackA(color)) { 92 if (0xFF == GrColorUnpackA(color)) {
94 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); 93 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
95 } 94 }
96 } 95 }
97 96
98 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin gs) { 97 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin gs) {
99 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa ce; 98 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa ce;
100 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); 99 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace);
101 if (isWinding) { 100 if (isWinding) {
102 // Double check that it is in fact winding. 101 // Double check that it is in fact winding.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 133
135 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, 134 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds,
136 const SkRect& rect, 135 const SkRect& rect,
137 const SkRect* localRect, 136 const SkRect* localRect,
138 const SkMatrix* localMatrix) { 137 const SkMatrix* localMatrix) {
139 GrDrawState::AutoRestoreEffects are(ds); 138 GrDrawState::AutoRestoreEffects are(ds);
140 139
141 GrColor color = ds->getColor(); 140 GrColor color = ds->getColor();
142 set_vertex_attributes(ds, SkToBool(localRect), color); 141 set_vertex_attributes(ds, SkToBool(localRect), color);
143 142
144 AutoReleaseGeometry geo(this, 4, ds->getVertexStride(), 0); 143 size_t vstride = ds->getGeometryProcessor()->getVertexStride();
144 AutoReleaseGeometry geo(this, 4, vstride, 0);
145 if (!geo.succeeded()) { 145 if (!geo.succeeded()) {
146 SkDebugf("Failed to get space for vertices!\n"); 146 SkDebugf("Failed to get space for vertices!\n");
147 return; 147 return;
148 } 148 }
149 149
150 // Go to device coords to allow batching across matrix changes 150 // Go to device coords to allow batching across matrix changes
151 SkMatrix matrix = ds->getViewMatrix(); 151 SkMatrix matrix = ds->getViewMatrix();
152 152
153 // When the caller has provided an explicit source rect for a stage then we don't want to 153 // When the caller has provided an explicit source rect for a stage then we don't want to
154 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from 154 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from
155 // the vertex positions then we have to account for the view matrix change. 155 // the vertex positions then we have to account for the view matrix change.
156 GrDrawState::AutoViewMatrixRestore avmr; 156 GrDrawState::AutoViewMatrixRestore avmr;
157 if (!avmr.setIdentity(ds)) { 157 if (!avmr.setIdentity(ds)) {
158 return; 158 return;
159 } 159 }
160 160
161 size_t vstride = ds->getVertexStride();
162
163 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vstride); 161 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vstride);
164 matrix.mapPointsWithStride(geo.positions(), vstride, 4); 162 matrix.mapPointsWithStride(geo.positions(), vstride, 4);
165 163
166 SkRect devBounds; 164 SkRect devBounds;
167 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid 165 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid
168 // unnecessary clipping in our onDraw(). 166 // unnecessary clipping in our onDraw().
169 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds); 167 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds);
170 168
171 if (localRect) { 169 if (localRect) {
172 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); 170 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 226 }
229 227
230 SkASSERT(poolState.fPoolStartVertex == draw->fInfo.startVertex() + draw->fIn fo.vertexCount()); 228 SkASSERT(poolState.fPoolStartVertex == draw->fInfo.startVertex() + draw->fIn fo.vertexCount());
231 229
232 // how many instances can be concat'ed onto draw given the size of the index buffer 230 // how many instances can be concat'ed onto draw given the size of the index buffer
233 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); 231 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance();
234 instancesToConcat -= draw->fInfo.instanceCount(); 232 instancesToConcat -= draw->fInfo.instanceCount();
235 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); 233 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount());
236 234
237 // update the amount of reserved vertex data actually referenced in draws 235 // update the amount of reserved vertex data actually referenced in draws
238 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * ds.get VertexStride(); 236 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
237 ds.getGeometryProcessor()->getVertexStride();
239 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vert exBytes); 238 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vert exBytes);
240 239
241 draw->fInfo.adjustInstanceCount(instancesToConcat); 240 draw->fInfo.adjustInstanceCount(instancesToConcat);
242 241
243 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added 242 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added
244 if (this->getActiveTraceMarkers().count() > 0) { 243 if (this->getActiveTraceMarkers().count() > 0) {
245 if (cmd_has_trace_marker(draw->fType)) { 244 if (cmd_has_trace_marker(draw->fType)) {
246 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); 245 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers());
247 } else { 246 } else {
248 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); 247 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers());
(...skipping 27 matching lines...) Expand all
276 return; 275 return;
277 } 276 }
278 } else { 277 } else {
279 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); 278 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
280 } 279 }
281 this->recordTraceMarkersIfNecessary(); 280 this->recordTraceMarkersIfNecessary();
282 281
283 // Adjust the starting vertex and index when we are using reserved or array sources to 282 // Adjust the starting vertex and index when we are using reserved or array sources to
284 // compensate for the fact that the data was inserted into a larger vb/ib ow ned by the pool. 283 // compensate for the fact that the data was inserted into a larger vb/ib ow ned by the pool.
285 if (kBuffer_GeometrySrcType != this->getGeomSrc().fVertexSrc) { 284 if (kBuffer_GeometrySrcType != this->getGeomSrc().fVertexSrc) {
286 size_t bytes = (info.vertexCount() + info.startVertex()) * ds.getVertexS tride(); 285 size_t bytes = (info.vertexCount() + info.startVertex()) *
286 ds.getGeometryProcessor()->getVertexStride();
287 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, bytes); 287 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, bytes);
288 draw->fInfo.adjustStartVertex(poolState.fPoolStartVertex); 288 draw->fInfo.adjustStartVertex(poolState.fPoolStartVertex);
289 } 289 }
290 290
291 if (info.isIndexed() && kBuffer_GeometrySrcType != this->getGeomSrc().fIndex Src) { 291 if (info.isIndexed() && kBuffer_GeometrySrcType != this->getGeomSrc().fIndex Src) {
292 size_t bytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t ); 292 size_t bytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t );
293 poolState.fUsedPoolIndexBytes = SkTMax(poolState.fUsedPoolIndexBytes, by tes); 293 poolState.fUsedPoolIndexBytes = SkTMax(poolState.fUsedPoolIndexBytes, by tes);
294 draw->fInfo.adjustStartIndex(poolState.fPoolStartIndex); 294 draw->fInfo.adjustStartIndex(poolState.fPoolStartIndex);
295 } 295 }
296 } 296 }
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 753
754 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { 754 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() {
755 SkASSERT(!fCmdBuffer.empty()); 755 SkASSERT(!fCmdBuffer.empty());
756 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); 756 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType));
757 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 757 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
758 if (activeTraceMarkers.count() > 0) { 758 if (activeTraceMarkers.count() > 0) {
759 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); 759 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType);
760 fGpuCmdMarkers.push_back(activeTraceMarkers); 760 fGpuCmdMarkers.push_back(activeTraceMarkers);
761 } 761 }
762 } 762 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698