OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TILE_PRIORITY_H_ | 5 #ifndef CC_TILE_PRIORITY_H_ |
6 #define CC_TILE_PRIORITY_H_ | 6 #define CC_TILE_PRIORITY_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "cc/picture_pile.h" | 9 #include "cc/picture_pile.h" |
10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
11 #include "ui/gfx/size.h" | 11 #include "ui/gfx/size.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
| 15 enum TileResolution { |
| 16 LOW_RESOLUTION = 0 , |
| 17 HIGH_RESOLUTION = 1, |
| 18 NON_IDEAL_RESOLUTION = 2 |
| 19 }; |
| 20 |
15 struct TilePriority { | 21 struct TilePriority { |
16 // Set to true for tiles that should be favored during, for example, | 22 TilePriority() |
17 // scrolls. | 23 : resolution(NON_IDEAL_RESOLUTION), |
18 bool on_primary_tree; | 24 time_to_visible_in_seconds(std::numeric_limits<float>::max()), |
| 25 time_to_ideal_resolution_in_seconds(std::numeric_limits<float>::max()), |
| 26 distance_to_visible_in_pixels(std::numeric_limits<float>::max()) {} |
19 | 27 |
20 // A given layer may have multiple tilings, of differing quality. | 28 TilePriority(const TilePriority& active, const TilePriority& pending) { |
21 // would_be_drawn is set for the tiles that are visible that would be | 29 if (active.resolution == HIGH_RESOLUTION || |
22 // drawn if they were chosen. | 30 pending.resolution == HIGH_RESOLUTION) |
23 bool would_be_drawn; | 31 resolution = HIGH_RESOLUTION; |
| 32 else if (active.resolution == LOW_RESOLUTION || |
| 33 pending.resolution == LOW_RESOLUTION) |
| 34 resolution = LOW_RESOLUTION; |
| 35 else |
| 36 resolution = NON_IDEAL_RESOLUTION; |
24 | 37 |
25 // We expect it to be useful soon. | 38 time_to_visible_in_seconds = |
26 bool nice_to_have; | 39 std::min(active.time_to_visible_in_seconds, |
| 40 pending.time_to_visible_in_seconds); |
| 41 time_to_ideal_resolution_in_seconds = |
| 42 std::min(active.time_to_ideal_resolution_in_seconds, |
| 43 pending.time_to_ideal_resolution_in_seconds); |
| 44 distance_to_visible_in_pixels = |
| 45 std::min(active.distance_to_visible_in_pixels, |
| 46 pending.distance_to_visible_in_pixels); |
| 47 } |
27 | 48 |
28 // Used to prefer tiles near to the viewport. | 49 float time_to_needed_in_seconds() const { |
29 float distance_to_viewport; | 50 return std::min(time_to_visible_in_seconds, |
| 51 time_to_ideal_resolution_in_seconds); |
| 52 } |
30 | 53 |
31 // TODO(enne): some metric that penalizes blurriness. | 54 TileResolution resolution; |
| 55 float time_to_visible_in_seconds; |
| 56 float time_to_ideal_resolution_in_seconds; |
| 57 float distance_to_visible_in_pixels; |
32 }; | 58 }; |
33 | 59 |
34 enum TileMemoryLimitPolicy { | 60 enum TileMemoryLimitPolicy { |
35 // Nothing. | 61 // Nothing. |
36 ALLOW_NOTHING, | 62 ALLOW_NOTHING, |
37 | 63 |
38 // Use as little as possible. | 64 // You might be made visible, but you're not being interacted with. |
39 ALLOW_ONLY_REQUIRED, // On primary tree, would be drawn. | 65 ALLOW_ABSOLUTE_MINIMUM, // Tall. |
40 | 66 |
41 // Use as little as possible. | 67 // You're being interacted with, but we're low on memory. |
42 ALLOW_NICE_TO_HAVE, // On either tree, nice to have | 68 ALLOW_PREPAINT_ONLY, // Grande. |
43 | 69 |
44 // Use as much memory, up to memory size. | 70 // You're the only thing in town. Go crazy. |
45 ALLOW_ANYTHING, | 71 ALLOW_ANYTHING, // Venti. |
46 }; | 72 }; |
47 | 73 |
48 class GlobalStateThatImpactsTilePriority { | 74 class GlobalStateThatImpactsTilePriority { |
49 public: | 75 public: |
50 GlobalStateThatImpactsTilePriority() | 76 GlobalStateThatImpactsTilePriority() |
51 : memory_limit_policy(ALLOW_NOTHING) | 77 : memory_limit_policy(ALLOW_NOTHING) |
52 , memory_limit_in_bytes(0) | 78 , memory_limit_in_bytes(0) |
53 , smoothness_takes_priority(false) | 79 , smoothness_takes_priority(false) { |
54 , pending_tree_frame_number(-1) | |
55 , active_tree_frame_number(-1) { | |
56 } | 80 } |
57 | 81 |
58 TileMemoryLimitPolicy memory_limit_policy; | 82 TileMemoryLimitPolicy memory_limit_policy; |
59 | 83 |
60 size_t memory_limit_in_bytes; | 84 size_t memory_limit_in_bytes; |
61 | 85 |
62 // Set when scrolling. | 86 // Set when scrolling. |
63 bool smoothness_takes_priority; | 87 bool smoothness_takes_priority; |
64 | |
65 // Use -1 if no tree. | |
66 int pending_tree_frame_number; | |
67 int active_tree_frame_number; | |
68 }; | |
69 | |
70 class TilePriorityComparator { | |
71 public: | |
72 TilePriorityComparator(GlobalStateThatImpactsTilePriority& global_state) | |
73 : global_state_(global_state) {} | |
74 | |
75 int compare(const TilePriority& a, const TilePriority& b) { | |
76 // TODO(nduca,enne): Implement a comparator using the attributes here. | |
77 return 0; | |
78 } | |
79 | |
80 private: | |
81 GlobalStateThatImpactsTilePriority global_state_; | |
82 }; | 88 }; |
83 | 89 |
84 } // namespace cc | 90 } // namespace cc |
85 | 91 |
86 #endif // CC_TILE_PRIORITY_H_ | 92 #endif // CC_TILE_PRIORITY_H_ |
OLD | NEW |