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 using gpu::MemoryAllocation; 15 16 ManagedMemoryPolicy::ManagedMemoryPolicy(size_t bytes_limit_when_visible) 17 : bytes_limit_when_visible(bytes_limit_when_visible), 18 priority_cutoff_when_visible(MemoryAllocation::CUTOFF_ALLOW_EVERYTHING), 19 num_resources_limit(kDefaultNumResourcesLimit) {} 20 21 ManagedMemoryPolicy::ManagedMemoryPolicy( 22 const gpu::MemoryAllocation& allocation) 23 : bytes_limit_when_visible(allocation.bytes_limit_when_visible), 24 priority_cutoff_when_visible(allocation.priority_cutoff_when_visible), 25 num_resources_limit(kDefaultNumResourcesLimit) {} 26 27 ManagedMemoryPolicy::ManagedMemoryPolicy( 28 size_t bytes_limit_when_visible, 29 MemoryAllocation::PriorityCutoff priority_cutoff_when_visible, 30 size_t num_resources_limit) 31 : bytes_limit_when_visible(bytes_limit_when_visible), 32 priority_cutoff_when_visible(priority_cutoff_when_visible), 33 num_resources_limit(num_resources_limit) {} 34 35 bool ManagedMemoryPolicy::operator==(const ManagedMemoryPolicy& other) const { 36 return bytes_limit_when_visible == other.bytes_limit_when_visible && 37 priority_cutoff_when_visible == other.priority_cutoff_when_visible && 38 num_resources_limit == other.num_resources_limit; 39 } 40 41 bool ManagedMemoryPolicy::operator!=(const ManagedMemoryPolicy& other) const { 42 return !(*this == other); 43 } 44 45 // static 46 int ManagedMemoryPolicy::PriorityCutoffToValue( 47 MemoryAllocation::PriorityCutoff priority_cutoff) { 48 switch (priority_cutoff) { 49 case MemoryAllocation::CUTOFF_ALLOW_NOTHING: 50 return PriorityCalculator::AllowNothingCutoff(); 51 case MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY: 52 return PriorityCalculator::AllowVisibleOnlyCutoff(); 53 case MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE: 54 return PriorityCalculator::AllowVisibleAndNearbyCutoff(); 55 case MemoryAllocation::CUTOFF_ALLOW_EVERYTHING: 56 return PriorityCalculator::AllowEverythingCutoff(); 57 } 58 NOTREACHED(); 59 return PriorityCalculator::AllowNothingCutoff(); 60 } 61 62 // static 63 TileMemoryLimitPolicy 64 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( 65 gpu::MemoryAllocation::PriorityCutoff priority_cutoff) { 66 switch (priority_cutoff) { 67 case MemoryAllocation::CUTOFF_ALLOW_NOTHING: 68 return ALLOW_NOTHING; 69 case MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY: 70 return ALLOW_ABSOLUTE_MINIMUM; 71 case MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE: 72 return ALLOW_PREPAINT_ONLY; 73 case MemoryAllocation::CUTOFF_ALLOW_EVERYTHING: 74 return ALLOW_ANYTHING; 75 } 76 NOTREACHED(); 77 return ALLOW_NOTHING; 78 } 79 80 } // namespace cc 81