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/scoped_ptr.h"
13 #include "base/trace_event/trace_event_argument.h"
14 #include "cc/base/cc_export.h"
23 // Note: these must be 0 and 1 because we index with them in various places,
24 // e.g. in Tile::priority_.
28 // Be sure to update WhichTreeAsValue when adding new fields.
30 scoped_ptr
<base::Value
> WhichTreeAsValue(WhichTree tree
);
35 NON_IDEAL_RESOLUTION
= 2,
37 std::string
TileResolutionToString(TileResolution resolution
);
39 struct CC_EXPORT TilePriority
{
40 enum PriorityBin
{ NOW
, SOON
, EVENTUALLY
};
43 : resolution(NON_IDEAL_RESOLUTION
),
44 priority_bin(EVENTUALLY
),
45 distance_to_visible(std::numeric_limits
<float>::infinity()) {}
47 TilePriority(TileResolution resolution
,
49 float distance_to_visible
)
50 : resolution(resolution
),
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
;
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
;
71 priority_bin
= active
.priority_bin
;
73 std::min(active
.distance_to_visible
, pending
.distance_to_visible
);
77 void AsValueInto(base::trace_event::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.
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
);
118 SAME_PRIORITY_FOR_BOTH_TREES
,
119 SMOOTHNESS_TAKES_PRIORITY
,
120 NEW_CONTENT_TAKES_PRIORITY
,
121 LAST_TREE_PRIORITY
= NEW_CONTENT_TAKES_PRIORITY
122 // Be sure to update TreePriorityAsValue when adding new fields.
124 std::string
TreePriorityToString(TreePriority prio
);
126 class GlobalStateThatImpactsTilePriority
{
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::trace_event::TracedValue
* dict
) const;
159 #endif // CC_RESOURCES_TILE_PRIORITY_H_