| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/test/test_shared_bitmap_manager.h" | 5 #include "cc/test/test_shared_bitmap_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 | 8 |
| 9 namespace cc { | 9 namespace cc { |
| 10 | 10 |
| 11 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { | 11 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { |
| 12 delete shared_bitmap->memory(); | 12 delete shared_bitmap->memory(); |
| 13 } | 13 } |
| 14 | 14 |
| 15 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} | 15 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} |
| 16 | 16 |
| 17 TestSharedBitmapManager::TestSharedBitmapManager() {} | 17 TestSharedBitmapManager::TestSharedBitmapManager() {} |
| 18 | 18 |
| 19 TestSharedBitmapManager::~TestSharedBitmapManager() {} | 19 TestSharedBitmapManager::~TestSharedBitmapManager() {} |
| 20 | 20 |
| 21 scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap( | 21 scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap( |
| 22 const gfx::Size& size) { | 22 const gfx::Size& size) { |
| 23 base::AutoLock lock(lock_); | 23 base::AutoLock lock(lock_); |
| 24 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); | 24 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); |
| 25 memory->CreateAndMapAnonymous(size.GetArea() * 4); | 25 memory->CreateAndMapAnonymous(size.GetArea() * 4); |
| 26 SharedBitmapId id = SharedBitmap::GenerateId(); | 26 SharedBitmapId id = SharedBitmap::GenerateId(); |
| 27 bitmap_map_[id] = memory.get(); | 27 bitmap_map_[id] = memory.get(); |
| 28 return scoped_ptr<SharedBitmap>( | 28 return make_scoped_ptr( |
| 29 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); | 29 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); |
| 30 } | 30 } |
| 31 | 31 |
| 32 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId( | 32 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId( |
| 33 const gfx::Size&, | 33 const gfx::Size&, |
| 34 const SharedBitmapId& id) { | 34 const SharedBitmapId& id) { |
| 35 base::AutoLock lock(lock_); | 35 base::AutoLock lock(lock_); |
| 36 if (bitmap_map_.find(id) == bitmap_map_.end()) | 36 if (bitmap_map_.find(id) == bitmap_map_.end()) |
| 37 return scoped_ptr<SharedBitmap>(); | 37 return nullptr; |
| 38 return scoped_ptr<SharedBitmap>( | 38 return make_scoped_ptr( |
| 39 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); | 39 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); |
| 40 } | 40 } |
| 41 | 41 |
| 42 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory( | 42 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory( |
| 43 base::SharedMemory* memory) { | 43 base::SharedMemory* memory) { |
| 44 base::AutoLock lock(lock_); | 44 base::AutoLock lock(lock_); |
| 45 SharedBitmapId id = SharedBitmap::GenerateId(); | 45 SharedBitmapId id = SharedBitmap::GenerateId(); |
| 46 bitmap_map_[id] = memory; | 46 bitmap_map_[id] = memory; |
| 47 return scoped_ptr<SharedBitmap>( | 47 return make_scoped_ptr( |
| 48 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); | 48 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace cc | 51 } // namespace cc |
| OLD | NEW |