Remove GetBitmapForSharedMemory from cc::SharedBitmapManager
[chromium-blink-merge.git] / cc / test / test_shared_bitmap_manager.cc
blobb96d01837ae73645c0e3e845a565e3d0a8a4df81
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/memory/shared_memory.h"
9 namespace cc {
11 namespace {
12 class OwnedSharedBitmap : public SharedBitmap {
13 public:
14 OwnedSharedBitmap(scoped_ptr<base::SharedMemory> shared_memory,
15 const SharedBitmapId& id)
16 : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id),
17 shared_memory_(shared_memory.Pass()) {}
19 ~OwnedSharedBitmap() override {}
21 base::SharedMemory* memory() override { return shared_memory_.get(); }
23 private:
24 scoped_ptr<base::SharedMemory> shared_memory_;
27 class UnownedSharedBitmap : public SharedBitmap {
28 public:
29 UnownedSharedBitmap(base::SharedMemory* shared_memory,
30 const SharedBitmapId& id)
31 : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id),
32 shared_memory_(shared_memory) {}
34 ~UnownedSharedBitmap() override {}
36 base::SharedMemory* memory() override { return shared_memory_; }
38 private:
39 base::SharedMemory* shared_memory_;
41 } // namespace
43 TestSharedBitmapManager::TestSharedBitmapManager() {}
45 TestSharedBitmapManager::~TestSharedBitmapManager() {}
47 scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap(
48 const gfx::Size& size) {
49 base::AutoLock lock(lock_);
50 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory);
51 memory->CreateAndMapAnonymous(size.GetArea() * 4);
52 SharedBitmapId id = SharedBitmap::GenerateId();
53 bitmap_map_[id] = memory.get();
54 return make_scoped_ptr(new OwnedSharedBitmap(memory.Pass(), id));
57 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId(
58 const gfx::Size&,
59 const SharedBitmapId& id) {
60 base::AutoLock lock(lock_);
61 if (bitmap_map_.find(id) == bitmap_map_.end())
62 return nullptr;
63 return make_scoped_ptr(new UnownedSharedBitmap(bitmap_map_[id], id));
66 } // namespace cc