OLD | NEW |
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 unsigned int chunk_size_multiple_; | 192 unsigned int chunk_size_multiple_; |
193 CommandBufferHelper* helper_; | 193 CommandBufferHelper* helper_; |
194 base::Closure poll_callback_; | 194 base::Closure poll_callback_; |
195 MemoryChunkVector chunks_; | 195 MemoryChunkVector chunks_; |
196 size_t allocated_memory_; | 196 size_t allocated_memory_; |
197 size_t max_free_bytes_; | 197 size_t max_free_bytes_; |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); | 199 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); |
200 }; | 200 }; |
201 | 201 |
| 202 // A class that will manage the lifetime of a mapped memory allocation |
| 203 class GPU_EXPORT ScopedMappedMemoryPtr { |
| 204 public: |
| 205 ScopedMappedMemoryPtr( |
| 206 uint32_t size, |
| 207 CommandBufferHelper* helper, |
| 208 MappedMemoryManager* mapped_memory_manager) |
| 209 : buffer_(NULL), |
| 210 size_(0), |
| 211 shm_id_(0), |
| 212 shm_offset_(0), |
| 213 flush_after_release_(false), |
| 214 helper_(helper), |
| 215 mapped_memory_manager_(mapped_memory_manager) { |
| 216 Reset(size); |
| 217 } |
| 218 |
| 219 ~ScopedMappedMemoryPtr() { |
| 220 Release(); |
| 221 } |
| 222 |
| 223 bool valid() const { |
| 224 return buffer_ != NULL; |
| 225 } |
| 226 |
| 227 void SetFlushAfterRelease(bool flush_after_release) { |
| 228 flush_after_release_ = flush_after_release; |
| 229 } |
| 230 |
| 231 uint32_t size() const { |
| 232 return size_; |
| 233 } |
| 234 |
| 235 int32_t shm_id() const { |
| 236 return shm_id_; |
| 237 } |
| 238 |
| 239 uint32_t offset() const { |
| 240 return shm_offset_; |
| 241 } |
| 242 |
| 243 void* address() const { |
| 244 return buffer_; |
| 245 } |
| 246 |
| 247 void Release(); |
| 248 |
| 249 void Reset(uint32_t new_size); |
| 250 |
| 251 private: |
| 252 void* buffer_; |
| 253 uint32_t size_; |
| 254 int32_t shm_id_; |
| 255 uint32_t shm_offset_; |
| 256 bool flush_after_release_; |
| 257 CommandBufferHelper* helper_; |
| 258 MappedMemoryManager* mapped_memory_manager_; |
| 259 DISALLOW_COPY_AND_ASSIGN(ScopedMappedMemoryPtr); |
| 260 }; |
| 261 |
202 } // namespace gpu | 262 } // namespace gpu |
203 | 263 |
204 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ | 264 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ |
OLD | NEW |