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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
10 #include "base/process/memory.h" | 11 #include "base/process/memory.h" |
11 #include "base/process/process_metrics.h" | 12 #include "base/process/process_metrics.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "content/child/child_thread_impl.h" | 14 #include "content/child/child_thread_impl.h" |
14 #include "content/common/child_process_messages.h" | 15 #include "content/common/child_process_messages.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 class ChildSharedBitmap : public SharedMemoryBitmap { | 22 class ChildSharedBitmap : public SharedMemoryBitmap { |
22 public: | 23 public: |
23 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, | 24 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, |
24 base::SharedMemory* shared_memory, | 25 base::SharedMemory* shared_memory, |
25 const cc::SharedBitmapId& id) | 26 const cc::SharedBitmapId& id) |
26 : SharedMemoryBitmap(static_cast<uint8_t*>(shared_memory->memory()), | 27 : SharedMemoryBitmap(static_cast<uint8_t*>(shared_memory->memory()), |
27 id, | 28 id, |
28 shared_memory), | 29 shared_memory), |
29 sender_(sender) {} | 30 sender_(sender) {} |
30 | 31 |
31 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, | 32 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender, |
32 scoped_ptr<base::SharedMemory> shared_memory_holder, | 33 scoped_ptr<base::SharedMemory> shared_memory_holder, |
33 const cc::SharedBitmapId& id) | 34 const cc::SharedBitmapId& id) |
34 : ChildSharedBitmap(sender, shared_memory_holder.get(), id) { | 35 : ChildSharedBitmap(sender, shared_memory_holder.get(), id) { |
35 shared_memory_holder_ = shared_memory_holder.Pass(); | 36 shared_memory_holder_ = std::move(shared_memory_holder); |
36 } | 37 } |
37 | 38 |
38 ~ChildSharedBitmap() override { | 39 ~ChildSharedBitmap() override { |
39 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); | 40 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); |
40 } | 41 } |
41 | 42 |
42 private: | 43 private: |
43 scoped_refptr<ThreadSafeSender> sender_; | 44 scoped_refptr<ThreadSafeSender> sender_; |
44 scoped_ptr<base::SharedMemory> shared_memory_holder_; | 45 scoped_ptr<base::SharedMemory> shared_memory_holder_; |
45 }; | 46 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ChildSharedBitmapManager::~ChildSharedBitmapManager() {} | 84 ChildSharedBitmapManager::~ChildSharedBitmapManager() {} |
84 | 85 |
85 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap( | 86 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap( |
86 const gfx::Size& size) { | 87 const gfx::Size& size) { |
87 scoped_ptr<SharedMemoryBitmap> bitmap = AllocateSharedMemoryBitmap(size); | 88 scoped_ptr<SharedMemoryBitmap> bitmap = AllocateSharedMemoryBitmap(size); |
88 #if defined(OS_POSIX) | 89 #if defined(OS_POSIX) |
89 // Close file descriptor to avoid running out. | 90 // Close file descriptor to avoid running out. |
90 if (bitmap) | 91 if (bitmap) |
91 bitmap->shared_memory()->Close(); | 92 bitmap->shared_memory()->Close(); |
92 #endif | 93 #endif |
93 return bitmap.Pass(); | 94 return std::move(bitmap); |
94 } | 95 } |
95 | 96 |
96 scoped_ptr<SharedMemoryBitmap> | 97 scoped_ptr<SharedMemoryBitmap> |
97 ChildSharedBitmapManager::AllocateSharedMemoryBitmap(const gfx::Size& size) { | 98 ChildSharedBitmapManager::AllocateSharedMemoryBitmap(const gfx::Size& size) { |
98 TRACE_EVENT2("renderer", | 99 TRACE_EVENT2("renderer", |
99 "ChildSharedBitmapManager::AllocateSharedMemoryBitmap", "width", | 100 "ChildSharedBitmapManager::AllocateSharedMemoryBitmap", "width", |
100 size.width(), "height", size.height()); | 101 size.width(), "height", size.height()); |
101 size_t memory_size; | 102 size_t memory_size; |
102 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) | 103 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) |
103 return scoped_ptr<SharedMemoryBitmap>(); | 104 return scoped_ptr<SharedMemoryBitmap>(); |
(...skipping 11 matching lines...) Expand all Loading... |
115 if (!memory) | 116 if (!memory) |
116 CollectMemoryUsageAndDie(size, memory_size); | 117 CollectMemoryUsageAndDie(size, memory_size); |
117 | 118 |
118 if (!memory->Map(memory_size)) | 119 if (!memory->Map(memory_size)) |
119 CollectMemoryUsageAndDie(size, memory_size); | 120 CollectMemoryUsageAndDie(size, memory_size); |
120 | 121 |
121 base::SharedMemoryHandle handle_to_send = memory->handle(); | 122 base::SharedMemoryHandle handle_to_send = memory->handle(); |
122 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 123 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
123 memory_size, handle_to_send, id)); | 124 memory_size, handle_to_send, id)); |
124 #endif | 125 #endif |
125 return make_scoped_ptr(new ChildSharedBitmap(sender_, memory.Pass(), id)); | 126 return make_scoped_ptr(new ChildSharedBitmap(sender_, std::move(memory), id)); |
126 } | 127 } |
127 | 128 |
128 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId( | 129 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId( |
129 const gfx::Size&, | 130 const gfx::Size&, |
130 const cc::SharedBitmapId&) { | 131 const cc::SharedBitmapId&) { |
131 NOTREACHED(); | 132 NOTREACHED(); |
132 return scoped_ptr<cc::SharedBitmap>(); | 133 return scoped_ptr<cc::SharedBitmap>(); |
133 } | 134 } |
134 | 135 |
135 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory( | 136 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory( |
136 base::SharedMemory* mem) { | 137 base::SharedMemory* mem) { |
137 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 138 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
138 base::SharedMemoryHandle handle_to_send = mem->handle(); | 139 base::SharedMemoryHandle handle_to_send = mem->handle(); |
139 #if defined(OS_POSIX) | 140 #if defined(OS_POSIX) |
140 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) | 141 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) |
141 return scoped_ptr<cc::SharedBitmap>(); | 142 return scoped_ptr<cc::SharedBitmap>(); |
142 #endif | 143 #endif |
143 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 144 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
144 mem->mapped_size(), handle_to_send, id)); | 145 mem->mapped_size(), handle_to_send, id)); |
145 | 146 |
146 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); | 147 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); |
147 } | 148 } |
148 | 149 |
149 } // namespace content | 150 } // namespace content |
OLD | NEW |