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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 }; | 57 }; |
58 | 58 |
59 /** | 59 /** |
60 * Constructor | 60 * Constructor |
61 * | 61 * |
62 * @param gpu The GrGpu used to create the buffers. | 62 * @param gpu The GrGpu used to create the buffers. |
63 * @param bufferType The type of buffers to create. | 63 * @param bufferType The type of buffers to create. |
64 * @param bufferSize The minimum size of created buffers. | 64 * @param bufferSize The minimum size of created buffers. |
65 * This value will be clamped to some | 65 * This value will be clamped to some |
66 * reasonable minimum. | 66 * reasonable minimum. |
| 67 * @param preallocBufferCnt The pool will allocate this number of |
| 68 * buffers at bufferSize and keep them until it |
| 69 * is destroyed. |
67 */ | 70 */ |
68 GrBufferAllocPool(GrGpu* gpu, | 71 GrBufferAllocPool(GrGpu* gpu, |
69 BufferType bufferType, | 72 BufferType bufferType, |
70 size_t bufferSize = 0); | 73 size_t bufferSize = 0, |
| 74 int preallocBufferCnt = 0); |
71 | 75 |
72 virtual ~GrBufferAllocPool(); | 76 virtual ~GrBufferAllocPool(); |
73 | 77 |
74 /** | 78 /** |
75 * Returns a block of memory to hold data. A buffer designated to hold the | 79 * Returns a block of memory to hold data. A buffer designated to hold the |
76 * data is given to the caller. The buffer may or may not be locked. The | 80 * data is given to the caller. The buffer may or may not be locked. The |
77 * returned ptr remains valid until any of the following: | 81 * returned ptr remains valid until any of the following: |
78 * *makeSpace is called again. | 82 * *makeSpace is called again. |
79 * *unmap is called. | 83 * *unmap is called. |
80 * *reset is called. | 84 * *reset is called. |
81 * *this object is destroyed. | 85 * *this object is destroyed. |
82 * | 86 * |
83 * Once unmap on the pool is called the data is guaranteed to be in the | 87 * Once unmap on the pool is called the data is guaranteed to be in the |
84 * buffer at the offset indicated by offset. Until that time it may be | 88 * buffer at the offset indicated by offset. Until that time it may be |
85 * in temporary storage and/or the buffer may be locked. | 89 * in temporary storage and/or the buffer may be locked. |
86 * | 90 * |
87 * @param size the amount of data to make space for | 91 * @param size the amount of data to make space for |
88 * @param alignment alignment constraint from start of buffer | 92 * @param alignment alignment constraint from start of buffer |
89 * @param buffer returns the buffer that will hold the data. | 93 * @param buffer returns the buffer that will hold the data. |
90 * @param offset returns the offset into buffer of the data. | 94 * @param offset returns the offset into buffer of the data. |
91 * @return pointer to where the client should write the data. | 95 * @return pointer to where the client should write the data. |
92 */ | 96 */ |
93 void* makeSpace(size_t size, | 97 void* makeSpace(size_t size, |
94 size_t alignment, | 98 size_t alignment, |
95 const GrGeometryBuffer** buffer, | 99 const GrGeometryBuffer** buffer, |
96 size_t* offset); | 100 size_t* offset); |
97 | 101 |
98 GrGeometryBuffer* getBuffer(size_t size); | 102 GrGeometryBuffer* createBuffer(size_t size); |
99 | 103 |
100 private: | 104 private: |
101 struct BufferBlock { | 105 struct BufferBlock { |
102 size_t fBytesFree; | 106 size_t fBytesFree; |
103 GrGeometryBuffer* fBuffer; | 107 GrGeometryBuffer* fBuffer; |
104 }; | 108 }; |
105 | 109 |
106 bool createBlock(size_t requestSize); | 110 bool createBlock(size_t requestSize); |
107 void destroyBlock(); | 111 void destroyBlock(); |
108 void deleteBlocks(); | |
109 void flushCpuData(const BufferBlock& block, size_t flushSize); | 112 void flushCpuData(const BufferBlock& block, size_t flushSize); |
110 #ifdef SK_DEBUG | 113 #ifdef SK_DEBUG |
111 void validate(bool unusedBlockAllowed = false) const; | 114 void validate(bool unusedBlockAllowed = false) const; |
112 #endif | 115 #endif |
113 | 116 |
114 size_t fBytesInUse; | 117 size_t fBytesInUse; |
115 | 118 |
116 GrGpu* fGpu; | 119 GrGpu* fGpu; |
| 120 SkTDArray<GrGeometryBuffer*> fPreallocBuffers; |
117 size_t fMinBlockSize; | 121 size_t fMinBlockSize; |
118 BufferType fBufferType; | 122 BufferType fBufferType; |
119 | 123 |
120 SkTArray<BufferBlock> fBlocks; | 124 SkTArray<BufferBlock> fBlocks; |
| 125 int fPreallocBuffersInUse; |
| 126 // We attempt to cycle through the preallocated buffers rather than |
| 127 // always starting from the first. |
| 128 int fPreallocBufferStartIdx; |
121 SkAutoMalloc fCpuData; | 129 SkAutoMalloc fCpuData; |
122 void* fBufferPtr; | 130 void* fBufferPtr; |
123 size_t fGeometryBufferMapThreshold; | 131 size_t fGeometryBufferMapThreshold; |
124 }; | 132 }; |
125 | 133 |
126 class GrVertexBuffer; | 134 class GrVertexBuffer; |
127 | 135 |
128 /** | 136 /** |
129 * A GrBufferAllocPool of vertex buffers | 137 * A GrBufferAllocPool of vertex buffers |
130 */ | 138 */ |
131 class GrVertexBufferAllocPool : public GrBufferAllocPool { | 139 class GrVertexBufferAllocPool : public GrBufferAllocPool { |
132 public: | 140 public: |
133 /** | 141 /** |
134 * Constructor | 142 * Constructor |
135 * | 143 * |
136 * @param gpu The GrGpu used to create the vertex buffers. | 144 * @param gpu The GrGpu used to create the vertex buffers. |
| 145 * @param bufferSize The minimum size of created VBs. This value |
| 146 * will be clamped to some reasonable minimum. |
| 147 * @param preallocBufferCnt The pool will allocate this number of VBs at |
| 148 * bufferSize and keep them until it is |
| 149 * destroyed. |
137 */ | 150 */ |
138 GrVertexBufferAllocPool(GrGpu* gpu); | 151 GrVertexBufferAllocPool(GrGpu* gpu, size_t bufferSize = 0, int preallocBuffe
rCnt = 0); |
139 | 152 |
140 /** | 153 /** |
141 * Returns a block of memory to hold vertices. A buffer designated to hold | 154 * Returns a block of memory to hold vertices. A buffer designated to hold |
142 * the vertices given to the caller. The buffer may or may not be locked. | 155 * the vertices given to the caller. The buffer may or may not be locked. |
143 * The returned ptr remains valid until any of the following: | 156 * The returned ptr remains valid until any of the following: |
144 * *makeSpace is called again. | 157 * *makeSpace is called again. |
145 * *unmap is called. | 158 * *unmap is called. |
146 * *reset is called. | 159 * *reset is called. |
147 * *this object is destroyed. | 160 * *this object is destroyed. |
148 * | 161 * |
(...skipping 22 matching lines...) Expand all Loading... |
171 | 184 |
172 /** | 185 /** |
173 * A GrBufferAllocPool of index buffers | 186 * A GrBufferAllocPool of index buffers |
174 */ | 187 */ |
175 class GrIndexBufferAllocPool : public GrBufferAllocPool { | 188 class GrIndexBufferAllocPool : public GrBufferAllocPool { |
176 public: | 189 public: |
177 /** | 190 /** |
178 * Constructor | 191 * Constructor |
179 * | 192 * |
180 * @param gpu The GrGpu used to create the index buffers. | 193 * @param gpu The GrGpu used to create the index buffers. |
| 194 * @param bufferSize The minimum size of created IBs. This value |
| 195 * will be clamped to some reasonable minimum. |
| 196 * @param preallocBufferCnt The pool will allocate this number of VBs at |
| 197 * bufferSize and keep them until it is |
| 198 * destroyed. |
181 */ | 199 */ |
182 GrIndexBufferAllocPool(GrGpu* gpu); | 200 GrIndexBufferAllocPool(GrGpu* gpu, |
| 201 size_t bufferSize = 0, |
| 202 int preallocBufferCnt = 0); |
183 | 203 |
184 /** | 204 /** |
185 * Returns a block of memory to hold indices. A buffer designated to hold | 205 * Returns a block of memory to hold indices. A buffer designated to hold |
186 * the indices is given to the caller. The buffer may or may not be locked. | 206 * the indices is given to the caller. The buffer may or may not be locked. |
187 * The returned ptr remains valid until any of the following: | 207 * The returned ptr remains valid until any of the following: |
188 * *makeSpace is called again. | 208 * *makeSpace is called again. |
189 * *unmap is called. | 209 * *unmap is called. |
190 * *reset is called. | 210 * *reset is called. |
191 * *this object is destroyed. | 211 * *this object is destroyed. |
192 * | 212 * |
193 * Once unmap on the pool is called the indices are guaranteed to be in the | 213 * Once unmap on the pool is called the indices are guaranteed to be in the |
194 * buffer at the offset indicated by startIndex. Until that time they may be | 214 * buffer at the offset indicated by startIndex. Until that time they may be |
195 * in temporary storage and/or the buffer may be locked. | 215 * in temporary storage and/or the buffer may be locked. |
196 * | 216 * |
197 * @param indexCount number of indices to allocate space for | 217 * @param indexCount number of indices to allocate space for |
198 * @param buffer returns the index buffer that will hold the indices. | 218 * @param buffer returns the index buffer that will hold the indices. |
199 * @param startIndex returns the offset into buffer of the first index. | 219 * @param startIndex returns the offset into buffer of the first index. |
200 * @return pointer to first index. | 220 * @return pointer to first index. |
201 */ | 221 */ |
202 void* makeSpace(int indexCount, | 222 void* makeSpace(int indexCount, |
203 const GrIndexBuffer** buffer, | 223 const GrIndexBuffer** buffer, |
204 int* startIndex); | 224 int* startIndex); |
205 | 225 |
206 private: | 226 private: |
207 typedef GrBufferAllocPool INHERITED; | 227 typedef GrBufferAllocPool INHERITED; |
208 }; | 228 }; |
209 | 229 |
210 #endif | 230 #endif |
OLD | NEW |