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" |
23 | 24 |
24 using ::base::SharedMemory; | 25 using ::base::SharedMemory; |
25 | 26 |
26 namespace gpu { | 27 namespace gpu { |
27 | 28 |
28 TransferBufferManagerInterface::~TransferBufferManagerInterface() { | 29 TransferBufferManagerInterface::~TransferBufferManagerInterface() { |
29 } | 30 } |
30 | 31 |
31 TransferBufferManager::TransferBufferManager( | 32 TransferBufferManager::TransferBufferManager( |
32 gles2::MemoryTracker* memory_tracker) | 33 gles2::MemoryTracker* memory_tracker) |
33 : shared_memory_bytes_allocated_(0), memory_tracker_(memory_tracker) {} | 34 : shared_memory_bytes_allocated_(0), memory_tracker_(memory_tracker) {} |
34 | 35 |
35 TransferBufferManager::~TransferBufferManager() { | 36 TransferBufferManager::~TransferBufferManager() { |
36 while (!registered_buffers_.empty()) { | 37 while (!registered_buffers_.empty()) { |
37 BufferMap::iterator it = registered_buffers_.begin(); | 38 BufferMap::iterator it = registered_buffers_.begin(); |
38 if (it->second->backing()->is_shared()) { | 39 if (it->second->backing()->shared_memory()) { |
39 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); | 40 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); |
40 shared_memory_bytes_allocated_ -= it->second->size(); | 41 shared_memory_bytes_allocated_ -= it->second->size(); |
41 } | 42 } |
42 registered_buffers_.erase(it); | 43 registered_buffers_.erase(it); |
43 } | 44 } |
44 DCHECK(!shared_memory_bytes_allocated_); | 45 DCHECK(!shared_memory_bytes_allocated_); |
45 | 46 |
46 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 47 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
47 this); | 48 this); |
48 } | 49 } |
(...skipping 23 matching lines...) Expand all Loading... |
72 return false; | 73 return false; |
73 } | 74 } |
74 | 75 |
75 // Register the shared memory with the ID. | 76 // Register the shared memory with the ID. |
76 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing))); | 77 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing))); |
77 | 78 |
78 // Check buffer alignment is sane. | 79 // Check buffer alignment is sane. |
79 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & | 80 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & |
80 (kCommandBufferEntrySize - 1))); | 81 (kCommandBufferEntrySize - 1))); |
81 | 82 |
82 if (buffer->backing()->is_shared()) | 83 if (buffer->backing()->shared_memory()) |
83 shared_memory_bytes_allocated_ += buffer->size(); | 84 shared_memory_bytes_allocated_ += buffer->size(); |
84 registered_buffers_[id] = buffer; | 85 registered_buffers_[id] = buffer; |
85 | 86 |
86 return true; | 87 return true; |
87 } | 88 } |
88 | 89 |
89 void TransferBufferManager::DestroyTransferBuffer(int32_t id) { | 90 void TransferBufferManager::DestroyTransferBuffer(int32_t id) { |
90 BufferMap::iterator it = registered_buffers_.find(id); | 91 BufferMap::iterator it = registered_buffers_.find(id); |
91 if (it == registered_buffers_.end()) { | 92 if (it == registered_buffers_.end()) { |
92 DVLOG(0) << "Transfer buffer ID was not registered."; | 93 DVLOG(0) << "Transfer buffer ID was not registered."; |
93 return; | 94 return; |
94 } | 95 } |
95 | 96 |
96 if (it->second->backing()->is_shared()) { | 97 if (it->second->backing()->shared_memory()) { |
97 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); | 98 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); |
98 shared_memory_bytes_allocated_ -= it->second->size(); | 99 shared_memory_bytes_allocated_ -= it->second->size(); |
99 } | 100 } |
100 registered_buffers_.erase(it); | 101 registered_buffers_.erase(it); |
101 } | 102 } |
102 | 103 |
103 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32_t id) { | 104 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32_t id) { |
104 if (id == 0) | 105 if (id == 0) |
105 return NULL; | 106 return NULL; |
106 | 107 |
(...skipping 24 matching lines...) Expand all Loading... |
131 | 132 |
132 for (const auto& buffer_entry : registered_buffers_) { | 133 for (const auto& buffer_entry : registered_buffers_) { |
133 int32_t buffer_id = buffer_entry.first; | 134 int32_t buffer_id = buffer_entry.first; |
134 const Buffer* buffer = buffer_entry.second.get(); | 135 const Buffer* buffer = buffer_entry.second.get(); |
135 std::string dump_name = | 136 std::string dump_name = |
136 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d", | 137 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d", |
137 memory_tracker_->ClientId(), buffer_id); | 138 memory_tracker_->ClientId(), buffer_id); |
138 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); | 139 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); |
139 dump->AddScalar(MemoryAllocatorDump::kNameSize, | 140 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
140 MemoryAllocatorDump::kUnitsBytes, buffer->size()); | 141 MemoryAllocatorDump::kUnitsBytes, buffer->size()); |
141 if (buffer->backing()->is_shared()) { | 142 base::SharedMemory* shared_memory = |
| 143 buffer_entry.second->backing()->shared_memory(); |
| 144 if (shared_memory) { |
142 auto guid = GetBufferGUIDForTracing(memory_tracker_->ClientTracingId(), | 145 auto guid = GetBufferGUIDForTracing(memory_tracker_->ClientTracingId(), |
143 buffer_id); | 146 buffer_id); |
144 pmd->CreateSharedGlobalAllocatorDump(guid); | 147 pmd->CreateSharedGlobalAllocatorDump(guid); |
145 pmd->AddOwnershipEdge(dump->guid(), guid); | 148 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 149 base::SharedMemoryTracker::AddOwnershipEdgeToSharedGlobalDump(pmd, guid, |
| 150 shared_memory->handle(), shared_memory->mapped_size()); |
146 } | 151 } |
147 } | 152 } |
148 | 153 |
149 return true; | 154 return true; |
150 } | 155 } |
151 | 156 |
152 } // namespace gpu | 157 } // namespace gpu |
OLD | NEW |