Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/gpu/GrBufferAllocPool.h

Issue 1129863008: Revert of Refactor GrBufferAllocPools to use resource cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrBatchTarget.cpp ('k') | src/gpu/GrBufferAllocPool.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }; 131 };
124 132
125 class GrVertexBuffer; 133 class GrVertexBuffer;
126 134
127 /** 135 /**
128 * A GrBufferAllocPool of vertex buffers 136 * A GrBufferAllocPool of vertex buffers
129 */ 137 */
130 class GrVertexBufferAllocPool : public GrBufferAllocPool { 138 class GrVertexBufferAllocPool : public GrBufferAllocPool {
131 public: 139 public:
132 /** 140 /**
133 * Constructor 141 * Constructor
134 * 142 *
135 * @param gpu The GrGpu used to create the vertex buffers. 143 * @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.
136 */ 149 */
137 GrVertexBufferAllocPool(GrGpu* gpu); 150 GrVertexBufferAllocPool(GrGpu* gpu, size_t bufferSize = 0, int preallocBuffe rCnt = 0);
138 151
139 /** 152 /**
140 * Returns a block of memory to hold vertices. A buffer designated to hold 153 * Returns a block of memory to hold vertices. A buffer designated to hold
141 * the vertices given to the caller. The buffer may or may not be locked. 154 * the vertices given to the caller. The buffer may or may not be locked.
142 * The returned ptr remains valid until any of the following: 155 * The returned ptr remains valid until any of the following:
143 * *makeSpace is called again. 156 * *makeSpace is called again.
144 * *unmap is called. 157 * *unmap is called.
145 * *reset is called. 158 * *reset is called.
146 * *this object is destroyed. 159 * *this object is destroyed.
147 * 160 *
(...skipping 22 matching lines...) Expand all
170 183
171 /** 184 /**
172 * A GrBufferAllocPool of index buffers 185 * A GrBufferAllocPool of index buffers
173 */ 186 */
174 class GrIndexBufferAllocPool : public GrBufferAllocPool { 187 class GrIndexBufferAllocPool : public GrBufferAllocPool {
175 public: 188 public:
176 /** 189 /**
177 * Constructor 190 * Constructor
178 * 191 *
179 * @param gpu The GrGpu used to create the index buffers. 192 * @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.
180 */ 198 */
181 GrIndexBufferAllocPool(GrGpu* gpu); 199 GrIndexBufferAllocPool(GrGpu* gpu,
200 size_t bufferSize = 0,
201 int preallocBufferCnt = 0);
182 202
183 /** 203 /**
184 * Returns a block of memory to hold indices. A buffer designated to hold 204 * Returns a block of memory to hold indices. A buffer designated to hold
185 * the indices is given to the caller. The buffer may or may not be locked. 205 * the indices is given to the caller. The buffer may or may not be locked.
186 * The returned ptr remains valid until any of the following: 206 * The returned ptr remains valid until any of the following:
187 * *makeSpace is called again. 207 * *makeSpace is called again.
188 * *unmap is called. 208 * *unmap is called.
189 * *reset is called. 209 * *reset is called.
190 * *this object is destroyed. 210 * *this object is destroyed.
191 * 211 *
192 * Once unmap on the pool is called the indices are guaranteed to be in the 212 * Once unmap on the pool is called the indices are guaranteed to be in the
193 * buffer at the offset indicated by startIndex. Until that time they may be 213 * buffer at the offset indicated by startIndex. Until that time they may be
194 * in temporary storage and/or the buffer may be locked. 214 * in temporary storage and/or the buffer may be locked.
195 * 215 *
196 * @param indexCount number of indices to allocate space for 216 * @param indexCount number of indices to allocate space for
197 * @param buffer returns the index buffer that will hold the indices. 217 * @param buffer returns the index buffer that will hold the indices.
198 * @param startIndex returns the offset into buffer of the first index. 218 * @param startIndex returns the offset into buffer of the first index.
199 * @return pointer to first index. 219 * @return pointer to first index.
200 */ 220 */
201 void* makeSpace(int indexCount, 221 void* makeSpace(int indexCount,
202 const GrIndexBuffer** buffer, 222 const GrIndexBuffer** buffer,
203 int* startIndex); 223 int* startIndex);
204 224
205 private: 225 private:
206 typedef GrBufferAllocPool INHERITED; 226 typedef GrBufferAllocPool INHERITED;
207 }; 227 };
208 228
209 #endif 229 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatchTarget.cpp ('k') | src/gpu/GrBufferAllocPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698