Enable gaia services for enterprise autotests.
[chromium-blink-merge.git] / cc / test / test_shared_bitmap_manager.cc
blobe985572ed9cf2237924bf35c8444f42fbe91b3d3
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.
5 #include "cc/test/test_shared_bitmap_manager.h"
7 #include "base/bind.h"
9 namespace cc {
11 void FreeSharedBitmap(SharedBitmap* shared_bitmap) {
12 delete shared_bitmap->memory();
15 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {}
17 TestSharedBitmapManager::TestSharedBitmapManager() {}
19 TestSharedBitmapManager::~TestSharedBitmapManager() {}
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 scoped_ptr<SharedBitmap>(
29 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap)));
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 scoped_ptr<SharedBitmap>();
38 return scoped_ptr<SharedBitmap>(
39 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap)));
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 scoped_ptr<SharedBitmap>(
48 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap)));
51 } // namespace cc