diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:25:45 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:25:45 +0000 |
commit | 4e2eb35838d42017542959dbef29d84ca6d2bbc4 (patch) | |
tree | 7eabd0b457f008c43398e158cabdd616d9cf7a61 /cc/test/test_shared_bitmap_manager.cc | |
parent | 22e548845b1548ebad28c9d68ad075bce949ec57 (diff) | |
download | chromium_src-4e2eb35838d42017542959dbef29d84ca6d2bbc4.zip chromium_src-4e2eb35838d42017542959dbef29d84ca6d2bbc4.tar.gz chromium_src-4e2eb35838d42017542959dbef29d84ca6d2bbc4.tar.bz2 |
Switch to use SharedBitmapManager all the time in cc_unittests
This matches the behavior of the browser and renderer better, and lets us use SharedBitmaps in more tests.
Review URL: https://codereview.chromium.org/202763002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test/test_shared_bitmap_manager.cc')
-rw-r--r-- | cc/test/test_shared_bitmap_manager.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cc/test/test_shared_bitmap_manager.cc b/cc/test/test_shared_bitmap_manager.cc new file mode 100644 index 0000000..e985572 --- /dev/null +++ b/cc/test/test_shared_bitmap_manager.cc @@ -0,0 +1,51 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/test/test_shared_bitmap_manager.h" + +#include "base/bind.h" + +namespace cc { + +void FreeSharedBitmap(SharedBitmap* shared_bitmap) { + delete shared_bitmap->memory(); +} + +void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} + +TestSharedBitmapManager::TestSharedBitmapManager() {} + +TestSharedBitmapManager::~TestSharedBitmapManager() {} + +scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap( + const gfx::Size& size) { + base::AutoLock lock(lock_); + scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); + memory->CreateAndMapAnonymous(size.GetArea() * 4); + SharedBitmapId id = SharedBitmap::GenerateId(); + bitmap_map_[id] = memory.get(); + return scoped_ptr<SharedBitmap>( + new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); +} + +scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId( + const gfx::Size&, + const SharedBitmapId& id) { + base::AutoLock lock(lock_); + if (bitmap_map_.find(id) == bitmap_map_.end()) + return scoped_ptr<SharedBitmap>(); + return scoped_ptr<SharedBitmap>( + new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); +} + +scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory( + base::SharedMemory* memory) { + base::AutoLock lock(lock_); + SharedBitmapId id = SharedBitmap::GenerateId(); + bitmap_map_[id] = memory; + return scoped_ptr<SharedBitmap>( + new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); +} + +} // namespace cc |