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 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 5 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/shared_memory_tracker.h" |
13 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/trace_event/memory_allocator_dump.h" | 17 #include "base/trace_event/memory_allocator_dump.h" |
17 #include "base/trace_event/memory_dump_manager.h" | 18 #include "base/trace_event/memory_dump_manager.h" |
18 #include "base/trace_event/process_memory_dump.h" | 19 #include "base/trace_event/process_memory_dump.h" |
19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
20 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 21 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
22 #include "gpu/command_buffer/service/memory_tracking.h" | 23 #include "gpu/command_buffer/service/memory_tracking.h" |
(...skipping 10 matching lines...) Expand all Loading... |
33 if (memory_tracker_) { | 34 if (memory_tracker_) { |
34 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 35 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
35 this, "gpu::TransferBufferManager", | 36 this, "gpu::TransferBufferManager", |
36 base::ThreadTaskRunnerHandle::Get()); | 37 base::ThreadTaskRunnerHandle::Get()); |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 TransferBufferManager::~TransferBufferManager() { | 41 TransferBufferManager::~TransferBufferManager() { |
41 while (!registered_buffers_.empty()) { | 42 while (!registered_buffers_.empty()) { |
42 BufferMap::iterator it = registered_buffers_.begin(); | 43 BufferMap::iterator it = registered_buffers_.begin(); |
43 if (it->second->backing()->is_shared()) { | 44 if (it->second->backing()->shared_memory()) { |
44 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); | 45 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); |
45 shared_memory_bytes_allocated_ -= it->second->size(); | 46 shared_memory_bytes_allocated_ -= it->second->size(); |
46 } | 47 } |
47 registered_buffers_.erase(it); | 48 registered_buffers_.erase(it); |
48 } | 49 } |
49 DCHECK(!shared_memory_bytes_allocated_); | 50 DCHECK(!shared_memory_bytes_allocated_); |
50 | 51 |
51 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 52 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
52 this); | 53 this); |
53 } | 54 } |
(...skipping 12 matching lines...) Expand all Loading... |
66 return false; | 67 return false; |
67 } | 68 } |
68 | 69 |
69 // Register the shared memory with the ID. | 70 // Register the shared memory with the ID. |
70 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing))); | 71 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing))); |
71 | 72 |
72 // Check buffer alignment is sane. | 73 // Check buffer alignment is sane. |
73 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & | 74 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & |
74 (kCommandBufferEntrySize - 1))); | 75 (kCommandBufferEntrySize - 1))); |
75 | 76 |
76 if (buffer->backing()->is_shared()) | 77 if (buffer->backing()->shared_memory()) |
77 shared_memory_bytes_allocated_ += buffer->size(); | 78 shared_memory_bytes_allocated_ += buffer->size(); |
78 registered_buffers_[id] = buffer; | 79 registered_buffers_[id] = buffer; |
79 | 80 |
80 return true; | 81 return true; |
81 } | 82 } |
82 | 83 |
83 void TransferBufferManager::DestroyTransferBuffer(int32_t id) { | 84 void TransferBufferManager::DestroyTransferBuffer(int32_t id) { |
84 BufferMap::iterator it = registered_buffers_.find(id); | 85 BufferMap::iterator it = registered_buffers_.find(id); |
85 if (it == registered_buffers_.end()) { | 86 if (it == registered_buffers_.end()) { |
86 DVLOG(0) << "Transfer buffer ID was not registered."; | 87 DVLOG(0) << "Transfer buffer ID was not registered."; |
87 return; | 88 return; |
88 } | 89 } |
89 | 90 |
90 if (it->second->backing()->is_shared()) { | 91 if (it->second->backing()->shared_memory()) { |
91 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); | 92 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); |
92 shared_memory_bytes_allocated_ -= it->second->size(); | 93 shared_memory_bytes_allocated_ -= it->second->size(); |
93 } | 94 } |
94 registered_buffers_.erase(it); | 95 registered_buffers_.erase(it); |
95 } | 96 } |
96 | 97 |
97 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32_t id) { | 98 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32_t id) { |
98 if (id == 0) | 99 if (id == 0) |
99 return NULL; | 100 return NULL; |
100 | 101 |
(...skipping 24 matching lines...) Expand all Loading... |
125 | 126 |
126 for (const auto& buffer_entry : registered_buffers_) { | 127 for (const auto& buffer_entry : registered_buffers_) { |
127 int32_t buffer_id = buffer_entry.first; | 128 int32_t buffer_id = buffer_entry.first; |
128 const Buffer* buffer = buffer_entry.second.get(); | 129 const Buffer* buffer = buffer_entry.second.get(); |
129 std::string dump_name = | 130 std::string dump_name = |
130 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d", | 131 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d", |
131 memory_tracker_->ClientId(), buffer_id); | 132 memory_tracker_->ClientId(), buffer_id); |
132 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); | 133 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); |
133 dump->AddScalar(MemoryAllocatorDump::kNameSize, | 134 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
134 MemoryAllocatorDump::kUnitsBytes, buffer->size()); | 135 MemoryAllocatorDump::kUnitsBytes, buffer->size()); |
135 if (buffer->backing()->is_shared()) { | 136 base::SharedMemory* shared_memory = |
136 auto guid = GetBufferGUIDForTracing(memory_tracker_->ClientTracingId(), | 137 buffer_entry.second->backing()->shared_memory(); |
137 buffer_id); | 138 if (shared_memory) { |
138 pmd->CreateSharedGlobalAllocatorDump(guid); | 139 base::SharedMemoryTracker::AddOwnershipEdges(pmd, dump->guid(), |
139 pmd->AddOwnershipEdge(dump->guid(), guid); | 140 *shared_memory); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 return true; | 144 return true; |
144 } | 145 } |
145 | 146 |
146 } // namespace gpu | 147 } // namespace gpu |
OLD | NEW |