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 void* GrBatch::operator new(size_t size) { | 43 void* GrBatch::operator new(size_t size) { |
44 return MemoryPoolAccessor().pool()->allocate(size); | 44 return MemoryPoolAccessor().pool()->allocate(size); |
45 } | 45 } |
46 | 46 |
47 void GrBatch::operator delete(void* target) { | 47 void GrBatch::operator delete(void* target) { |
48 return MemoryPoolAccessor().pool()->release(target); | 48 return MemoryPoolAccessor().pool()->release(target); |
49 } | 49 } |
50 | 50 |
51 GrBatch::GrBatch() | 51 GrBatch::GrBatch() |
52 : fClassID(kIllegalBatchID) | 52 : fClassID(kIllegalBatchID) |
53 , fNumberOfDraws(0) | |
54 , fPipelineInstalled(false) | |
55 #if GR_BATCH_SPEW | 53 #if GR_BATCH_SPEW |
56 , fUniqueID(GenID(&gCurrBatchUniqueID)) | 54 , fUniqueID(GenID(&gCurrBatchUniqueID)) |
57 #endif | 55 #endif |
58 { | 56 { |
59 SkDEBUGCODE(fUsed = false;) | 57 SkDEBUGCODE(fUsed = false;) |
60 } | 58 } |
61 | 59 |
62 GrBatch::~GrBatch() { | 60 GrBatch::~GrBatch() {} |
| 61 |
| 62 ////////////////////////////////////////////////////////////////////////////// |
| 63 |
| 64 GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { } |
| 65 |
| 66 GrDrawBatch::~GrDrawBatch() { |
63 if (fPipelineInstalled) { | 67 if (fPipelineInstalled) { |
64 this->pipeline()->~GrPipeline(); | 68 this->pipeline()->~GrPipeline(); |
65 } | 69 } |
66 } | 70 } |
67 | 71 |
68 void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType
primType, | 72 bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) { |
| 73 GrPipelineOptimizations opts; |
| 74 void* location = fPipelineStorage.get(); |
| 75 if (!GrPipeline::CreateAt(location, args, &opts)) { |
| 76 return false; |
| 77 } |
| 78 this->initBatchTracker(opts); |
| 79 fPipelineInstalled = true; |
| 80 return true; |
| 81 } |
| 82 |
| 83 ////////////////////////////////////////////////////////////////////////////// |
| 84 |
| 85 GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {} |
| 86 |
| 87 void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimiti
veType primType, |
69 size_t vertexStride, const GrIndexBuffer* i
ndexBuffer, | 88 size_t vertexStride, const GrIndexBuffer* i
ndexBuffer, |
70 int verticesPerInstance, int indicesPerInst
ance, | 89 int verticesPerInstance, int indicesPerInst
ance, |
71 int instancesToDraw) { | 90 int instancesToDraw) { |
72 SkASSERT(batchTarget); | 91 SkASSERT(batchTarget); |
73 if (!indexBuffer) { | 92 if (!indexBuffer) { |
74 return NULL; | 93 return NULL; |
75 } | 94 } |
76 const GrVertexBuffer* vertexBuffer; | 95 const GrVertexBuffer* vertexBuffer; |
77 int firstVertex; | 96 int firstVertex; |
78 int vertexCount = verticesPerInstance * instancesToDraw; | 97 int vertexCount = verticesPerInstance * instancesToDraw; |
79 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, | 98 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, |
80 &vertexBuffer, &firstVertex); | 99 &vertexBuffer, &firstVertex); |
81 if (!vertices) { | 100 if (!vertices) { |
82 SkDebugf("Vertices could not be allocated for instanced rendering."); | 101 SkDebugf("Vertices could not be allocated for instanced rendering."); |
83 return NULL; | 102 return NULL; |
84 } | 103 } |
85 SkASSERT(vertexBuffer); | 104 SkASSERT(vertexBuffer); |
86 size_t ibSize = indexBuffer->gpuMemorySize(); | 105 size_t ibSize = indexBuffer->gpuMemorySize(); |
87 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi
cesPerInstance)); | 106 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi
cesPerInstance)); |
88 | 107 |
89 fVertices.initInstanced(primType, vertexBuffer, indexBuffer, | 108 fVertices.initInstanced(primType, vertexBuffer, indexBuffer, |
90 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, | 109 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, |
91 maxInstancesPerDraw); | 110 maxInstancesPerDraw); |
92 return vertices; | 111 return vertices; |
93 } | 112 } |
94 | 113 |
95 void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride,
int quadsToDraw) { | 114 void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexS
tride, |
| 115 int quadsToDraw) { |
96 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( | 116 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( |
97 batchTarget->resourceProvider()->refQuadIndexBuffer()); | 117 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
98 if (!quadIndexBuffer) { | 118 if (!quadIndexBuffer) { |
99 SkDebugf("Could not get quad index buffer."); | 119 SkDebugf("Could not get quad index buffer."); |
100 return NULL; | 120 return NULL; |
101 } | 121 } |
102 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex
Stride, | 122 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex
Stride, |
103 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ
uad, quadsToDraw); | 123 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ
uad, quadsToDraw); |
104 } | 124 } |
105 | |
106 bool GrBatch::installPipeline(const GrPipeline::CreateArgs& args) { | |
107 GrPipelineOptimizations opts; | |
108 void* location = fPipelineStorage.get(); | |
109 if (!GrPipeline::CreateAt(location, args, &opts)) { | |
110 return false; | |
111 } | |
112 this->initBatchTracker(opts); | |
113 fPipelineInstalled = true; | |
114 return true; | |
115 } | |
OLD | NEW |