summaryrefslogtreecommitdiffstats
path: root/cc/resources/managed_memory_policy.cc
blob: 3571d7a2c85f673285441c17912e3fc9fe90551a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/resources/managed_memory_policy.h"

#include "base/logging.h"
#include "cc/resources/priority_calculator.h"

namespace cc {

ManagedMemoryPolicy::ManagedMemoryPolicy(size_t bytes_limit_when_visible)
    : bytes_limit_when_visible(bytes_limit_when_visible),
      priority_cutoff_when_visible(CUTOFF_ALLOW_EVERYTHING),
      bytes_limit_when_not_visible(0),
      priority_cutoff_when_not_visible(CUTOFF_ALLOW_NOTHING) {}

ManagedMemoryPolicy::ManagedMemoryPolicy(
    size_t bytes_limit_when_visible,
    PriorityCutoff priority_cutoff_when_visible,
    size_t bytes_limit_when_not_visible,
    PriorityCutoff priority_cutoff_when_not_visible)
    : bytes_limit_when_visible(bytes_limit_when_visible),
      priority_cutoff_when_visible(priority_cutoff_when_visible),
      bytes_limit_when_not_visible(bytes_limit_when_not_visible),
      priority_cutoff_when_not_visible(priority_cutoff_when_not_visible) {}

bool ManagedMemoryPolicy::operator==(const ManagedMemoryPolicy& other) const {
  return bytes_limit_when_visible == other.bytes_limit_when_visible &&
         priority_cutoff_when_visible == other.priority_cutoff_when_visible &&
         bytes_limit_when_not_visible == other.bytes_limit_when_not_visible &&
         priority_cutoff_when_not_visible ==
         other.priority_cutoff_when_not_visible;
}

bool ManagedMemoryPolicy::operator!=(const ManagedMemoryPolicy& other) const {
  return !(*this == other);
}

// static
int ManagedMemoryPolicy::PriorityCutoffToValue(PriorityCutoff priority_cutoff) {
  switch (priority_cutoff) {
    case CUTOFF_ALLOW_NOTHING:
      return PriorityCalculator::AllowNothingCutoff();
    case CUTOFF_ALLOW_REQUIRED_ONLY:
      return PriorityCalculator::AllowVisibleOnlyCutoff();
    case CUTOFF_ALLOW_NICE_TO_HAVE:
      return PriorityCalculator::AllowVisibleAndNearbyCutoff();
    case CUTOFF_ALLOW_EVERYTHING:
      return PriorityCalculator::AllowEverythingCutoff();
  }
  NOTREACHED();
  return PriorityCalculator::AllowNothingCutoff();
}

// static
TileMemoryLimitPolicy
ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
    PriorityCutoff priority_cutoff) {
  switch (priority_cutoff) {
    case CUTOFF_ALLOW_NOTHING:
      return ALLOW_NOTHING;
    case CUTOFF_ALLOW_REQUIRED_ONLY:
      return ALLOW_ABSOLUTE_MINIMUM;
    case CUTOFF_ALLOW_NICE_TO_HAVE:
      return ALLOW_PREPAINT_ONLY;
    case CUTOFF_ALLOW_EVERYTHING:
      return ALLOW_ANYTHING;
  }
  NOTREACHED();
  return ALLOW_NOTHING;
}

}  // namespace cc