OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/host_shared_bitmap_manager.h" | 5 #include "content/common/host_shared_bitmap_manager.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/trace_event/process_memory_dump.h" | 10 #include "base/trace_event/process_memory_dump.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 ~HostSharedBitmap() override { | 45 ~HostSharedBitmap() override { |
46 if (manager_) | 46 if (manager_) |
47 manager_->FreeSharedMemoryFromMap(id()); | 47 manager_->FreeSharedMemoryFromMap(id()); |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 scoped_refptr<BitmapData> bitmap_data_; | 51 scoped_refptr<BitmapData> bitmap_data_; |
52 HostSharedBitmapManager* manager_; | 52 HostSharedBitmapManager* manager_; |
53 }; | 53 }; |
54 | 54 |
55 const char kMemoryAllocatorName[] = "sharedbitmap"; | |
56 | |
57 } // namespace | 55 } // namespace |
58 | 56 |
59 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = | 57 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = |
60 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
61 | 59 |
62 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( | 60 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( |
63 HostSharedBitmapManager* manager) | 61 HostSharedBitmapManager* manager) |
64 : manager_(manager) { | 62 : manager_(manager) { |
65 } | 63 } |
66 | 64 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 146 |
149 return make_scoped_ptr(new HostSharedBitmap( | 147 return make_scoped_ptr(new HostSharedBitmap( |
150 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); | 148 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); |
151 } | 149 } |
152 | 150 |
153 bool HostSharedBitmapManager::OnMemoryDump( | 151 bool HostSharedBitmapManager::OnMemoryDump( |
154 base::trace_event::ProcessMemoryDump* pmd) { | 152 base::trace_event::ProcessMemoryDump* pmd) { |
155 base::AutoLock lock(lock_); | 153 base::AutoLock lock(lock_); |
156 | 154 |
157 for (const auto& bitmap : handle_map_) { | 155 for (const auto& bitmap : handle_map_) { |
158 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | 156 base::trace_event::MemoryAllocatorDump* dump = |
159 base::StringPrintf("%s/%s", kMemoryAllocatorName, | 157 pmd->CreateAllocatorDump(base::StringPrintf( |
160 base::HexEncode(bitmap.first.name, | 158 "sharedbitmap/%s", |
161 sizeof(bitmap.first.name)).c_str())); | 159 base::HexEncode(bitmap.first.name, sizeof(bitmap.first.name)) |
| 160 .c_str())); |
162 if (!dump) | 161 if (!dump) |
163 return false; | 162 return false; |
164 | 163 |
165 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 164 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
166 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 165 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
167 bitmap.second->buffer_size); | 166 bitmap.second->buffer_size); |
| 167 |
| 168 // Generate a global GUID used to share this allocation with renderer |
| 169 // processes. |
| 170 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); |
| 171 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 172 pmd->AddOwnershipEdge(dump->guid(), guid); |
168 } | 173 } |
169 | 174 |
170 return true; | 175 return true; |
171 } | 176 } |
172 | 177 |
173 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 178 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( |
174 size_t buffer_size, | 179 size_t buffer_size, |
175 const base::SharedMemoryHandle& handle, | 180 const base::SharedMemoryHandle& handle, |
176 base::ProcessHandle process_handle, | 181 base::ProcessHandle process_handle, |
177 const cc::SharedBitmapId& id) { | 182 const cc::SharedBitmapId& id) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return handle_map_.size(); | 239 return handle_map_.size(); |
235 } | 240 } |
236 | 241 |
237 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 242 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
238 const cc::SharedBitmapId& id) { | 243 const cc::SharedBitmapId& id) { |
239 base::AutoLock lock(lock_); | 244 base::AutoLock lock(lock_); |
240 handle_map_.erase(id); | 245 handle_map_.erase(id); |
241 } | 246 } |
242 | 247 |
243 } // namespace content | 248 } // namespace content |
OLD | NEW |