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"
12 class OwnedSharedBitmap
: public SharedBitmap
{
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
{}
22 scoped_ptr
<base::SharedMemory
> shared_memory_
;
27 TestSharedBitmapManager::TestSharedBitmapManager() {}
29 TestSharedBitmapManager::~TestSharedBitmapManager() {}
31 scoped_ptr
<SharedBitmap
> TestSharedBitmapManager::AllocateSharedBitmap(
32 const gfx::Size
& size
) {
33 base::AutoLock
lock(lock_
);
34 scoped_ptr
<base::SharedMemory
> memory(new base::SharedMemory
);
35 memory
->CreateAndMapAnonymous(size
.GetArea() * 4);
36 SharedBitmapId id
= SharedBitmap::GenerateId();
37 bitmap_map_
[id
] = memory
.get();
38 return make_scoped_ptr(new OwnedSharedBitmap(memory
.Pass(), id
));
41 scoped_ptr
<SharedBitmap
> TestSharedBitmapManager::GetSharedBitmapFromId(
43 const SharedBitmapId
& id
) {
44 base::AutoLock
lock(lock_
);
45 if (bitmap_map_
.find(id
) == bitmap_map_
.end())
47 uint8
* pixels
= static_cast<uint8
*>(bitmap_map_
[id
]->memory());
48 return make_scoped_ptr(new SharedBitmap(pixels
, id
));