OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/viz/frame_sinks/frame_eviction_manager.h" | 5 #include "components/viz/frame_sinks/frame_eviction_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/memory_coordinator_client_registry.h" | 11 #include "base/memory/memory_coordinator_client_registry.h" |
12 #include "base/memory/memory_coordinator_proxy.h" | 12 #include "base/memory/memory_coordinator_proxy.h" |
13 #include "base/memory/memory_pressure_listener.h" | 13 #include "base/memory/memory_pressure_listener.h" |
14 #include "base/memory/memory_pressure_monitor.h" | 14 #include "base/memory/memory_pressure_monitor.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "components/display_compositor/host_shared_bitmap_manager.h" | 18 #include "components/viz/display_compositor/host_shared_bitmap_manager.h" |
19 | 19 |
20 namespace viz { | 20 namespace viz { |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kModeratePressurePercentage = 50; | 23 const int kModeratePressurePercentage = 50; |
24 const int kCriticalPressurePercentage = 10; | 24 const int kCriticalPressurePercentage = 10; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 FrameEvictionManager* FrameEvictionManager::GetInstance() { | 28 FrameEvictionManager* FrameEvictionManager::GetInstance() { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); | 127 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); |
128 #endif | 128 #endif |
129 max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f; | 129 max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f; |
130 } | 130 } |
131 | 131 |
132 FrameEvictionManager::~FrameEvictionManager() {} | 132 FrameEvictionManager::~FrameEvictionManager() {} |
133 | 133 |
134 void FrameEvictionManager::CullUnlockedFrames(size_t saved_frame_limit) { | 134 void FrameEvictionManager::CullUnlockedFrames(size_t saved_frame_limit) { |
135 if (unlocked_frames_.size() + locked_frames_.size() > 0) { | 135 if (unlocked_frames_.size() + locked_frames_.size() > 0) { |
136 float handles_per_frame = | 136 float handles_per_frame = |
137 display_compositor::HostSharedBitmapManager::current() | 137 HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f / |
138 ->AllocatedBitmapCount() * | 138 (unlocked_frames_.size() + locked_frames_.size()); |
139 1.0f / (unlocked_frames_.size() + locked_frames_.size()); | |
140 | 139 |
141 saved_frame_limit = std::max( | 140 saved_frame_limit = std::max( |
142 1, static_cast<int>(std::min(static_cast<float>(saved_frame_limit), | 141 1, static_cast<int>(std::min(static_cast<float>(saved_frame_limit), |
143 max_handles_ / handles_per_frame))); | 142 max_handles_ / handles_per_frame))); |
144 } | 143 } |
145 while (!unlocked_frames_.empty() && | 144 while (!unlocked_frames_.empty() && |
146 unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) { | 145 unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) { |
147 size_t old_size = unlocked_frames_.size(); | 146 size_t old_size = unlocked_frames_.size(); |
148 // Should remove self from list. | 147 // Should remove self from list. |
149 unlocked_frames_.back()->EvictCurrentFrame(); | 148 unlocked_frames_.back()->EvictCurrentFrame(); |
(...skipping 21 matching lines...) Expand all Loading... |
171 } | 170 } |
172 | 171 |
173 void FrameEvictionManager::PurgeMemory(int percentage) { | 172 void FrameEvictionManager::PurgeMemory(int percentage) { |
174 int saved_frame_limit = max_number_of_saved_frames_; | 173 int saved_frame_limit = max_number_of_saved_frames_; |
175 if (saved_frame_limit <= 1) | 174 if (saved_frame_limit <= 1) |
176 return; | 175 return; |
177 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); | 176 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); |
178 } | 177 } |
179 | 178 |
180 } // namespace viz | 179 } // namespace viz |
OLD | NEW |