Chromium Code Reviews| 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 "base/debug/alias.h" | |
| 8 #include "base/process/process_metrics.h" | |
| 7 #include "content/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
| 8 #include "content/common/child_process_messages.h" | 10 #include "content/common/child_process_messages.h" |
| 9 #include "ui/gfx/size.h" | 11 #include "ui/gfx/size.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 class ChildSharedBitmap : public SharedMemoryBitmap { | 17 class ChildSharedBitmap : public SharedMemoryBitmap { |
| 16 public: | 18 public: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 31 | 33 |
| 32 ~ChildSharedBitmap() override { | 34 ~ChildSharedBitmap() override { |
| 33 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); | 35 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id())); |
| 34 } | 36 } |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 scoped_refptr<ThreadSafeSender> sender_; | 39 scoped_refptr<ThreadSafeSender> sender_; |
| 38 scoped_ptr<base::SharedMemory> shared_memory_holder_; | 40 scoped_ptr<base::SharedMemory> shared_memory_holder_; |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 #if defined(OS_WIN) | |
| 44 | |
| 45 // Collect extra information for debugging bitmap creation failures. | |
| 46 void CollectMemoryUsageAndDie(const gfx::Size& size) { | |
| 47 int width = size.width(); | |
| 48 int height = size.height(); | |
| 49 DWORD last_error = GetLastError(); | |
| 50 | |
| 51 scoped_ptr<base::ProcessMetrics> metrics( | |
| 52 base::ProcessMetrics::CreateProcessMetrics( | |
| 53 base::GetCurrentProcessHandle())); | |
| 54 | |
| 55 size_t private_bytes = 0; | |
| 56 size_t shared_bytes = 0; | |
| 57 metrics->GetMemoryBytes(&private_bytes, &shared_bytes); | |
| 58 | |
| 59 base::debug::Alias(&width); | |
| 60 base::debug::Alias(&height); | |
| 61 base::debug::Alias(&last_error); | |
| 62 base::debug::Alias(&private_bytes); | |
| 63 base::debug::Alias(&shared_bytes); | |
| 64 | |
| 65 CHECK(false); | |
| 66 } | |
| 67 | |
| 68 #endif | |
| 69 | |
| 41 } // namespace | 70 } // namespace |
| 42 | 71 |
| 43 SharedMemoryBitmap::SharedMemoryBitmap(uint8* pixels, | 72 SharedMemoryBitmap::SharedMemoryBitmap(uint8* pixels, |
| 44 const cc::SharedBitmapId& id, | 73 const cc::SharedBitmapId& id, |
| 45 base::SharedMemory* shared_memory) | 74 base::SharedMemory* shared_memory) |
| 46 : SharedBitmap(pixels, id), shared_memory_(shared_memory) { | 75 : SharedBitmap(pixels, id), shared_memory_(shared_memory) { |
| 47 } | 76 } |
| 48 | 77 |
| 49 ChildSharedBitmapManager::ChildSharedBitmapManager( | 78 ChildSharedBitmapManager::ChildSharedBitmapManager( |
| 50 scoped_refptr<ThreadSafeSender> sender) | 79 scoped_refptr<ThreadSafeSender> sender) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 76 scoped_ptr<base::SharedMemory> memory; | 105 scoped_ptr<base::SharedMemory> memory; |
| 77 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
| 78 base::SharedMemoryHandle handle; | 107 base::SharedMemoryHandle handle; |
| 79 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( | 108 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( |
| 80 memory_size, id, &handle)); | 109 memory_size, id, &handle)); |
| 81 memory = make_scoped_ptr(new base::SharedMemory(handle, false)); | 110 memory = make_scoped_ptr(new base::SharedMemory(handle, false)); |
| 82 if (!memory->Map(memory_size)) | 111 if (!memory->Map(memory_size)) |
| 83 CHECK(false); | 112 CHECK(false); |
| 84 #else | 113 #else |
| 85 memory = ChildThread::AllocateSharedMemory(memory_size, sender_.get()); | 114 memory = ChildThread::AllocateSharedMemory(memory_size, sender_.get()); |
| 115 #if defined(OS_WIN) | |
| 116 if (!memory) | |
| 117 CollectMemoryUsageAndDie(size); | |
| 118 #endif | |
| 119 | |
| 86 CHECK(memory); | 120 CHECK(memory); |
| 87 if (!memory->Map(memory_size)) | 121 if (!memory->Map(memory_size)) { |
| 122 #if defined(OS_WIN) | |
| 123 if (!memory) | |
|
piman
2014/12/20 02:40:45
nit: memory is !null here, so you can remove the i
| |
| 124 CollectMemoryUsageAndDie(size); | |
| 125 #endif | |
| 88 CHECK(false); | 126 CHECK(false); |
| 127 } | |
| 89 base::SharedMemoryHandle handle_to_send = memory->handle(); | 128 base::SharedMemoryHandle handle_to_send = memory->handle(); |
| 90 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 129 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
| 91 memory_size, handle_to_send, id)); | 130 memory_size, handle_to_send, id)); |
| 92 #endif | 131 #endif |
| 93 return make_scoped_ptr(new ChildSharedBitmap(sender_, memory.Pass(), id)); | 132 return make_scoped_ptr(new ChildSharedBitmap(sender_, memory.Pass(), id)); |
| 94 } | 133 } |
| 95 | 134 |
| 96 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId( | 135 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId( |
| 97 const gfx::Size&, | 136 const gfx::Size&, |
| 98 const cc::SharedBitmapId&) { | 137 const cc::SharedBitmapId&) { |
| 99 NOTREACHED(); | 138 NOTREACHED(); |
| 100 return scoped_ptr<cc::SharedBitmap>(); | 139 return scoped_ptr<cc::SharedBitmap>(); |
| 101 } | 140 } |
| 102 | 141 |
| 103 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory( | 142 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory( |
| 104 base::SharedMemory* mem) { | 143 base::SharedMemory* mem) { |
| 105 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 144 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
| 106 base::SharedMemoryHandle handle_to_send = mem->handle(); | 145 base::SharedMemoryHandle handle_to_send = mem->handle(); |
| 107 #if defined(OS_POSIX) | 146 #if defined(OS_POSIX) |
| 108 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) | 147 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) |
| 109 return scoped_ptr<cc::SharedBitmap>(); | 148 return scoped_ptr<cc::SharedBitmap>(); |
| 110 #endif | 149 #endif |
| 111 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 150 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
| 112 mem->mapped_size(), handle_to_send, id)); | 151 mem->mapped_size(), handle_to_send, id)); |
| 113 | 152 |
| 114 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); | 153 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id)); |
| 115 } | 154 } |
| 116 | 155 |
| 117 } // namespace content | 156 } // namespace content |
| OLD | NEW |