1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "cc/output/managed_memory_policy.h" 6 7 #include "base/logging.h" 8 #include "cc/resources/priority_calculator.h" 9 10 namespace cc { 11 12 const size_t ManagedMemoryPolicy::kDefaultNumResourcesLimit = 10 * 1000 * 1000; 13 14 ManagedMemoryPolicy::ManagedMemoryPolicy(size_t bytes_limit_when_visible) 15 : bytes_limit_when_visible(bytes_limit_when_visible), 16 priority_cutoff_when_visible(CUTOFF_ALLOW_EVERYTHING), 17 bytes_limit_when_not_visible(0), 18 priority_cutoff_when_not_visible(CUTOFF_ALLOW_NOTHING), 19 num_resources_limit(kDefaultNumResourcesLimit) {} 20 21 ManagedMemoryPolicy::ManagedMemoryPolicy( 22 size_t bytes_limit_when_visible, 23 PriorityCutoff priority_cutoff_when_visible, 24 size_t bytes_limit_when_not_visible, 25 PriorityCutoff priority_cutoff_when_not_visible, 26 size_t num_resources_limit) 27 : bytes_limit_when_visible(bytes_limit_when_visible), 28 priority_cutoff_when_visible(priority_cutoff_when_visible), 29 bytes_limit_when_not_visible(bytes_limit_when_not_visible), 30 priority_cutoff_when_not_visible(priority_cutoff_when_not_visible), 31 num_resources_limit(num_resources_limit) {} 32 33 bool ManagedMemoryPolicy::operator==(const ManagedMemoryPolicy& other) const { 34 return bytes_limit_when_visible == other.bytes_limit_when_visible && 35 priority_cutoff_when_visible == other.priority_cutoff_when_visible && 36 bytes_limit_when_not_visible == other.bytes_limit_when_not_visible && 37 priority_cutoff_when_not_visible == 38 other.priority_cutoff_when_not_visible && 39 num_resources_limit == other.num_resources_limit; 40 } 41 42 bool ManagedMemoryPolicy::operator!=(const ManagedMemoryPolicy& other) const { 43 return !(*this == other); 44 } 45 46 // static 47 int ManagedMemoryPolicy::PriorityCutoffToValue(PriorityCutoff priority_cutoff) { 48 switch (priority_cutoff) { 49 case CUTOFF_ALLOW_NOTHING: 50 return PriorityCalculator::AllowNothingCutoff(); 51 case CUTOFF_ALLOW_REQUIRED_ONLY: 52 return PriorityCalculator::AllowVisibleOnlyCutoff(); 53 case CUTOFF_ALLOW_NICE_TO_HAVE: 54 return PriorityCalculator::AllowVisibleAndNearbyCutoff(); 55 case CUTOFF_ALLOW_EVERYTHING: 56 return PriorityCalculator::AllowEverythingCutoff(); 57 } 58 NOTREACHED(); 59 return PriorityCalculator::AllowNothingCutoff(); 60 } 61 62 // static 63 TileMemoryLimitPolicy 64 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( 65 PriorityCutoff priority_cutoff) { 66 switch (priority_cutoff) { 67 case CUTOFF_ALLOW_NOTHING: 68 return ALLOW_NOTHING; 69 case CUTOFF_ALLOW_REQUIRED_ONLY: 70 return ALLOW_ABSOLUTE_MINIMUM; 71 case CUTOFF_ALLOW_NICE_TO_HAVE: 72 return ALLOW_PREPAINT_ONLY; 73 case CUTOFF_ALLOW_EVERYTHING: 74 return ALLOW_ANYTHING; 75 } 76 NOTREACHED(); 77 return ALLOW_NOTHING; 78 } 79 80 } // namespace cc 81