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 15 matching lines...) Expand all Loading... |
26 if (!s.IsValid()) | 26 if (!s.IsValid()) |
27 return false; | 27 return false; |
28 *size_in_bytes = s.ValueOrDie(); | 28 *size_in_bytes = s.ValueOrDie(); |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
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 } | |
38 | 37 |
39 GLImageSharedMemory::~GLImageSharedMemory() { | 38 GLImageSharedMemory::~GLImageSharedMemory() { |
40 DCHECK(!shared_memory_); | 39 DCHECK(!shared_memory_); |
41 } | 40 } |
42 | 41 |
43 bool GLImageSharedMemory::Initialize(const gfx::GpuMemoryBufferHandle& handle, | 42 bool GLImageSharedMemory::Initialize(const gfx::GpuMemoryBufferHandle& handle, |
44 gfx::BufferFormat format) { | 43 gfx::BufferFormat format) { |
45 size_t size_in_bytes; | 44 size_t size_in_bytes; |
46 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) | 45 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) |
47 return false; | 46 return false; |
(...skipping 18 matching lines...) Expand all Loading... |
66 return false; | 65 return false; |
67 } | 66 } |
68 | 67 |
69 if (!GLImageMemory::Initialize( | 68 if (!GLImageMemory::Initialize( |
70 static_cast<unsigned char*>(duped_shared_memory->memory()), format)) { | 69 static_cast<unsigned char*>(duped_shared_memory->memory()), format)) { |
71 return false; | 70 return false; |
72 } | 71 } |
73 | 72 |
74 DCHECK(!shared_memory_); | 73 DCHECK(!shared_memory_); |
75 shared_memory_ = duped_shared_memory.Pass(); | 74 shared_memory_ = duped_shared_memory.Pass(); |
| 75 shared_memory_id_ = handle.id; |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 void GLImageSharedMemory::Destroy(bool have_context) { | 79 void GLImageSharedMemory::Destroy(bool have_context) { |
80 GLImageMemory::Destroy(have_context); | 80 GLImageMemory::Destroy(have_context); |
81 shared_memory_.reset(); | 81 shared_memory_.reset(); |
82 } | 82 } |
83 | 83 |
| 84 void GLImageSharedMemory::DumpMemory(base::trace_event::ProcessMemoryDump* pmd, |
| 85 uint64_t process_tracing_id, |
| 86 const std::string& dump_name) { |
| 87 size_t size_bytes; |
| 88 SizeInBytes(GetSize(), format(), &size_bytes); |
| 89 |
| 90 base::trace_event::MemoryAllocatorDump* dump = |
| 91 pmd->CreateAllocatorDump(dump_name); |
| 92 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 93 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 94 static_cast<uint64_t>(size_bytes)); |
| 95 |
| 96 auto guid = base::trace_event::GetGenericSharedMemoryGUIDForTracing( |
| 97 process_tracing_id, shared_memory_id_); |
| 98 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 99 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 100 } |
| 101 |
84 } // namespace gfx | 102 } // namespace gfx |
OLD | NEW |