Chromium Code Reviews| 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/stringprintf.h" | |
| 10 #include "base/thread_task_runner_handle.h" | |
| 11 #include "base/trace_event/memory_dump_manager.h" | |
| 12 #include "base/trace_event/process_memory_dump.h" | |
| 9 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 10 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 11 | 15 |
| 12 namespace content { | 16 namespace content { |
| 13 | 17 |
| 14 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { | 18 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { |
| 15 public: | 19 public: |
| 16 BitmapData(base::ProcessHandle process_handle, | 20 BitmapData(base::ProcessHandle process_handle, |
| 17 size_t buffer_size) | 21 size_t buffer_size) |
| 18 : process_handle(process_handle), | 22 : process_handle(process_handle), |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 43 ~HostSharedBitmap() override { | 47 ~HostSharedBitmap() override { |
| 44 if (manager_) | 48 if (manager_) |
| 45 manager_->FreeSharedMemoryFromMap(id()); | 49 manager_->FreeSharedMemoryFromMap(id()); |
| 46 } | 50 } |
| 47 | 51 |
| 48 private: | 52 private: |
| 49 scoped_refptr<BitmapData> bitmap_data_; | 53 scoped_refptr<BitmapData> bitmap_data_; |
| 50 HostSharedBitmapManager* manager_; | 54 HostSharedBitmapManager* manager_; |
| 51 }; | 55 }; |
| 52 | 56 |
| 57 const char kMemoryAllocatorName[] = "sharedbitmap"; | |
| 58 | |
| 53 } // namespace | 59 } // namespace |
| 54 | 60 |
| 55 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = | 61 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = |
| 56 LAZY_INSTANCE_INITIALIZER; | 62 LAZY_INSTANCE_INITIALIZER; |
| 57 | 63 |
| 58 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( | 64 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( |
| 59 HostSharedBitmapManager* manager) | 65 HostSharedBitmapManager* manager) |
| 60 : manager_(manager) { | 66 : manager_(manager) { |
| 61 } | 67 } |
| 62 | 68 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 83 manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id); | 89 manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id); |
| 84 owned_bitmaps_.insert(id); | 90 owned_bitmaps_.insert(id); |
| 85 } | 91 } |
| 86 | 92 |
| 87 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( | 93 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( |
| 88 const cc::SharedBitmapId& id) { | 94 const cc::SharedBitmapId& id) { |
| 89 manager_->ChildDeletedSharedBitmap(id); | 95 manager_->ChildDeletedSharedBitmap(id); |
| 90 owned_bitmaps_.erase(id); | 96 owned_bitmaps_.erase(id); |
| 91 } | 97 } |
| 92 | 98 |
| 93 HostSharedBitmapManager::HostSharedBitmapManager() {} | 99 HostSharedBitmapManager::HostSharedBitmapManager() { |
| 100 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 101 this); | |
|
Primiano Tucci (use gerrit)
2015/04/28 21:40:06
I think you want a task_runner (IIRC the HostSBM i
reveman
2015/04/29 01:45:58
This is a singleton. See HostSharedBitmapManager::
| |
| 102 } | |
| 103 | |
| 94 HostSharedBitmapManager::~HostSharedBitmapManager() { | 104 HostSharedBitmapManager::~HostSharedBitmapManager() { |
| 95 DCHECK(handle_map_.empty()); | 105 DCHECK(handle_map_.empty()); |
| 106 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 107 this); | |
|
Primiano Tucci (use gerrit)
2015/04/28 21:40:06
Hmm if you unregister you should specify a task_ru
reveman
2015/04/29 01:45:58
Makes sense. I moved RegisterDumpProvider() call t
| |
| 96 } | 108 } |
| 97 | 109 |
| 98 HostSharedBitmapManager* HostSharedBitmapManager::current() { | 110 HostSharedBitmapManager* HostSharedBitmapManager::current() { |
| 99 return g_shared_memory_manager.Pointer(); | 111 return g_shared_memory_manager.Pointer(); |
| 100 } | 112 } |
| 101 | 113 |
| 102 scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::AllocateSharedBitmap( | 114 scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::AllocateSharedBitmap( |
| 103 const gfx::Size& size) { | 115 const gfx::Size& size) { |
| 104 base::AutoLock lock(lock_); | 116 base::AutoLock lock(lock_); |
| 105 size_t bitmap_size; | 117 size_t bitmap_size; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 new HostSharedBitmap(data->pixels.get(), data, id, nullptr)); | 151 new HostSharedBitmap(data->pixels.get(), data, id, nullptr)); |
| 140 } | 152 } |
| 141 if (!data->memory->memory()) { | 153 if (!data->memory->memory()) { |
| 142 return scoped_ptr<cc::SharedBitmap>(); | 154 return scoped_ptr<cc::SharedBitmap>(); |
| 143 } | 155 } |
| 144 | 156 |
| 145 return make_scoped_ptr(new HostSharedBitmap( | 157 return make_scoped_ptr(new HostSharedBitmap( |
| 146 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); | 158 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); |
| 147 } | 159 } |
| 148 | 160 |
| 161 bool HostSharedBitmapManager::OnMemoryDump( | |
| 162 base::trace_event::ProcessMemoryDump* pmd) { | |
| 163 base::AutoLock lock(lock_); | |
| 164 | |
| 165 for (const auto& bitmap_it : handle_map_) { | |
| 166 std::string heap_name; | |
| 167 | |
| 168 for (size_t i = 0; i < sizeof(bitmap_it.first.name); ++i) | |
| 169 base::StringAppendF(&heap_name, "%02x", bitmap_it.first.name[i]); | |
| 170 | |
| 171 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | |
| 172 base::StringPrintf("%s/%s", kMemoryAllocatorName, heap_name.c_str())); | |
| 173 if (!dump) | |
| 174 return false; | |
| 175 | |
| 176 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameOuterSize, | |
| 177 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 178 bitmap_it.second->buffer_size); | |
| 179 } | |
| 180 | |
| 181 return true; | |
| 182 } | |
| 183 | |
| 149 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 184 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( |
| 150 size_t buffer_size, | 185 size_t buffer_size, |
| 151 const base::SharedMemoryHandle& handle, | 186 const base::SharedMemoryHandle& handle, |
| 152 base::ProcessHandle process_handle, | 187 base::ProcessHandle process_handle, |
| 153 const cc::SharedBitmapId& id) { | 188 const cc::SharedBitmapId& id) { |
| 154 base::AutoLock lock(lock_); | 189 base::AutoLock lock(lock_); |
| 155 if (handle_map_.find(id) != handle_map_.end()) | 190 if (handle_map_.find(id) != handle_map_.end()) |
| 156 return; | 191 return; |
| 157 scoped_refptr<BitmapData> data( | 192 scoped_refptr<BitmapData> data( |
| 158 new BitmapData(process_handle, buffer_size)); | 193 new BitmapData(process_handle, buffer_size)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 return handle_map_.size(); | 245 return handle_map_.size(); |
| 211 } | 246 } |
| 212 | 247 |
| 213 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 248 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
| 214 const cc::SharedBitmapId& id) { | 249 const cc::SharedBitmapId& id) { |
| 215 base::AutoLock lock(lock_); | 250 base::AutoLock lock(lock_); |
| 216 handle_map_.erase(id); | 251 handle_map_.erase(id); |
| 217 } | 252 } |
| 218 | 253 |
| 219 } // namespace content | 254 } // namespace content |
| OLD | NEW |