| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "gpu/command_buffer/client/mapped_memory.h" | 5 #include "gpu/command_buffer/client/mapped_memory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 13 | 13 |
| 14 namespace gpu { | 14 namespace gpu { |
| 15 | 15 |
| 16 MemoryChunk::MemoryChunk(int32 shm_id, | 16 MemoryChunk::MemoryChunk(int32 shm_id, |
| 17 scoped_refptr<gpu::Buffer> shm, | 17 scoped_refptr<gpu::Buffer> shm, |
| 18 CommandBufferHelper* helper, | 18 CommandBufferHelper* helper) |
| 19 const base::Closure& poll_callback) | |
| 20 : shm_id_(shm_id), | 19 : shm_id_(shm_id), |
| 21 shm_(shm), | 20 shm_(shm), |
| 22 allocator_(shm->size(), helper, poll_callback, shm->memory()) {} | 21 allocator_(shm->size(), helper, shm->memory()) {} |
| 23 | 22 |
| 24 MemoryChunk::~MemoryChunk() {} | 23 MemoryChunk::~MemoryChunk() {} |
| 25 | 24 |
| 26 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, | 25 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, |
| 27 const base::Closure& poll_callback, | |
| 28 size_t unused_memory_reclaim_limit) | 26 size_t unused_memory_reclaim_limit) |
| 29 : chunk_size_multiple_(1), | 27 : chunk_size_multiple_(1), |
| 30 helper_(helper), | 28 helper_(helper), |
| 31 poll_callback_(poll_callback), | |
| 32 allocated_memory_(0), | 29 allocated_memory_(0), |
| 33 max_free_bytes_(unused_memory_reclaim_limit) { | 30 max_free_bytes_(unused_memory_reclaim_limit) { |
| 34 } | 31 } |
| 35 | 32 |
| 36 MappedMemoryManager::~MappedMemoryManager() { | 33 MappedMemoryManager::~MappedMemoryManager() { |
| 37 CommandBuffer* cmd_buf = helper_->command_buffer(); | 34 CommandBuffer* cmd_buf = helper_->command_buffer(); |
| 38 for (MemoryChunkVector::iterator iter = chunks_.begin(); | 35 for (MemoryChunkVector::iterator iter = chunks_.begin(); |
| 39 iter != chunks_.end(); ++iter) { | 36 iter != chunks_.end(); ++iter) { |
| 40 MemoryChunk* chunk = *iter; | 37 MemoryChunk* chunk = *iter; |
| 41 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); | 38 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Make a new chunk to satisfy the request. | 81 // Make a new chunk to satisfy the request. |
| 85 CommandBuffer* cmd_buf = helper_->command_buffer(); | 82 CommandBuffer* cmd_buf = helper_->command_buffer(); |
| 86 unsigned int chunk_size = | 83 unsigned int chunk_size = |
| 87 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * | 84 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * |
| 88 chunk_size_multiple_; | 85 chunk_size_multiple_; |
| 89 int32 id = -1; | 86 int32 id = -1; |
| 90 scoped_refptr<gpu::Buffer> shm = | 87 scoped_refptr<gpu::Buffer> shm = |
| 91 cmd_buf->CreateTransferBuffer(chunk_size, &id); | 88 cmd_buf->CreateTransferBuffer(chunk_size, &id); |
| 92 if (id < 0) | 89 if (id < 0) |
| 93 return NULL; | 90 return NULL; |
| 94 MemoryChunk* mc = new MemoryChunk(id, shm, helper_, poll_callback_); | 91 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); |
| 95 allocated_memory_ += mc->GetSize(); | 92 allocated_memory_ += mc->GetSize(); |
| 96 chunks_.push_back(mc); | 93 chunks_.push_back(mc); |
| 97 void* mem = mc->Alloc(size); | 94 void* mem = mc->Alloc(size); |
| 98 DCHECK(mem); | 95 DCHECK(mem); |
| 99 *shm_id = mc->shm_id(); | 96 *shm_id = mc->shm_id(); |
| 100 *shm_offset = mc->GetOffset(mem); | 97 *shm_offset = mc->GetOffset(mem); |
| 101 return mem; | 98 return mem; |
| 102 } | 99 } |
| 103 | 100 |
| 104 void MappedMemoryManager::Free(void* pointer) { | 101 void MappedMemoryManager::Free(void* pointer) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 133 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); | 130 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); |
| 134 allocated_memory_ -= chunk->GetSize(); | 131 allocated_memory_ -= chunk->GetSize(); |
| 135 iter = chunks_.erase(iter); | 132 iter = chunks_.erase(iter); |
| 136 } else { | 133 } else { |
| 137 ++iter; | 134 ++iter; |
| 138 } | 135 } |
| 139 } | 136 } |
| 140 } | 137 } |
| 141 | 138 |
| 142 } // namespace gpu | 139 } // namespace gpu |
| OLD | NEW |