Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / cc / resources / tile_priority.h
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.
4
5 #ifndef CC_RESOURCES_TILE_PRIORITY_H_
6 #define CC_RESOURCES_TILE_PRIORITY_H_
7
8 #include <algorithm>
9 #include <limits>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "cc/resources/picture_pile.h"
14 #include "ui/gfx/quad_f.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/size.h"
17
18 namespace base {
19 class Value;
20 }
21
22 namespace cc {
23
24 enum WhichTree {
25   // Note: these must be 0 and 1 because we index with them in various places,
26   // e.g. in Tile::priority_.
27   ACTIVE_TREE = 0,
28   PENDING_TREE = 1,
29   NUM_TREES = 2
30   // Be sure to update WhichTreeAsValue when adding new fields.
31 };
32 scoped_ptr<base::Value> WhichTreeAsValue(
33     WhichTree tree);
34
35 enum TileResolution {
36   LOW_RESOLUTION = 0 ,
37   HIGH_RESOLUTION = 1,
38   NON_IDEAL_RESOLUTION = 2,
39 };
40 scoped_ptr<base::Value> TileResolutionAsValue(
41     TileResolution resolution);
42
43 struct CC_EXPORT TilePriority {
44   enum PriorityBin { NOW, SOON, EVENTUALLY };
45
46   TilePriority()
47       : resolution(NON_IDEAL_RESOLUTION),
48         required_for_activation(false),
49         priority_bin(EVENTUALLY),
50         distance_to_visible(std::numeric_limits<float>::infinity()) {}
51
52   TilePriority(TileResolution resolution,
53                PriorityBin bin,
54                float distance_to_visible)
55       : resolution(resolution),
56         required_for_activation(false),
57         priority_bin(bin),
58         distance_to_visible(distance_to_visible) {}
59
60   TilePriority(const TilePriority& active, const TilePriority& pending) {
61     if (active.resolution == HIGH_RESOLUTION ||
62         pending.resolution == HIGH_RESOLUTION)
63       resolution = HIGH_RESOLUTION;
64     else if (active.resolution == LOW_RESOLUTION ||
65              pending.resolution == LOW_RESOLUTION)
66       resolution = LOW_RESOLUTION;
67     else
68       resolution = NON_IDEAL_RESOLUTION;
69
70     required_for_activation =
71         active.required_for_activation || pending.required_for_activation;
72
73     if (active.priority_bin < pending.priority_bin) {
74       priority_bin = active.priority_bin;
75       distance_to_visible = active.distance_to_visible;
76     } else if (active.priority_bin > pending.priority_bin) {
77       priority_bin = pending.priority_bin;
78       distance_to_visible = pending.distance_to_visible;
79     } else {
80       priority_bin = active.priority_bin;
81       distance_to_visible =
82           std::min(active.distance_to_visible, pending.distance_to_visible);
83     }
84   }
85
86   scoped_ptr<base::Value> AsValue() const;
87
88   bool operator ==(const TilePriority& other) const {
89     return resolution == other.resolution &&
90            priority_bin == other.priority_bin &&
91            distance_to_visible == other.distance_to_visible &&
92            required_for_activation == other.required_for_activation;
93   }
94
95   bool operator !=(const TilePriority& other) const {
96     return !(*this == other);
97   }
98
99   TileResolution resolution;
100   bool required_for_activation;
101   PriorityBin priority_bin;
102   float distance_to_visible;
103 };
104
105 scoped_ptr<base::Value> TilePriorityBinAsValue(TilePriority::PriorityBin bin);
106
107 enum TileMemoryLimitPolicy {
108   // Nothing.
109   ALLOW_NOTHING = 0,
110
111   // You might be made visible, but you're not being interacted with.
112   ALLOW_ABSOLUTE_MINIMUM = 1,  // Tall.
113
114   // You're being interacted with, but we're low on memory.
115   ALLOW_PREPAINT_ONLY = 2,  // Grande.
116
117   // You're the only thing in town. Go crazy.
118   ALLOW_ANYTHING = 3,  // Venti.
119
120   NUM_TILE_MEMORY_LIMIT_POLICIES = 4,
121
122   // NOTE: Be sure to update TreePriorityAsValue and kBinPolicyMap when adding
123   // or reordering fields.
124 };
125 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue(
126     TileMemoryLimitPolicy policy);
127
128 enum TreePriority {
129   SAME_PRIORITY_FOR_BOTH_TREES,
130   SMOOTHNESS_TAKES_PRIORITY,
131   NEW_CONTENT_TAKES_PRIORITY
132
133   // Be sure to update TreePriorityAsValue when adding new fields.
134 };
135 scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio);
136
137 class GlobalStateThatImpactsTilePriority {
138  public:
139   GlobalStateThatImpactsTilePriority()
140       : memory_limit_policy(ALLOW_NOTHING),
141         soft_memory_limit_in_bytes(0),
142         hard_memory_limit_in_bytes(0),
143         unused_memory_limit_in_bytes(0),
144         num_resources_limit(0),
145         tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {}
146
147   TileMemoryLimitPolicy memory_limit_policy;
148
149   size_t soft_memory_limit_in_bytes;
150   size_t hard_memory_limit_in_bytes;
151   size_t unused_memory_limit_in_bytes;
152   size_t num_resources_limit;
153
154   TreePriority tree_priority;
155
156   bool operator==(const GlobalStateThatImpactsTilePriority& other) const {
157     return memory_limit_policy == other.memory_limit_policy &&
158            soft_memory_limit_in_bytes == other.soft_memory_limit_in_bytes &&
159            hard_memory_limit_in_bytes == other.hard_memory_limit_in_bytes &&
160            unused_memory_limit_in_bytes == other.unused_memory_limit_in_bytes &&
161            num_resources_limit == other.num_resources_limit &&
162            tree_priority == other.tree_priority;
163   }
164   bool operator!=(const GlobalStateThatImpactsTilePriority& other) const {
165     return !(*this == other);
166   }
167
168   scoped_ptr<base::Value> AsValue() const;
169 };
170
171 }  // namespace cc
172
173 #endif  // CC_RESOURCES_TILE_PRIORITY_H_