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/memory/shared_memory.h" |
8 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
9 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "base/trace_event/memory_allocator_dump.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "base/trace_event/process_memory_dump.h" |
10 | 14 |
11 namespace gfx { | 15 namespace gfx { |
12 namespace { | 16 namespace { |
13 | 17 |
14 // Returns true if the size is valid and false otherwise. | 18 // Returns true if the size is valid and false otherwise. |
15 bool SizeInBytes(const gfx::Size& size, | 19 bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) { |
16 gfx::BufferFormat format, | |
17 size_t* size_in_bytes) { | |
18 if (size.IsEmpty()) | 20 if (size.IsEmpty()) |
19 return false; | 21 return false; |
20 | 22 |
21 size_t stride_in_bytes = 0; | 23 size_t stride_in_bytes = 0; |
22 if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes)) | 24 if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes)) |
23 return false; | 25 return false; |
24 base::CheckedNumeric<size_t> s = stride_in_bytes; | 26 base::CheckedNumeric<size_t> s = stride_in_bytes; |
25 s *= size.height(); | 27 s *= size.height(); |
26 if (!s.IsValid()) | 28 if (!s.IsValid()) |
27 return false; | 29 return false; |
28 *size_in_bytes = s.ValueOrDie(); | 30 *size_in_bytes = s.ValueOrDie(); |
29 return true; | 31 return true; |
30 } | 32 } |
31 | 33 |
32 } // namespace | 34 } // namespace |
33 | 35 |
34 GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size, | 36 GLImageSharedMemory::GLImageSharedMemory(const Size& size, |
35 unsigned internalformat) | 37 unsigned internalformat) |
36 : GLImageMemory(size, internalformat) { | 38 : GLImageMemory(size, internalformat) {} |
37 } | |
38 | 39 |
39 GLImageSharedMemory::~GLImageSharedMemory() { | 40 GLImageSharedMemory::~GLImageSharedMemory() { |
40 DCHECK(!shared_memory_); | 41 DCHECK(!shared_memory_); |
41 } | 42 } |
42 | 43 |
43 bool GLImageSharedMemory::Initialize( | 44 bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle, |
44 const base::SharedMemoryHandle& handle, | 45 GenericSharedMemoryId shared_memory_id, |
45 gfx::GenericSharedMemoryId shared_memory_id, | 46 BufferFormat format) { |
46 gfx::BufferFormat format) { | |
47 size_t size_in_bytes; | 47 size_t size_in_bytes; |
48 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) | 48 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) |
49 return false; | 49 return false; |
50 | 50 |
51 if (!base::SharedMemory::IsHandleValid(handle)) | 51 if (!base::SharedMemory::IsHandleValid(handle)) |
52 return false; | 52 return false; |
53 | 53 |
54 base::SharedMemory shared_memory(handle, true); | 54 base::SharedMemory shared_memory(handle, true); |
55 | 55 |
56 // Duplicate the handle. | 56 // Duplicate the handle. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 size_t size_in_bytes = 0; | 91 size_t size_in_bytes = 0; |
92 | 92 |
93 if (shared_memory_) { | 93 if (shared_memory_) { |
94 bool result = SizeInBytes(GetSize(), format(), &size_in_bytes); | 94 bool result = SizeInBytes(GetSize(), format(), &size_in_bytes); |
95 DCHECK(result); | 95 DCHECK(result); |
96 } | 96 } |
97 | 97 |
98 // Dump under "/shared_memory", as the base class may also dump to | 98 // Dump under "/shared_memory", as the base class may also dump to |
99 // "/texture_memory". | 99 // "/texture_memory". |
100 base::trace_event::MemoryAllocatorDump* dump = | 100 base::trace_event::MemoryAllocatorDump* dump = |
101 pmd->CreateAllocatorDump(dump_name + "/private_memory"); | 101 pmd->CreateAllocatorDump(dump_name + "/shared_memory"); |
102 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 102 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
103 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 103 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
104 static_cast<uint64_t>(size_in_bytes)); | 104 static_cast<uint64_t>(size_in_bytes)); |
105 | 105 |
106 auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id, | 106 auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id, |
107 shared_memory_id_); | 107 shared_memory_id_); |
108 pmd->CreateSharedGlobalAllocatorDump(guid); | 108 pmd->CreateSharedGlobalAllocatorDump(guid); |
109 pmd->AddOwnershipEdge(dump->guid(), guid); | 109 pmd->AddOwnershipEdge(dump->guid(), guid); |
110 | |
111 // Also dump the base class's texture memory. | |
112 GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name); | |
113 } | 110 } |
114 | 111 |
115 } // namespace gfx | 112 } // namespace gfx |
OLD | NEW |