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.
5 #include "cc/output/managed_memory_policy.h"
7 #include "base/logging.h"
8 #include "cc/resources/priority_calculator.h"
12 const size_t ManagedMemoryPolicy::kDefaultNumResourcesLimit
= 10 * 1000 * 1000;
14 using gpu::MemoryAllocation
;
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
) {}
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
) {}
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
) {}
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
;
41 bool ManagedMemoryPolicy::operator!=(const ManagedMemoryPolicy
& other
) const {
42 return !(*this == other
);
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();
59 return PriorityCalculator::AllowNothingCutoff();
64 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
65 gpu::MemoryAllocation::PriorityCutoff priority_cutoff
) {
66 switch (priority_cutoff
) {
67 case MemoryAllocation::CUTOFF_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
;