Chromium Code Reviews| Index: src/gpu/GrInOrderDrawBuffer.cpp |
| diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp |
| index 9835200598d76ddadb1cd94661b8d299b24c961b..00df4c62baa0c236ce28bf3292c83f9ddbfbdfcc 100644 |
| --- a/src/gpu/GrInOrderDrawBuffer.cpp |
| +++ b/src/gpu/GrInOrderDrawBuffer.cpp |
| @@ -32,6 +32,9 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
| SkASSERT(vertexPool); |
| SkASSERT(indexPool); |
| + fPathIndexBuffer.setReserve(kPathIdxBufferMinReserve); |
| + fPathTransformBuffer.setReserve(kPathXformBufferMinReserve); |
| + |
| GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| poolState.fUsedPoolVertexBytes = 0; |
| poolState.fUsedPoolIndexBytes = 0; |
| @@ -101,6 +104,42 @@ static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G |
| } |
| } |
| +static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) { |
| + static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face; |
| + bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| + if (isWinding) { |
| + // Double check that it is in fact winding. |
| + SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| + SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| + SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| + SkASSERT(!pathStencilSettings.isTwoSided()); |
| + } |
| + return isWinding; |
| +} |
| + |
| +static bool draw_uses_dst_color(const GrDrawState& drawState) { |
| + GrBlendCoeff dstBlendCoeff = drawState.getDstBlendCoeff(); |
| + if (kZero_GrBlendCoeff != dstBlendCoeff && |
| + (kISA_GrBlendCoeff != dstBlendCoeff || !drawState.srcAlphaWillBeOne())) { |
| + return true; |
| + } |
| + |
| + return drawState.willEffectReadDstColor(); |
|
Chris Dalton
2014/11/11 22:34:40
My understanding is that this should work. srcAlph
|
| +} |
| + |
| +template<typename T> static void reset_data_buffer(SkTDArray<T>* buffer, int minReserve) { |
| + // Assume the next time this buffer fills up it will use approximately the same amount |
| + // of space as last time. Only resize if we're using less than a third of the |
| + // allocated space, and leave enough for 50% growth over last time. |
| + if (3 * buffer->count() < buffer->reserved() && buffer->reserved() > minReserve) { |
| + int reserve = SkTMax(minReserve, buffer->count() * 3 / 2); |
| + buffer->reset(); |
| + buffer->setReserve(reserve); |
| + } else { |
| + buffer->rewind(); |
| + } |
| +} |
| + |
| enum { |
| kTraceCmdBit = 0x80, |
| kCmdMask = 0x7f, |
| @@ -333,15 +372,35 @@ void GrInOrderDrawBuffer::onDrawPaths(const GrPathRange* pathRange, |
| this->recordStateIfNecessary(); |
| - int sizeOfIndices = sizeof(uint32_t) * count; |
| - int sizeOfTransforms = sizeof(float) * count * |
| - GrPathRendering::PathTransformSize(transformsType); |
| + uint32_t* savedIndices = fPathIndexBuffer.append(count, indices); |
| + float* savedTransforms = fPathTransformBuffer.append(count * |
| + GrPathRendering::PathTransformSize(transformsType), transforms); |
| + |
| + if (kDrawPaths_Cmd == fCmdBuffer.back().fType) { |
| + // The previous command was also DrawPaths. Try to collapse this call into the one |
| + // before. Note that stencilling all the paths at once, then covering, may not be |
| + // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| + // and the combined calls may also cancel each other's winding numbers in some |
| + // places. For now the winding numbers are only an issue if the fill is even/odd, |
| + // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| + // font tend to all wind in the same direction. |
| + DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| + if (pathRange == previous->pathRange() && |
| + transformsType == previous->fTransformsType && |
| + scissorState == previous->fScissorState && |
| + stencilSettings == previous->fStencilSettings && |
| + path_fill_type_is_winding(stencilSettings) && |
| + !draw_uses_dst_color(this->getDrawState())) { |
| + // Fold this DrawPaths call into the one previous. |
| + previous->fCount += count; |
| + return; |
| + } |
| + } |
| - DrawPaths* dp = GrNEW_APPEND_WITH_DATA_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange), |
| - sizeOfIndices + sizeOfTransforms); |
| - memcpy(dp->indices(), indices, sizeOfIndices); |
| + DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
| + dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); |
| dp->fCount = count; |
| - memcpy(dp->transforms(), transforms, sizeOfTransforms); |
| + dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); |
| dp->fTransformsType = transformsType; |
| dp->fScissorState = scissorState; |
| dp->fStencilSettings = stencilSettings; |
| @@ -406,6 +465,8 @@ void GrInOrderDrawBuffer::reset() { |
| fLastState = NULL; |
| fVertexPool.reset(); |
| fIndexPool.reset(); |
| + reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
| + reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
| fGpuCmdMarkers.reset(); |
| } |
| @@ -452,7 +513,7 @@ void GrInOrderDrawBuffer::flush() { |
| kDrawPaths_Cmd == strip_trace_bit(iter->fType)); |
| SkASSERT(!isDraw || fDstGpu->drawState() != prevDrawState); |
| - iter->execute(fDstGpu); |
| + iter->execute(this); |
| if (cmd_has_trace_marker(iter->fType)) { |
| fDstGpu->removeGpuTraceMarker(&newMarker); |
| @@ -468,7 +529,8 @@ void GrInOrderDrawBuffer::flush() { |
| ++fDrawID; |
| } |
| -void GrInOrderDrawBuffer::Draw::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| gpu->setVertexSourceToBuffer(this->vertexBuffer()); |
| if (fInfo.isIndexed()) { |
| gpu->setIndexSourceToBuffer(this->indexBuffer()); |
| @@ -476,26 +538,31 @@ void GrInOrderDrawBuffer::Draw::execute(GrGpu* gpu) { |
| gpu->draw(fInfo, fScissorState); |
| } |
| -void GrInOrderDrawBuffer::StencilPath::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| gpu->stencilPath(this->path(), fScissorState, fStencilSettings); |
| } |
| -void GrInOrderDrawBuffer::DrawPath::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| gpu->drawPath(this->path(), fScissorState, fStencilSettings, |
| - fDstCopy.texture() ? &fDstCopy : NULL); |
| + fDstCopy.texture() ? &fDstCopy : NULL); |
| } |
| -void GrInOrderDrawBuffer::DrawPaths::execute(GrGpu* gpu) { |
| - gpu->drawPaths(this->pathRange(), this->indices(), fCount, this->transforms(), |
| - fTransformsType, fScissorState, fStencilSettings, |
| - fDstCopy.texture() ? &fDstCopy : NULL); |
| +void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| + gpu->drawPaths(this->pathRange(), buf->pathIndexBuffer() + fIndicesLocation, fCount, |
| + buf->pathTransformBuffer() + fTransformsLocation, fTransformsType, |
| + fScissorState, fStencilSettings, fDstCopy.texture() ? &fDstCopy : NULL); |
| } |
| -void GrInOrderDrawBuffer::SetState::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| gpu->setDrawState(&fState); |
| } |
| -void GrInOrderDrawBuffer::Clear::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| if (GrColor_ILLEGAL == fColor) { |
| gpu->discard(this->renderTarget()); |
| } else { |
| @@ -503,11 +570,13 @@ void GrInOrderDrawBuffer::Clear::execute(GrGpu* gpu) { |
| } |
| } |
| -void GrInOrderDrawBuffer::ClearStencilClip::execute(GrGpu* gpu) { |
| - gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
| +void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| + gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
| } |
| -void GrInOrderDrawBuffer::CopySurface::execute(GrGpu* gpu) { |
| +void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf) { |
| + GrGpu* gpu = buf->dstGpu(); |
| gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
| } |