| 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 |
| 11 #include "SkTArray.h" | 11 #include "SkTArray.h" |
| 12 #include "SkTDArray.h" | 12 #include "SkTDArray.h" |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 | 14 |
| 15 class GrGeometryBuffer; | 15 class GrGeometryBuffer; |
| 16 class GrGpu; | 16 class GrGpu; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A pool of geometry buffers tied to a GrGpu. | 19 * A pool of geometry buffers tied to a GrGpu. |
| 20 * | 20 * |
| 21 * The pool allows a client to make space for geometry and then put back excess | 21 * The pool allows a client to make space for geometry and then put back excess |
| 22 * space if it over allocated. When a client is ready to draw from the pool | 22 * space if it over allocated. When a client is ready to draw from the pool |
| 23 * it calls unlock on the pool ensure buffers are ready for drawing. The pool | 23 * it calls unmap on the pool ensure buffers are ready for drawing. The pool |
| 24 * can be reset after drawing is completed to recycle space. | 24 * can be reset after drawing is completed to recycle space. |
| 25 * | 25 * |
| 26 * At creation time a minimum per-buffer size can be specified. Additionally, | 26 * At creation time a minimum per-buffer size can be specified. Additionally, |
| 27 * a number of buffers to preallocate can be specified. These will | 27 * a number of buffers to preallocate can be specified. These will |
| 28 * be allocated at the min size and kept around until the pool is destroyed. | 28 * be allocated at the min size and kept around until the pool is destroyed. |
| 29 */ | 29 */ |
| 30 class GrBufferAllocPool : SkNoncopyable { | 30 class GrBufferAllocPool : SkNoncopyable { |
| 31 public: | 31 public: |
| 32 /** | 32 /** |
| 33 * Ensures all buffers are unlocked and have all data written to them. | 33 * Ensures all buffers are unmapped and have all data written to them. |
| 34 * Call before drawing using buffers from the pool. | 34 * Call before drawing using buffers from the pool. |
| 35 */ | 35 */ |
| 36 void unlock(); | 36 void unmap(); |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Invalidates all the data in the pool, unrefs non-preallocated buffers. | 39 * Invalidates all the data in the pool, unrefs non-preallocated buffers. |
| 40 */ | 40 */ |
| 41 void reset(); | 41 void reset(); |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Gets the number of preallocated buffers that are yet to be used. | 44 * Gets the number of preallocated buffers that are yet to be used. |
| 45 */ | 45 */ |
| 46 int preallocatedBuffersRemaining() const; | 46 int preallocatedBuffersRemaining() const; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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 | 79 * @param frequentResetHint A hint that indicates that the pool |
| 80 * should expect frequent unlock() calls | 80 * should expect frequent unmap() calls |
| 81 * (as opposed to many makeSpace / acquires | 81 * (as opposed to many makeSpace / acquires |
| 82 * between resets). | 82 * between resets). |
| 83 * @param bufferSize The minimum size of created buffers. | 83 * @param bufferSize The minimum size of created buffers. |
| 84 * This value will be clamped to some | 84 * This value will be clamped to some |
| 85 * reasonable minimum. | 85 * reasonable minimum. |
| 86 * @param preallocBufferCnt The pool will allocate this number of | 86 * @param preallocBufferCnt The pool will allocate this number of |
| 87 * buffers at bufferSize and keep them until it | 87 * buffers at bufferSize and keep them until it |
| 88 * is destroyed. | 88 * is destroyed. |
| 89 */ | 89 */ |
| 90 GrBufferAllocPool(GrGpu* gpu, | 90 GrBufferAllocPool(GrGpu* gpu, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 102 */ | 102 */ |
| 103 size_t preallocatedBufferSize() const { | 103 size_t preallocatedBufferSize() const { |
| 104 return fPreallocBuffers.count() ? fMinBlockSize : 0; | 104 return fPreallocBuffers.count() ? fMinBlockSize : 0; |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Returns a block of memory to hold data. A buffer designated to hold the | 108 * Returns a block of memory to hold data. A buffer designated to hold the |
| 109 * data is given to the caller. The buffer may or may not be locked. The | 109 * data is given to the caller. The buffer may or may not be locked. The |
| 110 * returned ptr remains valid until any of the following: | 110 * returned ptr remains valid until any of the following: |
| 111 * *makeSpace is called again. | 111 * *makeSpace is called again. |
| 112 * *unlock is called. | 112 * *unmap is called. |
| 113 * *reset is called. | 113 * *reset is called. |
| 114 * *this object is destroyed. | 114 * *this object is destroyed. |
| 115 * | 115 * |
| 116 * Once unlock on the pool is called the data is guaranteed to be in the | 116 * Once unmap on the pool is called the data is guaranteed to be in the |
| 117 * buffer at the offset indicated by offset. Until that time it may be | 117 * buffer at the offset indicated by offset. Until that time it may be |
| 118 * in temporary storage and/or the buffer may be locked. | 118 * in temporary storage and/or the buffer may be locked. |
| 119 * | 119 * |
| 120 * @param size the amount of data to make space for | 120 * @param size the amount of data to make space for |
| 121 * @param alignment alignment constraint from start of buffer | 121 * @param alignment alignment constraint from start of buffer |
| 122 * @param buffer returns the buffer that will hold the data. | 122 * @param buffer returns the buffer that will hold the data. |
| 123 * @param offset returns the offset into buffer of the data. | 123 * @param offset returns the offset into buffer of the data. |
| 124 * @return pointer to where the client should write the data. | 124 * @return pointer to where the client should write the data. |
| 125 */ | 125 */ |
| 126 void* makeSpace(size_t size, | 126 void* makeSpace(size_t size, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 /** | 183 /** |
| 184 * A GrBufferAllocPool of vertex buffers | 184 * A GrBufferAllocPool of vertex buffers |
| 185 */ | 185 */ |
| 186 class GrVertexBufferAllocPool : public GrBufferAllocPool { | 186 class GrVertexBufferAllocPool : public GrBufferAllocPool { |
| 187 public: | 187 public: |
| 188 /** | 188 /** |
| 189 * Constructor | 189 * Constructor |
| 190 * | 190 * |
| 191 * @param gpu The GrGpu used to create the vertex buffers. | 191 * @param gpu The GrGpu used to create the vertex buffers. |
| 192 * @param frequentResetHint A hint that indicates that the pool | 192 * @param frequentResetHint A hint that indicates that the pool |
| 193 * should expect frequent unlock() calls | 193 * should expect frequent unmap() calls |
| 194 * (as opposed to many makeSpace / acquires | 194 * (as opposed to many makeSpace / acquires |
| 195 * between resets). | 195 * between resets). |
| 196 * @param bufferSize The minimum size of created VBs This value | 196 * @param bufferSize The minimum size of created VBs This value |
| 197 * will be clamped to some reasonable minimum. | 197 * will be clamped to some reasonable minimum. |
| 198 * @param preallocBufferCnt The pool will allocate this number of VBs at | 198 * @param preallocBufferCnt The pool will allocate this number of VBs at |
| 199 * bufferSize and keep them until it is | 199 * bufferSize and keep them until it is |
| 200 * destroyed. | 200 * destroyed. |
| 201 */ | 201 */ |
| 202 GrVertexBufferAllocPool(GrGpu* gpu, | 202 GrVertexBufferAllocPool(GrGpu* gpu, |
| 203 bool frequentResetHint, | 203 bool frequentResetHint, |
| 204 size_t bufferSize = 0, | 204 size_t bufferSize = 0, |
| 205 int preallocBufferCnt = 0); | 205 int preallocBufferCnt = 0); |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * Returns a block of memory to hold vertices. A buffer designated to hold | 208 * 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. | 209 * 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: | 210 * The returned ptr remains valid until any of the following: |
| 211 * *makeSpace is called again. | 211 * *makeSpace is called again. |
| 212 * *unlock is called. | 212 * *unmap is called. |
| 213 * *reset is called. | 213 * *reset is called. |
| 214 * *this object is destroyed. | 214 * *this object is destroyed. |
| 215 * | 215 * |
| 216 * Once unlock on the pool is called the vertices are guaranteed to be in | 216 * Once unmap on the pool is called the vertices are guaranteed to be in |
| 217 * the buffer at the offset indicated by startVertex. Until that time they | 217 * the buffer at the offset indicated by startVertex. Until that time they |
| 218 * may be in temporary storage and/or the buffer may be locked. | 218 * may be in temporary storage and/or the buffer may be locked. |
| 219 * | 219 * |
| 220 * @param vertexSize specifies size of a vertex to allocate space for | 220 * @param vertexSize specifies size of a vertex to allocate space for |
| 221 * @param vertexCount number of vertices to allocate space for | 221 * @param vertexCount number of vertices to allocate space for |
| 222 * @param buffer returns the vertex buffer that will hold the | 222 * @param buffer returns the vertex buffer that will hold the |
| 223 * vertices. | 223 * vertices. |
| 224 * @param startVertex returns the offset into buffer of the first vertex. | 224 * @param startVertex returns the offset into buffer of the first vertex. |
| 225 * In units of the size of a vertex from layout param. | 225 * In units of the size of a vertex from layout param. |
| 226 * @return pointer to first vertex. | 226 * @return pointer to first vertex. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 /** | 271 /** |
| 272 * A GrBufferAllocPool of index buffers | 272 * A GrBufferAllocPool of index buffers |
| 273 */ | 273 */ |
| 274 class GrIndexBufferAllocPool : public GrBufferAllocPool { | 274 class GrIndexBufferAllocPool : public GrBufferAllocPool { |
| 275 public: | 275 public: |
| 276 /** | 276 /** |
| 277 * Constructor | 277 * Constructor |
| 278 * | 278 * |
| 279 * @param gpu The GrGpu used to create the index buffers. | 279 * @param gpu The GrGpu used to create the index buffers. |
| 280 * @param frequentResetHint A hint that indicates that the pool | 280 * @param frequentResetHint A hint that indicates that the pool |
| 281 * should expect frequent unlock() calls | 281 * should expect frequent unmap() calls |
| 282 * (as opposed to many makeSpace / acquires | 282 * (as opposed to many makeSpace / acquires |
| 283 * between resets). | 283 * between resets). |
| 284 * @param bufferSize The minimum size of created IBs This value | 284 * @param bufferSize The minimum size of created IBs This value |
| 285 * will be clamped to some reasonable minimum. | 285 * will be clamped to some reasonable minimum. |
| 286 * @param preallocBufferCnt The pool will allocate this number of VBs at | 286 * @param preallocBufferCnt The pool will allocate this number of VBs at |
| 287 * bufferSize and keep them until it is | 287 * bufferSize and keep them until it is |
| 288 * destroyed. | 288 * destroyed. |
| 289 */ | 289 */ |
| 290 GrIndexBufferAllocPool(GrGpu* gpu, | 290 GrIndexBufferAllocPool(GrGpu* gpu, |
| 291 bool frequentResetHint, | 291 bool frequentResetHint, |
| 292 size_t bufferSize = 0, | 292 size_t bufferSize = 0, |
| 293 int preallocBufferCnt = 0); | 293 int preallocBufferCnt = 0); |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * Returns a block of memory to hold indices. A buffer designated to hold | 296 * Returns a block of memory to hold indices. A buffer designated to hold |
| 297 * the indices is given to the caller. The buffer may or may not be locked. | 297 * the indices is given to the caller. The buffer may or may not be locked. |
| 298 * The returned ptr remains valid until any of the following: | 298 * The returned ptr remains valid until any of the following: |
| 299 * *makeSpace is called again. | 299 * *makeSpace is called again. |
| 300 * *unlock is called. | 300 * *unmap is called. |
| 301 * *reset is called. | 301 * *reset is called. |
| 302 * *this object is destroyed. | 302 * *this object is destroyed. |
| 303 * | 303 * |
| 304 * Once unlock on the pool is called the indices are guaranteed to be in the | 304 * Once unmap on the pool is called the indices are guaranteed to be in the |
| 305 * buffer at the offset indicated by startIndex. Until that time they may be | 305 * buffer at the offset indicated by startIndex. Until that time they may be |
| 306 * in temporary storage and/or the buffer may be locked. | 306 * in temporary storage and/or the buffer may be locked. |
| 307 * | 307 * |
| 308 * @param indexCount number of indices to allocate space for | 308 * @param indexCount number of indices to allocate space for |
| 309 * @param buffer returns the index buffer that will hold the indices. | 309 * @param buffer returns the index buffer that will hold the indices. |
| 310 * @param startIndex returns the offset into buffer of the first index. | 310 * @param startIndex returns the offset into buffer of the first index. |
| 311 * @return pointer to first index. | 311 * @return pointer to first index. |
| 312 */ | 312 */ |
| 313 void* makeSpace(int indexCount, | 313 void* makeSpace(int indexCount, |
| 314 const GrIndexBuffer** buffer, | 314 const GrIndexBuffer** buffer, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 338 * @return number of indices that fit in one of the preallocated index | 338 * @return number of indices that fit in one of the preallocated index |
| 339 * buffers. | 339 * buffers. |
| 340 */ | 340 */ |
| 341 int preallocatedBufferIndices() const; | 341 int preallocatedBufferIndices() const; |
| 342 | 342 |
| 343 private: | 343 private: |
| 344 typedef GrBufferAllocPool INHERITED; | 344 typedef GrBufferAllocPool INHERITED; |
| 345 }; | 345 }; |
| 346 | 346 |
| 347 #endif | 347 #endif |
| OLD | NEW |