OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/resources/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/format_macros.h" |
| 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" |
7 #include "cc/resources/resource_provider.h" | 13 #include "cc/resources/resource_provider.h" |
8 #include "cc/resources/resource_util.h" | 14 #include "cc/resources/resource_util.h" |
9 #include "cc/resources/scoped_resource.h" | 15 #include "cc/resources/scoped_resource.h" |
10 | 16 |
11 namespace cc { | 17 namespace cc { |
12 | 18 |
| 19 void ResourcePool::PoolResource::OnMemoryDump( |
| 20 base::trace_event::ProcessMemoryDump* pmd, |
| 21 bool is_free) const { |
| 22 // TODO(ericrk): Add per-compositor ID in name. |
| 23 std::string parent_node = |
| 24 base::StringPrintf("cc/resource_memory/resource_%d", resource->id()); |
| 25 std::string dump_name = |
| 26 base::StringPrintf("cc/tile_memory/resource_%d", resource->id()); |
| 27 base::trace_event::MemoryAllocatorDump* dump = |
| 28 pmd->CreateAllocatorDump(dump_name); |
| 29 |
| 30 pmd->AddSuballocation(dump->guid(), parent_node); |
| 31 |
| 32 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( |
| 33 resource->size(), resource->format()); |
| 34 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 35 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 36 total_bytes); |
| 37 dump->AddScalar("free_size", |
| 38 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 39 is_free ? total_bytes : 0); |
| 40 } |
| 41 |
13 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) | 42 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) |
14 : resource_provider_(resource_provider), | 43 : resource_provider_(resource_provider), |
15 target_(target), | 44 target_(target), |
16 max_memory_usage_bytes_(0), | 45 max_memory_usage_bytes_(0), |
17 max_unused_memory_usage_bytes_(0), | 46 max_unused_memory_usage_bytes_(0), |
18 max_resource_count_(0), | 47 max_resource_count_(0), |
19 memory_usage_bytes_(0), | 48 memory_usage_bytes_(0), |
20 unused_memory_usage_bytes_(0), | 49 unused_memory_usage_bytes_(0), |
21 resource_count_(0) {} | 50 resource_count_(0) { |
| 51 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 52 this, base::ThreadTaskRunnerHandle::Get()); |
| 53 } |
22 | 54 |
23 ResourcePool::~ResourcePool() { | 55 ResourcePool::~ResourcePool() { |
| 56 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 57 this); |
24 while (!busy_resources_.empty()) { | 58 while (!busy_resources_.empty()) { |
25 auto const& front = busy_resources_.front(); | 59 auto const& front = busy_resources_.front(); |
26 DidFinishUsingResource(front.resource, front.content_id); | 60 DidFinishUsingResource(front.resource, front.content_id); |
27 busy_resources_.pop_front(); | 61 busy_resources_.pop_front(); |
28 } | 62 } |
29 | 63 |
30 SetResourceUsageLimits(0, 0, 0); | 64 SetResourceUsageLimits(0, 0, 0); |
31 DCHECK_EQ(0u, unused_resources_.size()); | 65 DCHECK_EQ(0u, unused_resources_.size()); |
32 DCHECK_EQ(0u, memory_usage_bytes_); | 66 DCHECK_EQ(0u, memory_usage_bytes_); |
33 DCHECK_EQ(0u, unused_memory_usage_bytes_); | 67 DCHECK_EQ(0u, unused_memory_usage_bytes_); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 194 } |
161 } | 195 } |
162 | 196 |
163 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, | 197 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
164 uint64_t content_id) { | 198 uint64_t content_id) { |
165 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 199 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
166 resource->size(), resource->format()); | 200 resource->size(), resource->format()); |
167 unused_resources_.push_back(PoolResource(resource, content_id)); | 201 unused_resources_.push_back(PoolResource(resource, content_id)); |
168 } | 202 } |
169 | 203 |
| 204 bool ResourcePool::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 205 base::trace_event::ProcessMemoryDump* pmd) { |
| 206 for (const auto& resource : unused_resources_) { |
| 207 resource.OnMemoryDump(pmd, true /* is_free */); |
| 208 } |
| 209 for (const auto& resource : busy_resources_) { |
| 210 resource.OnMemoryDump(pmd, false /* is_free */); |
| 211 } |
| 212 // TODO(ericrk): Dump vended out resources once that data is available. |
| 213 // crbug.com/516541 |
| 214 return true; |
| 215 } |
| 216 |
170 } // namespace cc | 217 } // namespace cc |
OLD | NEW |