| OLD | NEW |
| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return instancesToConcat; | 238 return instancesToConcat; |
| 239 } | 239 } |
| 240 | 240 |
| 241 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, | 241 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, |
| 242 const GrGeometryProcessor* gp, | 242 const GrGeometryProcessor* gp, |
| 243 const DrawInfo& info, | 243 const DrawInfo& info, |
| 244 const GrScissorState& scissorState, | 244 const GrScissorState& scissorState, |
| 245 const GrDeviceCoordTexture* dstCopy) { | 245 const GrDeviceCoordTexture* dstCopy) { |
| 246 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); | 246 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
| 247 | 247 |
| 248 if (!this->recordStateAndShouldDraw(ds, gp, | 248 if (!this->recordStateAndShouldDraw(ds, gp, scissorState, dstCopy)) { |
| 249 GrGpu::PrimTypeToDrawType(info.primitive
Type()), | |
| 250 scissorState, dstCopy)) { | |
| 251 return; | 249 return; |
| 252 } | 250 } |
| 253 | 251 |
| 254 Draw* draw; | 252 Draw* draw; |
| 255 if (info.isInstanced()) { | 253 if (info.isInstanced()) { |
| 256 int instancesConcated = this->concatInstancedDraw(ds, info); | 254 int instancesConcated = this->concatInstancedDraw(ds, info); |
| 257 if (info.instanceCount() > instancesConcated) { | 255 if (info.instanceCount() > instancesConcated) { |
| 258 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); | 256 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
| 259 draw->fInfo.adjustInstanceCount(-instancesConcated); | 257 draw->fInfo.adjustInstanceCount(-instancesConcated); |
| 260 } else { | 258 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 280 this->recordTraceMarkersIfNecessary(); | 278 this->recordTraceMarkersIfNecessary(); |
| 281 } | 279 } |
| 282 | 280 |
| 283 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, | 281 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, |
| 284 const GrPathProcessor* pathProc, | 282 const GrPathProcessor* pathProc, |
| 285 const GrPath* path, | 283 const GrPath* path, |
| 286 const GrScissorState& scissorState, | 284 const GrScissorState& scissorState, |
| 287 const GrStencilSettings& stencilSettings, | 285 const GrStencilSettings& stencilSettings, |
| 288 const GrDeviceCoordTexture* dstCopy) { | 286 const GrDeviceCoordTexture* dstCopy) { |
| 289 // TODO: Only compare the subset of GrDrawState relevant to path covering? | 287 // TODO: Only compare the subset of GrDrawState relevant to path covering? |
| 290 if (!this->recordStateAndShouldDraw(ds, pathProc, GrGpu::kDrawPath_DrawType, | 288 if (!this->recordStateAndShouldDraw(ds, pathProc, scissorState, dstCopy)) { |
| 291 scissorState, dstCopy)) { | |
| 292 return; | 289 return; |
| 293 } | 290 } |
| 294 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); | 291 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
| 295 dp->fStencilSettings = stencilSettings; | 292 dp->fStencilSettings = stencilSettings; |
| 296 this->recordTraceMarkersIfNecessary(); | 293 this->recordTraceMarkersIfNecessary(); |
| 297 } | 294 } |
| 298 | 295 |
| 299 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, | 296 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, |
| 300 const GrPathProcessor* pathProc, | 297 const GrPathProcessor* pathProc, |
| 301 const GrPathRange* pathRange, | 298 const GrPathRange* pathRange, |
| 302 const void* indices, | 299 const void* indices, |
| 303 PathIndexType indexType, | 300 PathIndexType indexType, |
| 304 const float transformValues[], | 301 const float transformValues[], |
| 305 PathTransformType transformType, | 302 PathTransformType transformType, |
| 306 int count, | 303 int count, |
| 307 const GrScissorState& scissorState, | 304 const GrScissorState& scissorState, |
| 308 const GrStencilSettings& stencilSettings, | 305 const GrStencilSettings& stencilSettings, |
| 309 const GrDeviceCoordTexture* dstCopy) { | 306 const GrDeviceCoordTexture* dstCopy) { |
| 310 SkASSERT(pathRange); | 307 SkASSERT(pathRange); |
| 311 SkASSERT(indices); | 308 SkASSERT(indices); |
| 312 SkASSERT(transformValues); | 309 SkASSERT(transformValues); |
| 313 | 310 |
| 314 if (!this->recordStateAndShouldDraw(ds, pathProc, GrGpu::kDrawPath_DrawType,
scissorState, | 311 if (!this->recordStateAndShouldDraw(ds, pathProc, scissorState, dstCopy)) { |
| 315 dstCopy)) { | |
| 316 return; | 312 return; |
| 317 } | 313 } |
| 318 | 314 |
| 319 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); | 315 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 320 if (int misalign = fPathIndexBuffer.count() % indexBytes) { | 316 if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
| 321 // Add padding to the index buffer so the indices are aligned properly. | 317 // Add padding to the index buffer so the indices are aligned properly. |
| 322 fPathIndexBuffer.append(indexBytes - misalign); | 318 fPathIndexBuffer.append(indexBytes - misalign); |
| 323 } | 319 } |
| 324 | 320 |
| 325 char* savedIndices = fPathIndexBuffer.append(count * indexBytes, | 321 char* savedIndices = fPathIndexBuffer.append(count * indexBytes, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 traceString = fGpuCmdMarkers[currCmdMarker].toString(); | 424 traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
| 429 newMarker.fMarker = traceString.c_str(); | 425 newMarker.fMarker = traceString.c_str(); |
| 430 this->getGpu()->addGpuTraceMarker(&newMarker); | 426 this->getGpu()->addGpuTraceMarker(&newMarker); |
| 431 ++currCmdMarker; | 427 ++currCmdMarker; |
| 432 } | 428 } |
| 433 | 429 |
| 434 if (kSetState_Cmd == strip_trace_bit(iter->fType)) { | 430 if (kSetState_Cmd == strip_trace_bit(iter->fType)) { |
| 435 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | 431 SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
| 436 | 432 |
| 437 this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcesso
r, ss->fState, | 433 this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcesso
r, ss->fState, |
| 438 ss->fState.descInfo(), ss->fDrawTyp
e, | 434 ss->fState.descInfo(), ss->fBatchTr
acker); |
| 439 ss->fBatchTracker); | |
| 440 currentState = ss; | 435 currentState = ss; |
| 441 | 436 |
| 442 } else { | 437 } else { |
| 443 iter->execute(this, currentState); | 438 iter->execute(this, currentState); |
| 444 } | 439 } |
| 445 | 440 |
| 446 if (cmd_has_trace_marker(iter->fType)) { | 441 if (cmd_has_trace_marker(iter->fType)) { |
| 447 this->getGpu()->removeGpuTraceMarker(&newMarker); | 442 this->getGpu()->removeGpuTraceMarker(&newMarker); |
| 448 } | 443 } |
| 449 } | 444 } |
| 450 | 445 |
| 451 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); | 446 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
| 452 ++fDrawID; | 447 ++fDrawID; |
| 453 } | 448 } |
| 454 | 449 |
| 455 void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState
* state) { | 450 void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState
* state) { |
| 456 SkASSERT(state); | 451 SkASSERT(state); |
| 457 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, | 452 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, |
| 458 &state->fBatchTracker, state->fDrawType); | 453 &state->fBatchTracker); |
| 459 buf->getGpu()->draw(args, fInfo); | 454 buf->getGpu()->draw(args, fInfo); |
| 460 } | 455 } |
| 461 | 456 |
| 462 void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const S
etState*) { | 457 void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const S
etState*) { |
| 463 GrGpu::StencilPathState state; | 458 GrGpu::StencilPathState state; |
| 464 state.fRenderTarget = fRenderTarget.get(); | 459 state.fRenderTarget = fRenderTarget.get(); |
| 465 state.fScissor = &fScissor; | 460 state.fScissor = &fScissor; |
| 466 state.fStencil = &fStencil; | 461 state.fStencil = &fStencil; |
| 467 state.fUseHWAA = fUseHWAA; | 462 state.fUseHWAA = fUseHWAA; |
| 468 state.fViewMatrix = &fViewMatrix; | 463 state.fViewMatrix = &fViewMatrix; |
| 469 | 464 |
| 470 buf->getGpu()->stencilPath(this->path(), state); | 465 buf->getGpu()->stencilPath(this->path(), state); |
| 471 } | 466 } |
| 472 | 467 |
| 473 void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetS
tate* state) { | 468 void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetS
tate* state) { |
| 474 SkASSERT(state); | 469 SkASSERT(state); |
| 475 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, | 470 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, |
| 476 &state->fBatchTracker, state->fDrawType); | 471 &state->fBatchTracker); |
| 477 buf->getGpu()->drawPath(args, this->path(), fStencilSettings); | 472 buf->getGpu()->drawPath(args, this->path(), fStencilSettings); |
| 478 } | 473 } |
| 479 | 474 |
| 480 void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const Set
State* state) { | 475 void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const Set
State* state) { |
| 481 SkASSERT(state); | 476 SkASSERT(state); |
| 482 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, | 477 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fState, &state->fDes
c, |
| 483 &state->fBatchTracker, state->fDrawType); | 478 &state->fBatchTracker); |
| 484 buf->getGpu()->drawPaths(args, this->pathRange(), | 479 buf->getGpu()->drawPaths(args, this->pathRange(), |
| 485 &buf->fPathIndexBuffer[fIndicesLocation], fIndexType
, | 480 &buf->fPathIndexBuffer[fIndicesLocation], fIndexType
, |
| 486 &buf->fPathTransformBuffer[fTransformsLocation], fTr
ansformType, | 481 &buf->fPathTransformBuffer[fTransformsLocation], fTr
ansformType, |
| 487 fCount, fStencilSettings); | 482 fCount, fStencilSettings); |
| 488 } | 483 } |
| 489 | 484 |
| 490 void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState
*) {} | 485 void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState
*) {} |
| 491 | 486 |
| 492 void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetStat
e*) { | 487 void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetStat
e*) { |
| 493 if (GrColor_ILLEGAL == fColor) { | 488 if (GrColor_ILLEGAL == fColor) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 514 cs->fSrcRect = srcRect; | 509 cs->fSrcRect = srcRect; |
| 515 cs->fDstPoint = dstPoint; | 510 cs->fDstPoint = dstPoint; |
| 516 this->recordTraceMarkersIfNecessary(); | 511 this->recordTraceMarkersIfNecessary(); |
| 517 return true; | 512 return true; |
| 518 } | 513 } |
| 519 return false; | 514 return false; |
| 520 } | 515 } |
| 521 | 516 |
| 522 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, | 517 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, |
| 523 const GrPrimitiveProcessor* p
rimProc, | 518 const GrPrimitiveProcessor* p
rimProc, |
| 524 GrGpu::DrawType drawType, | |
| 525 const GrScissorState& scissor
, | 519 const GrScissorState& scissor
, |
| 526 const GrDeviceCoordTexture* d
stCopy) { | 520 const GrDeviceCoordTexture* d
stCopy) { |
| 527 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, | 521 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
| 528 (ds, primProc, *this->getGpu()->caps
(), scissor, | 522 (ds, primProc, *this->getGpu()->caps
(), scissor, |
| 529 dstCopy, drawType)); | 523 dstCopy)); |
| 530 if (ss->fState.mustSkip()) { | 524 if (ss->fState.mustSkip()) { |
| 531 fCmdBuffer.pop_back(); | 525 fCmdBuffer.pop_back(); |
| 532 return false; | 526 return false; |
| 533 } | 527 } |
| 534 | 528 |
| 535 ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, | 529 ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
| 536 ss->fState.getInitBatchTracker()); | 530 ss->fState.getInitBatchTracker()); |
| 537 | 531 |
| 538 if (fPrevState && | 532 if (fPrevState && |
| 539 fPrevState->fDrawType == ss->fDrawType && | |
| 540 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | 533 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 541 *ss->fPrimitiveProcessor, | 534 *ss->fPrimitiveProcessor, |
| 542 ss->fBatchTracker) && | 535 ss->fBatchTracker) && |
| 543 fPrevState->fState.isEqual(ss->fState)) { | 536 fPrevState->fState.isEqual(ss->fState)) { |
| 544 fCmdBuffer.pop_back(); | 537 fCmdBuffer.pop_back(); |
| 545 } else { | 538 } else { |
| 546 fPrevState = ss; | 539 fPrevState = ss; |
| 547 this->recordTraceMarkersIfNecessary(); | 540 this->recordTraceMarkersIfNecessary(); |
| 548 } | 541 } |
| 549 return true; | 542 return true; |
| 550 } | 543 } |
| 551 | 544 |
| 552 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 545 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 553 SkASSERT(!fCmdBuffer.empty()); | 546 SkASSERT(!fCmdBuffer.empty()); |
| 554 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 547 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
| 555 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 548 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 556 if (activeTraceMarkers.count() > 0) { | 549 if (activeTraceMarkers.count() > 0) { |
| 557 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 550 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
| 558 fGpuCmdMarkers.push_back(activeTraceMarkers); | 551 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 559 } | 552 } |
| 560 } | 553 } |
| OLD | NEW |