Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/child/child_shared_bitmap_manager.h" | |
| 6 | |
| 7 #include "content/child/child_thread.h" | |
| 8 #include "content/common/child_process_messages.h" | |
| 9 #include "ui/gfx/size.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 ChildSharedBitmapManager::ChildSharedBitmapManager( | |
| 14 scoped_refptr<ThreadSafeSender> sender) | |
| 15 : sender_(sender) {} | |
| 16 | |
| 17 ChildSharedBitmapManager::~ChildSharedBitmapManager() {} | |
| 18 | |
| 19 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap( | |
| 20 gfx::Size size) { | |
| 21 TRACE_EVENT2("renderer", | |
| 22 "ChildSharedBitmapManager::AllocateSharedMemory", | |
| 23 "width", | |
| 24 size.width(), | |
| 25 "height", | |
| 26 size.height()); | |
| 27 size_t memory_size = cc::SharedBitmap::GetSizeInBytes(size); | |
| 28 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | |
|
danakj
2014/01/30 22:59:01
It seems potentially problematic to me that the ch
| |
| 29 scoped_ptr<base::SharedMemory> memory; | |
| 30 #if defined(OS_POSIX) | |
| 31 base::SharedMemoryHandle handle; | |
| 32 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( | |
| 33 memory_size, id, &handle)); | |
| 34 memory = make_scoped_ptr(new base::SharedMemory(handle, false)); | |
| 35 memory->Map(memory_size); | |
| 36 #else | |
| 37 memory = | |
| 38 make_scoped_ptr(ChildThread::AllocateSharedMemory(memory_size, sender_)); | |
| 39 CHECK(memory); | |
| 40 memory->Map(memory_size); | |
| 41 base::SharedMemoryHandle handle_to_send = memory->handle(); | |
| 42 sender_->Send( | |
| 43 new ChildProcessHostMsg_AllocatedSharedBitmap(handle_to_send, id)); | |
| 44 #endif | |
| 45 return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap( | |
| 46 memory.release(), | |
| 47 id, | |
| 48 base::Bind(&ChildSharedBitmapManager::FreeSharedMemory, | |
| 49 base::Unretained(this)))); | |
| 50 } | |
| 51 | |
| 52 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId( | |
| 53 gfx::Size, | |
| 54 const cc::SharedBitmapId&) { | |
| 55 return scoped_ptr<cc::SharedBitmap>(); | |
|
danakj
2014/01/30 22:59:01
Future: It looks like ResourceProvider::ReceiveFro
danakj
2014/01/31 17:44:22
dongseong pointed out that returning NULL here cau
| |
| 56 } | |
| 57 | |
| 58 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory( | |
| 59 base::SharedMemory* mem) { | |
| 60 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | |
| 61 base::SharedMemoryHandle handle_to_send = mem->handle(); | |
|
danakj
2014/01/30 22:59:01
Could the id here come from the browser where the
| |
| 62 #if defined(OS_POSIX) | |
| 63 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) | |
| 64 return scoped_ptr<cc::SharedBitmap>(); | |
| 65 #endif | |
| 66 sender_->Send( | |
| 67 new ChildProcessHostMsg_AllocatedSharedBitmap(handle_to_send, id)); | |
| 68 return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap( | |
| 69 mem, | |
| 70 id, | |
| 71 base::Bind(&ChildSharedBitmapManager::ReleaseSharedBitmap, | |
| 72 base::Unretained(this)))); | |
| 73 } | |
| 74 | |
| 75 void ChildSharedBitmapManager::FreeSharedMemory(cc::SharedBitmap* bitmap) { | |
| 76 TRACE_EVENT0("renderer", "ChildSharedBitmapManager::FreeSharedMemory"); | |
| 77 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(bitmap->id())); | |
| 78 delete bitmap->memory(); | |
| 79 } | |
| 80 | |
| 81 void ChildSharedBitmapManager::ReleaseSharedBitmap(cc::SharedBitmap* handle) { | |
| 82 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(handle->id())); | |
|
danakj
2014/01/30 22:59:01
TRACE_EVENT here?
| |
| 83 } | |
| 84 | |
| 85 } // namespace content | |
| OLD | NEW |