| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrBatch.h" | 8 #include "GrBatch.h" |
| 9 #include "GrBatchTarget.h" | 9 #include "GrBatchTarget.h" |
| 10 #include "GrResourceProvider.h" | 10 #include "GrResourceProvider.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 void GrBatch::operator delete(void* target) { | 45 void GrBatch::operator delete(void* target) { |
| 46 return MemoryPoolAccessor().pool()->release(target); | 46 return MemoryPoolAccessor().pool()->release(target); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType
primType, | 49 void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType
primType, |
| 50 size_t vertexStride, const GrIndexBuffer* i
ndexBuffer, | 50 size_t vertexStride, const GrIndexBuffer* i
ndexBuffer, |
| 51 int verticesPerInstance, int indicesPerInst
ance, | 51 int verticesPerInstance, int indicesPerInst
ance, |
| 52 int instancesToDraw) { | 52 int instancesToDraw) { |
| 53 SkASSERT(!fInstancesRemaining); | |
| 54 SkASSERT(batchTarget); | 53 SkASSERT(batchTarget); |
| 55 if (!indexBuffer) { | 54 if (!indexBuffer) { |
| 56 return NULL; | 55 return NULL; |
| 57 } | 56 } |
| 58 const GrVertexBuffer* vertexBuffer; | 57 const GrVertexBuffer* vertexBuffer; |
| 59 int firstVertex; | 58 int firstVertex; |
| 60 int vertexCount = verticesPerInstance * instancesToDraw; | 59 int vertexCount = verticesPerInstance * instancesToDraw; |
| 61 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, | 60 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, |
| 62 &vertexBuffer, &firstVertex); | 61 &vertexBuffer, &firstVertex); |
| 63 if (!vertices) { | 62 if (!vertices) { |
| 64 SkDebugf("Vertices could not be allocated for instanced rendering."); | 63 SkDebugf("Vertices could not be allocated for instanced rendering."); |
| 65 return NULL; | 64 return NULL; |
| 66 } | 65 } |
| 67 SkASSERT(vertexBuffer); | 66 SkASSERT(vertexBuffer); |
| 68 fInstancesRemaining = instancesToDraw; | |
| 69 size_t ibSize = indexBuffer->gpuMemorySize(); | 67 size_t ibSize = indexBuffer->gpuMemorySize(); |
| 70 fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indices
PerInstance)); | 68 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi
cesPerInstance)); |
| 71 | 69 |
| 72 fVertices.initInstanced(primType, vertexBuffer, indexBuffer, | 70 fVertices.initInstanced(primType, vertexBuffer, indexBuffer, |
| 73 firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaini
ng, | 71 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, |
| 74 fMaxInstancesPerDraw); | 72 maxInstancesPerDraw); |
| 75 SkASSERT(fMaxInstancesPerDraw > 0); | |
| 76 return vertices; | 73 return vertices; |
| 77 } | 74 } |
| 78 | 75 |
| 79 void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride,
int quadsToDraw) { | 76 void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride,
int quadsToDraw) { |
| 80 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( | 77 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( |
| 81 batchTarget->resourceProvider()->refQuadIndexBuffer()); | 78 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 82 if (!quadIndexBuffer) { | 79 if (!quadIndexBuffer) { |
| 83 SkDebugf("Could not get quad index buffer."); | 80 SkDebugf("Could not get quad index buffer."); |
| 84 return NULL; | 81 return NULL; |
| 85 } | 82 } |
| 86 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex
Stride, | 83 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex
Stride, |
| 87 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ
uad, quadsToDraw); | 84 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ
uad, quadsToDraw); |
| 88 } | 85 } |
| OLD | NEW |