Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: cc/test/test_shared_bitmap_manager.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/solid_color_content_layer_client.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/test_shared_bitmap_manager.h" 5 #include "cc/test/test_shared_bitmap_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/memory/shared_memory.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
11 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { 11 namespace {
12 delete shared_bitmap->memory(); 12 class OwnedSharedBitmap : public SharedBitmap {
13 } 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()) {}
14 18
15 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} 19 ~OwnedSharedBitmap() override {}
20
21 base::SharedMemory* memory() override { return shared_memory_.get(); }
22
23 private:
24 scoped_ptr<base::SharedMemory> shared_memory_;
25 };
26
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) {}
33
34 ~UnownedSharedBitmap() override {}
35
36 base::SharedMemory* memory() override { return shared_memory_; }
37
38 private:
39 base::SharedMemory* shared_memory_;
40 };
41 } // namespace
16 42
17 TestSharedBitmapManager::TestSharedBitmapManager() {} 43 TestSharedBitmapManager::TestSharedBitmapManager() {}
18 44
19 TestSharedBitmapManager::~TestSharedBitmapManager() {} 45 TestSharedBitmapManager::~TestSharedBitmapManager() {}
20 46
21 scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap( 47 scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap(
22 const gfx::Size& size) { 48 const gfx::Size& size) {
23 base::AutoLock lock(lock_); 49 base::AutoLock lock(lock_);
24 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); 50 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory);
25 memory->CreateAndMapAnonymous(size.GetArea() * 4); 51 memory->CreateAndMapAnonymous(size.GetArea() * 4);
26 SharedBitmapId id = SharedBitmap::GenerateId(); 52 SharedBitmapId id = SharedBitmap::GenerateId();
27 bitmap_map_[id] = memory.get(); 53 bitmap_map_[id] = memory.get();
28 return make_scoped_ptr( 54 return make_scoped_ptr(new OwnedSharedBitmap(memory.Pass(), id));
29 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap)));
30 } 55 }
31 56
32 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId( 57 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId(
33 const gfx::Size&, 58 const gfx::Size&,
34 const SharedBitmapId& id) { 59 const SharedBitmapId& id) {
35 base::AutoLock lock(lock_); 60 base::AutoLock lock(lock_);
36 if (bitmap_map_.find(id) == bitmap_map_.end()) 61 if (bitmap_map_.find(id) == bitmap_map_.end())
37 return nullptr; 62 return nullptr;
38 return make_scoped_ptr( 63 return make_scoped_ptr(new UnownedSharedBitmap(bitmap_map_[id], id));
39 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap)));
40 } 64 }
41 65
42 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory( 66 scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory(
43 base::SharedMemory* memory) { 67 base::SharedMemory* memory) {
44 base::AutoLock lock(lock_); 68 base::AutoLock lock(lock_);
45 SharedBitmapId id = SharedBitmap::GenerateId(); 69 SharedBitmapId id = SharedBitmap::GenerateId();
46 bitmap_map_[id] = memory; 70 bitmap_map_[id] = memory;
47 return make_scoped_ptr( 71 return make_scoped_ptr(new UnownedSharedBitmap(memory, id));
48 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap)));
49 } 72 }
50 73
51 } // namespace cc 74 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/solid_color_content_layer_client.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698