WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / tile_priority.h
blob615bc75a6f886eb7246fb3988fb15279c0a3ac78
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_TILE_PRIORITY_H_
6 #define CC_TILE_PRIORITY_H_
8 #include <limits>
10 #include "base/memory/ref_counted.h"
11 #include "cc/picture_pile.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/size.h"
15 namespace cc {
17 enum WhichTree {
18 // Note: these must be 0 and 1 because we index with them in various places,
19 // e.g. in Tile::priority_.
20 ACTIVE_TREE = 0,
21 PENDING_TREE = 1,
22 NUM_TREES = 2
25 enum TileResolution {
26 LOW_RESOLUTION = 0 ,
27 HIGH_RESOLUTION = 1,
28 NON_IDEAL_RESOLUTION = 2
31 struct CC_EXPORT TilePriority {
32 TilePriority()
33 : resolution(NON_IDEAL_RESOLUTION),
34 time_to_visible_in_seconds(std::numeric_limits<float>::max()),
35 time_to_ideal_resolution_in_seconds(std::numeric_limits<float>::max()),
36 distance_to_visible_in_pixels(std::numeric_limits<float>::max()) {}
38 TilePriority(const TilePriority& active, const TilePriority& pending) {
39 if (active.resolution == HIGH_RESOLUTION ||
40 pending.resolution == HIGH_RESOLUTION)
41 resolution = HIGH_RESOLUTION;
42 else if (active.resolution == LOW_RESOLUTION ||
43 pending.resolution == LOW_RESOLUTION)
44 resolution = LOW_RESOLUTION;
45 else
46 resolution = NON_IDEAL_RESOLUTION;
48 time_to_visible_in_seconds =
49 std::min(active.time_to_visible_in_seconds,
50 pending.time_to_visible_in_seconds);
51 time_to_ideal_resolution_in_seconds =
52 std::min(active.time_to_ideal_resolution_in_seconds,
53 pending.time_to_ideal_resolution_in_seconds);
54 distance_to_visible_in_pixels =
55 std::min(active.distance_to_visible_in_pixels,
56 pending.distance_to_visible_in_pixels);
59 float time_to_needed_in_seconds() const {
60 return std::min(time_to_visible_in_seconds,
61 time_to_ideal_resolution_in_seconds);
64 static const double kMaxTimeToVisibleInSeconds;
66 static int manhattanDistance(const gfx::RectF& a, const gfx::RectF& b);
68 // Calculate the time for the |current_bounds| to intersect with the
69 // |target_bounds| given its previous location and time delta.
70 // This function should work for both scaling and scrolling case.
71 static double TimeForBoundsToIntersect(gfx::RectF previous_bounds,
72 gfx::RectF current_bounds,
73 double time_delta,
74 gfx::RectF target_bounds);
76 TileResolution resolution;
77 float time_to_visible_in_seconds;
78 float time_to_ideal_resolution_in_seconds;
79 float distance_to_visible_in_pixels;
82 enum TileMemoryLimitPolicy {
83 // Nothing.
84 ALLOW_NOTHING,
86 // You might be made visible, but you're not being interacted with.
87 ALLOW_ABSOLUTE_MINIMUM, // Tall.
89 // You're being interacted with, but we're low on memory.
90 ALLOW_PREPAINT_ONLY, // Grande.
92 // You're the only thing in town. Go crazy.
93 ALLOW_ANYTHING, // Venti.
96 class GlobalStateThatImpactsTilePriority {
97 public:
98 GlobalStateThatImpactsTilePriority()
99 : memory_limit_policy(ALLOW_NOTHING)
100 , memory_limit_in_bytes(0)
101 , smoothness_takes_priority(false) {
104 TileMemoryLimitPolicy memory_limit_policy;
106 size_t memory_limit_in_bytes;
108 // Set when scrolling.
109 bool smoothness_takes_priority;
112 } // namespace cc
114 #endif // CC_TILE_PRIORITY_H_