| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/display_compositor/host_shared_bitmap_manager.h" | 5 #include "components/display_compositor/host_shared_bitmap_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 mojo::ScopedSharedBufferHandle buffer, | 79 mojo::ScopedSharedBufferHandle buffer, |
| 80 const cc::SharedBitmapId& id) { | 80 const cc::SharedBitmapId& id) { |
| 81 base::SharedMemoryHandle memory_handle; | 81 base::SharedMemoryHandle memory_handle; |
| 82 size_t size; | 82 size_t size; |
| 83 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 83 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 84 std::move(buffer), &memory_handle, &size, NULL); | 84 std::move(buffer), &memory_handle, &size, NULL); |
| 85 DCHECK_EQ(result, MOJO_RESULT_OK); | 85 DCHECK_EQ(result, MOJO_RESULT_OK); |
| 86 this->ChildAllocatedSharedBitmap(size, memory_handle, id); | 86 this->ChildAllocatedSharedBitmap(size, memory_handle, id); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( | |
| 90 base::ProcessHandle process_handle, | |
| 91 size_t buffer_size, | |
| 92 const cc::SharedBitmapId& id, | |
| 93 base::SharedMemoryHandle* shared_memory_handle) { | |
| 94 manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id, | |
| 95 shared_memory_handle); | |
| 96 if (*shared_memory_handle != base::SharedMemory::NULLHandle()) { | |
| 97 base::AutoLock lock(lock_); | |
| 98 owned_bitmaps_.insert(id); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( | 89 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( |
| 103 size_t buffer_size, | 90 size_t buffer_size, |
| 104 const base::SharedMemoryHandle& handle, | 91 const base::SharedMemoryHandle& handle, |
| 105 const cc::SharedBitmapId& id) { | 92 const cc::SharedBitmapId& id) { |
| 106 if (manager_->ChildAllocatedSharedBitmap(buffer_size, handle, id)) { | 93 if (manager_->ChildAllocatedSharedBitmap(buffer_size, handle, id)) { |
| 107 base::AutoLock lock(lock_); | 94 base::AutoLock lock(lock_); |
| 108 owned_bitmaps_.insert(id); | 95 owned_bitmaps_.insert(id); |
| 109 } | 96 } |
| 110 } | 97 } |
| 111 | 98 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return false; | 195 return false; |
| 209 scoped_refptr<BitmapData> data(new BitmapData(buffer_size)); | 196 scoped_refptr<BitmapData> data(new BitmapData(buffer_size)); |
| 210 | 197 |
| 211 handle_map_[id] = data; | 198 handle_map_[id] = data; |
| 212 data->memory = base::MakeUnique<base::SharedMemory>(handle, false); | 199 data->memory = base::MakeUnique<base::SharedMemory>(handle, false); |
| 213 data->memory->Map(data->buffer_size); | 200 data->memory->Map(data->buffer_size); |
| 214 data->memory->Close(); | 201 data->memory->Close(); |
| 215 return true; | 202 return true; |
| 216 } | 203 } |
| 217 | 204 |
| 218 void HostSharedBitmapManager::AllocateSharedBitmapForChild( | |
| 219 base::ProcessHandle process_handle, | |
| 220 size_t buffer_size, | |
| 221 const cc::SharedBitmapId& id, | |
| 222 base::SharedMemoryHandle* shared_memory_handle) { | |
| 223 base::AutoLock lock(lock_); | |
| 224 if (handle_map_.find(id) != handle_map_.end()) { | |
| 225 *shared_memory_handle = base::SharedMemory::NULLHandle(); | |
| 226 return; | |
| 227 } | |
| 228 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | |
| 229 if (!shared_memory->CreateAndMapAnonymous(buffer_size)) { | |
| 230 LOG(ERROR) << "Cannot create shared memory buffer"; | |
| 231 *shared_memory_handle = base::SharedMemory::NULLHandle(); | |
| 232 return; | |
| 233 } | |
| 234 | |
| 235 scoped_refptr<BitmapData> data(new BitmapData(buffer_size)); | |
| 236 data->memory = std::move(shared_memory); | |
| 237 | |
| 238 handle_map_[id] = data; | |
| 239 if (!data->memory->ShareToProcess(process_handle, shared_memory_handle)) { | |
| 240 LOG(ERROR) << "Cannot share shared memory buffer"; | |
| 241 *shared_memory_handle = base::SharedMemory::NULLHandle(); | |
| 242 return; | |
| 243 } | |
| 244 data->memory->Close(); | |
| 245 } | |
| 246 | |
| 247 void HostSharedBitmapManager::ChildDeletedSharedBitmap( | 205 void HostSharedBitmapManager::ChildDeletedSharedBitmap( |
| 248 const cc::SharedBitmapId& id) { | 206 const cc::SharedBitmapId& id) { |
| 249 base::AutoLock lock(lock_); | 207 base::AutoLock lock(lock_); |
| 250 handle_map_.erase(id); | 208 handle_map_.erase(id); |
| 251 } | 209 } |
| 252 | 210 |
| 253 size_t HostSharedBitmapManager::AllocatedBitmapCount() const { | 211 size_t HostSharedBitmapManager::AllocatedBitmapCount() const { |
| 254 base::AutoLock lock(lock_); | 212 base::AutoLock lock(lock_); |
| 255 return handle_map_.size(); | 213 return handle_map_.size(); |
| 256 } | 214 } |
| 257 | 215 |
| 258 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 216 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
| 259 const cc::SharedBitmapId& id) { | 217 const cc::SharedBitmapId& id) { |
| 260 base::AutoLock lock(lock_); | 218 base::AutoLock lock(lock_); |
| 261 handle_map_.erase(id); | 219 handle_map_.erase(id); |
| 262 } | 220 } |
| 263 | 221 |
| 264 } // namespace display_compositor | 222 } // namespace display_compositor |
| OLD | NEW |