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_
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "cc/resources/picture_pile.h"
15 #include "ui/gfx/quad_f.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
26 // Note: these must be 0 and 1 because we index with them in various places,
27 // e.g. in Tile::priority_.
31 // Be sure to update WhichTreeAsValue when adding new fields.
33 scoped_ptr
<base::Value
> WhichTreeAsValue(WhichTree tree
);
38 NON_IDEAL_RESOLUTION
= 2,
40 std::string
TileResolutionToString(TileResolution resolution
);
42 struct CC_EXPORT TilePriority
{
43 enum PriorityBin
{ NOW
, SOON
, EVENTUALLY
};
46 : resolution(NON_IDEAL_RESOLUTION
),
47 required_for_activation(false),
48 priority_bin(EVENTUALLY
),
49 distance_to_visible(std::numeric_limits
<float>::infinity()) {}
51 TilePriority(TileResolution resolution
,
53 float distance_to_visible
)
54 : resolution(resolution
),
55 required_for_activation(false),
57 distance_to_visible(distance_to_visible
) {}
59 TilePriority(const TilePriority
& active
, const TilePriority
& pending
) {
60 if (active
.resolution
== HIGH_RESOLUTION
||
61 pending
.resolution
== HIGH_RESOLUTION
)
62 resolution
= HIGH_RESOLUTION
;
63 else if (active
.resolution
== LOW_RESOLUTION
||
64 pending
.resolution
== LOW_RESOLUTION
)
65 resolution
= LOW_RESOLUTION
;
67 resolution
= NON_IDEAL_RESOLUTION
;
69 required_for_activation
=
70 active
.required_for_activation
|| pending
.required_for_activation
;
72 if (active
.priority_bin
< pending
.priority_bin
) {
73 priority_bin
= active
.priority_bin
;
74 distance_to_visible
= active
.distance_to_visible
;
75 } else if (active
.priority_bin
> pending
.priority_bin
) {
76 priority_bin
= pending
.priority_bin
;
77 distance_to_visible
= pending
.distance_to_visible
;
79 priority_bin
= active
.priority_bin
;
81 std::min(active
.distance_to_visible
, pending
.distance_to_visible
);
85 void AsValueInto(base::debug::TracedValue
* dict
) const;
87 bool operator ==(const TilePriority
& other
) const {
88 return resolution
== other
.resolution
&&
89 priority_bin
== other
.priority_bin
&&
90 distance_to_visible
== other
.distance_to_visible
&&
91 required_for_activation
== other
.required_for_activation
;
94 bool operator !=(const TilePriority
& other
) const {
95 return !(*this == other
);
98 bool IsHigherPriorityThan(const TilePriority
& other
) const {
99 return priority_bin
< other
.priority_bin
||
100 (priority_bin
== other
.priority_bin
&&
101 distance_to_visible
< other
.distance_to_visible
);
104 TileResolution resolution
;
105 bool required_for_activation
;
106 PriorityBin priority_bin
;
107 float distance_to_visible
;
110 std::string
TilePriorityBinToString(TilePriority::PriorityBin bin
);
112 enum TileMemoryLimitPolicy
{
116 // You might be made visible, but you're not being interacted with.
117 ALLOW_ABSOLUTE_MINIMUM
= 1, // Tall.
119 // You're being interacted with, but we're low on memory.
120 ALLOW_PREPAINT_ONLY
= 2, // Grande.
122 // You're the only thing in town. Go crazy.
123 ALLOW_ANYTHING
= 3, // Venti.
125 NUM_TILE_MEMORY_LIMIT_POLICIES
= 4,
127 // NOTE: Be sure to update TreePriorityAsValue and kBinPolicyMap when adding
128 // or reordering fields.
130 std::string
TileMemoryLimitPolicyToString(TileMemoryLimitPolicy policy
);
133 SAME_PRIORITY_FOR_BOTH_TREES
,
134 SMOOTHNESS_TAKES_PRIORITY
,
135 NEW_CONTENT_TAKES_PRIORITY
,
137 // Be sure to update TreePriorityAsValue when adding new fields.
139 std::string
TreePriorityToString(TreePriority prio
);
141 class GlobalStateThatImpactsTilePriority
{
143 GlobalStateThatImpactsTilePriority()
144 : memory_limit_policy(ALLOW_NOTHING
),
145 soft_memory_limit_in_bytes(0),
146 hard_memory_limit_in_bytes(0),
147 num_resources_limit(0),
148 tree_priority(SAME_PRIORITY_FOR_BOTH_TREES
) {}
150 TileMemoryLimitPolicy memory_limit_policy
;
152 size_t soft_memory_limit_in_bytes
;
153 size_t hard_memory_limit_in_bytes
;
154 size_t num_resources_limit
;
156 TreePriority tree_priority
;
158 bool operator==(const GlobalStateThatImpactsTilePriority
& other
) const {
159 return memory_limit_policy
== other
.memory_limit_policy
&&
160 soft_memory_limit_in_bytes
== other
.soft_memory_limit_in_bytes
&&
161 hard_memory_limit_in_bytes
== other
.hard_memory_limit_in_bytes
&&
162 num_resources_limit
== other
.num_resources_limit
&&
163 tree_priority
== other
.tree_priority
;
165 bool operator!=(const GlobalStateThatImpactsTilePriority
& other
) const {
166 return !(*this == other
);
169 void AsValueInto(base::debug::TracedValue
* dict
) const;
174 #endif // CC_RESOURCES_TILE_PRIORITY_H_