OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/child/child_shared_bitmap_manager.h" | 5 #include "content/child/child_shared_bitmap_manager.h" |
6 | 6 |
7 #include "content/child/child_thread.h" | 7 #include "content/child/child_thread.h" |
8 #include "content/common/child_process_messages.h" | 8 #include "content/common/child_process_messages.h" |
9 #include "ui/gfx/size.h" | 9 #include "ui/gfx/size.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class ChildSharedBitmap : public cc::SharedBitmap { | 15 class ChildSharedBitmap : public SharedMemoryBitmap { |
16 public: | 16 public: |
17 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, | 17 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, |
18 base::SharedMemory* shared_memory, | 18 base::SharedMemory* shared_memory, |
19 const cc::SharedBitmapId& id) | 19 const cc::SharedBitmapId& id) |
20 : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id), | 20 : SharedMemoryBitmap(static_cast<uint8*>(shared_memory->memory()), |
21 sender_(sender), | 21 id, |
22 shared_memory_(shared_memory) {} | 22 shared_memory), |
| 23 sender_(sender) {} |
23 | 24 |
24 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, | 25 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, |
25 scoped_ptr<base::SharedMemory> shared_memory_holder, | 26 scoped_ptr<base::SharedMemory> shared_memory_holder, |
26 const cc::SharedBitmapId& id) | 27 const cc::SharedBitmapId& id) |
27 : ChildSharedBitmap(sender, shared_memory_holder.get(), id) { | 28 : ChildSharedBitmap(sender, shared_memory_holder.get(), id) { |
28 shared_memory_holder_ = shared_memory_holder.Pass(); | 29 shared_memory_holder_ = shared_memory_holder.Pass(); |
29 } | 30 } |
30 | 31 |
31 ~ChildSharedBitmap() override { | 32 ~ChildSharedBitmap() override { |
32 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); | 33 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); |
33 } | 34 } |
34 | 35 |
35 base::SharedMemory* memory() override { return shared_memory_; } | |
36 | |
37 private: | 36 private: |
38 scoped_refptr<ThreadSafeSender> sender_; | 37 scoped_refptr<ThreadSafeSender> sender_; |
39 base::SharedMemory* shared_memory_; | |
40 scoped_ptr<base::SharedMemory> shared_memory_holder_; | 38 scoped_ptr<base::SharedMemory> shared_memory_holder_; |
41 }; | 39 }; |
42 | 40 |
43 } // namespace | 41 } // namespace |
44 | 42 |
| 43 SharedMemoryBitmap::SharedMemoryBitmap(uint8* pixels, |
| 44 const cc::SharedBitmapId& id, |
| 45 base::SharedMemory* shared_memory) |
| 46 : SharedBitmap(pixels, id), shared_memory_(shared_memory) { |
| 47 } |
| 48 |
45 ChildSharedBitmapManager::ChildSharedBitmapManager( | 49 ChildSharedBitmapManager::ChildSharedBitmapManager( |
46 scoped_refptr<ThreadSafeSender> sender) | 50 scoped_refptr<ThreadSafeSender> sender) |
47 : sender_(sender) { | 51 : sender_(sender) { |
48 } | 52 } |
49 | 53 |
50 ChildSharedBitmapManager::~ChildSharedBitmapManager() {} | 54 ChildSharedBitmapManager::~ChildSharedBitmapManager() {} |
51 | 55 |
52 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap( | 56 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap( |
53 const gfx::Size& size) { | 57 const gfx::Size& size) { |
| 58 return AllocateSharedMemoryBitmap(size); |
| 59 } |
| 60 |
| 61 scoped_ptr<SharedMemoryBitmap> |
| 62 ChildSharedBitmapManager::AllocateSharedMemoryBitmap(const gfx::Size& size) { |
54 TRACE_EVENT2("renderer", | 63 TRACE_EVENT2("renderer", |
55 "ChildSharedBitmapManager::AllocateSharedMemory", | 64 "ChildSharedBitmapManager::AllocateSharedMemoryBitmap", "width", |
56 "width", | 65 size.width(), "height", size.height()); |
57 size.width(), | |
58 "height", | |
59 size.height()); | |
60 size_t memory_size; | 66 size_t memory_size; |
61 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) | 67 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) |
62 return scoped_ptr<cc::SharedBitmap>(); | 68 return scoped_ptr<SharedMemoryBitmap>(); |
63 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 69 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
64 scoped_ptr<base::SharedMemory> memory; | 70 scoped_ptr<base::SharedMemory> memory; |
65 #if defined(OS_POSIX) | 71 #if defined(OS_POSIX) |
66 base::SharedMemoryHandle handle; | 72 base::SharedMemoryHandle handle; |
67 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( | 73 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( |
68 memory_size, id, &handle)); | 74 memory_size, id, &handle)); |
69 memory = make_scoped_ptr(new base::SharedMemory(handle, false)); | 75 memory = make_scoped_ptr(new base::SharedMemory(handle, false)); |
70 if (!memory->Map(memory_size)) | 76 if (!memory->Map(memory_size)) |
71 CHECK(false); | 77 CHECK(false); |
72 #else | 78 #else |
(...skipping 23 matching lines...) Expand all Loading... |
96 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) | 102 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) |
97 return scoped_ptr<cc::SharedBitmap>(); | 103 return scoped_ptr<cc::SharedBitmap>(); |
98 #endif | 104 #endif |
99 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 105 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
100 mem->mapped_size(), handle_to_send, id)); | 106 mem->mapped_size(), handle_to_send, id)); |
101 | 107 |
102 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); | 108 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); |
103 } | 109 } |
104 | 110 |
105 } // namespace content | 111 } // namespace content |
OLD | NEW |