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); |
bsalomon
2015/05/13 16:24:07
should we remove bufferSize?
robertphillips
2015/05/13 16:56:14
I still use it in the GrVertexBufferAllocPool ctor
| |
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 }; | 123 }; |
132 | 124 |
133 class GrVertexBuffer; | 125 class GrVertexBuffer; |
134 | 126 |
135 /** | 127 /** |
136 * A GrBufferAllocPool of vertex buffers | 128 * A GrBufferAllocPool of vertex buffers |
137 */ | 129 */ |
138 class GrVertexBufferAllocPool : public GrBufferAllocPool { | 130 class GrVertexBufferAllocPool : public GrBufferAllocPool { |
139 public: | 131 public: |
140 /** | 132 /** |
141 * Constructor | 133 * Constructor |
142 * | 134 * |
143 * @param gpu The GrGpu used to create the vertex buffers. | 135 * @param gpu The GrGpu used to create the vertex buffers. |
144 * @param bufferSize The minimum size of created VBs. This value | |
145 * will be clamped to some reasonable minimum. | |
146 * @param preallocBufferCnt The pool will allocate this number of VBs at | |
147 * bufferSize and keep them until it is | |
148 * destroyed. | |
149 */ | 136 */ |
150 GrVertexBufferAllocPool(GrGpu* gpu, size_t bufferSize = 0, int preallocBuffe rCnt = 0); | 137 GrVertexBufferAllocPool(GrGpu* gpu); |
151 | 138 |
152 /** | 139 /** |
153 * Returns a block of memory to hold vertices. A buffer designated to hold | 140 * Returns a block of memory to hold vertices. A buffer designated to hold |
154 * the vertices given to the caller. The buffer may or may not be locked. | 141 * the vertices given to the caller. The buffer may or may not be locked. |
155 * The returned ptr remains valid until any of the following: | 142 * The returned ptr remains valid until any of the following: |
156 * *makeSpace is called again. | 143 * *makeSpace is called again. |
157 * *unmap is called. | 144 * *unmap is called. |
158 * *reset is called. | 145 * *reset is called. |
159 * *this object is destroyed. | 146 * *this object is destroyed. |
160 * | 147 * |
(...skipping 22 matching lines...) Expand all Loading... | |
183 | 170 |
184 /** | 171 /** |
185 * A GrBufferAllocPool of index buffers | 172 * A GrBufferAllocPool of index buffers |
186 */ | 173 */ |
187 class GrIndexBufferAllocPool : public GrBufferAllocPool { | 174 class GrIndexBufferAllocPool : public GrBufferAllocPool { |
188 public: | 175 public: |
189 /** | 176 /** |
190 * Constructor | 177 * Constructor |
191 * | 178 * |
192 * @param gpu The GrGpu used to create the index buffers. | 179 * @param gpu The GrGpu used to create the index buffers. |
193 * @param bufferSize The minimum size of created IBs. This value | |
194 * will be clamped to some reasonable minimum. | |
195 * @param preallocBufferCnt The pool will allocate this number of VBs at | |
196 * bufferSize and keep them until it is | |
197 * destroyed. | |
198 */ | 180 */ |
199 GrIndexBufferAllocPool(GrGpu* gpu, | 181 GrIndexBufferAllocPool(GrGpu* gpu); |
200 size_t bufferSize = 0, | |
201 int preallocBufferCnt = 0); | |
202 | 182 |
203 /** | 183 /** |
204 * Returns a block of memory to hold indices. A buffer designated to hold | 184 * Returns a block of memory to hold indices. A buffer designated to hold |
205 * the indices is given to the caller. The buffer may or may not be locked. | 185 * the indices is given to the caller. The buffer may or may not be locked. |
206 * The returned ptr remains valid until any of the following: | 186 * The returned ptr remains valid until any of the following: |
207 * *makeSpace is called again. | 187 * *makeSpace is called again. |
208 * *unmap is called. | 188 * *unmap is called. |
209 * *reset is called. | 189 * *reset is called. |
210 * *this object is destroyed. | 190 * *this object is destroyed. |
211 * | 191 * |
212 * Once unmap on the pool is called the indices are guaranteed to be in the | 192 * Once unmap on the pool is called the indices are guaranteed to be in the |
213 * buffer at the offset indicated by startIndex. Until that time they may be | 193 * buffer at the offset indicated by startIndex. Until that time they may be |
214 * in temporary storage and/or the buffer may be locked. | 194 * in temporary storage and/or the buffer may be locked. |
215 * | 195 * |
216 * @param indexCount number of indices to allocate space for | 196 * @param indexCount number of indices to allocate space for |
217 * @param buffer returns the index buffer that will hold the indices. | 197 * @param buffer returns the index buffer that will hold the indices. |
218 * @param startIndex returns the offset into buffer of the first index. | 198 * @param startIndex returns the offset into buffer of the first index. |
219 * @return pointer to first index. | 199 * @return pointer to first index. |
220 */ | 200 */ |
221 void* makeSpace(int indexCount, | 201 void* makeSpace(int indexCount, |
222 const GrIndexBuffer** buffer, | 202 const GrIndexBuffer** buffer, |
223 int* startIndex); | 203 int* startIndex); |
224 | 204 |
225 private: | 205 private: |
226 typedef GrBufferAllocPool INHERITED; | 206 typedef GrBufferAllocPool INHERITED; |
227 }; | 207 }; |
228 | 208 |
229 #endif | 209 #endif |
OLD | NEW |