Index: src/gpu/GrBatch.cpp |
diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp |
index ce30499ff8d4b4202c92170f6b5844158591355a..1ef6c9797c1f4b08e8d1b8ad945706841b2b7d00 100644 |
--- a/src/gpu/GrBatch.cpp |
+++ b/src/gpu/GrBatch.cpp |
@@ -6,6 +6,8 @@ |
*/ |
#include "GrBatch.h" |
+#include "GrBatchTarget.h" |
+#include "GrResourceProvider.h" |
#include "GrMemoryPool.h" |
#include "SkSpinlock.h" |
@@ -43,3 +45,43 @@ void* GrBatch::operator new(size_t size) { |
void GrBatch::operator delete(void* target) { |
return MemoryPoolAccessor().pool()->release(target); |
} |
+ |
+void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, size_t vertexStride, |
+ const GrIndexBuffer* indexBuffer, int verticesPerInstance, |
+ int indicesPerInstance, int instancesToDraw) { |
+ SkASSERT(!fInstancesRemaining); |
+ SkASSERT(batchTarget); |
+ if (!indexBuffer) { |
+ return NULL; |
+ } |
+ const GrVertexBuffer* vertexBuffer; |
+ int firstVertex; |
+ int vertexCount = verticesPerInstance * instancesToDraw; |
+ void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, vertexCount, &vertexBuffer, |
+ &firstVertex); |
+ if (!vertices) { |
+ SkDebugf("Vertices could not be allocated for instanced rendering."); |
+ return NULL; |
+ } |
+ SkASSERT(vertexBuffer); |
+ fInstancesRemaining = instancesToDraw; |
+ |
+ fDrawInfo.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, |
+ firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaining, |
+ indexBuffer->maxQuads()); |
+ size_t ibSize = fDrawInfo.indexBuffer()->gpuMemorySize(); |
+ fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance)); |
+ SkASSERT(fMaxInstancesPerDraw > 0); |
+ return vertices; |
+} |
+ |
+void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw) { |
+ SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( |
+ batchTarget->resourceProvider()->refQuadIndexBuffer()); |
+ if (!quadIndexBuffer) { |
+ SkDebugf("Could not get quad index buffer."); |
+ return NULL; |
+ } |
+ return this->INHERITED::init(batchTarget, vertexStride, quadIndexBuffer, kVerticesPerQuad, |
+ kIndicesPerQuad, quadsToDraw); |
+} |