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

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

Issue 791743003: Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: 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 "GrDefaultGeoProcFactory.h" 10 #include "GrDefaultGeoProcFactory.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we 55 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we
56 have explicit local coords and sometimes not. We *could* always provide expl icit local coords 56 have explicit local coords and sometimes not. We *could* always provide expl icit local coords
57 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 57 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
58 haven't seen a use case which frequently switches between local rect and no local rect draws. 58 haven't seen a use case which frequently switches between local rect and no local rect draws.
59 59
60 The color param is used to determine whether the opaque hint can be set on t he draw state. 60 The color param is used to determine whether the opaque hint can be set on t he draw state.
61 The caller must populate the vertex colors itself. 61 The caller must populate the vertex colors itself.
62 62
63 The vertex attrib order is always pos, color, [local coords]. 63 The vertex attrib order is always pos, color, [local coords].
64 */ 64 */
65 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G rColor color) { 65 static const GrGeometryProcessor* set_vertex_attributes(GrDrawState* drawState,
bsalomon 2014/12/10 15:27:00 create_rect_gp?
66 bool hasLocalCoords,
67 GrColor color) {
66 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | 68 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
67 GrDefaultGeoProcFactory::kColor_GPType; 69 GrDefaultGeoProcFactory::kColor_GPType;
68 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; 70 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0;
69 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags ))->unref(); 71 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(color, flags );
70 if (0xFF == GrColorUnpackA(color)) { 72 if (0xFF == GrColorUnpackA(color)) {
71 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); 73 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
bsalomon 2014/12/10 15:27:00 just a note: replacing hint would be a good candid
72 } 74 }
75 return gp;
73 } 76 }
74 77
75 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin gs) { 78 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin gs) {
76 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa ce; 79 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa ce;
77 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); 80 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace);
78 if (isWinding) { 81 if (isWinding) {
79 // Double check that it is in fact winding. 82 // Double check that it is in fact winding.
80 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); 83 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace));
81 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); 84 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace));
82 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); 85 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace));
(...skipping 26 matching lines...) Expand all
109 112
110 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr aceCmdBit); } 113 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr aceCmdBit); }
111 114
112 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, 115 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds,
113 GrColor color, 116 GrColor color,
114 const SkRect& rect, 117 const SkRect& rect,
115 const SkRect* localRect, 118 const SkRect* localRect,
116 const SkMatrix* localMatrix) { 119 const SkMatrix* localMatrix) {
117 GrDrawState::AutoRestoreEffects are(ds); 120 GrDrawState::AutoRestoreEffects are(ds);
118 121
119 set_vertex_attributes(ds, SkToBool(localRect), color); 122 SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(ds, SkToBoo l(localRect),
123 color));
120 124
121 size_t vstride = ds->getGeometryProcessor()->getVertexStride(); 125 size_t vstride = gp->getVertexStride();
122 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect) ? sizeof(SkPoint) : 126 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect) ? sizeof(SkPoint) :
123 0)); 127 0));
124 AutoReleaseGeometry geo(this, 4, vstride, 0); 128 AutoReleaseGeometry geo(this, 4, vstride, 0);
125 if (!geo.succeeded()) { 129 if (!geo.succeeded()) {
126 SkDebugf("Failed to get space for vertices!\n"); 130 SkDebugf("Failed to get space for vertices!\n");
127 return; 131 return;
128 } 132 }
129 133
130 // Go to device coords to allow batching across matrix changes 134 // Go to device coords to allow batching across matrix changes
131 SkMatrix matrix = ds->getViewMatrix(); 135 SkMatrix matrix = ds->getViewMatrix();
(...skipping 26 matching lines...) Expand all
158 } 162 }
159 163
160 static const int kColorOffset = sizeof(SkPoint); 164 static const int kColorOffset = sizeof(SkPoint);
161 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k ColorOffset); 165 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k ColorOffset);
162 for (int i = 0; i < 4; ++i) { 166 for (int i = 0; i < 4; ++i) {
163 *vertColor = color; 167 *vertColor = color;
164 vertColor = (GrColor*) ((intptr_t) vertColor + vstride); 168 vertColor = (GrColor*) ((intptr_t) vertColor + vstride);
165 } 169 }
166 170
167 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); 171 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
168 this->drawIndexedInstances(ds, kTriangles_GrPrimitiveType, 1, 4, 6, &devBoun ds); 172 this->drawIndexedInstances(ds, gp, kTriangles_GrPrimitiveType, 1, 4, 6, &dev Bounds);
169 } 173 }
170 174
171 int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds, const DrawIn fo& info) { 175 int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds, const DrawIn fo& info) {
172 SkASSERT(!fCmdBuffer.empty()); 176 SkASSERT(!fCmdBuffer.empty());
173 SkASSERT(info.isInstanced()); 177 SkASSERT(info.isInstanced());
174 178
175 const GeometrySrcState& geomSrc = this->getGeomSrc(); 179 const GeometrySrcState& geomSrc = this->getGeomSrc();
176 180
177 // we only attempt to concat the case when reserved verts are used with a cl ient-specified index 181 // we only attempt to concat the case when reserved verts are used with a cl ient-specified index
178 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated 182 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } else { 218 } else {
215 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); 219 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers());
216 draw->fType = add_trace_bit(draw->fType); 220 draw->fType = add_trace_bit(draw->fType);
217 } 221 }
218 } 222 }
219 223
220 return instancesToConcat; 224 return instancesToConcat;
221 } 225 }
222 226
223 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, 227 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds,
228 const GrGeometryProcessor* gp,
224 const DrawInfo& info, 229 const DrawInfo& info,
225 const ScissorState& scissorState, 230 const ScissorState& scissorState,
226 const GrDeviceCoordTexture* dstCopy) { 231 const GrDeviceCoordTexture* dstCopy) {
227 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); 232 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer()));
228 233
229 const GrGeometryProcessor* gp = ds.getGeometryProcessor(); 234 if (!this->recordStateAndShouldDraw(ds, gp, NULL,
230 if (!this->recordStateAndShouldDraw(ds, gp->getColor(), gp->getCoverage(),
231 GrGpu::PrimTypeToDrawType(info.primitive Type()), 235 GrGpu::PrimTypeToDrawType(info.primitive Type()),
232 scissorState, dstCopy)) { 236 scissorState, dstCopy)) {
233 return; 237 return;
234 } 238 }
235 239
236 Draw* draw; 240 Draw* draw;
237 if (info.isInstanced()) { 241 if (info.isInstanced()) {
238 int instancesConcated = this->concatInstancedDraw(ds, info); 242 int instancesConcated = this->concatInstancedDraw(ds, info);
239 if (info.instanceCount() > instancesConcated) { 243 if (info.instanceCount() > instancesConcated) {
240 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); 244 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
241 draw->fInfo.adjustInstanceCount(-instancesConcated); 245 draw->fInfo.adjustInstanceCount(-instancesConcated);
242 } else { 246 } else {
243 return; 247 return;
244 } 248 }
245 } else { 249 } else {
246 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); 250 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
247 } 251 }
248 this->recordTraceMarkersIfNecessary(); 252 this->recordTraceMarkersIfNecessary();
249 } 253 }
250 254
251 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, 255 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds,
256 const GrPathProcessor* pp,
252 const GrPath* path, 257 const GrPath* path,
253 const GrClipMaskManager::ScissorState& s cissorState, 258 const GrClipMaskManager::ScissorState& s cissorState,
254 const GrStencilSettings& stencilSettings ) { 259 const GrStencilSettings& stencilSettings ) {
255 // Only compare the subset of GrDrawState relevant to path stenciling? 260 // Only compare the subset of GrDrawState relevant to path stenciling?
256 if (!this->recordStateAndShouldDraw(ds, GrColor_WHITE, 0xff, GrGpu::kStencil Path_DrawType, 261 if (!this->recordStateAndShouldDraw(ds, NULL, pp, GrGpu::kStencilPath_DrawTy pe,
257 scissorState, NULL)) { 262 scissorState, NULL)) {
258 return; 263 return;
259 } 264 }
260 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); 265 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path));
261 sp->fStencilSettings = stencilSettings; 266 sp->fStencilSettings = stencilSettings;
262 this->recordTraceMarkersIfNecessary(); 267 this->recordTraceMarkersIfNecessary();
263 } 268 }
264 269
265 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, 270 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds,
266 GrColor color, 271 const GrPathProcessor* pp,
267 const GrPath* path, 272 const GrPath* path,
268 const GrClipMaskManager::ScissorState& scis sorState, 273 const GrClipMaskManager::ScissorState& scis sorState,
269 const GrStencilSettings& stencilSettings, 274 const GrStencilSettings& stencilSettings,
270 const GrDeviceCoordTexture* dstCopy) { 275 const GrDeviceCoordTexture* dstCopy) {
271 // TODO: Only compare the subset of GrDrawState relevant to path covering? 276 // TODO: Only compare the subset of GrDrawState relevant to path covering?
272 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy pe, scissorState, 277 if (!this->recordStateAndShouldDraw(ds, NULL, pp, GrGpu::kDrawPath_DrawType,
273 dstCopy)) { 278 scissorState, dstCopy)) {
274 return; 279 return;
275 } 280 }
276 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); 281 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path));
277 dp->fStencilSettings = stencilSettings; 282 dp->fStencilSettings = stencilSettings;
278 this->recordTraceMarkersIfNecessary(); 283 this->recordTraceMarkersIfNecessary();
279 } 284 }
280 285
281 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, 286 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds,
282 GrColor color, 287 const GrPathProcessor* pp,
283 const GrPathRange* pathRange, 288 const GrPathRange* pathRange,
284 const void* indices, 289 const void* indices,
285 PathIndexType indexType, 290 PathIndexType indexType,
286 const float transformValues[], 291 const float transformValues[],
287 PathTransformType transformType, 292 PathTransformType transformType,
288 int count, 293 int count,
289 const GrClipMaskManager::ScissorState& sci ssorState, 294 const GrClipMaskManager::ScissorState& sci ssorState,
290 const GrStencilSettings& stencilSettings, 295 const GrStencilSettings& stencilSettings,
291 const GrDeviceCoordTexture* dstCopy) { 296 const GrDeviceCoordTexture* dstCopy) {
292 SkASSERT(pathRange); 297 SkASSERT(pathRange);
293 SkASSERT(indices); 298 SkASSERT(indices);
294 SkASSERT(transformValues); 299 SkASSERT(transformValues);
295 300
296 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy pe, scissorState, 301 if (!this->recordStateAndShouldDraw(ds, NULL, pp, GrGpu::kDrawPath_DrawType, scissorState,
297 dstCopy)) { 302 dstCopy)) {
298 return; 303 return;
299 } 304 }
300 305
301 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); 306 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
302 if (int misalign = fPathIndexBuffer.count() % indexBytes) { 307 if (int misalign = fPathIndexBuffer.count() % indexBytes) {
303 // Add padding to the index buffer so the indices are aligned properly. 308 // Add padding to the index buffer so the indices are aligned properly.
304 fPathIndexBuffer.append(indexBytes - misalign); 309 fPathIndexBuffer.append(indexBytes - misalign);
305 } 310 }
306 311
(...skipping 10 matching lines...) Expand all
317 // and the combined calls may also cancel each other's winding numbers i n some 322 // and the combined calls may also cancel each other's winding numbers i n some
318 // places. For now the winding numbers are only an issue if the fill is even/odd, 323 // places. For now the winding numbers are only an issue if the fill is even/odd,
319 // because DrawPaths is currently only used for glyphs, and glyphs in th e same 324 // because DrawPaths is currently only used for glyphs, and glyphs in th e same
320 // font tend to all wind in the same direction. 325 // font tend to all wind in the same direction.
321 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); 326 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back());
322 if (pathRange == previous->pathRange() && 327 if (pathRange == previous->pathRange() &&
323 indexType == previous->fIndexType && 328 indexType == previous->fIndexType &&
324 transformType == previous->fTransformType && 329 transformType == previous->fTransformType &&
325 stencilSettings == previous->fStencilSettings && 330 stencilSettings == previous->fStencilSettings &&
326 path_fill_type_is_winding(stencilSettings) && 331 path_fill_type_is_winding(stencilSettings) &&
327 !ds.willBlendWithDst(color, GrColor_WHITE)) { 332 !ds.willBlendWithDst(pp)) {
328 // Fold this DrawPaths call into the one previous. 333 // Fold this DrawPaths call into the one previous.
329 previous->fCount += count; 334 previous->fCount += count;
330 return; 335 return;
331 } 336 }
332 } 337 }
333 338
334 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ; 339 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ;
335 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); 340 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin();
336 dp->fIndexType = indexType; 341 dp->fIndexType = indexType;
337 dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); 342 dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst , src)); 488 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst , src));
484 cs->fSrcRect = srcRect; 489 cs->fSrcRect = srcRect;
485 cs->fDstPoint = dstPoint; 490 cs->fDstPoint = dstPoint;
486 this->recordTraceMarkersIfNecessary(); 491 this->recordTraceMarkersIfNecessary();
487 return true; 492 return true;
488 } 493 }
489 return false; 494 return false;
490 } 495 }
491 496
492 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, 497 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds,
493 GrColor color, 498 const GrGeometryProcessor* gp ,
494 uint8_t coverage, 499 const GrPathProcessor* pp,
495 GrGpu::DrawType drawType, 500 GrGpu::DrawType drawType,
496 const GrClipMaskManager::Scis sorState& scissor, 501 const GrClipMaskManager::Scis sorState& scissor,
497 const GrDeviceCoordTexture* d stCopy) { 502 const GrDeviceCoordTexture* d stCopy) {
498 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, 503 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
499 (ds, color, coverage, *this->getGpu( )->caps(), scissor, 504 (ds, gp, pp, *this->getGpu()->caps() , scissor, dstCopy,
500 dstCopy, drawType)); 505 drawType));
501 if (ss->fState.mustSkip()) { 506 if (ss->fState.mustSkip()) {
502 fCmdBuffer.pop_back(); 507 fCmdBuffer.pop_back();
503 return false; 508 return false;
504 } 509 }
505 if (fPrevState && *fPrevState == ss->fState) { 510 if (fPrevState && *fPrevState == ss->fState) {
506 fCmdBuffer.pop_back(); 511 fCmdBuffer.pop_back();
507 } else { 512 } else {
508 fPrevState = &ss->fState; 513 fPrevState = &ss->fState;
509 this->recordTraceMarkersIfNecessary(); 514 this->recordTraceMarkersIfNecessary();
510 } 515 }
511 return true; 516 return true;
512 } 517 }
513 518
514 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { 519 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() {
515 SkASSERT(!fCmdBuffer.empty()); 520 SkASSERT(!fCmdBuffer.empty());
516 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); 521 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType));
517 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 522 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
518 if (activeTraceMarkers.count() > 0) { 523 if (activeTraceMarkers.count() > 0) {
519 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); 524 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType);
520 fGpuCmdMarkers.push_back(activeTraceMarkers); 525 fGpuCmdMarkers.push_back(activeTraceMarkers);
521 } 526 }
522 } 527 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698