| 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/memory/ptr_util.h" |
| 16 #include "base/memory/shared_memory_tracker.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/memory_dump_manager.h" | 19 #include "base/trace_event/memory_dump_manager.h" |
| 19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 20 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 21 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 21 #include "gpu/command_buffer/client/shared_memory_limits.h" | 22 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 22 #include "gpu/command_buffer/common/buffer.h" | 23 #include "gpu/command_buffer/common/buffer.h" |
| 23 | 24 |
| 24 namespace gpu { | 25 namespace gpu { |
| 25 namespace { | 26 namespace { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 for (const auto& chunk : chunks_) { | 180 for (const auto& chunk : chunks_) { |
| 180 std::string dump_name = base::StringPrintf( | 181 std::string dump_name = base::StringPrintf( |
| 181 "gpu/mapped_memory/manager_%d/chunk_%d", tracing_id_, chunk->shm_id()); | 182 "gpu/mapped_memory/manager_%d/chunk_%d", tracing_id_, chunk->shm_id()); |
| 182 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); | 183 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); |
| 183 | 184 |
| 184 dump->AddScalar(MemoryAllocatorDump::kNameSize, | 185 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
| 185 MemoryAllocatorDump::kUnitsBytes, chunk->GetSize()); | 186 MemoryAllocatorDump::kUnitsBytes, chunk->GetSize()); |
| 186 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, | 187 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, |
| 187 chunk->GetFreeSize()); | 188 chunk->GetFreeSize()); |
| 188 | 189 |
| 189 auto guid = GetBufferGUIDForTracing(tracing_process_id, chunk->shm_id()); | 190 auto shared_memory = chunk->buffer()->backing()->shared_memory(); |
| 191 if (shared_memory) { |
| 192 auto guid = GetBufferGUIDForTracing(tracing_process_id, chunk->shm_id()); |
| 190 | 193 |
| 191 const int kImportance = 2; | 194 const int kImportance = 2; |
| 192 pmd->CreateSharedGlobalAllocatorDump(guid); | 195 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 193 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 196 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 197 base::SharedMemoryTracker::AddOwnershipEdgeToSharedGlobalDump(pmd, guid, |
| 198 shared_memory->handle(), shared_memory->mapped_size()); |
| 199 } |
| 194 } | 200 } |
| 195 | 201 |
| 196 return true; | 202 return true; |
| 197 } | 203 } |
| 198 | 204 |
| 199 void ScopedMappedMemoryPtr::Release() { | 205 void ScopedMappedMemoryPtr::Release() { |
| 200 if (buffer_) { | 206 if (buffer_) { |
| 201 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken()); | 207 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken()); |
| 202 buffer_ = nullptr; | 208 buffer_ = nullptr; |
| 203 size_ = 0; | 209 size_ = 0; |
| 204 shm_id_ = 0; | 210 shm_id_ = 0; |
| 205 shm_offset_ = 0; | 211 shm_offset_ = 0; |
| 206 | 212 |
| 207 if (flush_after_release_) | 213 if (flush_after_release_) |
| 208 helper_->CommandBufferHelper::Flush(); | 214 helper_->CommandBufferHelper::Flush(); |
| 209 } | 215 } |
| 210 } | 216 } |
| 211 | 217 |
| 212 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { | 218 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { |
| 213 Release(); | 219 Release(); |
| 214 | 220 |
| 215 if (new_size) { | 221 if (new_size) { |
| 216 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); | 222 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); |
| 217 size_ = buffer_ ? new_size : 0; | 223 size_ = buffer_ ? new_size : 0; |
| 218 } | 224 } |
| 219 } | 225 } |
| 220 | 226 |
| 221 } // namespace gpu | 227 } // namespace gpu |
| OLD | NEW |