| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gl/gl_image_shared_memory.h" | 5 #include "ui/gl/gl_image_shared_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
| 9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size, | 34 GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size, |
| 35 unsigned internalformat) | 35 unsigned internalformat) |
| 36 : GLImageMemory(size, internalformat) { | 36 : GLImageMemory(size, internalformat) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 GLImageSharedMemory::~GLImageSharedMemory() { | 39 GLImageSharedMemory::~GLImageSharedMemory() { |
| 40 DCHECK(!shared_memory_); | 40 DCHECK(!shared_memory_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool GLImageSharedMemory::Initialize(const gfx::GpuMemoryBufferHandle& handle, | 43 bool GLImageSharedMemory::Initialize( |
| 44 gfx::BufferFormat format) { | 44 const base::SharedMemoryHandle& handle, |
| 45 gfx::GenericSharedMemoryId shared_memory_id, |
| 46 gfx::BufferFormat format) { |
| 45 size_t size_in_bytes; | 47 size_t size_in_bytes; |
| 46 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) | 48 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) |
| 47 return false; | 49 return false; |
| 48 | 50 |
| 49 if (!base::SharedMemory::IsHandleValid(handle.handle)) | 51 if (!base::SharedMemory::IsHandleValid(handle)) |
| 50 return false; | 52 return false; |
| 51 | 53 |
| 52 base::SharedMemory shared_memory(handle.handle, true); | 54 base::SharedMemory shared_memory(handle, true); |
| 53 | 55 |
| 54 // Duplicate the handle. | 56 // Duplicate the handle. |
| 55 base::SharedMemoryHandle duped_shared_memory_handle; | 57 base::SharedMemoryHandle duped_shared_memory_handle; |
| 56 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 58 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
| 57 &duped_shared_memory_handle)) { | 59 &duped_shared_memory_handle)) { |
| 58 DVLOG(0) << "Failed to duplicate shared memory handle."; | 60 DVLOG(0) << "Failed to duplicate shared memory handle."; |
| 59 return false; | 61 return false; |
| 60 } | 62 } |
| 61 | 63 |
| 62 scoped_ptr<base::SharedMemory> duped_shared_memory( | 64 scoped_ptr<base::SharedMemory> duped_shared_memory( |
| 63 new base::SharedMemory(duped_shared_memory_handle, true)); | 65 new base::SharedMemory(duped_shared_memory_handle, true)); |
| 64 if (!duped_shared_memory->Map(size_in_bytes)) { | 66 if (!duped_shared_memory->Map(size_in_bytes)) { |
| 65 DVLOG(0) << "Failed to map shared memory."; | 67 DVLOG(0) << "Failed to map shared memory."; |
| 66 return false; | 68 return false; |
| 67 } | 69 } |
| 68 | 70 |
| 69 if (!GLImageMemory::Initialize( | 71 if (!GLImageMemory::Initialize( |
| 70 static_cast<unsigned char*>(duped_shared_memory->memory()), format)) { | 72 static_cast<unsigned char*>(duped_shared_memory->memory()), format)) { |
| 71 return false; | 73 return false; |
| 72 } | 74 } |
| 73 | 75 |
| 74 DCHECK(!shared_memory_); | 76 DCHECK(!shared_memory_); |
| 75 shared_memory_ = duped_shared_memory.Pass(); | 77 shared_memory_ = duped_shared_memory.Pass(); |
| 76 shared_memory_id_ = handle.id; | 78 shared_memory_id_ = shared_memory_id; |
| 77 return true; | 79 return true; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void GLImageSharedMemory::Destroy(bool have_context) { | 82 void GLImageSharedMemory::Destroy(bool have_context) { |
| 81 GLImageMemory::Destroy(have_context); | 83 GLImageMemory::Destroy(have_context); |
| 82 shared_memory_.reset(); | 84 shared_memory_.reset(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void GLImageSharedMemory::OnMemoryDump( | 87 void GLImageSharedMemory::OnMemoryDump( |
| 86 base::trace_event::ProcessMemoryDump* pmd, | 88 base::trace_event::ProcessMemoryDump* pmd, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 104 auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id, | 106 auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id, |
| 105 shared_memory_id_); | 107 shared_memory_id_); |
| 106 pmd->CreateSharedGlobalAllocatorDump(guid); | 108 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 107 pmd->AddOwnershipEdge(dump->guid(), guid); | 109 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 108 | 110 |
| 109 // Also dump the base class's texture memory. | 111 // Also dump the base class's texture memory. |
| 110 GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name); | 112 GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name); |
| 111 } | 113 } |
| 112 | 114 |
| 113 } // namespace gfx | 115 } // namespace gfx |
| OLD | NEW |