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