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

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: 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,
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);
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, gp->getColor(), gp->getCoverage( ),
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,
252 const GrPath* path, 256 const GrPath* path,
253 const GrClipMaskManager::ScissorState& s cissorState, 257 const GrClipMaskManager::ScissorState& s cissorState,
254 const GrStencilSettings& stencilSettings ) { 258 const GrStencilSettings& stencilSettings ) {
255 // Only compare the subset of GrDrawState relevant to path stenciling? 259 // Only compare the subset of GrDrawState relevant to path stenciling?
256 if (!this->recordStateAndShouldDraw(ds, GrColor_WHITE, 0xff, GrGpu::kStencil Path_DrawType, 260 if (!this->recordStateAndShouldDraw(ds, NULL, GrColor_WHITE, 0xff, GrGpu::kS tencilPath_DrawType,
257 scissorState, NULL)) { 261 scissorState, NULL)) {
258 return; 262 return;
259 } 263 }
260 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); 264 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path));
261 sp->fStencilSettings = stencilSettings; 265 sp->fStencilSettings = stencilSettings;
262 this->recordTraceMarkersIfNecessary(); 266 this->recordTraceMarkersIfNecessary();
263 } 267 }
264 268
265 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, 269 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds,
266 GrColor color, 270 GrColor color,
267 const GrPath* path, 271 const GrPath* path,
268 const GrClipMaskManager::ScissorState& scis sorState, 272 const GrClipMaskManager::ScissorState& scis sorState,
269 const GrStencilSettings& stencilSettings, 273 const GrStencilSettings& stencilSettings,
270 const GrDeviceCoordTexture* dstCopy) { 274 const GrDeviceCoordTexture* dstCopy) {
271 // TODO: Only compare the subset of GrDrawState relevant to path covering? 275 // TODO: Only compare the subset of GrDrawState relevant to path covering?
272 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy pe, scissorState, 276 if (!this->recordStateAndShouldDraw(ds, NULL, color, 0xff, GrGpu::kDrawPath_ DrawType,
273 dstCopy)) { 277 scissorState, dstCopy)) {
274 return; 278 return;
275 } 279 }
276 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); 280 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path));
277 dp->fStencilSettings = stencilSettings; 281 dp->fStencilSettings = stencilSettings;
278 this->recordTraceMarkersIfNecessary(); 282 this->recordTraceMarkersIfNecessary();
279 } 283 }
280 284
281 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, 285 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds,
282 GrColor color, 286 GrColor color,
283 const GrPathRange* pathRange, 287 const GrPathRange* pathRange,
284 const void* indices, 288 const void* indices,
285 PathIndexType indexType, 289 PathIndexType indexType,
286 const float transformValues[], 290 const float transformValues[],
287 PathTransformType transformType, 291 PathTransformType transformType,
288 int count, 292 int count,
289 const GrClipMaskManager::ScissorState& sci ssorState, 293 const GrClipMaskManager::ScissorState& sci ssorState,
290 const GrStencilSettings& stencilSettings, 294 const GrStencilSettings& stencilSettings,
291 const GrDeviceCoordTexture* dstCopy) { 295 const GrDeviceCoordTexture* dstCopy) {
292 SkASSERT(pathRange); 296 SkASSERT(pathRange);
293 SkASSERT(indices); 297 SkASSERT(indices);
294 SkASSERT(transformValues); 298 SkASSERT(transformValues);
295 299
296 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy pe, scissorState, 300 if (!this->recordStateAndShouldDraw(ds, NULL, color, 0xff, GrGpu::kDrawPath_ DrawType,
297 dstCopy)) { 301 scissorState, dstCopy)) {
298 return; 302 return;
299 } 303 }
300 304
301 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); 305 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
302 if (int misalign = fPathIndexBuffer.count() % indexBytes) { 306 if (int misalign = fPathIndexBuffer.count() % indexBytes) {
303 // Add padding to the index buffer so the indices are aligned properly. 307 // Add padding to the index buffer so the indices are aligned properly.
304 fPathIndexBuffer.append(indexBytes - misalign); 308 fPathIndexBuffer.append(indexBytes - misalign);
305 } 309 }
306 310
307 char* savedIndices = fPathIndexBuffer.append(count * indexBytes, 311 char* savedIndices = fPathIndexBuffer.append(count * indexBytes,
308 reinterpret_cast<const char*>(i ndices)); 312 reinterpret_cast<const char*>(i ndices));
309 float* savedTransforms = fPathTransformBuffer.append( 313 float* savedTransforms = fPathTransformBuffer.append(
310 count * GrPathRendering::PathTransformSize(tran sformType), 314 count * GrPathRendering::PathTransformSize(tran sformType),
311 transformValues); 315 transformValues);
312 316
313 if (kDrawPaths_Cmd == strip_trace_bit(fCmdBuffer.back().fType)) { 317 if (kDrawPaths_Cmd == strip_trace_bit(fCmdBuffer.back().fType)) {
314 // The previous command was also DrawPaths. Try to collapse this call in to the one 318 // The previous command was also DrawPaths. Try to collapse this call in to the one
315 // before. Note that stenciling all the paths at once, then covering, ma y not be 319 // before. Note that stenciling all the paths at once, then covering, ma y not be
316 // equivalent to two separate draw calls if there is overlap. Blending w on't work, 320 // equivalent to two separate draw calls if there is overlap. Blending w on't work,
317 // and the combined calls may also cancel each other's winding numbers i n some 321 // 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, 322 // 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 323 // because DrawPaths is currently only used for glyphs, and glyphs in th e same
320 // font tend to all wind in the same direction. 324 // font tend to all wind in the same direction.
321 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); 325 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back());
322 if (pathRange == previous->pathRange() && 326 if (pathRange == previous->pathRange() &&
323 indexType == previous->fIndexType && 327 indexType == previous->fIndexType &&
324 transformType == previous->fTransformType && 328 transformType == previous->fTransformType &&
325 stencilSettings == previous->fStencilSettings && 329 stencilSettings == previous->fStencilSettings &&
326 path_fill_type_is_winding(stencilSettings) && 330 path_fill_type_is_winding(stencilSettings) &&
327 !ds.willBlendWithDst(color, GrColor_WHITE)) { 331 !ds.willBlendWithDst(NULL, color, GrColor_WHITE)) {
328 // Fold this DrawPaths call into the one previous. 332 // Fold this DrawPaths call into the one previous.
329 previous->fCount += count; 333 previous->fCount += count;
330 return; 334 return;
331 } 335 }
332 } 336 }
333 337
334 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ; 338 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ;
335 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); 339 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin();
336 dp->fIndexType = indexType; 340 dp->fIndexType = indexType;
337 dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); 341 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)); 487 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst , src));
484 cs->fSrcRect = srcRect; 488 cs->fSrcRect = srcRect;
485 cs->fDstPoint = dstPoint; 489 cs->fDstPoint = dstPoint;
486 this->recordTraceMarkersIfNecessary(); 490 this->recordTraceMarkersIfNecessary();
487 return true; 491 return true;
488 } 492 }
489 return false; 493 return false;
490 } 494 }
491 495
492 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, 496 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds,
497 const GrGeometryProcessor* gp ,
493 GrColor color, 498 GrColor color,
494 uint8_t coverage, 499 uint8_t coverage,
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, color, coverage, *this->get Gpu()->caps(),
500 dstCopy, drawType)); 505 scissor, dstCopy, 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