| 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" |
| 10 #include "base/trace_event/process_memory_dump.h" |
| 9 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 10 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 14 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { | 16 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { |
| 15 public: | 17 public: |
| 16 BitmapData(base::ProcessHandle process_handle, | 18 BitmapData(base::ProcessHandle process_handle, |
| 17 size_t buffer_size) | 19 size_t buffer_size) |
| 18 : process_handle(process_handle), | 20 : process_handle(process_handle), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 ~HostSharedBitmap() override { | 45 ~HostSharedBitmap() override { |
| 44 if (manager_) | 46 if (manager_) |
| 45 manager_->FreeSharedMemoryFromMap(id()); | 47 manager_->FreeSharedMemoryFromMap(id()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 scoped_refptr<BitmapData> bitmap_data_; | 51 scoped_refptr<BitmapData> bitmap_data_; |
| 50 HostSharedBitmapManager* manager_; | 52 HostSharedBitmapManager* manager_; |
| 51 }; | 53 }; |
| 52 | 54 |
| 55 const char kMemoryAllocatorName[] = "sharedbitmap"; |
| 56 |
| 53 } // namespace | 57 } // namespace |
| 54 | 58 |
| 55 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = | 59 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = |
| 56 LAZY_INSTANCE_INITIALIZER; | 60 LAZY_INSTANCE_INITIALIZER; |
| 57 | 61 |
| 58 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( | 62 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( |
| 59 HostSharedBitmapManager* manager) | 63 HostSharedBitmapManager* manager) |
| 60 : manager_(manager) { | 64 : manager_(manager) { |
| 61 } | 65 } |
| 62 | 66 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 new HostSharedBitmap(data->pixels.get(), data, id, nullptr)); | 143 new HostSharedBitmap(data->pixels.get(), data, id, nullptr)); |
| 140 } | 144 } |
| 141 if (!data->memory->memory()) { | 145 if (!data->memory->memory()) { |
| 142 return scoped_ptr<cc::SharedBitmap>(); | 146 return scoped_ptr<cc::SharedBitmap>(); |
| 143 } | 147 } |
| 144 | 148 |
| 145 return make_scoped_ptr(new HostSharedBitmap( | 149 return make_scoped_ptr(new HostSharedBitmap( |
| 146 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); | 150 static_cast<uint8*>(data->memory->memory()), data, id, nullptr)); |
| 147 } | 151 } |
| 148 | 152 |
| 153 bool HostSharedBitmapManager::OnMemoryDump( |
| 154 base::trace_event::ProcessMemoryDump* pmd) { |
| 155 base::AutoLock lock(lock_); |
| 156 |
| 157 for (const auto& bitmap : handle_map_) { |
| 158 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( |
| 159 base::StringPrintf("%s/%s", kMemoryAllocatorName, |
| 160 base::HexEncode(bitmap.first.name, |
| 161 sizeof(bitmap.first.name)).c_str())); |
| 162 if (!dump) |
| 163 return false; |
| 164 |
| 165 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameOuterSize, |
| 166 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 167 bitmap.second->buffer_size); |
| 168 } |
| 169 |
| 170 return true; |
| 171 } |
| 172 |
| 149 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 173 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( |
| 150 size_t buffer_size, | 174 size_t buffer_size, |
| 151 const base::SharedMemoryHandle& handle, | 175 const base::SharedMemoryHandle& handle, |
| 152 base::ProcessHandle process_handle, | 176 base::ProcessHandle process_handle, |
| 153 const cc::SharedBitmapId& id) { | 177 const cc::SharedBitmapId& id) { |
| 154 base::AutoLock lock(lock_); | 178 base::AutoLock lock(lock_); |
| 155 if (handle_map_.find(id) != handle_map_.end()) | 179 if (handle_map_.find(id) != handle_map_.end()) |
| 156 return; | 180 return; |
| 157 scoped_refptr<BitmapData> data( | 181 scoped_refptr<BitmapData> data( |
| 158 new BitmapData(process_handle, buffer_size)); | 182 new BitmapData(process_handle, buffer_size)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return handle_map_.size(); | 234 return handle_map_.size(); |
| 211 } | 235 } |
| 212 | 236 |
| 213 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 237 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
| 214 const cc::SharedBitmapId& id) { | 238 const cc::SharedBitmapId& id) { |
| 215 base::AutoLock lock(lock_); | 239 base::AutoLock lock(lock_); |
| 216 handle_map_.erase(id); | 240 handle_map_.erase(id); |
| 217 } | 241 } |
| 218 | 242 |
| 219 } // namespace content | 243 } // namespace content |
| OLD | NEW |