1 // Copyright 2012 The Chromium Authors
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_TILES_TILE_PRIORITY_H_
6 #define CC_TILES_TILE_PRIORITY_H_
15 #include "base/trace_event/traced_value.h"
16 #include "cc/cc_export.h"
17 #include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_compositor_scheduler_state.pbzero.h"
22 // Note: these must be 0 and 1 because we index with them in various places,
23 // e.g. in Tile::priority_.
32 NON_IDEAL_RESOLUTION = 2,
34 std::string TileResolutionToString(TileResolution resolution);
36 struct CC_EXPORT TilePriority {
37 enum PriorityBin { NOW, SOON, EVENTUALLY };
40 : resolution(NON_IDEAL_RESOLUTION),
41 priority_bin(EVENTUALLY),
42 distance_to_visible(std::numeric_limits<float>::infinity()) {}
44 TilePriority(TileResolution resolution,
46 float distance_to_visible)
47 : resolution(resolution),
49 distance_to_visible(distance_to_visible) {}
51 void AsValueInto(base::trace_event::TracedValue* dict) const;
53 bool IsHigherPriorityThan(const TilePriority& other) const {
54 return priority_bin < other.priority_bin ||
55 (priority_bin == other.priority_bin &&
56 distance_to_visible < other.distance_to_visible);
59 TileResolution resolution;
60 PriorityBin priority_bin;
61 float distance_to_visible;
64 std::string TilePriorityBinToString(TilePriority::PriorityBin bin);
66 // It is expected the values are ordered from most restrictive to least
67 // restrictive. See IsTileMemoryLimitPolicyMoreRestictive().
68 enum TileMemoryLimitPolicy {
69 // Nothing. This mode is used when visible is set to false.
70 ALLOW_NOTHING = 0, // Decaf.
72 // You might be made visible, but you're not being interacted with.
73 ALLOW_ABSOLUTE_MINIMUM = 1, // Tall.
75 // You're being interacted with, but we're low on memory.
76 ALLOW_PREPAINT_ONLY = 2, // Grande.
78 // You're the only thing in town. Go crazy.
79 ALLOW_ANYTHING = 3 // Venti.
81 std::string TileMemoryLimitPolicyToString(TileMemoryLimitPolicy policy);
83 // Returns true if `policy1` is more restrictive than `policy2`.
84 bool IsTileMemoryLimitPolicyMoreRestictive(TileMemoryLimitPolicy policy1,
85 TileMemoryLimitPolicy policy2);
88 SAME_PRIORITY_FOR_BOTH_TREES,
89 SMOOTHNESS_TAKES_PRIORITY,
90 NEW_CONTENT_TAKES_PRIORITY,
91 LAST_TREE_PRIORITY = NEW_CONTENT_TAKES_PRIORITY
92 // Be sure to update TreePriorityAsValue when adding new fields.
94 // TODO(nuskos): remove TreePriorityToString once we have a utility function to
95 // take protozero to strings.
96 std::string TreePriorityToString(TreePriority prio);
97 perfetto::protos::pbzero::ChromeCompositorStateMachine::MinorState::TreePriority
98 TreePriorityToProtozeroEnum(TreePriority priority);
100 class GlobalStateThatImpactsTilePriority {
102 GlobalStateThatImpactsTilePriority()
103 : memory_limit_policy(ALLOW_NOTHING),
104 soft_memory_limit_in_bytes(0),
105 hard_memory_limit_in_bytes(0),
106 num_resources_limit(0),
107 tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {}
109 TileMemoryLimitPolicy memory_limit_policy;
111 size_t soft_memory_limit_in_bytes;
112 size_t hard_memory_limit_in_bytes;
113 size_t num_resources_limit;
115 TreePriority tree_priority;
117 bool operator==(const GlobalStateThatImpactsTilePriority& other) const {
118 return memory_limit_policy == other.memory_limit_policy &&
119 soft_memory_limit_in_bytes == other.soft_memory_limit_in_bytes &&
120 hard_memory_limit_in_bytes == other.hard_memory_limit_in_bytes &&
121 num_resources_limit == other.num_resources_limit &&
122 tree_priority == other.tree_priority;
124 bool operator!=(const GlobalStateThatImpactsTilePriority& other) const {
125 return !(*this == other);
128 void AsValueInto(base::trace_event::TracedValue* dict) const;
133 #endif // CC_TILES_TILE_PRIORITY_H_