| 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" | |
| 9 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
| 10 #include "base/process/process_handle.h" | 9 #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" | |
| 14 | 10 |
| 15 namespace gfx { | 11 namespace gfx { |
| 16 namespace { | 12 namespace { |
| 17 | 13 |
| 18 // Returns true if the size is valid and false otherwise. | 14 // Returns true if the size is valid and false otherwise. |
| 19 bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) { | 15 bool SizeInBytes(const gfx::Size& size, |
| 16 gfx::BufferFormat format, |
| 17 size_t* size_in_bytes) { |
| 20 if (size.IsEmpty()) | 18 if (size.IsEmpty()) |
| 21 return false; | 19 return false; |
| 22 | 20 |
| 23 size_t stride_in_bytes = 0; | 21 size_t stride_in_bytes = 0; |
| 24 if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes)) | 22 if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes)) |
| 25 return false; | 23 return false; |
| 26 base::CheckedNumeric<size_t> s = stride_in_bytes; | 24 base::CheckedNumeric<size_t> s = stride_in_bytes; |
| 27 s *= size.height(); | 25 s *= size.height(); |
| 28 if (!s.IsValid()) | 26 if (!s.IsValid()) |
| 29 return false; | 27 return false; |
| 30 *size_in_bytes = s.ValueOrDie(); | 28 *size_in_bytes = s.ValueOrDie(); |
| 31 return true; | 29 return true; |
| 32 } | 30 } |
| 33 | 31 |
| 34 } // namespace | 32 } // namespace |
| 35 | 33 |
| 36 GLImageSharedMemory::GLImageSharedMemory(const Size& size, | 34 GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size, |
| 37 unsigned internalformat) | 35 unsigned internalformat) |
| 38 : GLImageMemory(size, internalformat) {} | 36 : GLImageMemory(size, internalformat) { |
| 37 } |
| 39 | 38 |
| 40 GLImageSharedMemory::~GLImageSharedMemory() { | 39 GLImageSharedMemory::~GLImageSharedMemory() { |
| 41 DCHECK(!shared_memory_); | 40 DCHECK(!shared_memory_); |
| 42 } | 41 } |
| 43 | 42 |
| 44 bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle, | 43 bool GLImageSharedMemory::Initialize( |
| 45 GenericSharedMemoryId shared_memory_id, | 44 const base::SharedMemoryHandle& handle, |
| 46 BufferFormat format) { | 45 gfx::GenericSharedMemoryId shared_memory_id, |
| 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 + "/shared_memory"); | 101 pmd->CreateAllocatorDump(dump_name + "/private_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 = GetGenericSharedMemoryGUIDForTracing(process_tracing_id, | 106 auto guid = gfx::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); |
| 110 } | 113 } |
| 111 | 114 |
| 112 } // namespace gfx | 115 } // namespace gfx |
| OLD | NEW |