[Android] Add a device-side test HTTP server via ChromeInstrumentationTestRunner.
[chromium-blink-merge.git] / cc / resources / tile_priority.h
blobd1610571863a81e39f47057f581cbdfb31f7f078
1 // Copyright 2012 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 #ifndef CC_RESOURCES_TILE_PRIORITY_H_
6 #define CC_RESOURCES_TILE_PRIORITY_H_
8 #include <algorithm>
9 #include <limits>
10 #include <string>
12 #include "base/debug/trace_event_argument.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "cc/base/cc_export.h"
16 namespace base {
17 class Value;
20 namespace cc {
22 enum WhichTree {
23 // Note: these must be 0 and 1 because we index with them in various places,
24 // e.g. in Tile::priority_.
25 ACTIVE_TREE = 0,
26 PENDING_TREE = 1,
27 NUM_TREES = 2
28 // Be sure to update WhichTreeAsValue when adding new fields.
30 scoped_ptr<base::Value> WhichTreeAsValue(WhichTree tree);
32 enum TileResolution {
33 LOW_RESOLUTION = 0 ,
34 HIGH_RESOLUTION = 1,
35 NON_IDEAL_RESOLUTION = 2,
37 std::string TileResolutionToString(TileResolution resolution);
39 struct CC_EXPORT TilePriority {
40 enum PriorityBin { NOW, SOON, EVENTUALLY };
42 TilePriority()
43 : resolution(NON_IDEAL_RESOLUTION),
44 priority_bin(EVENTUALLY),
45 distance_to_visible(std::numeric_limits<float>::infinity()) {}
47 TilePriority(TileResolution resolution,
48 PriorityBin bin,
49 float distance_to_visible)
50 : resolution(resolution),
51 priority_bin(bin),
52 distance_to_visible(distance_to_visible) {}
54 TilePriority(const TilePriority& active, const TilePriority& pending) {
55 if (active.resolution == HIGH_RESOLUTION ||
56 pending.resolution == HIGH_RESOLUTION)
57 resolution = HIGH_RESOLUTION;
58 else if (active.resolution == LOW_RESOLUTION ||
59 pending.resolution == LOW_RESOLUTION)
60 resolution = LOW_RESOLUTION;
61 else
62 resolution = NON_IDEAL_RESOLUTION;
64 if (active.priority_bin < pending.priority_bin) {
65 priority_bin = active.priority_bin;
66 distance_to_visible = active.distance_to_visible;
67 } else if (active.priority_bin > pending.priority_bin) {
68 priority_bin = pending.priority_bin;
69 distance_to_visible = pending.distance_to_visible;
70 } else {
71 priority_bin = active.priority_bin;
72 distance_to_visible =
73 std::min(active.distance_to_visible, pending.distance_to_visible);
77 void AsValueInto(base::debug::TracedValue* dict) const;
79 bool operator ==(const TilePriority& other) const {
80 return resolution == other.resolution &&
81 priority_bin == other.priority_bin &&
82 distance_to_visible == other.distance_to_visible;
85 bool operator !=(const TilePriority& other) const {
86 return !(*this == other);
89 bool IsHigherPriorityThan(const TilePriority& other) const {
90 return priority_bin < other.priority_bin ||
91 (priority_bin == other.priority_bin &&
92 distance_to_visible < other.distance_to_visible);
95 TileResolution resolution;
96 PriorityBin priority_bin;
97 float distance_to_visible;
100 std::string TilePriorityBinToString(TilePriority::PriorityBin bin);
102 enum TileMemoryLimitPolicy {
103 // Nothing. This mode is used when visible is set to false.
104 ALLOW_NOTHING = 0,
106 // You might be made visible, but you're not being interacted with.
107 ALLOW_ABSOLUTE_MINIMUM = 1, // Tall.
109 // You're being interacted with, but we're low on memory.
110 ALLOW_PREPAINT_ONLY = 2, // Grande.
112 // You're the only thing in town. Go crazy.
113 ALLOW_ANYTHING = 3 // Venti.
115 std::string TileMemoryLimitPolicyToString(TileMemoryLimitPolicy policy);
117 enum TreePriority {
118 SAME_PRIORITY_FOR_BOTH_TREES,
119 SMOOTHNESS_TAKES_PRIORITY,
120 NEW_CONTENT_TAKES_PRIORITY,
121 NUM_TREE_PRIORITIES
122 // Be sure to update TreePriorityAsValue when adding new fields.
124 std::string TreePriorityToString(TreePriority prio);
126 class GlobalStateThatImpactsTilePriority {
127 public:
128 GlobalStateThatImpactsTilePriority()
129 : memory_limit_policy(ALLOW_NOTHING),
130 soft_memory_limit_in_bytes(0),
131 hard_memory_limit_in_bytes(0),
132 num_resources_limit(0),
133 tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {}
135 TileMemoryLimitPolicy memory_limit_policy;
137 size_t soft_memory_limit_in_bytes;
138 size_t hard_memory_limit_in_bytes;
139 size_t num_resources_limit;
141 TreePriority tree_priority;
143 bool operator==(const GlobalStateThatImpactsTilePriority& other) const {
144 return memory_limit_policy == other.memory_limit_policy &&
145 soft_memory_limit_in_bytes == other.soft_memory_limit_in_bytes &&
146 hard_memory_limit_in_bytes == other.hard_memory_limit_in_bytes &&
147 num_resources_limit == other.num_resources_limit &&
148 tree_priority == other.tree_priority;
150 bool operator!=(const GlobalStateThatImpactsTilePriority& other) const {
151 return !(*this == other);
154 void AsValueInto(base::debug::TracedValue* dict) const;
157 } // namespace cc
159 #endif // CC_RESOURCES_TILE_PRIORITY_H_