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"
11 const size_t ManagedMemoryPolicy::kDefaultNumResourcesLimit
= 10 * 1000 * 1000;
13 using gpu::MemoryAllocation
;
15 ManagedMemoryPolicy::ManagedMemoryPolicy(size_t bytes_limit_when_visible
)
16 : bytes_limit_when_visible(bytes_limit_when_visible
),
17 priority_cutoff_when_visible(MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
),
18 num_resources_limit(kDefaultNumResourcesLimit
) {}
20 ManagedMemoryPolicy::ManagedMemoryPolicy(
21 const gpu::MemoryAllocation
& allocation
)
22 : bytes_limit_when_visible(allocation
.bytes_limit_when_visible
),
23 priority_cutoff_when_visible(allocation
.priority_cutoff_when_visible
),
24 num_resources_limit(kDefaultNumResourcesLimit
) {}
26 ManagedMemoryPolicy::ManagedMemoryPolicy(
27 size_t bytes_limit_when_visible
,
28 MemoryAllocation::PriorityCutoff priority_cutoff_when_visible
,
29 size_t num_resources_limit
)
30 : bytes_limit_when_visible(bytes_limit_when_visible
),
31 priority_cutoff_when_visible(priority_cutoff_when_visible
),
32 num_resources_limit(num_resources_limit
) {}
34 bool ManagedMemoryPolicy::operator==(const ManagedMemoryPolicy
& other
) const {
35 return bytes_limit_when_visible
== other
.bytes_limit_when_visible
&&
36 priority_cutoff_when_visible
== other
.priority_cutoff_when_visible
&&
37 num_resources_limit
== other
.num_resources_limit
;
40 bool ManagedMemoryPolicy::operator!=(const ManagedMemoryPolicy
& other
) const {
41 return !(*this == other
);
46 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
47 gpu::MemoryAllocation::PriorityCutoff priority_cutoff
) {
48 switch (priority_cutoff
) {
49 case MemoryAllocation::CUTOFF_ALLOW_NOTHING
:
51 case MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY
:
52 return ALLOW_ABSOLUTE_MINIMUM
;
53 case MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE
:
54 return ALLOW_PREPAINT_ONLY
;
55 case MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
:
56 return ALLOW_ANYTHING
;