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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 max_memory_usage_bytes_(0), | 63 max_memory_usage_bytes_(0), |
64 max_resource_count_(0), | 64 max_resource_count_(0), |
65 in_use_memory_usage_bytes_(0), | 65 in_use_memory_usage_bytes_(0), |
66 total_memory_usage_bytes_(0), | 66 total_memory_usage_bytes_(0), |
67 total_resource_count_(0), | 67 total_resource_count_(0), |
68 task_runner_(task_runner), | 68 task_runner_(task_runner), |
69 evict_expired_resources_pending_(false), | 69 evict_expired_resources_pending_(false), |
70 resource_expiration_delay_(expiration_delay), | 70 resource_expiration_delay_(expiration_delay), |
71 weak_ptr_factory_(this) { | 71 weak_ptr_factory_(this) { |
72 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 72 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
73 this, "cc::ResourcePool", task_runner_.get()); | 73 this, "cc::ResourcePool", task_runner_.get()); |
tasak
2016/08/26 10:08:04
Need to register this with ChildMemoryCoordinator
| |
74 } | 74 } |
75 | 75 |
76 ResourcePool::~ResourcePool() { | 76 ResourcePool::~ResourcePool() { |
77 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 77 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
78 this); | 78 this); |
79 | 79 |
80 DCHECK_EQ(0u, in_use_resources_.size()); | 80 DCHECK_EQ(0u, in_use_resources_.size()); |
81 | 81 |
82 while (!busy_resources_.empty()) { | 82 while (!busy_resources_.empty()) { |
83 DidFinishUsingResource(PopBack(&busy_resources_)); | 83 DidFinishUsingResource(PopBack(&busy_resources_)); |
84 } | 84 } |
85 | 85 |
86 SetResourceUsageLimits(0, 0); | 86 SetResourceUsageLimits(0, 0); |
87 DCHECK_EQ(0u, unused_resources_.size()); | 87 DCHECK_EQ(0u, unused_resources_.size()); |
88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); | 88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); |
89 DCHECK_EQ(0u, total_memory_usage_bytes_); | 89 DCHECK_EQ(0u, total_memory_usage_bytes_); |
90 DCHECK_EQ(0u, total_resource_count_); | 90 DCHECK_EQ(0u, total_resource_count_); |
tasak
2016/08/26 10:08:04
Need to unregister this with ChildMemoryCoordinato
| |
91 } | 91 } |
92 | 92 |
93 Resource* ResourcePool::ReuseResource(const gfx::Size& size, | 93 Resource* ResourcePool::ReuseResource(const gfx::Size& size, |
94 ResourceFormat format, | 94 ResourceFormat format, |
95 const gfx::ColorSpace& color_space) { | 95 const gfx::ColorSpace& color_space) { |
96 // Finding resources in |unused_resources_| from MRU to LRU direction, touches | 96 // Finding resources in |unused_resources_| from MRU to LRU direction, touches |
97 // LRU resources only if needed, which increases possibility of expiring more | 97 // LRU resources only if needed, which increases possibility of expiring more |
98 // LRU resources within kResourceExpirationDelayMs. | 98 // LRU resources within kResourceExpirationDelayMs. |
99 for (ResourceDeque::iterator it = unused_resources_.begin(); | 99 for (ResourceDeque::iterator it = unused_resources_.begin(); |
100 it != unused_resources_.end(); ++it) { | 100 it != unused_resources_.end(); ++it) { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 } | 446 } |
447 for (const auto& resource : busy_resources_) { | 447 for (const auto& resource : busy_resources_) { |
448 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 448 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
449 } | 449 } |
450 for (const auto& entry : in_use_resources_) { | 450 for (const auto& entry : in_use_resources_) { |
451 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 451 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
452 } | 452 } |
453 return true; | 453 return true; |
454 } | 454 } |
455 | 455 |
456 void ResourcePool::OnMemoryStateChange( | |
457 memory_coordinator::mojom::MemoryState state) { | |
458 if (state == memory_coordinator::mojom::MemoryState::SUSPENDED) { | |
459 while (!unused_resources_.empty()) | |
460 DeleteResource(PopBack(&unused_resources_)); | |
ericrk
2016/08/31 17:50:32
This doesn't free "busy" resources, which can safe
| |
461 } | |
462 } | |
463 | |
456 } // namespace cc | 464 } // namespace cc |
OLD | NEW |