| 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 "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 new BitmapData(base::GetCurrentProcessHandle(), | 56 new BitmapData(base::GetCurrentProcessHandle(), |
| 57 base::SharedMemory::NULLHandle(), | 57 base::SharedMemory::NULLHandle(), |
| 58 bitmap_size)); | 58 bitmap_size)); |
| 59 // Bitmaps allocated in host don't need to be shared to other processes, so | 59 // Bitmaps allocated in host don't need to be shared to other processes, so |
| 60 // allocate them with new instead. | 60 // allocate them with new instead. |
| 61 data->pixels = scoped_ptr<uint8[]>(new uint8[bitmap_size]); | 61 data->pixels = scoped_ptr<uint8[]>(new uint8[bitmap_size]); |
| 62 | 62 |
| 63 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 63 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
| 64 handle_map_[id] = data; | 64 handle_map_[id] = data; |
| 65 return make_scoped_ptr(new cc::SharedBitmap( | 65 return make_scoped_ptr(new cc::SharedBitmap( |
| 66 data->pixels.get(), id, base::Bind(&FreeSharedMemory, data))); | 66 data->pixels.get(), |
| 67 id, |
| 68 base::Bind(&HostSharedBitmapManager::FreeSharedMemoryFromMap, |
| 69 base::Unretained(this)))); |
| 67 } | 70 } |
| 68 | 71 |
| 69 scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::GetSharedBitmapFromId( | 72 scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::GetSharedBitmapFromId( |
| 70 const gfx::Size& size, | 73 const gfx::Size& size, |
| 71 const cc::SharedBitmapId& id) { | 74 const cc::SharedBitmapId& id) { |
| 72 base::AutoLock lock(lock_); | 75 base::AutoLock lock(lock_); |
| 73 BitmapMap::iterator it = handle_map_.find(id); | 76 BitmapMap::iterator it = handle_map_.find(id); |
| 74 if (it == handle_map_.end()) | 77 if (it == handle_map_.end()) |
| 75 return scoped_ptr<cc::SharedBitmap>(); | 78 return scoped_ptr<cc::SharedBitmap>(); |
| 76 | 79 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 base::hash_set<cc::SharedBitmapId>& res = proc_it->second; | 180 base::hash_set<cc::SharedBitmapId>& res = proc_it->second; |
| 178 | 181 |
| 179 for (base::hash_set<cc::SharedBitmapId>::iterator it = res.begin(); | 182 for (base::hash_set<cc::SharedBitmapId>::iterator it = res.begin(); |
| 180 it != res.end(); | 183 it != res.end(); |
| 181 ++it) { | 184 ++it) { |
| 182 handle_map_.erase(*it); | 185 handle_map_.erase(*it); |
| 183 } | 186 } |
| 184 process_map_.erase(proc_it); | 187 process_map_.erase(proc_it); |
| 185 } | 188 } |
| 186 | 189 |
| 190 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
| 191 cc::SharedBitmap* bitmap) { |
| 192 base::AutoLock lock(lock_); |
| 193 handle_map_.erase(bitmap->id()); |
| 194 } |
| 195 |
| 187 } // namespace content | 196 } // namespace content |
| OLD | NEW |