| Index: src/gpu/GrBatch.cpp
|
| diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp
|
| index ce30499ff8d4b4202c92170f6b5844158591355a..38ab1429a2f87766c3afe192946f7620c6a5128b 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,44 @@ void* GrBatch::operator new(size_t size) {
|
| void GrBatch::operator delete(void* target) {
|
| return MemoryPoolAccessor().pool()->release(target);
|
| }
|
| +
|
| +void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType,
|
| + 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;
|
| + size_t ibSize = indexBuffer->gpuMemorySize();
|
| + fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
|
| +
|
| + fDrawInfo.initInstanced(primType, vertexBuffer, indexBuffer,
|
| + firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaining,
|
| + fMaxInstancesPerDraw);
|
| + 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, kTriangles_GrPrimitiveType, vertexStride,
|
| + quadIndexBuffer, kVerticesPerQuad, kIndicesPerQuad, quadsToDraw);
|
| +}
|
|
|