[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / tiles / tile_priority.h
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.
4
5 #ifndef CC_TILES_TILE_PRIORITY_H_
6 #define CC_TILES_TILE_PRIORITY_H_
7
8 #include <stddef.h>
9
10 #include <algorithm>
11 #include <limits>
12 #include <memory>
13 #include <string>
14
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"
18
19 namespace cc {
20
21 enum WhichTree {
22   // Note: these must be 0 and 1 because we index with them in various places,
23   // e.g. in Tile::priority_.
24   ACTIVE_TREE = 0,
25   PENDING_TREE = 1,
26   LAST_TREE = 1
27 };
28
29 enum TileResolution {
30   LOW_RESOLUTION = 0 ,
31   HIGH_RESOLUTION = 1,
32   NON_IDEAL_RESOLUTION = 2,
33 };
34 std::string TileResolutionToString(TileResolution resolution);
35
36 struct CC_EXPORT TilePriority {
37   enum PriorityBin { NOW, SOON, EVENTUALLY };
38
39   TilePriority()
40       : resolution(NON_IDEAL_RESOLUTION),
41         priority_bin(EVENTUALLY),
42         distance_to_visible(std::numeric_limits<float>::infinity()) {}
43
44   TilePriority(TileResolution resolution,
45                PriorityBin bin,
46                float distance_to_visible)
47       : resolution(resolution),
48         priority_bin(bin),
49         distance_to_visible(distance_to_visible) {}
50
51   void AsValueInto(base::trace_event::TracedValue* dict) const;
52
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);
57   }
58
59   TileResolution resolution;
60   PriorityBin priority_bin;
61   float distance_to_visible;
62 };
63
64 std::string TilePriorityBinToString(TilePriority::PriorityBin bin);
65
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.
71
72   // You might be made visible, but you're not being interacted with.
73   ALLOW_ABSOLUTE_MINIMUM = 1,  // Tall.
74
75   // You're being interacted with, but we're low on memory.
76   ALLOW_PREPAINT_ONLY = 2,  // Grande.
77
78   // You're the only thing in town. Go crazy.
79   ALLOW_ANYTHING = 3  // Venti.
80 };
81 std::string TileMemoryLimitPolicyToString(TileMemoryLimitPolicy policy);
82
83 // Returns true if `policy1` is more restrictive than `policy2`.
84 bool IsTileMemoryLimitPolicyMoreRestictive(TileMemoryLimitPolicy policy1,
85                                            TileMemoryLimitPolicy policy2);
86
87 enum TreePriority {
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.
93 };
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);
99
100 class GlobalStateThatImpactsTilePriority {
101  public:
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) {}
108
109   TileMemoryLimitPolicy memory_limit_policy;
110
111   size_t soft_memory_limit_in_bytes;
112   size_t hard_memory_limit_in_bytes;
113   size_t num_resources_limit;
114
115   TreePriority tree_priority;
116
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;
123   }
124   bool operator!=(const GlobalStateThatImpactsTilePriority& other) const {
125     return !(*this == other);
126   }
127
128   void AsValueInto(base::trace_event::TracedValue* dict) const;
129 };
130
131 }  // namespace cc
132
133 #endif  // CC_TILES_TILE_PRIORITY_H_