| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <functional> | 11 #include <functional> |
| 12 | 12 |
| 13 #include "base/atomic_sequence_num.h" | 13 #include "base/atomic_sequence_num.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/trace_event/memory_dump_manager.h" | 18 #include "base/trace_event/memory_dump_manager.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 20 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 20 #include "gpu/command_buffer/common/buffer.h" | 21 #include "gpu/command_buffer/common/buffer.h" |
| 21 | 22 |
| 22 namespace gpu { | 23 namespace gpu { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * | 114 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * |
| 114 chunk_size_multiple_; | 115 chunk_size_multiple_; |
| 115 int32_t id = -1; | 116 int32_t id = -1; |
| 116 scoped_refptr<gpu::Buffer> shm = | 117 scoped_refptr<gpu::Buffer> shm = |
| 117 cmd_buf->CreateTransferBuffer(chunk_size, &id); | 118 cmd_buf->CreateTransferBuffer(chunk_size, &id); |
| 118 if (id < 0) | 119 if (id < 0) |
| 119 return NULL; | 120 return NULL; |
| 120 DCHECK(shm.get()); | 121 DCHECK(shm.get()); |
| 121 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); | 122 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); |
| 122 allocated_memory_ += mc->GetSize(); | 123 allocated_memory_ += mc->GetSize(); |
| 123 chunks_.push_back(make_scoped_ptr(mc)); | 124 chunks_.push_back(base::WrapUnique(mc)); |
| 124 void* mem = mc->Alloc(size); | 125 void* mem = mc->Alloc(size); |
| 125 DCHECK(mem); | 126 DCHECK(mem); |
| 126 *shm_id = mc->shm_id(); | 127 *shm_id = mc->shm_id(); |
| 127 *shm_offset = mc->GetOffset(mem); | 128 *shm_offset = mc->GetOffset(mem); |
| 128 return mem; | 129 return mem; |
| 129 } | 130 } |
| 130 | 131 |
| 131 void MappedMemoryManager::Free(void* pointer) { | 132 void MappedMemoryManager::Free(void* pointer) { |
| 132 for (auto& chunk : chunks_) { | 133 for (auto& chunk : chunks_) { |
| 133 if (chunk->IsInChunk(pointer)) { | 134 if (chunk->IsInChunk(pointer)) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { | 211 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { |
| 211 Release(); | 212 Release(); |
| 212 | 213 |
| 213 if (new_size) { | 214 if (new_size) { |
| 214 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); | 215 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); |
| 215 size_ = buffer_ ? new_size : 0; | 216 size_ = buffer_ ? new_size : 0; |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace gpu | 220 } // namespace gpu |
| OLD | NEW |