Chromium Code Reviews| 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::OnMemoryDump( | |
| 85 base::trace_event::ProcessMemoryDump* pmd, | |
| 86 uint64_t process_tracing_id, | |
| 87 const std::string& dump_name) { | |
|
reveman
2015/08/18 08:32:52
This function should report 0 size or early out af
ericrk
2015/08/18 09:00:47
Switched both to report 0.
| |
| 88 size_t size_bytes; | |
| 89 SizeInBytes(GetSize(), format(), &size_bytes); | |
| 90 | |
| 91 base::trace_event::MemoryAllocatorDump* dump = | |
| 92 pmd->CreateAllocatorDump(dump_name); | |
| 93 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 94 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 95 static_cast<uint64_t>(size_bytes)); | |
| 96 | |
| 97 auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id, | |
| 98 shared_memory_id_); | |
| 99 pmd->CreateSharedGlobalAllocatorDump(guid); | |
| 100 pmd->AddOwnershipEdge(dump->guid(), guid); | |
| 101 } | |
| 102 | |
| 84 } // namespace gfx | 103 } // namespace gfx |
| OLD | NEW |