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