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

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

Issue 1825393002: Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: asserts Created 4 years, 9 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/GrBuffer.h ('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
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 #include "GrTypesPriv.h"
14 15
15 class GrGeometryBuffer; 16 class GrBuffer;
16 class GrGpu; 17 class GrGpu;
17 18
18 /** 19 /**
19 * A pool of geometry buffers tied to a GrGpu. 20 * A pool of geometry buffers tied to a GrGpu.
20 * 21 *
21 * The pool allows a client to make space for geometry and then put back excess 22 * 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 23 * space if it over allocated. When a client is ready to draw from the pool
23 * it calls unmap on the pool ensure buffers are ready for drawing. The pool 24 * 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. 25 * can be reset after drawing is completed to recycle space.
25 * 26 *
(...skipping 14 matching lines...) Expand all
40 */ 41 */
41 void reset(); 42 void reset();
42 43
43 /** 44 /**
44 * Frees data from makeSpaces in LIFO order. 45 * Frees data from makeSpaces in LIFO order.
45 */ 46 */
46 void putBack(size_t bytes); 47 void putBack(size_t bytes);
47 48
48 protected: 49 protected:
49 /** 50 /**
50 * Used to determine what type of buffers to create. We could make the
51 * createBuffer a virtual except that we want to use it in the cons for
52 * pre-allocated buffers.
53 */
54 enum BufferType {
55 kVertex_BufferType,
56 kIndex_BufferType,
57 };
58
59 /**
60 * Constructor 51 * Constructor
61 * 52 *
62 * @param gpu The GrGpu used to create the buffers. 53 * @param gpu The GrGpu used to create the buffers.
63 * @param bufferType The type of buffers to create. 54 * @param bufferType The type of buffers to create.
64 * @param bufferSize The minimum size of created buffers. 55 * @param bufferSize The minimum size of created buffers.
65 * This value will be clamped to some 56 * This value will be clamped to some
66 * reasonable minimum. 57 * reasonable minimum.
67 */ 58 */
68 GrBufferAllocPool(GrGpu* gpu, 59 GrBufferAllocPool(GrGpu* gpu,
69 BufferType bufferType, 60 GrBufferType bufferType,
70 size_t bufferSize = 0); 61 size_t bufferSize = 0);
71 62
72 virtual ~GrBufferAllocPool(); 63 virtual ~GrBufferAllocPool();
73 64
74 /** 65 /**
75 * Returns a block of memory to hold data. A buffer designated to hold the 66 * 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 67 * 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: 68 * returned ptr remains valid until any of the following:
78 * *makeSpace is called again. 69 * *makeSpace is called again.
79 * *unmap is called. 70 * *unmap is called.
80 * *reset is called. 71 * *reset is called.
81 * *this object is destroyed. 72 * *this object is destroyed.
82 * 73 *
83 * Once unmap on the pool is called the data is guaranteed to be in the 74 * 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 75 * buffer at the offset indicated by offset. Until that time it may be
85 * in temporary storage and/or the buffer may be locked. 76 * in temporary storage and/or the buffer may be locked.
86 * 77 *
87 * @param size the amount of data to make space for 78 * @param size the amount of data to make space for
88 * @param alignment alignment constraint from start of buffer 79 * @param alignment alignment constraint from start of buffer
89 * @param buffer returns the buffer that will hold the data. 80 * @param buffer returns the buffer that will hold the data.
90 * @param offset returns the offset into buffer of the data. 81 * @param offset returns the offset into buffer of the data.
91 * @return pointer to where the client should write the data. 82 * @return pointer to where the client should write the data.
92 */ 83 */
93 void* makeSpace(size_t size, 84 void* makeSpace(size_t size,
94 size_t alignment, 85 size_t alignment,
95 const GrGeometryBuffer** buffer, 86 const GrBuffer** buffer,
96 size_t* offset); 87 size_t* offset);
97 88
98 GrGeometryBuffer* getBuffer(size_t size); 89 GrBuffer* getBuffer(size_t size);
99 90
100 private: 91 private:
101 struct BufferBlock { 92 struct BufferBlock {
102 size_t fBytesFree; 93 size_t fBytesFree;
103 GrGeometryBuffer* fBuffer; 94 GrBuffer* fBuffer;
104 }; 95 };
105 96
106 bool createBlock(size_t requestSize); 97 bool createBlock(size_t requestSize);
107 void destroyBlock(); 98 void destroyBlock();
108 void deleteBlocks(); 99 void deleteBlocks();
109 void flushCpuData(const BufferBlock& block, size_t flushSize); 100 void flushCpuData(const BufferBlock& block, size_t flushSize);
110 void* resetCpuData(size_t newSize); 101 void* resetCpuData(size_t newSize);
111 #ifdef SK_DEBUG 102 #ifdef SK_DEBUG
112 void validate(bool unusedBlockAllowed = false) const; 103 void validate(bool unusedBlockAllowed = false) const;
113 #endif 104 #endif
114 size_t fBytesInUse; 105 size_t fBytesInUse;
115 106
116 GrGpu* fGpu; 107 GrGpu* fGpu;
117 size_t fMinBlockSize; 108 size_t fMinBlockSize;
118 BufferType fBufferType; 109 GrBufferType fBufferType;
119 110
120 SkTArray<BufferBlock> fBlocks; 111 SkTArray<BufferBlock> fBlocks;
121 void* fCpuData; 112 void* fCpuData;
122 void* fBufferPtr; 113 void* fBufferPtr;
123 size_t fGeometryBufferMapThreshold; 114 size_t fBufferMapThreshold;
124 }; 115 };
125 116
126 class GrVertexBuffer;
127
128 /** 117 /**
129 * A GrBufferAllocPool of vertex buffers 118 * A GrBufferAllocPool of vertex buffers
130 */ 119 */
131 class GrVertexBufferAllocPool : public GrBufferAllocPool { 120 class GrVertexBufferAllocPool : public GrBufferAllocPool {
132 public: 121 public:
133 /** 122 /**
134 * Constructor 123 * Constructor
135 * 124 *
136 * @param gpu The GrGpu used to create the vertex buffers. 125 * @param gpu The GrGpu used to create the vertex buffers.
137 */ 126 */
(...skipping 15 matching lines...) Expand all
153 * @param vertexSize specifies size of a vertex to allocate space for 142 * @param vertexSize specifies size of a vertex to allocate space for
154 * @param vertexCount number of vertices to allocate space for 143 * @param vertexCount number of vertices to allocate space for
155 * @param buffer returns the vertex buffer that will hold the 144 * @param buffer returns the vertex buffer that will hold the
156 * vertices. 145 * vertices.
157 * @param startVertex returns the offset into buffer of the first vertex. 146 * @param startVertex returns the offset into buffer of the first vertex.
158 * In units of the size of a vertex from layout param. 147 * In units of the size of a vertex from layout param.
159 * @return pointer to first vertex. 148 * @return pointer to first vertex.
160 */ 149 */
161 void* makeSpace(size_t vertexSize, 150 void* makeSpace(size_t vertexSize,
162 int vertexCount, 151 int vertexCount,
163 const GrVertexBuffer** buffer, 152 const GrBuffer** buffer,
164 int* startVertex); 153 int* startVertex);
165 154
166 private: 155 private:
167 typedef GrBufferAllocPool INHERITED; 156 typedef GrBufferAllocPool INHERITED;
168 }; 157 };
169 158
170 class GrIndexBuffer;
171
172 /** 159 /**
173 * A GrBufferAllocPool of index buffers 160 * A GrBufferAllocPool of index buffers
174 */ 161 */
175 class GrIndexBufferAllocPool : public GrBufferAllocPool { 162 class GrIndexBufferAllocPool : public GrBufferAllocPool {
176 public: 163 public:
177 /** 164 /**
178 * Constructor 165 * Constructor
179 * 166 *
180 * @param gpu The GrGpu used to create the index buffers. 167 * @param gpu The GrGpu used to create the index buffers.
181 */ 168 */
(...skipping 11 matching lines...) Expand all
193 * Once unmap on the pool is called the indices are guaranteed to be in the 180 * 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 181 * buffer at the offset indicated by startIndex. Until that time they may be
195 * in temporary storage and/or the buffer may be locked. 182 * in temporary storage and/or the buffer may be locked.
196 * 183 *
197 * @param indexCount number of indices to allocate space for 184 * @param indexCount number of indices to allocate space for
198 * @param buffer returns the index buffer that will hold the indices. 185 * @param buffer returns the index buffer that will hold the indices.
199 * @param startIndex returns the offset into buffer of the first index. 186 * @param startIndex returns the offset into buffer of the first index.
200 * @return pointer to first index. 187 * @return pointer to first index.
201 */ 188 */
202 void* makeSpace(int indexCount, 189 void* makeSpace(int indexCount,
203 const GrIndexBuffer** buffer, 190 const GrBuffer** buffer,
204 int* startIndex); 191 int* startIndex);
205 192
206 private: 193 private:
207 typedef GrBufferAllocPool INHERITED; 194 typedef GrBufferAllocPool INHERITED;
208 }; 195 };
209 196
210 #endif 197 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBuffer.h ('k') | src/gpu/GrBufferAllocPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698