Index: src/gpu/GrInOrderDrawBuffer.cpp |
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp |
index 468045c6340a639feea92386dab66425df5eb2e2..363fcdf3ecee40cd5f746bb48d5f873239531887 100644 |
--- a/src/gpu/GrInOrderDrawBuffer.cpp |
+++ b/src/gpu/GrInOrderDrawBuffer.cpp |
@@ -266,6 +266,32 @@ void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, |
this->recordTraceMarkersIfNecessary(); |
} |
+void GrInOrderDrawBuffer::onBatchDraw(GrBatch* batch, |
+ const GrDrawState& ds, |
+ GrPrimitiveType type, |
+ const GrScissorState& scissorState, |
+ const GrDeviceCoordTexture* dstCopy) { |
+ if (!this->recordStateAndShouldDraw(batch, ds, GrGpu::PrimTypeToDrawType(type), scissorState, |
+ dstCopy)) { |
+ return; |
+ } |
+ |
+ // Check if there is a Batch Draw we can batch with |
+ if (kBatchDraw != strip_trace_bit(fCmdBuffer.back().fType)) { |
+ GrNEW_APPEND_TO_RECORDER(fCmdBuffer, BatchDraw, (batch)); |
+ return; |
+ } |
+ |
+ BatchDraw* draw = static_cast<BatchDraw*>(&fCmdBuffer.back()); |
+ if (draw->fBatch->canMakeEqual(*batch)) { |
bsalomon
2015/01/20 16:14:03
probably want to rename these... canMerge? canComb
|
+ draw->fBatch->makeEqual(batch); |
+ return; |
+ } else { |
+ GrNEW_APPEND_TO_RECORDER(fCmdBuffer, BatchDraw, (batch)); |
+ } |
+ this->recordTraceMarkersIfNecessary(); |
+} |
+ |
void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, |
const GrPathProcessor* pathProc, |
const GrPath* path, |
@@ -434,7 +460,10 @@ void GrInOrderDrawBuffer::onFlush() { |
if (kSetState_Cmd == strip_trace_bit(iter->fType)) { |
SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
currentOptState = &ss->fState; |
- currentOptState->finalize(this->getGpu()); |
+ // Batch draws will finalize later. TODO remove this when we use batch everywhere |
+ if (currentOptState->getPrimitiveProcessor()) { |
+ currentOptState->finalize(this->getGpu()); |
+ } |
} else { |
iter->execute(this, currentOptState); |
} |
@@ -479,6 +508,14 @@ void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, |
fCount, fStencilSettings); |
} |
+void GrInOrderDrawBuffer::BatchDraw::execute(GrInOrderDrawBuffer* buf, |
+ const GrOptDrawState* optState) { |
+ SkASSERT(optState); |
+ fBatch->generateGeometry(buf->getGpu(), buf->getVertexAllocPool(), buf->getIndexAllocPool(), |
+ const_cast<GrOptDrawState*>(optState)); |
+ fBatch->draw(buf->getGpu(), const_cast<GrOptDrawState*>(optState)); |
+} |
+ |
void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {} |
void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) { |
@@ -520,6 +557,24 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, |
SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
(ds, primProc, *this->getGpu()->caps(), scissor, |
dstCopy, drawType)); |
+ return recordStateAndShouldDraw(ss); |
+} |
+ |
+bool GrInOrderDrawBuffer::recordStateAndShouldDraw(GrBatch* batch, |
+ const GrDrawState& ds, |
+ GrGpu::DrawType drawType, |
+ const GrScissorState& scissor, |
+ const GrDeviceCoordTexture* dstCopy) { |
+ // TODO this gets much simpler when we have batches everywhere. |
+ // If the previous command is also a set state, then we check to see if it has a Batch. If so, |
+ // and we can make the two batches equal, and we can combine the states, then we make them equal |
+ SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
+ (batch, ds, *this->getGpu()->caps(), scissor, |
+ dstCopy, drawType)); |
+ return recordStateAndShouldDraw(ss); |
+} |
+ |
+bool GrInOrderDrawBuffer::recordStateAndShouldDraw(SetState* ss) { |
if (ss->fState.mustSkip()) { |
fCmdBuffer.pop_back(); |
return false; |