| 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 "components/viz/display_compositor/host_shared_bitmap_manager.h" | 5 #include "components/viz/display_compositor/host_shared_bitmap_manager.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 | 8 | 
| 9 #include <utility> | 9 #include <utility> | 
| 10 | 10 | 
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" | 
| 12 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" | 
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" | 
|  | 15 #include "base/memory/shared_memory_tracker.h" | 
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" | 
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" | 
| 17 #include "base/trace_event/process_memory_dump.h" | 18 #include "base/trace_event/process_memory_dump.h" | 
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" | 
| 19 #include "mojo/public/cpp/system/platform_handle.h" | 20 #include "mojo/public/cpp/system/platform_handle.h" | 
| 20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" | 
| 21 | 22 | 
| 22 namespace viz { | 23 namespace viz { | 
| 23 | 24 | 
| 24 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { | 25 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 44                    HostSharedBitmapManager* manager) | 45                    HostSharedBitmapManager* manager) | 
| 45       : SharedBitmap(pixels, id), | 46       : SharedBitmap(pixels, id), | 
| 46         bitmap_data_(bitmap_data), | 47         bitmap_data_(bitmap_data), | 
| 47         manager_(manager) {} | 48         manager_(manager) {} | 
| 48 | 49 | 
| 49   ~HostSharedBitmap() override { | 50   ~HostSharedBitmap() override { | 
| 50     if (manager_) | 51     if (manager_) | 
| 51       manager_->FreeSharedMemoryFromMap(id()); | 52       manager_->FreeSharedMemoryFromMap(id()); | 
| 52   } | 53   } | 
| 53 | 54 | 
|  | 55   base::SharedMemory* GetSharedMemory() const override { | 
|  | 56     return bitmap_data_->memory.get(); | 
|  | 57   } | 
|  | 58 | 
| 54  private: | 59  private: | 
| 55   scoped_refptr<BitmapData> bitmap_data_; | 60   scoped_refptr<BitmapData> bitmap_data_; | 
| 56   HostSharedBitmapManager* manager_; | 61   HostSharedBitmapManager* manager_; | 
| 57 }; | 62 }; | 
| 58 | 63 | 
| 59 }  // namespace | 64 }  // namespace | 
| 60 | 65 | 
| 61 base::LazyInstance<HostSharedBitmapManager>::DestructorAtExit | 66 base::LazyInstance<HostSharedBitmapManager>::DestructorAtExit | 
| 62     g_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; | 67     g_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; | 
| 63 | 68 | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 169             "sharedbitmap/%s", | 174             "sharedbitmap/%s", | 
| 170             base::HexEncode(bitmap.first.name, sizeof(bitmap.first.name)) | 175             base::HexEncode(bitmap.first.name, sizeof(bitmap.first.name)) | 
| 171                 .c_str())); | 176                 .c_str())); | 
| 172     if (!dump) | 177     if (!dump) | 
| 173       return false; | 178       return false; | 
| 174 | 179 | 
| 175     dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 180     dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 
| 176                     base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 181                     base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 
| 177                     bitmap.second->buffer_size); | 182                     bitmap.second->buffer_size); | 
| 178 | 183 | 
| 179     // Generate a global GUID used to share this allocation with renderer | 184     if (bitmap.second->memory) { | 
| 180     // processes. | 185       base::SharedMemoryTracker::AddOwnershipEdges(pmd, dump->guid(), | 
| 181     auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); | 186                                                    *bitmap.second->memory); | 
| 182     pmd->CreateSharedGlobalAllocatorDump(guid); | 187     } else { | 
| 183     pmd->AddOwnershipEdge(dump->guid(), guid); | 188       // Generate a global GUID used to share this allocation with renderer | 
|  | 189       // processes. | 
|  | 190       auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); | 
|  | 191       pmd->CreateSharedGlobalAllocatorDump(guid); | 
|  | 192       pmd->AddOwnershipEdge(dump->guid(), guid); | 
|  | 193     } | 
| 184   } | 194   } | 
| 185 | 195 | 
| 186   return true; | 196   return true; | 
| 187 } | 197 } | 
| 188 | 198 | 
| 189 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 199 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 
| 190     size_t buffer_size, | 200     size_t buffer_size, | 
| 191     const base::SharedMemoryHandle& handle, | 201     const base::SharedMemoryHandle& handle, | 
| 192     const cc::SharedBitmapId& id) { | 202     const cc::SharedBitmapId& id) { | 
| 193   base::AutoLock lock(lock_); | 203   base::AutoLock lock(lock_); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 213   return handle_map_.size(); | 223   return handle_map_.size(); | 
| 214 } | 224 } | 
| 215 | 225 | 
| 216 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 226 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 
| 217     const cc::SharedBitmapId& id) { | 227     const cc::SharedBitmapId& id) { | 
| 218   base::AutoLock lock(lock_); | 228   base::AutoLock lock(lock_); | 
| 219   handle_map_.erase(id); | 229   handle_map_.erase(id); | 
| 220 } | 230 } | 
| 221 | 231 | 
| 222 }  // namespace viz | 232 }  // namespace viz | 
| OLD | NEW | 
|---|