OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_TILE_PRIORITY_H_ | 5 #ifndef CC_RESOURCES_TILE_PRIORITY_H_ |
6 #define CC_RESOURCES_TILE_PRIORITY_H_ | 6 #define CC_RESOURCES_TILE_PRIORITY_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 NON_IDEAL_RESOLUTION = 2, | 38 NON_IDEAL_RESOLUTION = 2, |
39 }; | 39 }; |
40 scoped_ptr<base::Value> TileResolutionAsValue( | 40 scoped_ptr<base::Value> TileResolutionAsValue( |
41 TileResolution resolution); | 41 TileResolution resolution); |
42 | 42 |
43 struct CC_EXPORT TilePriority { | 43 struct CC_EXPORT TilePriority { |
44 enum PriorityBin { NOW, SOON, EVENTUALLY }; | 44 enum PriorityBin { NOW, SOON, EVENTUALLY }; |
45 | 45 |
46 TilePriority() | 46 TilePriority() |
47 : resolution(NON_IDEAL_RESOLUTION), | 47 : resolution(NON_IDEAL_RESOLUTION), |
48 required_for_activation(false), | |
49 priority_bin(EVENTUALLY), | 48 priority_bin(EVENTUALLY), |
50 distance_to_visible(std::numeric_limits<float>::infinity()) {} | 49 distance_to_visible(std::numeric_limits<float>::infinity()) {} |
51 | 50 |
52 TilePriority(TileResolution resolution, | 51 TilePriority(TileResolution resolution, |
53 PriorityBin bin, | 52 PriorityBin bin, |
54 float distance_to_visible) | 53 float distance_to_visible) |
55 : resolution(resolution), | 54 : resolution(resolution), |
56 required_for_activation(false), | |
57 priority_bin(bin), | 55 priority_bin(bin), |
58 distance_to_visible(distance_to_visible) {} | 56 distance_to_visible(distance_to_visible) {} |
59 | 57 |
60 TilePriority(const TilePriority& active, const TilePriority& pending) { | 58 TilePriority(const TilePriority& active, const TilePriority& pending) { |
61 if (active.resolution == HIGH_RESOLUTION || | 59 if (active.resolution == HIGH_RESOLUTION || |
62 pending.resolution == HIGH_RESOLUTION) | 60 pending.resolution == HIGH_RESOLUTION) |
63 resolution = HIGH_RESOLUTION; | 61 resolution = HIGH_RESOLUTION; |
64 else if (active.resolution == LOW_RESOLUTION || | 62 else if (active.resolution == LOW_RESOLUTION || |
65 pending.resolution == LOW_RESOLUTION) | 63 pending.resolution == LOW_RESOLUTION) |
66 resolution = LOW_RESOLUTION; | 64 resolution = LOW_RESOLUTION; |
67 else | 65 else |
68 resolution = NON_IDEAL_RESOLUTION; | 66 resolution = NON_IDEAL_RESOLUTION; |
69 | 67 |
70 required_for_activation = | |
71 active.required_for_activation || pending.required_for_activation; | |
72 | |
73 if (active.priority_bin < pending.priority_bin) { | 68 if (active.priority_bin < pending.priority_bin) { |
74 priority_bin = active.priority_bin; | 69 priority_bin = active.priority_bin; |
75 distance_to_visible = active.distance_to_visible; | 70 distance_to_visible = active.distance_to_visible; |
76 } else if (active.priority_bin > pending.priority_bin) { | 71 } else if (active.priority_bin > pending.priority_bin) { |
77 priority_bin = pending.priority_bin; | 72 priority_bin = pending.priority_bin; |
78 distance_to_visible = pending.distance_to_visible; | 73 distance_to_visible = pending.distance_to_visible; |
79 } else { | 74 } else { |
80 priority_bin = active.priority_bin; | 75 priority_bin = active.priority_bin; |
81 distance_to_visible = | 76 distance_to_visible = |
82 std::min(active.distance_to_visible, pending.distance_to_visible); | 77 std::min(active.distance_to_visible, pending.distance_to_visible); |
83 } | 78 } |
84 } | 79 } |
85 | 80 |
86 scoped_ptr<base::Value> AsValue() const; | 81 scoped_ptr<base::Value> AsValue() const; |
87 | 82 |
88 bool operator ==(const TilePriority& other) const { | 83 bool operator ==(const TilePriority& other) const { |
89 return resolution == other.resolution && | 84 return resolution == other.resolution && |
90 priority_bin == other.priority_bin && | 85 priority_bin == other.priority_bin && |
91 distance_to_visible == other.distance_to_visible && | 86 distance_to_visible == other.distance_to_visible; |
92 required_for_activation == other.required_for_activation; | |
93 } | 87 } |
94 | 88 |
95 bool operator !=(const TilePriority& other) const { | 89 bool operator !=(const TilePriority& other) const { |
96 return !(*this == other); | 90 return !(*this == other); |
97 } | 91 } |
98 | 92 |
99 bool IsHigherPriorityThan(const TilePriority& other) const { | 93 bool IsHigherPriorityThan(const TilePriority& other) const { |
100 return priority_bin < other.priority_bin || | 94 return priority_bin < other.priority_bin || |
101 (priority_bin == other.priority_bin && | 95 (priority_bin == other.priority_bin && |
102 distance_to_visible < other.distance_to_visible); | 96 distance_to_visible < other.distance_to_visible); |
103 } | 97 } |
104 | 98 |
105 TileResolution resolution; | 99 TileResolution resolution; |
106 bool required_for_activation; | |
107 PriorityBin priority_bin; | 100 PriorityBin priority_bin; |
108 float distance_to_visible; | 101 float distance_to_visible; |
109 }; | 102 }; |
110 | 103 |
111 scoped_ptr<base::Value> TilePriorityBinAsValue(TilePriority::PriorityBin bin); | 104 scoped_ptr<base::Value> TilePriorityBinAsValue(TilePriority::PriorityBin bin); |
112 | 105 |
113 enum TileMemoryLimitPolicy { | 106 enum TileMemoryLimitPolicy { |
114 // Nothing. | 107 // Nothing. |
115 ALLOW_NOTHING = 0, | 108 ALLOW_NOTHING = 0, |
116 | 109 |
117 // You might be made visible, but you're not being interacted with. | 110 // You might be made visible, but you're not being interacted with. |
118 ALLOW_ABSOLUTE_MINIMUM = 1, // Tall. | 111 ALLOW_ABSOLUTE_MINIMUM = 1, // Tall. |
119 | 112 |
120 // You're being interacted with, but we're low on memory. | 113 // You're being interacted with, but we're low on memory. |
121 ALLOW_PREPAINT_ONLY = 2, // Grande. | 114 ALLOW_PREPAINT_ONLY = 2, // Grande. |
122 | 115 |
123 // You're the only thing in town. Go crazy. | 116 // You're the only thing in town. Go crazy. |
124 ALLOW_ANYTHING = 3, // Venti. | 117 ALLOW_ANYTHING = 3, // Venti. |
125 | |
126 NUM_TILE_MEMORY_LIMIT_POLICIES = 4, | |
127 | |
128 // NOTE: Be sure to update TreePriorityAsValue and kBinPolicyMap when adding | |
129 // or reordering fields. | |
130 }; | 118 }; |
131 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue( | 119 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue( |
132 TileMemoryLimitPolicy policy); | 120 TileMemoryLimitPolicy policy); |
133 | 121 |
134 enum TreePriority { | 122 enum TreePriority { |
135 SAME_PRIORITY_FOR_BOTH_TREES, | 123 SAME_PRIORITY_FOR_BOTH_TREES, |
136 SMOOTHNESS_TAKES_PRIORITY, | 124 SMOOTHNESS_TAKES_PRIORITY, |
137 NEW_CONTENT_TAKES_PRIORITY | 125 NEW_CONTENT_TAKES_PRIORITY |
138 | |
139 // Be sure to update TreePriorityAsValue when adding new fields. | |
140 }; | 126 }; |
141 scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio); | 127 scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio); |
142 | 128 |
143 class GlobalStateThatImpactsTilePriority { | 129 class GlobalStateThatImpactsTilePriority { |
144 public: | 130 public: |
145 GlobalStateThatImpactsTilePriority() | 131 GlobalStateThatImpactsTilePriority() |
146 : memory_limit_policy(ALLOW_NOTHING), | 132 : memory_limit_policy(ALLOW_NOTHING), |
147 soft_memory_limit_in_bytes(0), | 133 soft_memory_limit_in_bytes(0), |
148 hard_memory_limit_in_bytes(0), | 134 hard_memory_limit_in_bytes(0), |
149 num_resources_limit(0), | 135 num_resources_limit(0), |
150 tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {} | 136 tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {} |
151 | 137 |
152 TileMemoryLimitPolicy memory_limit_policy; | 138 TileMemoryLimitPolicy memory_limit_policy; |
153 | 139 |
154 size_t soft_memory_limit_in_bytes; | 140 size_t soft_memory_limit_in_bytes; |
155 size_t hard_memory_limit_in_bytes; | 141 size_t hard_memory_limit_in_bytes; |
156 size_t num_resources_limit; | 142 size_t num_resources_limit; |
157 | 143 |
158 TreePriority tree_priority; | 144 TreePriority tree_priority; |
159 | 145 |
160 bool operator==(const GlobalStateThatImpactsTilePriority& other) const { | |
161 return memory_limit_policy == other.memory_limit_policy && | |
162 soft_memory_limit_in_bytes == other.soft_memory_limit_in_bytes && | |
163 hard_memory_limit_in_bytes == other.hard_memory_limit_in_bytes && | |
164 num_resources_limit == other.num_resources_limit && | |
165 tree_priority == other.tree_priority; | |
166 } | |
167 bool operator!=(const GlobalStateThatImpactsTilePriority& other) const { | |
168 return !(*this == other); | |
169 } | |
170 | |
171 scoped_ptr<base::Value> AsValue() const; | 146 scoped_ptr<base::Value> AsValue() const; |
172 }; | 147 }; |
173 | 148 |
174 } // namespace cc | 149 } // namespace cc |
175 | 150 |
176 #endif // CC_RESOURCES_TILE_PRIORITY_H_ | 151 #endif // CC_RESOURCES_TILE_PRIORITY_H_ |
OLD | NEW |