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_ref_counted_memory.h" | 5 #include "ui/gl/gl_image_ref_counted_memory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/trace_event/memory_allocator_dump.h" | |
10 #include "base/trace_event/memory_dump_manager.h" | |
11 #include "base/trace_event/process_memory_dump.h" | |
12 | 9 |
13 namespace gfx { | 10 namespace gfx { |
14 | 11 |
15 GLImageRefCountedMemory::GLImageRefCountedMemory(const Size& size, | 12 GLImageRefCountedMemory::GLImageRefCountedMemory(const gfx::Size& size, |
16 unsigned internalformat) | 13 unsigned internalformat) |
17 : GLImageMemory(size, internalformat) {} | 14 : GLImageMemory(size, internalformat) { |
| 15 } |
18 | 16 |
19 GLImageRefCountedMemory::~GLImageRefCountedMemory() { | 17 GLImageRefCountedMemory::~GLImageRefCountedMemory() { |
20 DCHECK(!ref_counted_memory_.get()); | 18 DCHECK(!ref_counted_memory_.get()); |
21 } | 19 } |
22 | 20 |
23 bool GLImageRefCountedMemory::Initialize( | 21 bool GLImageRefCountedMemory::Initialize( |
24 base::RefCountedMemory* ref_counted_memory, | 22 base::RefCountedMemory* ref_counted_memory, |
25 BufferFormat format) { | 23 gfx::BufferFormat format) { |
26 if (!GLImageMemory::Initialize(ref_counted_memory->front(), format)) | 24 if (!GLImageMemory::Initialize(ref_counted_memory->front(), format)) |
27 return false; | 25 return false; |
28 | 26 |
29 DCHECK(!ref_counted_memory_.get()); | 27 DCHECK(!ref_counted_memory_.get()); |
30 ref_counted_memory_ = ref_counted_memory; | 28 ref_counted_memory_ = ref_counted_memory; |
31 return true; | 29 return true; |
32 } | 30 } |
33 | 31 |
34 void GLImageRefCountedMemory::Destroy(bool have_context) { | 32 void GLImageRefCountedMemory::Destroy(bool have_context) { |
35 GLImageMemory::Destroy(have_context); | 33 GLImageMemory::Destroy(have_context); |
36 ref_counted_memory_ = nullptr; | 34 ref_counted_memory_ = NULL; |
37 } | 35 } |
38 | 36 |
39 void GLImageRefCountedMemory::OnMemoryDump( | 37 void GLImageRefCountedMemory::OnMemoryDump( |
40 base::trace_event::ProcessMemoryDump* pmd, | 38 base::trace_event::ProcessMemoryDump* pmd, |
41 uint64_t process_tracing_id, | 39 uint64_t process_tracing_id, |
42 const std::string& dump_name) { | 40 const std::string& dump_name) { |
43 // Log size 0 if |ref_counted_memory_| has been released. | 41 // Log size 0 if |ref_counted_memory_| has been released. |
44 size_t size_in_bytes = ref_counted_memory_ ? ref_counted_memory_->size() : 0; | 42 size_t size_in_bytes = ref_counted_memory_ ? ref_counted_memory_->size() : 0; |
45 | 43 |
46 // Dump under "/private_memory", as the base class may also dump to | 44 // Dump under "/private_memory", as the base class may also dump to |
47 // "/texture_memory". | 45 // "/texture_memory". |
48 base::trace_event::MemoryAllocatorDump* dump = | 46 base::trace_event::MemoryAllocatorDump* dump = |
49 pmd->CreateAllocatorDump(dump_name + "/private_memory"); | 47 pmd->CreateAllocatorDump(dump_name + "/private_memory"); |
50 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 48 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
51 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 49 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
52 static_cast<uint64_t>(size_in_bytes)); | 50 static_cast<uint64_t>(size_in_bytes)); |
53 | 51 |
54 pmd->AddSuballocation(dump->guid(), | 52 pmd->AddSuballocation(dump->guid(), |
55 base::trace_event::MemoryDumpManager::GetInstance() | 53 base::trace_event::MemoryDumpManager::GetInstance() |
56 ->system_allocator_pool_name()); | 54 ->system_allocator_pool_name()); |
| 55 |
| 56 // Also dump the base class's texture memory. |
| 57 GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name); |
57 } | 58 } |
58 | 59 |
59 } // namespace gfx | 60 } // namespace gfx |
OLD | NEW |