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 |
13 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) | 19 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) |
14 : resource_provider_(resource_provider), | 20 : resource_provider_(resource_provider), |
15 target_(target), | 21 target_(target), |
16 max_memory_usage_bytes_(0), | 22 max_memory_usage_bytes_(0), |
17 max_unused_memory_usage_bytes_(0), | 23 max_unused_memory_usage_bytes_(0), |
18 max_resource_count_(0), | 24 max_resource_count_(0), |
19 memory_usage_bytes_(0), | 25 memory_usage_bytes_(0), |
20 unused_memory_usage_bytes_(0), | 26 unused_memory_usage_bytes_(0), |
21 resource_count_(0) {} | 27 resource_count_(0) { |
28 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
29 this, base::ThreadTaskRunnerHandle::Get()); | |
30 } | |
22 | 31 |
23 ResourcePool::~ResourcePool() { | 32 ResourcePool::~ResourcePool() { |
33 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
34 this); | |
24 while (!busy_resources_.empty()) { | 35 while (!busy_resources_.empty()) { |
25 auto const& front = busy_resources_.front(); | 36 auto const& front = busy_resources_.front(); |
26 DidFinishUsingResource(front.resource, front.content_id); | 37 DidFinishUsingResource(front.resource, front.content_id); |
27 busy_resources_.pop_front(); | 38 busy_resources_.pop_front(); |
28 } | 39 } |
29 | 40 |
30 SetResourceUsageLimits(0, 0, 0); | 41 SetResourceUsageLimits(0, 0, 0); |
31 DCHECK_EQ(0u, unused_resources_.size()); | 42 DCHECK_EQ(0u, unused_resources_.size()); |
32 DCHECK_EQ(0u, memory_usage_bytes_); | 43 DCHECK_EQ(0u, memory_usage_bytes_); |
33 DCHECK_EQ(0u, unused_memory_usage_bytes_); | 44 DCHECK_EQ(0u, unused_memory_usage_bytes_); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 } | 171 } |
161 } | 172 } |
162 | 173 |
163 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, | 174 void ResourcePool::DidFinishUsingResource(ScopedResource* resource, |
164 uint64_t content_id) { | 175 uint64_t content_id) { |
165 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 176 unused_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
166 resource->size(), resource->format()); | 177 resource->size(), resource->format()); |
167 unused_resources_.push_back(PoolResource(resource, content_id)); | 178 unused_resources_.push_back(PoolResource(resource, content_id)); |
168 } | 179 } |
169 | 180 |
181 bool ResourcePool::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | |
182 for (const auto& resource : unused_resources_) { | |
183 resource.OnMemoryDump(pmd, true /* is_free */); | |
184 } | |
185 for (const auto& resource : busy_resources_) { | |
186 resource.OnMemoryDump(pmd, false /* is_free */); | |
187 } | |
188 // TODO(ericrk): Dump vended out resources once that data is available. | |
189 // crbug.com/516541 | |
190 return true; | |
191 } | |
192 | |
193 void ResourcePool::PoolResource::OnMemoryDump( | |
reveman
2015/08/05 01:26:59
nit: definition of nested class usually go before
ericrk
2015/08/05 20:41:08
Done.
| |
194 base::trace_event::ProcessMemoryDump* pmd, | |
195 bool is_free) const { | |
196 // TODO(ericrk): Add per-compositor ID in name. | |
197 std::string parent_node = | |
198 base::StringPrintf("cc/resource_memory/resource_%d", resource->id()); | |
199 std::string dump_name = | |
200 base::StringPrintf("cc/tile_memory/resource_%d", resource->id()); | |
201 base::trace_event::MemoryAllocatorDump* dump = | |
202 pmd->CreateAllocatorDump(dump_name); | |
203 | |
204 pmd->AddSuballocation(dump->guid(), parent_node); | |
205 | |
206 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( | |
207 resource->size(), resource->format()); | |
208 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
209 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
210 total_bytes); | |
211 dump->AddScalar("free_size", | |
212 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
213 is_free ? total_bytes : 0); | |
214 } | |
215 | |
170 } // namespace cc | 216 } // namespace cc |
OLD | NEW |