OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #ifndef GrBufferAllocPool_DEFINED | 8 #ifndef GrBufferAllocPool_DEFINED |
9 #define GrBufferAllocPool_DEFINED | 9 #define GrBufferAllocPool_DEFINED |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 enum BufferType { | 69 enum BufferType { |
70 kVertex_BufferType, | 70 kVertex_BufferType, |
71 kIndex_BufferType, | 71 kIndex_BufferType, |
72 }; | 72 }; |
73 | 73 |
74 /** | 74 /** |
75 * Constructor | 75 * Constructor |
76 * | 76 * |
77 * @param gpu The GrGpu used to create the buffers. | 77 * @param gpu The GrGpu used to create the buffers. |
78 * @param bufferType The type of buffers to create. | 78 * @param bufferType The type of buffers to create. |
79 * @param frequentResetHint A hint that indicates that the pool | |
80 * should expect frequent unmap() calls | |
81 * (as opposed to many makeSpace / acquires | |
82 * between resets). | |
83 * @param bufferSize The minimum size of created buffers. | 79 * @param bufferSize The minimum size of created buffers. |
84 * This value will be clamped to some | 80 * This value will be clamped to some |
85 * reasonable minimum. | 81 * reasonable minimum. |
86 * @param preallocBufferCnt The pool will allocate this number of | 82 * @param preallocBufferCnt The pool will allocate this number of |
87 * buffers at bufferSize and keep them until it | 83 * buffers at bufferSize and keep them until it |
88 * is destroyed. | 84 * is destroyed. |
89 */ | 85 */ |
90 GrBufferAllocPool(GrGpu* gpu, | 86 GrBufferAllocPool(GrGpu* gpu, |
91 BufferType bufferType, | 87 BufferType bufferType, |
92 bool frequentResetHint, | |
93 size_t bufferSize = 0, | 88 size_t bufferSize = 0, |
94 int preallocBufferCnt = 0); | 89 int preallocBufferCnt = 0); |
95 | 90 |
96 virtual ~GrBufferAllocPool(); | 91 virtual ~GrBufferAllocPool(); |
97 | 92 |
98 /** | 93 /** |
99 * Gets the size of the preallocated buffers. | 94 * Gets the size of the preallocated buffers. |
100 * | 95 * |
101 * @return the size of preallocated buffers. | 96 * @return the size of preallocated buffers. |
102 */ | 97 */ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 * @return the number of items that would fit in the current buffer. | 134 * @return the number of items that would fit in the current buffer. |
140 */ | 135 */ |
141 int currentBufferItems(size_t itemSize) const; | 136 int currentBufferItems(size_t itemSize) const; |
142 | 137 |
143 GrGeometryBuffer* createBuffer(size_t size); | 138 GrGeometryBuffer* createBuffer(size_t size); |
144 | 139 |
145 private: | 140 private: |
146 | 141 |
147 // The GrGpu must be able to clear the ref of pools it creates as members | 142 // The GrGpu must be able to clear the ref of pools it creates as members |
148 friend class GrGpu; | 143 friend class GrGpu; |
149 void releaseGpuRef(); | |
150 | 144 |
151 struct BufferBlock { | 145 struct BufferBlock { |
152 size_t fBytesFree; | 146 size_t fBytesFree; |
153 GrGeometryBuffer* fBuffer; | 147 GrGeometryBuffer* fBuffer; |
154 }; | 148 }; |
155 | 149 |
156 bool createBlock(size_t requestSize); | 150 bool createBlock(size_t requestSize); |
157 void destroyBlock(); | 151 void destroyBlock(); |
158 void flushCpuData(const BufferBlock& block, size_t flushSize); | 152 void flushCpuData(const BufferBlock& block, size_t flushSize); |
159 #ifdef SK_DEBUG | 153 #ifdef SK_DEBUG |
160 void validate(bool unusedBlockAllowed = false) const; | 154 void validate(bool unusedBlockAllowed = false) const; |
161 #endif | 155 #endif |
162 | 156 |
163 size_t fBytesInUse; | 157 size_t fBytesInUse; |
164 | 158 |
165 GrGpu* fGpu; | 159 GrGpu* fGpu; |
166 bool fGpuIsReffed; | |
167 bool fFrequentResetHint; | |
168 SkTDArray<GrGeometryBuffer*> fPreallocBuffers; | 160 SkTDArray<GrGeometryBuffer*> fPreallocBuffers; |
169 size_t fMinBlockSize; | 161 size_t fMinBlockSize; |
170 BufferType fBufferType; | 162 BufferType fBufferType; |
171 | 163 |
172 SkTArray<BufferBlock> fBlocks; | 164 SkTArray<BufferBlock> fBlocks; |
173 int fPreallocBuffersInUse; | 165 int fPreallocBuffersInUse; |
174 // We attempt to cycle through the preallocated buffers rather than | 166 // We attempt to cycle through the preallocated buffers rather than |
175 // always starting from the first. | 167 // always starting from the first. |
176 int fPreallocBufferStartIdx; | 168 int fPreallocBufferStartIdx; |
177 SkAutoMalloc fCpuData; | 169 SkAutoMalloc fCpuData; |
178 void* fBufferPtr; | 170 void* fBufferPtr; |
179 }; | 171 }; |
180 | 172 |
181 class GrVertexBuffer; | 173 class GrVertexBuffer; |
182 | 174 |
183 /** | 175 /** |
184 * A GrBufferAllocPool of vertex buffers | 176 * A GrBufferAllocPool of vertex buffers |
185 */ | 177 */ |
186 class GrVertexBufferAllocPool : public GrBufferAllocPool { | 178 class GrVertexBufferAllocPool : public GrBufferAllocPool { |
187 public: | 179 public: |
188 /** | 180 /** |
189 * Constructor | 181 * Constructor |
190 * | 182 * |
191 * @param gpu The GrGpu used to create the vertex buffers. | 183 * @param gpu The GrGpu used to create the vertex buffers. |
192 * @param frequentResetHint A hint that indicates that the pool | |
193 * should expect frequent unmap() calls | |
194 * (as opposed to many makeSpace / acquires | |
195 * between resets). | |
196 * @param bufferSize The minimum size of created VBs This value | 184 * @param bufferSize The minimum size of created VBs This value |
197 * will be clamped to some reasonable minimum. | 185 * will be clamped to some reasonable minimum. |
198 * @param preallocBufferCnt The pool will allocate this number of VBs at | 186 * @param preallocBufferCnt The pool will allocate this number of VBs at |
199 * bufferSize and keep them until it is | 187 * bufferSize and keep them until it is |
200 * destroyed. | 188 * destroyed. |
201 */ | 189 */ |
202 GrVertexBufferAllocPool(GrGpu* gpu, | 190 GrVertexBufferAllocPool(GrGpu* gpu, size_t bufferSize = 0, int preallocBuffe
rCnt = 0); |
203 bool frequentResetHint, | |
204 size_t bufferSize = 0, | |
205 int preallocBufferCnt = 0); | |
206 | 191 |
207 /** | 192 /** |
208 * Returns a block of memory to hold vertices. A buffer designated to hold | 193 * Returns a block of memory to hold vertices. A buffer designated to hold |
209 * the vertices given to the caller. The buffer may or may not be locked. | 194 * the vertices given to the caller. The buffer may or may not be locked. |
210 * The returned ptr remains valid until any of the following: | 195 * The returned ptr remains valid until any of the following: |
211 * *makeSpace is called again. | 196 * *makeSpace is called again. |
212 * *unmap is called. | 197 * *unmap is called. |
213 * *reset is called. | 198 * *reset is called. |
214 * *this object is destroyed. | 199 * *this object is destroyed. |
215 * | 200 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 246 |
262 /** | 247 /** |
263 * A GrBufferAllocPool of index buffers | 248 * A GrBufferAllocPool of index buffers |
264 */ | 249 */ |
265 class GrIndexBufferAllocPool : public GrBufferAllocPool { | 250 class GrIndexBufferAllocPool : public GrBufferAllocPool { |
266 public: | 251 public: |
267 /** | 252 /** |
268 * Constructor | 253 * Constructor |
269 * | 254 * |
270 * @param gpu The GrGpu used to create the index buffers. | 255 * @param gpu The GrGpu used to create the index buffers. |
271 * @param frequentResetHint A hint that indicates that the pool | |
272 * should expect frequent unmap() calls | |
273 * (as opposed to many makeSpace / acquires | |
274 * between resets). | |
275 * @param bufferSize The minimum size of created IBs This value | 256 * @param bufferSize The minimum size of created IBs This value |
276 * will be clamped to some reasonable minimum. | 257 * will be clamped to some reasonable minimum. |
277 * @param preallocBufferCnt The pool will allocate this number of VBs at | 258 * @param preallocBufferCnt The pool will allocate this number of VBs at |
278 * bufferSize and keep them until it is | 259 * bufferSize and keep them until it is |
279 * destroyed. | 260 * destroyed. |
280 */ | 261 */ |
281 GrIndexBufferAllocPool(GrGpu* gpu, | 262 GrIndexBufferAllocPool(GrGpu* gpu, |
282 bool frequentResetHint, | |
283 size_t bufferSize = 0, | 263 size_t bufferSize = 0, |
284 int preallocBufferCnt = 0); | 264 int preallocBufferCnt = 0); |
285 | 265 |
286 /** | 266 /** |
287 * Returns a block of memory to hold indices. A buffer designated to hold | 267 * Returns a block of memory to hold indices. A buffer designated to hold |
288 * the indices is given to the caller. The buffer may or may not be locked. | 268 * the indices is given to the caller. The buffer may or may not be locked. |
289 * The returned ptr remains valid until any of the following: | 269 * The returned ptr remains valid until any of the following: |
290 * *makeSpace is called again. | 270 * *makeSpace is called again. |
291 * *unmap is called. | 271 * *unmap is called. |
292 * *reset is called. | 272 * *reset is called. |
(...skipping 28 matching lines...) Expand all Loading... |
321 * @return number of indices that fit in one of the preallocated index | 301 * @return number of indices that fit in one of the preallocated index |
322 * buffers. | 302 * buffers. |
323 */ | 303 */ |
324 int preallocatedBufferIndices() const; | 304 int preallocatedBufferIndices() const; |
325 | 305 |
326 private: | 306 private: |
327 typedef GrBufferAllocPool INHERITED; | 307 typedef GrBufferAllocPool INHERITED; |
328 }; | 308 }; |
329 | 309 |
330 #endif | 310 #endif |
OLD | NEW |