Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: cc/tile_priority.h

Issue 12471007: Part 8 of cc/ directory shuffles: resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tile_manager.cc ('k') | cc/tile_priority.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_TILE_PRIORITY_H_
6 #define CC_TILE_PRIORITY_H_
7
8 #include <limits>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/picture_pile.h"
13 #include "ui/gfx/quad_f.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/size.h"
16
17 namespace base {
18 class Value;
19 }
20
21 namespace cc {
22
23 enum WhichTree {
24 // Note: these must be 0 and 1 because we index with them in various places,
25 // e.g. in Tile::priority_.
26 ACTIVE_TREE = 0,
27 PENDING_TREE = 1,
28 NUM_TREES = 2
29 // Be sure to update WhichTreeAsValue when adding new fields.
30 };
31 scoped_ptr<base::Value> WhichTreeAsValue(
32 WhichTree tree);
33
34 enum TileResolution {
35 LOW_RESOLUTION = 0 ,
36 HIGH_RESOLUTION = 1,
37 NON_IDEAL_RESOLUTION = 2,
38 };
39 scoped_ptr<base::Value> TileResolutionAsValue(
40 TileResolution resolution);
41
42 struct CC_EXPORT TilePriority {
43 TilePriority()
44 : is_live(false),
45 resolution(NON_IDEAL_RESOLUTION),
46 time_to_visible_in_seconds(std::numeric_limits<float>::infinity()),
47 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) {}
48
49 TilePriority(
50 TileResolution resolution,
51 float time_to_visible_in_seconds,
52 float distance_to_visible_in_pixels)
53 : is_live(true),
54 resolution(resolution),
55 time_to_visible_in_seconds(time_to_visible_in_seconds),
56 distance_to_visible_in_pixels(distance_to_visible_in_pixels) {}
57
58 TilePriority(const TilePriority& active, const TilePriority& pending) {
59 if (!pending.is_live) {
60 if (!active.is_live) {
61 is_live = false;
62 return;
63 }
64 is_live = true;
65 resolution = active.resolution;
66 time_to_visible_in_seconds = active.time_to_visible_in_seconds;
67 distance_to_visible_in_pixels = active.distance_to_visible_in_pixels;
68 return;
69 } else if (!active.is_live) {
70 is_live = true;
71 resolution = pending.resolution;
72 time_to_visible_in_seconds = pending.time_to_visible_in_seconds;
73 distance_to_visible_in_pixels = pending.distance_to_visible_in_pixels;
74 return;
75 }
76
77 is_live = true;
78 if (active.resolution == HIGH_RESOLUTION ||
79 pending.resolution == HIGH_RESOLUTION)
80 resolution = HIGH_RESOLUTION;
81 else if (active.resolution == LOW_RESOLUTION ||
82 pending.resolution == LOW_RESOLUTION)
83 resolution = LOW_RESOLUTION;
84 else
85 resolution = NON_IDEAL_RESOLUTION;
86
87 time_to_visible_in_seconds =
88 std::min(active.time_to_visible_in_seconds,
89 pending.time_to_visible_in_seconds);
90 distance_to_visible_in_pixels =
91 std::min(active.distance_to_visible_in_pixels,
92 pending.distance_to_visible_in_pixels);
93 }
94 void set_current_screen_quad(const gfx::QuadF& q) { current_screen_quad = q; }
95
96 scoped_ptr<base::Value> AsValue() const;
97
98 static const float kMaxDistanceInContentSpace;
99 static const int64 kNumTilesToCoverWithInflatedViewportRectForPrioritization;
100
101 static inline float manhattanDistance(const gfx::RectF& a, const gfx::RectF& b ) {
102 // Compute the union explicitly.
103 gfx::RectF c = gfx::RectF(
104 std::min(a.x(), b.x()),
105 std::min(a.y(), b.y()),
106 std::max(a.right(), b.right()) - std::min(a.x(), b.x()),
107 std::max(a.bottom(), b.bottom()) - std::min(a.y(), b.y()));
108
109 // Rects touching the edge of the screen should not be considered visible.
110 // So we add 1 pixel here to avoid that situation.
111 float x = std::max(0.0f, c.width() - a.width() - b.width() + 1.0f);
112 float y = std::max(0.0f, c.height() - a.height() - b.height() + 1.0f);
113 return (x + y);
114 }
115
116 // Calculate the time for the |current_bounds| to intersect with the
117 // |target_bounds| given its previous location and time delta.
118 // This function should work for both scaling and scrolling case.
119 static float TimeForBoundsToIntersect(const gfx::RectF& previous_bounds,
120 const gfx::RectF& current_bounds,
121 float time_delta,
122 const gfx::RectF& target_bounds);
123
124 // If a tile is not live, then all other fields are invalid.
125 bool is_live;
126 TileResolution resolution;
127 float time_to_visible_in_seconds;
128 float distance_to_visible_in_pixels;
129
130 private:
131 gfx::QuadF current_screen_quad;
132 };
133
134 enum TileMemoryLimitPolicy {
135 // Nothing.
136 ALLOW_NOTHING,
137
138 // You might be made visible, but you're not being interacted with.
139 ALLOW_ABSOLUTE_MINIMUM, // Tall.
140
141 // You're being interacted with, but we're low on memory.
142 ALLOW_PREPAINT_ONLY, // Grande.
143
144 // You're the only thing in town. Go crazy.
145 ALLOW_ANYTHING, // Venti.
146
147 // Be sure to update TreePriorityAsValue when adding new fields.
148 };
149 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue(
150 TileMemoryLimitPolicy policy);
151
152 enum TreePriority {
153 SAME_PRIORITY_FOR_BOTH_TREES,
154 SMOOTHNESS_TAKES_PRIORITY,
155 NEW_CONTENT_TAKES_PRIORITY
156
157 // Be sure to update TreePriorityAsValue when adding new fields.
158 };
159 scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio);
160
161 class GlobalStateThatImpactsTilePriority {
162 public:
163 GlobalStateThatImpactsTilePriority()
164 : memory_limit_policy(ALLOW_NOTHING)
165 , memory_limit_in_bytes(0)
166 , tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {
167 }
168
169 TileMemoryLimitPolicy memory_limit_policy;
170
171 size_t memory_limit_in_bytes;
172
173 TreePriority tree_priority;
174
175 scoped_ptr<base::Value> AsValue() const;
176 };
177
178 } // namespace cc
179
180 #endif // CC_TILE_PRIORITY_H_
OLDNEW
« no previous file with comments | « cc/tile_manager.cc ('k') | cc/tile_priority.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698