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

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

Issue 973853002: Split command holding object (GrTargetCommands) out of GrInOrderDrawBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address compilation complaint Created 5 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
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.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 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"
11 #include "GrDefaultGeoProcFactory.h" 11 #include "GrDefaultGeoProcFactory.h"
12 #include "GrDrawTargetCaps.h" 12 #include "GrDrawTargetCaps.h"
13 #include "GrGpu.h" 13 #include "GrGpu.h"
14 #include "GrTemplates.h" 14 #include "GrTemplates.h"
15 #include "GrFontCache.h" 15 #include "GrFontCache.h"
16 #include "GrTexture.h" 16 #include "GrTexture.h"
17 17
18 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, 18 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
19 GrVertexBufferAllocPool* vertexPool, 19 GrVertexBufferAllocPool* vertexPool,
20 GrIndexBufferAllocPool* indexPool) 20 GrIndexBufferAllocPool* indexPool)
21 : INHERITED(gpu, vertexPool, indexPool) 21 : INHERITED(gpu, vertexPool, indexPool)
22 , fCmdBuffer(kCmdBufferInitialSizeInBytes) 22 , fCommands(gpu, vertexPool, indexPool)
23 , fPrevState(NULL)
24 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) 23 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
25 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) 24 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
26 , fDrawID(0) 25 , fDrawID(0) {
27 , fBatchTarget(gpu, vertexPool, indexPool)
28 , fDrawBatch(NULL) {
29 26
30 SkASSERT(vertexPool); 27 SkASSERT(vertexPool);
31 SkASSERT(indexPool); 28 SkASSERT(indexPool);
32 } 29 }
33 30
34 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { 31 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
35 this->reset(); 32 this->reset();
36 } 33 }
37 34
38 void GrInOrderDrawBuffer::closeBatch() { 35 void GrTargetCommands::closeBatch() {
39 if (fDrawBatch) { 36 if (fDrawBatch) {
40 fBatchTarget.resetNumberOfDraws(); 37 fBatchTarget.resetNumberOfDraws();
41 fDrawBatch->execute(this->getGpu(), fPrevState); 38 fDrawBatch->execute(NULL, fPrevState);
42 fDrawBatch->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); 39 fDrawBatch->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws());
43 fDrawBatch = NULL; 40 fDrawBatch = NULL;
44 } 41 }
45 } 42 }
46 43
47 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
48 45
49 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we 46 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we
50 have explicit local coords and sometimes not. We *could* always provide expl icit local coords 47 have explicit local coords and sometimes not. We *could* always provide expl icit local coords
51 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 48 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 geometry.fHasLocalMatrix = false; 312 geometry.fHasLocalMatrix = false;
316 } 313 }
317 314
318 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry)); 315 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry));
319 316
320 SkRect bounds = rect; 317 SkRect bounds = rect;
321 viewMatrix.mapRect(&bounds); 318 viewMatrix.mapRect(&bounds);
322 this->drawBatch(pipelineBuilder, batch, &bounds); 319 this->drawBatch(pipelineBuilder, batch, &bounds);
323 } 320 }
324 321
325 int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { 322 int GrTargetCommands::concatInstancedDraw(GrInOrderDrawBuffer* iodb,
323 const GrDrawTarget::DrawInfo& info) {
326 SkASSERT(!fCmdBuffer.empty()); 324 SkASSERT(!fCmdBuffer.empty());
327 SkASSERT(info.isInstanced()); 325 SkASSERT(info.isInstanced());
328 326
329 const GrIndexBuffer* ib; 327 const GrIndexBuffer* ib;
330 if (!this->canConcatToIndexBuffer(&ib)) { 328 if (!iodb->canConcatToIndexBuffer(&ib)) {
331 return 0; 329 return 0;
332 } 330 }
333 331
334 // Check if there is a draw info that is compatible that uses the same VB fr om the pool and 332 // Check if there is a draw info that is compatible that uses the same VB fr om the pool and
335 // the same IB 333 // the same IB
336 if (Cmd::kDraw_Cmd != fCmdBuffer.back().type()) { 334 if (Cmd::kDraw_Cmd != fCmdBuffer.back().type()) {
337 return 0; 335 return 0;
338 } 336 }
339 337
340 Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); 338 Draw* draw = static_cast<Draw*>(&fCmdBuffer.back());
341 339
342 if (!draw->fInfo.isInstanced() || 340 if (!draw->fInfo.isInstanced() ||
343 draw->fInfo.primitiveType() != info.primitiveType() || 341 draw->fInfo.primitiveType() != info.primitiveType() ||
344 draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || 342 draw->fInfo.verticesPerInstance() != info.verticesPerInstance() ||
345 draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || 343 draw->fInfo.indicesPerInstance() != info.indicesPerInstance() ||
346 draw->fInfo.vertexBuffer() != info.vertexBuffer() || 344 draw->fInfo.vertexBuffer() != info.vertexBuffer() ||
347 draw->fInfo.indexBuffer() != ib) { 345 draw->fInfo.indexBuffer() != ib) {
348 return 0; 346 return 0;
349 } 347 }
350 if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVerte x()) { 348 if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVerte x()) {
351 return 0; 349 return 0;
352 } 350 }
353 351
354 // how many instances can be concat'ed onto draw given the size of the index buffer 352 // how many instances can be concat'ed onto draw given the size of the index buffer
355 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); 353 int instancesToConcat = iodb->indexCountInCurrentSource() / info.indicesPerI nstance();
356 instancesToConcat -= draw->fInfo.instanceCount(); 354 instancesToConcat -= draw->fInfo.instanceCount();
357 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); 355 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount());
358 356
359 draw->fInfo.adjustInstanceCount(instancesToConcat); 357 draw->fInfo.adjustInstanceCount(instancesToConcat);
360 358
361 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added 359 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added
362 this->recordTraceMarkersIfNecessary(draw); 360 iodb->recordTraceMarkersIfNecessary(draw);
363 return instancesToConcat; 361 return instancesToConcat;
364 } 362 }
365 363
366 void GrInOrderDrawBuffer::onDraw(const GrGeometryProcessor* gp, 364 void GrInOrderDrawBuffer::onDraw(const GrGeometryProcessor* gp,
367 const DrawInfo& info, 365 const DrawInfo& info,
368 const PipelineInfo& pipelineInfo) { 366 const PipelineInfo& pipelineInfo) {
367 GrTargetCommands::Cmd* cmd = fCommands.recordDraw(this, gp, info, pipelineIn fo);
368 this->recordTraceMarkersIfNecessary(cmd);
369 }
370
371 GrTargetCommands::Cmd* GrTargetCommands::recordDraw(
372 GrInOrderDrawBuffer* iodb,
373 const GrGeometryProcessor* gp,
374 const GrDrawTarget::DrawInfo& info,
375 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
369 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); 376 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer()));
370 this->closeBatch(); 377 this->closeBatch();
371 378
372 if (!this->setupPipelineAndShouldDraw(gp, pipelineInfo)) { 379 if (!this->setupPipelineAndShouldDraw(iodb, gp, pipelineInfo)) {
373 return; 380 return NULL;
374 } 381 }
375 382
376 Draw* draw; 383 Draw* draw;
377 if (info.isInstanced()) { 384 if (info.isInstanced()) {
378 int instancesConcated = this->concatInstancedDraw(info); 385 int instancesConcated = this->concatInstancedDraw(iodb, info);
379 if (info.instanceCount() > instancesConcated) { 386 if (info.instanceCount() > instancesConcated) {
380 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); 387 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
381 draw->fInfo.adjustInstanceCount(-instancesConcated); 388 draw->fInfo.adjustInstanceCount(-instancesConcated);
382 } else { 389 } else {
383 return; 390 return NULL;
384 } 391 }
385 } else { 392 } else {
386 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); 393 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
387 } 394 }
388 this->recordTraceMarkersIfNecessary(draw); 395
396 return draw;
389 } 397 }
390 398
391 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, 399 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
392 const PipelineInfo& pipelineInfo) { 400 const PipelineInfo& pipelineInfo) {
393 if (!this->setupPipelineAndShouldDraw(batch, pipelineInfo)) { 401 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(this, batch, pipeline Info);
394 return; 402 this->recordTraceMarkersIfNecessary(cmd);
403 }
404
405 GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch(
406 GrInOrderDrawBuffer* iodb,
407 GrBatch* batch,
408 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
409 if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) {
410 return NULL;
395 } 411 }
396 412
397 // Check if there is a Batch Draw we can batch with 413 // Check if there is a Batch Draw we can batch with
398 if (Cmd::kDrawBatch_Cmd != fCmdBuffer.back().type() || !fDrawBatch) { 414 if (Cmd::kDrawBatch_Cmd != fCmdBuffer.back().type() || !fDrawBatch) {
399 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget)); 415 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget));
400 this->recordTraceMarkersIfNecessary(fDrawBatch); 416 return fDrawBatch;
401 return;
402 } 417 }
403 418
404 SkASSERT(&fCmdBuffer.back() == fDrawBatch); 419 SkASSERT(&fCmdBuffer.back() == fDrawBatch);
405 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { 420 if (!fDrawBatch->fBatch->combineIfPossible(batch)) {
406 this->closeBatch(); 421 this->closeBatch();
407 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget)); 422 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget));
408 } 423 }
409 this->recordTraceMarkersIfNecessary(fDrawBatch); 424
425 return fDrawBatch;
410 } 426 }
411 427
412 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder , 428 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder ,
413 const GrPathProcessor* pathProc, 429 const GrPathProcessor* pathProc,
414 const GrPath* path, 430 const GrPath* path,
415 const GrScissorState& scissorState, 431 const GrScissorState& scissorState,
416 const GrStencilSettings& stencilSettings ) { 432 const GrStencilSettings& stencilSettings ) {
433 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(this, pipelineBuild er,
434 pathProc, path, sci ssorState,
435 stencilSettings);
436 this->recordTraceMarkersIfNecessary(cmd);
437 }
438
439 GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath(
440 GrInOrderDrawBuffer* iod b,
441 const GrPipelineBuilder& pipelineBuilder,
442 const GrPathProcessor* p athProc,
443 const GrPath* path,
444 const GrScissorState& sc issorState,
445 const GrStencilSettings& stencilSettings) {
417 this->closeBatch(); 446 this->closeBatch();
418 447
419 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, 448 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath,
420 (path, pipelineBuilder.getRenderT arget())); 449 (path, pipelineBuilder.getRenderT arget()));
421 450
422 sp->fScissor = scissorState; 451 sp->fScissor = scissorState;
423 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); 452 sp->fUseHWAA = pipelineBuilder.isHWAntialias();
424 sp->fViewMatrix = pathProc->viewMatrix(); 453 sp->fViewMatrix = pathProc->viewMatrix();
425 sp->fStencil = stencilSettings; 454 sp->fStencil = stencilSettings;
426 this->recordTraceMarkersIfNecessary(sp); 455 return sp;
427 } 456 }
428 457
429 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, 458 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
430 const GrPath* path, 459 const GrPath* path,
431 const GrStencilSettings& stencilSettings, 460 const GrStencilSettings& stencilSettings,
432 const PipelineInfo& pipelineInfo) { 461 const PipelineInfo& pipelineInfo) {
462 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(this, pathProc,
463 path, stencilSettings,
464 pipelineInfo);
465 this->recordTraceMarkersIfNecessary(cmd);
466 }
467
468 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPath(
469 GrInOrderDrawBuffer* iodb,
470 const GrPathProcessor* pathPro c,
471 const GrPath* path,
472 const GrStencilSettings& stenc ilSettings,
473 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
433 this->closeBatch(); 474 this->closeBatch();
434 475
435 // TODO: Only compare the subset of GrPipelineBuilder relevant to path cover ing? 476 // TODO: Only compare the subset of GrPipelineBuilder relevant to path cover ing?
436 if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { 477 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) {
437 return; 478 return NULL;
438 } 479 }
439 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); 480 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path));
440 dp->fStencilSettings = stencilSettings; 481 dp->fStencilSettings = stencilSettings;
441 this->recordTraceMarkersIfNecessary(dp); 482 return dp;
442 } 483 }
443 484
444 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, 485 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
445 const GrPathRange* pathRange, 486 const GrPathRange* pathRange,
446 const void* indices, 487 const void* indices,
447 PathIndexType indexType, 488 PathIndexType indexType,
448 const float transformValues[], 489 const float transformValues[],
449 PathTransformType transformType, 490 PathTransformType transformType,
450 int count, 491 int count,
451 const GrStencilSettings& stencilSettings, 492 const GrStencilSettings& stencilSettings,
452 const PipelineInfo& pipelineInfo) { 493 const PipelineInfo& pipelineInfo) {
494 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(this, pathProc, pathR ange,
495 indices, indexType, t ransformValues,
496 transformType, count,
497 stencilSettings, pipe lineInfo);
498 this->recordTraceMarkersIfNecessary(cmd);
499 }
500
501 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPaths(
502 GrInOrderDrawBuffer* iodb,
503 const GrPathProcessor* pathPro c,
504 const GrPathRange* pathRange,
505 const void* indexValues,
506 GrDrawTarget::PathIndexType in dexType,
507 const float transformValues[],
508 GrDrawTarget::PathTransformTyp e transformType,
509 int count,
510 const GrStencilSettings& stenc ilSettings,
511 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
453 SkASSERT(pathRange); 512 SkASSERT(pathRange);
454 SkASSERT(indices); 513 SkASSERT(indexValues);
455 SkASSERT(transformValues); 514 SkASSERT(transformValues);
456 this->closeBatch(); 515 this->closeBatch();
457 516
458 if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { 517 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) {
459 return; 518 return NULL;
460 } 519 }
461 520
462 char* savedIndices; 521 char* savedIndices;
463 float* savedTransforms; 522 float* savedTransforms;
464 523
465 this->appendIndicesAndTransforms(indices, indexType, 524 iodb->appendIndicesAndTransforms(indexValues, indexType,
466 transformValues, transformType, 525 transformValues, transformType,
467 count, &savedIndices, &savedTransforms); 526 count, &savedIndices, &savedTransforms);
468 527
469 if (Cmd::kDrawPaths_Cmd == fCmdBuffer.back().type()) { 528 if (Cmd::kDrawPaths_Cmd == fCmdBuffer.back().type()) {
470 // The previous command was also DrawPaths. Try to collapse this call in to the one 529 // The previous command was also DrawPaths. Try to collapse this call in to the one
471 // before. Note that stenciling all the paths at once, then covering, ma y not be 530 // before. Note that stenciling all the paths at once, then covering, ma y not be
472 // equivalent to two separate draw calls if there is overlap. Blending w on't work, 531 // equivalent to two separate draw calls if there is overlap. Blending w on't work,
473 // and the combined calls may also cancel each other's winding numbers i n some 532 // and the combined calls may also cancel each other's winding numbers i n some
474 // places. For now the winding numbers are only an issue if the fill is even/odd, 533 // places. For now the winding numbers are only an issue if the fill is even/odd,
475 // because DrawPaths is currently only used for glyphs, and glyphs in th e same 534 // because DrawPaths is currently only used for glyphs, and glyphs in th e same
476 // font tend to all wind in the same direction. 535 // font tend to all wind in the same direction.
477 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); 536 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back());
478 if (pathRange == previous->pathRange() && 537 if (pathRange == previous->pathRange() &&
479 indexType == previous->fIndexType && 538 indexType == previous->fIndexType &&
480 transformType == previous->fTransformType && 539 transformType == previous->fTransformType &&
481 stencilSettings == previous->fStencilSettings && 540 stencilSettings == previous->fStencilSettings &&
482 path_fill_type_is_winding(stencilSettings) && 541 path_fill_type_is_winding(stencilSettings) &&
483 !pipelineInfo.willBlendWithDst(pathProc)) { 542 !pipelineInfo.willBlendWithDst(pathProc)) {
484 const int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); 543 const int indexBytes = GrPathRange::PathIndexSizeInBytes(indexTy pe);
485 const int xformSize = GrPathRendering::PathTransformSize(transformTy pe); 544 const int xformSize = GrPathRendering::PathTransformSize(transfo rmType);
486 if (&previous->fIndices[previous->fCount*indexBytes] == savedIndices && 545 if (&previous->fIndices[previous->fCount*indexBytes] == savedInd ices &&
487 (0 == xformSize || 546 (0 == xformSize ||
488 &previous->fTransforms[previous->fCount*xformSize] == savedTran sforms)) { 547 &previous->fTransforms[previous->fCount*xformSize] == saved Transforms)) {
489 // Fold this DrawPaths call into the one previous. 548 // Fold this DrawPaths call into the one previous.
490 previous->fCount += count; 549 previous->fCount += count;
491 return; 550 return NULL;
492 } 551 }
493 } 552 }
494 } 553 }
495 554
496 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ; 555 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)) ;
497 dp->fIndices = savedIndices; 556 dp->fIndices = savedIndices;
498 dp->fIndexType = indexType; 557 dp->fIndexType = indexType;
499 dp->fTransforms = savedTransforms; 558 dp->fTransforms = savedTransforms;
500 dp->fTransformType = transformType; 559 dp->fTransformType = transformType;
501 dp->fCount = count; 560 dp->fCount = count;
502 dp->fStencilSettings = stencilSettings; 561 dp->fStencilSettings = stencilSettings;
503 562 return dp;
504 this->recordTraceMarkersIfNecessary(dp);
505 } 563 }
506 564
507 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, 565 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
508 bool canIgnoreRect, GrRenderTarget* renderTarg et) { 566 bool canIgnoreRect, GrRenderTarget* renderTarg et) {
567 GrTargetCommands::Cmd* cmd = fCommands.recordClear(this, rect, color,
568 canIgnoreRect, renderTarg et);
569 this->recordTraceMarkersIfNecessary(cmd);
570 }
571
572 GrTargetCommands::Cmd* GrTargetCommands::recordClear(GrInOrderDrawBuffer* iodb,
573 const SkIRect* rect,
574 GrColor color,
575 bool canIgnoreRect,
576 GrRenderTarget* renderTarge t) {
509 SkASSERT(renderTarget); 577 SkASSERT(renderTarget);
510 this->closeBatch(); 578 this->closeBatch();
511 579
512 SkIRect r; 580 SkIRect r;
513 if (NULL == rect) { 581 if (NULL == rect) {
514 // We could do something smart and remove previous draws and clears to 582 // We could do something smart and remove previous draws and clears to
515 // the current render target. If we get that smart we have to make sure 583 // the current render target. If we get that smart we have to make sure
516 // those draws aren't read before this clear (render-to-texture). 584 // those draws aren't read before this clear (render-to-texture).
517 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); 585 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
518 rect = &r; 586 rect = &r;
519 } 587 }
520 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); 588 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget));
521 GrColorIsPMAssert(color); 589 GrColorIsPMAssert(color);
522 clr->fColor = color; 590 clr->fColor = color;
523 clr->fRect = *rect; 591 clr->fRect = *rect;
524 clr->fCanIgnoreRect = canIgnoreRect; 592 clr->fCanIgnoreRect = canIgnoreRect;
525 this->recordTraceMarkersIfNecessary(clr); 593 return clr;
526 } 594 }
527 595
528 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, 596 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
529 bool insideClip, 597 bool insideClip,
530 GrRenderTarget* renderTarget) { 598 GrRenderTarget* renderTarget) {
599 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(this, rect,
600 insideClip, re nderTarget);
601 this->recordTraceMarkersIfNecessary(cmd);
602 }
603
604 GrTargetCommands::Cmd* GrTargetCommands::recordClearStencilClip(GrInOrderDrawBuf fer* iodb,
605 const SkIRect& r ect,
606 bool insideClip,
607 GrRenderTarget* renderTarget) {
531 SkASSERT(renderTarget); 608 SkASSERT(renderTarget);
532 this->closeBatch(); 609 this->closeBatch();
533 610
534 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilCli p, (renderTarget)); 611 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilCli p, (renderTarget));
535 clr->fRect = rect; 612 clr->fRect = rect;
536 clr->fInsideClip = insideClip; 613 clr->fInsideClip = insideClip;
537 this->recordTraceMarkersIfNecessary(clr); 614 return clr;
538 } 615 }
539 616
540 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { 617 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
618 if (!this->caps()->discardRenderTargetSupport()) {
619 return;
620 }
621
622 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(this, renderTarget);
623 this->recordTraceMarkersIfNecessary(cmd);
624 }
625
626 GrTargetCommands::Cmd* GrTargetCommands::recordDiscard(GrInOrderDrawBuffer* iodb ,
627 GrRenderTarget* renderTar get) {
541 SkASSERT(renderTarget); 628 SkASSERT(renderTarget);
542 this->closeBatch(); 629 this->closeBatch();
543 630
544 if (!this->caps()->discardRenderTargetSupport()) {
545 return;
546 }
547 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); 631 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget));
548 clr->fColor = GrColor_ILLEGAL; 632 clr->fColor = GrColor_ILLEGAL;
549 this->recordTraceMarkersIfNecessary(clr); 633 return clr;
550 } 634 }
551 635
552 void GrInOrderDrawBuffer::onReset() { 636 void GrInOrderDrawBuffer::onReset() {
553 fCmdBuffer.reset(); 637 fCommands.reset();
554 fPrevState = NULL;
555 fPathIndexBuffer.rewind(); 638 fPathIndexBuffer.rewind();
556 fPathTransformBuffer.rewind(); 639 fPathTransformBuffer.rewind();
557 fGpuCmdMarkers.reset(); 640 fGpuCmdMarkers.reset();
641 }
642
643 void GrTargetCommands::reset() {
644 fCmdBuffer.reset();
645 fPrevState = NULL;
558 fDrawBatch = NULL; 646 fDrawBatch = NULL;
559 } 647 }
560 648
561 void GrInOrderDrawBuffer::onFlush() { 649 void GrInOrderDrawBuffer::onFlush() {
650 fCommands.flush(this);
651 ++fDrawID;
652 }
653
654 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) {
562 if (fCmdBuffer.empty()) { 655 if (fCmdBuffer.empty()) {
563 return; 656 return;
564 } 657 }
565 658
566 // Updated every time we find a set state cmd to reflect the current state i n the playback 659 // Updated every time we find a set state cmd to reflect the current state i n the playback
567 // stream. 660 // stream.
568 SetState* currentState = NULL; 661 SetState* currentState = NULL;
569 662
570 // TODO this is temporary while batch is being rolled out 663 // TODO this is temporary while batch is being rolled out
571 this->closeBatch(); 664 this->closeBatch();
572 this->getVertexAllocPool()->unmap(); 665 iodb->getVertexAllocPool()->unmap();
573 this->getIndexAllocPool()->unmap(); 666 iodb->getIndexAllocPool()->unmap();
574 fBatchTarget.preFlush(); 667 fBatchTarget.preFlush();
575 668
576 currentState = NULL; 669 currentState = NULL;
577 CmdBuffer::Iter iter(fCmdBuffer); 670 CmdBuffer::Iter iter(fCmdBuffer);
578 671
579 int currCmdMarker = 0; 672 int currCmdMarker = 0;
580 673
674 GrGpu* gpu = iodb->getGpu();
675
581 int i = 0; 676 int i = 0;
582 while (iter.next()) { 677 while (iter.next()) {
583 i++; 678 i++;
584 GrGpuTraceMarker newMarker("", -1); 679 GrGpuTraceMarker newMarker("", -1);
585 SkString traceString; 680 SkString traceString;
586 if (iter->isTraced()) { 681 if (iter->isTraced()) {
587 traceString = this->getCmdString(currCmdMarker); 682 traceString = iodb->getCmdString(currCmdMarker);
588 newMarker.fMarker = traceString.c_str(); 683 newMarker.fMarker = traceString.c_str();
589 this->getGpu()->addGpuTraceMarker(&newMarker); 684 gpu->addGpuTraceMarker(&newMarker);
590 ++currCmdMarker; 685 ++currCmdMarker;
591 } 686 }
592 687
593 // TODO temporary hack 688 // TODO temporary hack
594 if (Cmd::kDrawBatch_Cmd == iter->type()) { 689 if (Cmd::kDrawBatch_Cmd == iter->type()) {
595 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); 690 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get());
596 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); 691 fBatchTarget.flushNext(db->fBatch->numberOfDraws());
597 continue; 692 continue;
598 } 693 }
599 694
600 if (Cmd::kSetState_Cmd == iter->type()) { 695 if (Cmd::kSetState_Cmd == iter->type()) {
601 SetState* ss = reinterpret_cast<SetState*>(iter.get()); 696 SetState* ss = reinterpret_cast<SetState*>(iter.get());
602 697
603 // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will 698 // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we
604 // only have GrBatch and we can delete this 699 // will only have GrBatch and we can delete this
605 if (ss->fPrimitiveProcessor) { 700 if (ss->fPrimitiveProcessor) {
606 this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProc essor, 701 gpu->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor,
607 *ss->getPipeline(), 702 *ss->getPipeline(),
608 ss->fBatchTracker); 703 ss->fBatchTracker);
609 } 704 }
610 currentState = ss; 705 currentState = ss;
611 } else { 706 } else {
612 iter->execute(this->getGpu(), currentState); 707 iter->execute(gpu, currentState);
613 } 708 }
614 709
615 if (iter->isTraced()) { 710 if (iter->isTraced()) {
616 this->getGpu()->removeGpuTraceMarker(&newMarker); 711 gpu->removeGpuTraceMarker(&newMarker);
617 } 712 }
618 } 713 }
619 714
620 // TODO see copious notes about hack 715 // TODO see copious notes about hack
621 fBatchTarget.postFlush(); 716 fBatchTarget.postFlush();
622
623 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker);
624 ++fDrawID;
625 } 717 }
626 718
627 void GrInOrderDrawBuffer::Draw::execute(GrGpu* gpu, const SetState* state) { 719 void GrTargetCommands::Draw::execute(GrGpu* gpu, const SetState* state) {
628 SkASSERT(state); 720 SkASSERT(state);
629 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc, 721 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc,
630 &state->fBatchTracker); 722 &state->fBatchTracker);
631 gpu->draw(args, fInfo); 723 gpu->draw(args, fInfo);
632 } 724 }
633 725
634 void GrInOrderDrawBuffer::StencilPath::execute(GrGpu* gpu, const SetState*) { 726 void GrTargetCommands::StencilPath::execute(GrGpu* gpu, const SetState*) {
635 GrGpu::StencilPathState state; 727 GrGpu::StencilPathState state;
636 state.fRenderTarget = fRenderTarget.get(); 728 state.fRenderTarget = fRenderTarget.get();
637 state.fScissor = &fScissor; 729 state.fScissor = &fScissor;
638 state.fStencil = &fStencil; 730 state.fStencil = &fStencil;
639 state.fUseHWAA = fUseHWAA; 731 state.fUseHWAA = fUseHWAA;
640 state.fViewMatrix = &fViewMatrix; 732 state.fViewMatrix = &fViewMatrix;
641 733
642 gpu->stencilPath(this->path(), state); 734 gpu->stencilPath(this->path(), state);
643 } 735 }
644 736
645 void GrInOrderDrawBuffer::DrawPath::execute(GrGpu* gpu, const SetState* state) { 737 void GrTargetCommands::DrawPath::execute(GrGpu* gpu, const SetState* state) {
646 SkASSERT(state); 738 SkASSERT(state);
647 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc, 739 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc,
648 &state->fBatchTracker); 740 &state->fBatchTracker);
649 gpu->drawPath(args, this->path(), fStencilSettings); 741 gpu->drawPath(args, this->path(), fStencilSettings);
650 } 742 }
651 743
652 void GrInOrderDrawBuffer::DrawPaths::execute(GrGpu* gpu, const SetState* state) { 744 void GrTargetCommands::DrawPaths::execute(GrGpu* gpu, const SetState* state) {
653 SkASSERT(state); 745 SkASSERT(state);
654 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc, 746 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc,
655 &state->fBatchTracker); 747 &state->fBatchTracker);
656 gpu->drawPaths(args, this->pathRange(), 748 gpu->drawPaths(args, this->pathRange(),
657 fIndices, fIndexType, 749 fIndices, fIndexType,
658 fTransforms, fTransformType, 750 fTransforms, fTransformType,
659 fCount, fStencilSettings); 751 fCount, fStencilSettings);
660 } 752 }
661 753
662 void GrInOrderDrawBuffer::DrawBatch::execute(GrGpu* gpu, const SetState* state) { 754 void GrTargetCommands::DrawBatch::execute(GrGpu*, const SetState* state) {
663 SkASSERT(state); 755 SkASSERT(state);
664 fBatch->generateGeometry(fBatchTarget, state->getPipeline()); 756 fBatch->generateGeometry(fBatchTarget, state->getPipeline());
665 } 757 }
666 758
667 void GrInOrderDrawBuffer::SetState::execute(GrGpu* gpu, const SetState*) {} 759 void GrTargetCommands::SetState::execute(GrGpu*, const SetState*) {}
668 760
669 void GrInOrderDrawBuffer::Clear::execute(GrGpu* gpu, const SetState*) { 761 void GrTargetCommands::Clear::execute(GrGpu* gpu, const SetState*) {
670 if (GrColor_ILLEGAL == fColor) { 762 if (GrColor_ILLEGAL == fColor) {
671 gpu->discard(this->renderTarget()); 763 gpu->discard(this->renderTarget());
672 } else { 764 } else {
673 gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); 765 gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget());
674 } 766 }
675 } 767 }
676 768
677 void GrInOrderDrawBuffer::ClearStencilClip::execute(GrGpu* gpu, const SetState*) { 769 void GrTargetCommands::ClearStencilClip::execute(GrGpu* gpu, const SetState*) {
678 gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); 770 gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget());
679 } 771 }
680 772
681 void GrInOrderDrawBuffer::CopySurface::execute(GrGpu* gpu, const SetState*) { 773 void GrTargetCommands::CopySurface::execute(GrGpu* gpu, const SetState*) {
682 gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); 774 gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint);
683 } 775 }
684 776
685 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, 777 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
686 GrSurface* src, 778 GrSurface* src,
687 const SkIRect& srcRect, 779 const SkIRect& srcRect,
688 const SkIPoint& dstPoint) { 780 const SkIPoint& dstPoint) {
689 if (getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { 781 GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(this, dst, src,
782 srcRect, dstPoint);
783 this->recordTraceMarkersIfNecessary(cmd);
784 return SkToBool(cmd);
785 }
786
787 GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrInOrderDrawBuffer* iodb,
788 GrSurface* dst,
789 GrSurface* src,
790 const SkIRect& srcRec t,
791 const SkIPoint& dstPo int) {
792 if (iodb->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) {
690 this->closeBatch(); 793 this->closeBatch();
691 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst , src)); 794 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst , src));
692 cs->fSrcRect = srcRect; 795 cs->fSrcRect = srcRect;
693 cs->fDstPoint = dstPoint; 796 cs->fDstPoint = dstPoint;
694 this->recordTraceMarkersIfNecessary(cs); 797 return cs;
695 return true;
696 } 798 }
697 return false; 799 return NULL;
698 } 800 }
699 801
700 bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc, 802 bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb,
701 const PipelineInfo& pipelin eInfo) { 803 const GrPrimitiveProcessor* pr imProc,
804 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
702 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (primProc)); 805 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (primProc));
703 this->setupPipeline(pipelineInfo, ss->pipelineLocation()); 806 iodb->setupPipeline(pipelineInfo, ss->pipelineLocation());
704 807
705 if (ss->getPipeline()->mustSkip()) { 808 if (ss->getPipeline()->mustSkip()) {
706 fCmdBuffer.pop_back(); 809 fCmdBuffer.pop_back();
707 return false; 810 return false;
708 } 811 }
709 812
710 ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, 813 ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker,
711 ss->getPipeline()->getInitBatchTra cker()); 814 ss->getPipeline()->getInitBatchTra cker());
712 815
713 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && 816 if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
714 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, 817 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
715 *ss->fPrimitiveProcessor, 818 *ss->fPrimitiveProcessor,
716 ss->fBatchTracker) && 819 ss->fBatchTracker) &&
717 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { 820 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) {
718 fCmdBuffer.pop_back(); 821 fCmdBuffer.pop_back();
719 } else { 822 } else {
720 fPrevState = ss; 823 fPrevState = ss;
721 this->recordTraceMarkersIfNecessary(ss); 824 iodb->recordTraceMarkersIfNecessary(ss);
722 } 825 }
723 return true; 826 return true;
724 } 827 }
725 828
726 bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, 829 bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb,
727 const PipelineInfo& pipelin eInfo) { 830 GrBatch* batch,
831 const GrDrawTarget::PipelineIn fo& pipelineInfo) {
728 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, ()); 832 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, ());
729 this->setupPipeline(pipelineInfo, ss->pipelineLocation()); 833 iodb->setupPipeline(pipelineInfo, ss->pipelineLocation());
730 834
731 if (ss->getPipeline()->mustSkip()) { 835 if (ss->getPipeline()->mustSkip()) {
732 fCmdBuffer.pop_back(); 836 fCmdBuffer.pop_back();
733 return false; 837 return false;
734 } 838 }
735 839
736 batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); 840 batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker());
737 841
738 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && 842 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
739 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { 843 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) {
740 fCmdBuffer.pop_back(); 844 fCmdBuffer.pop_back();
741 } else { 845 } else {
742 this->closeBatch(); 846 this->closeBatch();
743 fPrevState = ss; 847 fPrevState = ss;
744 this->recordTraceMarkersIfNecessary(ss); 848 iodb->recordTraceMarkersIfNecessary(ss);
745 } 849 }
746 return true; 850 return true;
747 } 851 }
748 852
749 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(Cmd* cmd) { 853 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c md) {
750 if (!cmd) { 854 if (!cmd) {
751 return; 855 return;
752 } 856 }
753 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 857 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
754 if (activeTraceMarkers.count() > 0) { 858 if (activeTraceMarkers.count() > 0) {
755 if (cmd->isTraced()) { 859 if (cmd->isTraced()) {
756 fGpuCmdMarkers.back().addSet(activeTraceMarkers); 860 fGpuCmdMarkers.back().addSet(activeTraceMarkers);
757 } else { 861 } else {
758 cmd->makeTraced(); 862 cmd->makeTraced();
759 fGpuCmdMarkers.push_back(activeTraceMarkers); 863 fGpuCmdMarkers.push_back(activeTraceMarkers);
760 } 864 }
761 } 865 }
762 } 866 }
763 867
764 void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, 868 void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount,
765 size_t vertexStride, 869 size_t vertexStride,
766 int indexCount) { 870 int indexCount) {
767 this->closeBatch(); 871 fCommands.closeBatch();
768 872
769 this->INHERITED::willReserveVertexAndIndexSpace(vertexCount, vertexStride, i ndexCount); 873 this->INHERITED::willReserveVertexAndIndexSpace(vertexCount, vertexStride, i ndexCount);
770 } 874 }
OLDNEW
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698