blob: e9172108f33707485df1a39454121f5e21ad96f8 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com1c13c962011-02-14 16:51:21 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
bsalomon@google.com1c13c962011-02-14 16:51:21 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com1c13c962011-02-14 16:51:21 +000010#include "GrBufferAllocPool.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
robertphillips1b8e1b52015-06-24 06:54:10 -070012#include "GrContext.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000013#include "GrGpu.h"
14#include "GrIndexBuffer.h"
robertphillips1b8e1b52015-06-24 06:54:10 -070015#include "GrResourceProvider.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000016#include "GrTypes.h"
17#include "GrVertexBuffer.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000018
bsalomon3512eda2014-06-26 12:56:22 -070019#include "SkTraceEvent.h"
20
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000021#ifdef SK_DEBUG
bsalomon@google.com1c13c962011-02-14 16:51:21 +000022 #define VALIDATE validate
23#else
sugoi@google.come0e385c2013-03-11 18:50:03 +000024 static void VALIDATE(bool = false) {}
bsalomon@google.com1c13c962011-02-14 16:51:21 +000025#endif
26
robertphillips1b8e1b52015-06-24 06:54:10 -070027static const size_t MIN_VERTEX_BUFFER_SIZE = 1 << 15;
28static const size_t MIN_INDEX_BUFFER_SIZE = 1 << 12;
29
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000030// page size
joshualitt0709ca02015-06-04 09:13:46 -070031#define GrBufferAllocPool_MIN_BLOCK_SIZE ((size_t)1 << 15)
bsalomon@google.com1c13c962011-02-14 16:51:21 +000032
bsalomon3512eda2014-06-26 12:56:22 -070033#define UNMAP_BUFFER(block) \
34do { \
35 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), \
36 "GrBufferAllocPool Unmapping Buffer", \
37 TRACE_EVENT_SCOPE_THREAD, \
38 "percent_unwritten", \
39 (float)((block).fBytesFree) / (block).fBuffer->gpuMemorySize()); \
40 (block).fBuffer->unmap(); \
41} while (false)
42
bsalomon@google.com1c13c962011-02-14 16:51:21 +000043GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
44 BufferType bufferType,
robertphillips1b8e1b52015-06-24 06:54:10 -070045 size_t blockSize)
46 : fBlocks(8) {
bsalomon@google.com11f0b512011-03-29 20:52:23 +000047
bsalomonecb8e3e2015-04-29 04:33:52 -070048 fGpu = SkRef(gpu);
bsalomon@google.com11f0b512011-03-29 20:52:23 +000049
bsalomon@google.com1c13c962011-02-14 16:51:21 +000050 fBufferType = bufferType;
bsalomon@google.com1c13c962011-02-14 16:51:21 +000051 fBufferPtr = NULL;
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000052 fMinBlockSize = SkTMax(GrBufferAllocPool_MIN_BLOCK_SIZE, blockSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +000053
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000054 fBytesInUse = 0;
robertphillipseea2ff72015-05-14 05:24:53 -070055
joshualitt7224c862015-05-29 06:46:47 -070056 fGeometryBufferMapThreshold = gpu->caps()->geometryBufferMapThreshold();
bsalomon@google.com1c13c962011-02-14 16:51:21 +000057}
58
robertphillips1b8e1b52015-06-24 06:54:10 -070059void GrBufferAllocPool::deleteBlocks() {
bsalomon@google.com1c13c962011-02-14 16:51:21 +000060 if (fBlocks.count()) {
61 GrGeometryBuffer* buffer = fBlocks.back().fBuffer;
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000062 if (buffer->isMapped()) {
bsalomon3512eda2014-06-26 12:56:22 -070063 UNMAP_BUFFER(fBlocks.back());
bsalomon@google.com1c13c962011-02-14 16:51:21 +000064 }
65 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +000066 while (!fBlocks.empty()) {
robertphillips91d06bc2015-05-06 04:38:36 -070067 this->destroyBlock();
bsalomon@google.com1c13c962011-02-14 16:51:21 +000068 }
robertphillips1b8e1b52015-06-24 06:54:10 -070069 SkASSERT(!fBufferPtr);
70}
71
72GrBufferAllocPool::~GrBufferAllocPool() {
73 VALIDATE();
74 this->deleteBlocks();
bsalomonecb8e3e2015-04-29 04:33:52 -070075 fGpu->unref();
bsalomon@google.com1c13c962011-02-14 16:51:21 +000076}
77
78void GrBufferAllocPool::reset() {
79 VALIDATE();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000080 fBytesInUse = 0;
robertphillips1b8e1b52015-06-24 06:54:10 -070081 this->deleteBlocks();
bsalomon@google.com987dbc02011-12-14 14:44:19 +000082 // we may have created a large cpu mirror of a large VB. Reset the size
robertphillips1b8e1b52015-06-24 06:54:10 -070083 // to match our minimum.
bsalomon@google.com987dbc02011-12-14 14:44:19 +000084 fCpuData.reset(fMinBlockSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +000085 VALIDATE();
86}
87
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000088void GrBufferAllocPool::unmap() {
bsalomon@google.com1c13c962011-02-14 16:51:21 +000089 VALIDATE();
90
bsalomon49f085d2014-09-05 13:34:00 -070091 if (fBufferPtr) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +000092 BufferBlock& block = fBlocks.back();
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000093 if (block.fBuffer->isMapped()) {
bsalomon3512eda2014-06-26 12:56:22 -070094 UNMAP_BUFFER(block);
bsalomon@google.com1c13c962011-02-14 16:51:21 +000095 } else {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000096 size_t flushSize = block.fBuffer->gpuMemorySize() - block.fBytesFree;
bsalomon3512eda2014-06-26 12:56:22 -070097 this->flushCpuData(fBlocks.back(), flushSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +000098 }
99 fBufferPtr = NULL;
100 }
101 VALIDATE();
102}
103
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000104#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000105void GrBufferAllocPool::validate(bool unusedBlockAllowed) const {
bsalomon71cb0c22014-11-14 12:10:14 -0800106 bool wasDestroyed = false;
bsalomon49f085d2014-09-05 13:34:00 -0700107 if (fBufferPtr) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000108 SkASSERT(!fBlocks.empty());
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000109 if (fBlocks.back().fBuffer->isMapped()) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000110 GrGeometryBuffer* buf = fBlocks.back().fBuffer;
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000111 SkASSERT(buf->mapPtr() == fBufferPtr);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000112 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000113 SkASSERT(fCpuData.get() == fBufferPtr);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000114 }
115 } else {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000116 SkASSERT(fBlocks.empty() || !fBlocks.back().fBuffer->isMapped());
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000117 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000118 size_t bytesInUse = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000119 for (int i = 0; i < fBlocks.count() - 1; ++i) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000120 SkASSERT(!fBlocks[i].fBuffer->isMapped());
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000121 }
bsalomon71cb0c22014-11-14 12:10:14 -0800122 for (int i = 0; !wasDestroyed && i < fBlocks.count(); ++i) {
123 if (fBlocks[i].fBuffer->wasDestroyed()) {
124 wasDestroyed = true;
125 } else {
126 size_t bytes = fBlocks[i].fBuffer->gpuMemorySize() - fBlocks[i].fBytesFree;
127 bytesInUse += bytes;
128 SkASSERT(bytes || unusedBlockAllowed);
129 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000130 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000131
bsalomon71cb0c22014-11-14 12:10:14 -0800132 if (!wasDestroyed) {
133 SkASSERT(bytesInUse == fBytesInUse);
134 if (unusedBlockAllowed) {
135 SkASSERT((fBytesInUse && !fBlocks.empty()) ||
136 (!fBytesInUse && (fBlocks.count() < 2)));
137 } else {
138 SkASSERT((0 == fBytesInUse) == fBlocks.empty());
139 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000140 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000141}
142#endif
143
144void* GrBufferAllocPool::makeSpace(size_t size,
145 size_t alignment,
146 const GrGeometryBuffer** buffer,
147 size_t* offset) {
148 VALIDATE();
149
bsalomon49f085d2014-09-05 13:34:00 -0700150 SkASSERT(buffer);
151 SkASSERT(offset);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000152
bsalomon49f085d2014-09-05 13:34:00 -0700153 if (fBufferPtr) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000154 BufferBlock& back = fBlocks.back();
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000155 size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree;
robertphillips1b8e1b52015-06-24 06:54:10 -0700156 size_t pad = GrSizeAlignUpPad(usedBytes, alignment);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000157 if ((size + pad) <= back.fBytesFree) {
dongseong.hwang8f25c662015-01-22 10:40:20 -0800158 memset((void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes), 0, pad);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000159 usedBytes += pad;
160 *offset = usedBytes;
161 *buffer = back.fBuffer;
162 back.fBytesFree -= size + pad;
bsalomon@google.comd5108092012-03-08 15:10:39 +0000163 fBytesInUse += size + pad;
164 VALIDATE();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000165 return (void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes);
166 }
167 }
168
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000169 // We could honor the space request using by a partial update of the current
170 // VB (if there is room). But we don't currently use draw calls to GL that
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000171 // allow the driver to know that previously issued draws won't read from
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000172 // the part of the buffer we update. Also, the GL buffer implementation
173 // may be cheating on the actual buffer size by shrinking the buffer on
174 // updateData() if the amount of data passed is less than the full buffer
175 // size.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000176
robertphillips91d06bc2015-05-06 04:38:36 -0700177 if (!this->createBlock(size)) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000178 return NULL;
179 }
bsalomon49f085d2014-09-05 13:34:00 -0700180 SkASSERT(fBufferPtr);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000181
182 *offset = 0;
183 BufferBlock& back = fBlocks.back();
184 *buffer = back.fBuffer;
185 back.fBytesFree -= size;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000186 fBytesInUse += size;
187 VALIDATE();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000188 return fBufferPtr;
189}
190
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000191void GrBufferAllocPool::putBack(size_t bytes) {
192 VALIDATE();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000193
194 while (bytes) {
robertphillips91d06bc2015-05-06 04:38:36 -0700195 // caller shouldn't try to put back more than they've taken
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000196 SkASSERT(!fBlocks.empty());
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000197 BufferBlock& block = fBlocks.back();
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000198 size_t bytesUsed = block.fBuffer->gpuMemorySize() - block.fBytesFree;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000199 if (bytes >= bytesUsed) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000200 bytes -= bytesUsed;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000201 fBytesInUse -= bytesUsed;
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000202 // if we locked a vb to satisfy the make space and we're releasing
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000203 // beyond it, then unmap it.
204 if (block.fBuffer->isMapped()) {
bsalomon3512eda2014-06-26 12:56:22 -0700205 UNMAP_BUFFER(block);
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000206 }
207 this->destroyBlock();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000208 } else {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000209 block.fBytesFree += bytes;
210 fBytesInUse -= bytes;
211 bytes = 0;
212 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000213 }
214 }
robertphillips1b8e1b52015-06-24 06:54:10 -0700215
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000216 VALIDATE();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000217}
218
219bool GrBufferAllocPool::createBlock(size_t requestSize) {
220
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000221 size_t size = SkTMax(requestSize, fMinBlockSize);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000222 SkASSERT(size >= GrBufferAllocPool_MIN_BLOCK_SIZE);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000223
224 VALIDATE();
225
226 BufferBlock& block = fBlocks.push_back();
227
robertphillips1b8e1b52015-06-24 06:54:10 -0700228 block.fBuffer = this->getBuffer(size);
229 if (NULL == block.fBuffer) {
230 fBlocks.pop_back();
231 return false;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000232 }
233
robertphillips1b8e1b52015-06-24 06:54:10 -0700234 block.fBytesFree = block.fBuffer->gpuMemorySize();
bsalomon49f085d2014-09-05 13:34:00 -0700235 if (fBufferPtr) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000236 SkASSERT(fBlocks.count() > 1);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000237 BufferBlock& prev = fBlocks.fromBack(1);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000238 if (prev.fBuffer->isMapped()) {
bsalomon3512eda2014-06-26 12:56:22 -0700239 UNMAP_BUFFER(prev);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000240 } else {
bsalomon3512eda2014-06-26 12:56:22 -0700241 this->flushCpuData(prev, prev.fBuffer->gpuMemorySize() - prev.fBytesFree);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000242 }
243 fBufferPtr = NULL;
244 }
245
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000246 SkASSERT(NULL == fBufferPtr);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000247
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000248 // If the buffer is CPU-backed we map it because it is free to do so and saves a copy.
bsalomonecb8e3e2015-04-29 04:33:52 -0700249 // Otherwise when buffer mapping is supported we map if the buffer size is greater than the
250 // threshold.
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000251 bool attemptMap = block.fBuffer->isCPUBacked();
bsalomon4b91f762015-05-19 09:29:46 -0700252 if (!attemptMap && GrCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags()) {
joshualitt7224c862015-05-29 06:46:47 -0700253 attemptMap = size > fGeometryBufferMapThreshold;
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +0000254 }
255
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000256 if (attemptMap) {
257 fBufferPtr = block.fBuffer->map();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000258 }
259
260 if (NULL == fBufferPtr) {
robertphillips1b8e1b52015-06-24 06:54:10 -0700261 fBufferPtr = fCpuData.reset(block.fBytesFree);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000262 }
263
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000264 VALIDATE(true);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000265
266 return true;
267}
268
269void GrBufferAllocPool::destroyBlock() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000270 SkASSERT(!fBlocks.empty());
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000271
272 BufferBlock& block = fBlocks.back();
robertphillips1b8e1b52015-06-24 06:54:10 -0700273
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000274 SkASSERT(!block.fBuffer->isMapped());
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000275 block.fBuffer->unref();
276 fBlocks.pop_back();
277 fBufferPtr = NULL;
278}
279
bsalomon3512eda2014-06-26 12:56:22 -0700280void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize) {
281 GrGeometryBuffer* buffer = block.fBuffer;
bsalomon49f085d2014-09-05 13:34:00 -0700282 SkASSERT(buffer);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000283 SkASSERT(!buffer->isMapped());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000284 SkASSERT(fCpuData.get() == fBufferPtr);
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000285 SkASSERT(flushSize <= buffer->gpuMemorySize());
bsalomon@google.comd5108092012-03-08 15:10:39 +0000286 VALIDATE(true);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000287
bsalomon4b91f762015-05-19 09:29:46 -0700288 if (GrCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags() &&
joshualitt7224c862015-05-29 06:46:47 -0700289 flushSize > fGeometryBufferMapThreshold) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000290 void* data = buffer->map();
bsalomon49f085d2014-09-05 13:34:00 -0700291 if (data) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000292 memcpy(data, fBufferPtr, flushSize);
bsalomon3512eda2014-06-26 12:56:22 -0700293 UNMAP_BUFFER(block);
bsalomon@google.com71bd1ef2011-12-12 20:42:26 +0000294 return;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000295 }
296 }
297 buffer->updateData(fBufferPtr, flushSize);
bsalomon@google.comd5108092012-03-08 15:10:39 +0000298 VALIDATE(true);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000299}
300
robertphillips1b8e1b52015-06-24 06:54:10 -0700301GrGeometryBuffer* GrBufferAllocPool::getBuffer(size_t size) {
302
303 GrResourceProvider* rp = fGpu->getContext()->resourceProvider();
304
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000305 if (kIndex_BufferType == fBufferType) {
robertphillips1b8e1b52015-06-24 06:54:10 -0700306 return rp->getIndexBuffer(size, /* dynamic = */ true, /* duringFlush = */ true);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000307 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000308 SkASSERT(kVertex_BufferType == fBufferType);
robertphillips1b8e1b52015-06-24 06:54:10 -0700309 return rp->getVertexBuffer(size, /* dynamic = */ true, /* duringFlush = */ true);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000310 }
311}
312
313////////////////////////////////////////////////////////////////////////////////
314
robertphillips1b8e1b52015-06-24 06:54:10 -0700315GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu)
316 : GrBufferAllocPool(gpu, kVertex_BufferType, MIN_VERTEX_BUFFER_SIZE) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000317}
318
jvanverth@google.coma6338982013-01-31 21:34:25 +0000319void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000320 int vertexCount,
321 const GrVertexBuffer** buffer,
322 int* startVertex) {
323
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000324 SkASSERT(vertexCount >= 0);
bsalomon49f085d2014-09-05 13:34:00 -0700325 SkASSERT(buffer);
326 SkASSERT(startVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000327
bsalomon@google.com8b484412011-04-18 19:07:44 +0000328 size_t offset = 0; // assign to suppress warning
329 const GrGeometryBuffer* geomBuffer = NULL; // assign to suppress warning
jvanverth@google.coma6338982013-01-31 21:34:25 +0000330 void* ptr = INHERITED::makeSpace(vertexSize * vertexCount,
331 vertexSize,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000332 &geomBuffer,
333 &offset);
334
335 *buffer = (const GrVertexBuffer*) geomBuffer;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000336 SkASSERT(0 == offset % vertexSize);
robertphillips@google.comadacc702013-10-14 21:53:24 +0000337 *startVertex = static_cast<int>(offset / vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000338 return ptr;
339}
340
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000341////////////////////////////////////////////////////////////////////////////////
342
robertphillips1b8e1b52015-06-24 06:54:10 -0700343GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu)
344 : GrBufferAllocPool(gpu, kIndex_BufferType, MIN_INDEX_BUFFER_SIZE) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000345}
346
347void* GrIndexBufferAllocPool::makeSpace(int indexCount,
348 const GrIndexBuffer** buffer,
349 int* startIndex) {
350
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000351 SkASSERT(indexCount >= 0);
bsalomon49f085d2014-09-05 13:34:00 -0700352 SkASSERT(buffer);
353 SkASSERT(startIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000354
bsalomon@google.com8b484412011-04-18 19:07:44 +0000355 size_t offset = 0; // assign to suppress warning
356 const GrGeometryBuffer* geomBuffer = NULL; // assign to suppress warning
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000357 void* ptr = INHERITED::makeSpace(indexCount * sizeof(uint16_t),
358 sizeof(uint16_t),
359 &geomBuffer,
360 &offset);
361
362 *buffer = (const GrIndexBuffer*) geomBuffer;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000363 SkASSERT(0 == offset % sizeof(uint16_t));
robertphillips@google.comadacc702013-10-14 21:53:24 +0000364 *startIndex = static_cast<int>(offset / sizeof(uint16_t));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000365 return ptr;
366}
367
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000368