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

Side by Side Diff: gpu/command_buffer/client/mapped_memory.h

Issue 1168853002: Use mapped memory for uploading large textures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added dcheck and improved other error messages Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 unsigned int chunk_size_multiple() const { 133 unsigned int chunk_size_multiple() const {
134 return chunk_size_multiple_; 134 return chunk_size_multiple_;
135 } 135 }
136 136
137 void set_chunk_size_multiple(unsigned int multiple) { 137 void set_chunk_size_multiple(unsigned int multiple) {
138 DCHECK(multiple % FencedAllocator::kAllocAlignment == 0); 138 DCHECK(multiple % FencedAllocator::kAllocAlignment == 0);
139 chunk_size_multiple_ = multiple; 139 chunk_size_multiple_ = multiple;
140 } 140 }
141 141
142 size_t max_allocated_bytes() const {
143 return max_allocated_bytes_;
144 }
145
146 void set_max_allocated_bytes(size_t max_allocated_bytes) {
147 max_allocated_bytes_ = max_allocated_bytes;
148 }
149
142 // Allocates a block of memory 150 // Allocates a block of memory
143 // Parameters: 151 // Parameters:
144 // size: size of memory to allocate. 152 // size: size of memory to allocate.
145 // shm_id: pointer to variable to receive the shared memory id. 153 // shm_id: pointer to variable to receive the shared memory id.
146 // shm_offset: pointer to variable to receive the shared memory offset. 154 // shm_offset: pointer to variable to receive the shared memory offset.
147 // Returns: 155 // Returns:
148 // pointer to allocated block of memory. NULL if failure. 156 // pointer to allocated block of memory. NULL if failure.
149 void* Alloc( 157 void* Alloc(
150 unsigned int size, int32_t* shm_id, unsigned int* shm_offset); 158 unsigned int size, int32_t* shm_id, unsigned int* shm_offset);
151 159
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 private: 196 private:
189 typedef ScopedVector<MemoryChunk> MemoryChunkVector; 197 typedef ScopedVector<MemoryChunk> MemoryChunkVector;
190 198
191 // size a chunk is rounded up to. 199 // size a chunk is rounded up to.
192 unsigned int chunk_size_multiple_; 200 unsigned int chunk_size_multiple_;
193 CommandBufferHelper* helper_; 201 CommandBufferHelper* helper_;
194 base::Closure poll_callback_; 202 base::Closure poll_callback_;
195 MemoryChunkVector chunks_; 203 MemoryChunkVector chunks_;
196 size_t allocated_memory_; 204 size_t allocated_memory_;
197 size_t max_free_bytes_; 205 size_t max_free_bytes_;
206 size_t max_allocated_bytes_;
198 207
199 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 208 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
200 }; 209 };
201 210
211 // A class that will manage the lifetime of a mapped memory allocation
212 class GPU_EXPORT ScopedMappedMemoryPtr {
213 public:
214 ScopedMappedMemoryPtr(
215 uint32_t size,
216 CommandBufferHelper* helper,
217 MappedMemoryManager* mapped_memory_manager)
218 : buffer_(NULL),
219 size_(0),
220 shm_id_(0),
221 shm_offset_(0),
222 flush_after_release_(false),
223 helper_(helper),
224 mapped_memory_manager_(mapped_memory_manager) {
225 Reset(size);
226 }
227
228 ~ScopedMappedMemoryPtr() {
229 Release();
230 }
231
232 bool valid() const {
233 return buffer_ != NULL;
234 }
235
236 void SetFlushAfterRelease(bool flush_after_release) {
237 flush_after_release_ = flush_after_release;
238 }
239
240 uint32_t size() const {
241 return size_;
242 }
243
244 int32_t shm_id() const {
245 return shm_id_;
246 }
247
248 uint32_t offset() const {
249 return shm_offset_;
250 }
251
252 void* address() const {
253 return buffer_;
254 }
255
256 void Release();
257
258 void Reset(uint32_t new_size);
259
260 private:
261 void* buffer_;
262 uint32_t size_;
263 int32_t shm_id_;
264 uint32_t shm_offset_;
265 bool flush_after_release_;
266 CommandBufferHelper* helper_;
267 MappedMemoryManager* mapped_memory_manager_;
268 DISALLOW_COPY_AND_ASSIGN(ScopedMappedMemoryPtr);
269 };
270
202 } // namespace gpu 271 } // namespace gpu
203 272
204 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 273 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_unittest.cc ('k') | gpu/command_buffer/client/mapped_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698