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 "athena/resource_manager/public/resource_manager.h" | 5 #include "athena/resource_manager/public/resource_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "athena/activity/public/activity.h" | 10 #include "athena/activity/public/activity.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Remember that the activity order has changed. | 169 // Remember that the activity order has changed. |
170 activity_order_changed_ = true; | 170 activity_order_changed_ = true; |
171 } | 171 } |
172 | 172 |
173 void ResourceManagerImpl::OnOverviewModeEnter() { | 173 void ResourceManagerImpl::OnOverviewModeEnter() { |
174 in_overview_mode_ = true; | 174 in_overview_mode_ = true; |
175 } | 175 } |
176 | 176 |
177 void ResourceManagerImpl::OnOverviewModeExit() { | 177 void ResourceManagerImpl::OnOverviewModeExit() { |
178 in_overview_mode_ = false; | 178 in_overview_mode_ = false; |
179 // Reorder the activities. | 179 // Reorder the activities and manage the resources again since an order change |
| 180 // might have caused a visibility change. |
180 UpdateActivityOrder(); | 181 UpdateActivityOrder(); |
| 182 ManageResource(); |
181 } | 183 } |
182 | 184 |
183 void ResourceManagerImpl::OnSplitViewModeEnter() { | 185 void ResourceManagerImpl::OnSplitViewModeEnter() { |
184 // Re-apply the memory pressure to make sure enough items are visible. | 186 // Re-apply the memory pressure to make sure enough items are visible. |
185 in_splitview_mode_ = true; | 187 in_splitview_mode_ = true; |
186 ManageResource(); | 188 ManageResource(); |
187 } | 189 } |
188 | 190 |
189 | 191 |
190 void ResourceManagerImpl::OnSplitViewModeExit() { | 192 void ResourceManagerImpl::OnSplitViewModeExit() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 size_t max_running_activities = 5; | 242 size_t max_running_activities = 5; |
241 switch (current_memory_pressure_) { | 243 switch (current_memory_pressure_) { |
242 case MEMORY_PRESSURE_UNKNOWN: | 244 case MEMORY_PRESSURE_UNKNOWN: |
243 // If we do not know how much memory we have we assume that it must be a | 245 // If we do not know how much memory we have we assume that it must be a |
244 // high consumption. | 246 // high consumption. |
245 // Fallthrough. | 247 // Fallthrough. |
246 case MEMORY_PRESSURE_HIGH: | 248 case MEMORY_PRESSURE_HIGH: |
247 max_running_activities = 5; | 249 max_running_activities = 5; |
248 break; | 250 break; |
249 case MEMORY_PRESSURE_CRITICAL: | 251 case MEMORY_PRESSURE_CRITICAL: |
250 max_running_activities = 0; | 252 max_running_activities = 1 + (in_splitview_mode_ ? 1 : 0); |
251 break; | 253 break; |
252 case MEMORY_PRESSURE_MODERATE: | 254 case MEMORY_PRESSURE_MODERATE: |
253 max_running_activities = 7; | 255 max_running_activities = 7; |
254 break; | 256 break; |
255 case MEMORY_PRESSURE_LOW: | 257 case MEMORY_PRESSURE_LOW: |
256 // This doesn't really matter. We do not change anything but turning | 258 // This doesn't really matter. We do not change anything but turning |
257 // activities visible. | 259 // activities visible. |
258 max_running_activities = 10000; | 260 max_running_activities = 10000; |
259 break; | 261 break; |
260 } | 262 } |
261 | 263 |
262 // The first n activities should be trated as "visible", means they updated | 264 // The first n activities should be trated as "visible", means they updated |
263 // in overview mode and will keep their layer resources for faster switch | 265 // in overview mode and will keep their layer resources for faster switch |
264 // times. Usually we use |kMaxVisibleActivities| items, but when the memory | 266 // times. Usually we use |kMaxVisibleActivities| items, but when the memory |
265 // pressure gets critical we only hold as many as are really visible. | 267 // pressure gets critical we only hold as many as are really visible. |
266 size_t max_activities = kMaxVisibleActivities; | 268 size_t max_activities = kMaxVisibleActivities; |
267 if (current_memory_pressure_ == MEMORY_PRESSURE_CRITICAL) | 269 if (current_memory_pressure_ == MEMORY_PRESSURE_CRITICAL) |
268 max_activities = 1 + (in_splitview_mode_ ? 1 : 0); | 270 max_activities = max_running_activities; |
269 | 271 |
270 // Restart and / or bail if the order of activities changes due to our calls. | 272 // Restart and / or bail if the order of activities changes due to our calls. |
271 activity_order_changed_ = false; | 273 activity_order_changed_ = false; |
272 | 274 |
273 // Change the visibility of our activities in a pre-processing step. This is | 275 // Change the visibility of our activities in a pre-processing step. This is |
274 // required since it might change the order/number of activities. | 276 // required since it might change the order/number of activities. |
275 size_t index = 0; | 277 size_t index = 0; |
276 while (index < activity_list_.size()) { | 278 while (index < activity_list_.size()) { |
277 Activity* activity = activity_list_[index]; | 279 Activity* activity = activity_list_[index]; |
278 Activity::ActivityState state = activity->GetCurrentState(); | 280 Activity::ActivityState state = activity->GetCurrentState(); |
279 | 281 |
280 // The first |kMaxVisibleActivities| entries should be visible, all others | 282 // The first |kMaxVisibleActivities| entries should be visible, all others |
281 // invisible or at a lower activity state. | 283 // invisible or at a lower activity state. |
282 if (index < max_activities || | 284 if (index < max_activities || |
283 (state == Activity::ACTIVITY_INVISIBLE || | 285 (state == Activity::ACTIVITY_INVISIBLE || |
284 state == Activity::ACTIVITY_VISIBLE)) { | 286 state == Activity::ACTIVITY_VISIBLE)) { |
285 Activity::ActivityState visiblity_state = | 287 Activity::ActivityState visiblity_state = |
286 index < max_activities ? Activity::ACTIVITY_VISIBLE : | 288 index < max_activities ? Activity::ACTIVITY_VISIBLE : |
287 Activity::ACTIVITY_INVISIBLE; | 289 Activity::ACTIVITY_INVISIBLE; |
288 // Only change the state when it changes. Note that when the memory | 290 // Only change the state when it changes. Note that when the memory |
289 // pressure is critical, only the primary activities (1 or 2) are made | 291 // pressure is critical, only the primary activities (1 or 2) are made |
290 // visible. Furthermore, in relaxed mode we only want to make visible. | 292 // visible. Furthermore, in relaxed mode we only want to turn visible, |
| 293 // never invisible. |
291 if (visiblity_state != state && | 294 if (visiblity_state != state && |
292 (current_memory_pressure_ != MEMORY_PRESSURE_LOW || | 295 (current_memory_pressure_ != MEMORY_PRESSURE_LOW || |
293 visiblity_state == Activity::ACTIVITY_VISIBLE)) | 296 visiblity_state == Activity::ACTIVITY_VISIBLE)) { |
294 activity->SetCurrentState(visiblity_state); | 297 activity->SetCurrentState(visiblity_state); |
| 298 } |
295 } | 299 } |
296 | 300 |
297 // See which index we should handle next. | 301 // See which index we should handle next. |
298 if (activity_order_changed_) { | 302 if (activity_order_changed_) { |
299 activity_order_changed_ = false; | 303 activity_order_changed_ = false; |
300 index = 0; | 304 index = 0; |
301 } else { | 305 } else { |
302 ++index; | 306 ++index; |
303 } | 307 } |
304 } | 308 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 403 } |
400 | 404 |
401 ResourceManager::ResourceManager() {} | 405 ResourceManager::ResourceManager() {} |
402 | 406 |
403 ResourceManager::~ResourceManager() { | 407 ResourceManager::~ResourceManager() { |
404 DCHECK(instance); | 408 DCHECK(instance); |
405 instance = NULL; | 409 instance = NULL; |
406 } | 410 } |
407 | 411 |
408 } // namespace athena | 412 } // namespace athena |
OLD | NEW |