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