[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 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 | |
[email protected] | ffaa2a63 | 2012-11-11 14:47:50 | [diff] [blame] | 5 | #ifndef CC_TILE_PRIORITY_H_ |
| 6 | #define CC_TILE_PRIORITY_H_ |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 7 | |
| 8 | #include "base/memory/ref_counted.h" |
| 9 | #include "cc/picture_pile.h" |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 10 | #include "ui/gfx/rect.h" |
| 11 | #include "ui/gfx/size.h" |
| 12 | |
| 13 | namespace cc { |
| 14 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 15 | enum TileResolution { |
| 16 | LOW_RESOLUTION = 0 , |
| 17 | HIGH_RESOLUTION = 1, |
| 18 | NON_IDEAL_RESOLUTION = 2 |
| 19 | }; |
| 20 | |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 21 | struct TilePriority { |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 22 | TilePriority() |
| 23 | : resolution(NON_IDEAL_RESOLUTION), |
| 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()) {} |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 27 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 28 | TilePriority(const TilePriority& active, const TilePriority& pending) { |
| 29 | if (active.resolution == HIGH_RESOLUTION || |
| 30 | pending.resolution == HIGH_RESOLUTION) |
| 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; |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 37 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 38 | time_to_visible_in_seconds = |
| 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 | } |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 48 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 49 | float time_to_needed_in_seconds() const { |
| 50 | return std::min(time_to_visible_in_seconds, |
| 51 | time_to_ideal_resolution_in_seconds); |
| 52 | } |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 53 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 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; |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 58 | }; |
| 59 | |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 60 | enum TileMemoryLimitPolicy { |
| 61 | // Nothing. |
| 62 | ALLOW_NOTHING, |
| 63 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 64 | // You might be made visible, but you're not being interacted with. |
| 65 | ALLOW_ABSOLUTE_MINIMUM, // Tall. |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 66 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 67 | // You're being interacted with, but we're low on memory. |
| 68 | ALLOW_PREPAINT_ONLY, // Grande. |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 69 | |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 70 | // You're the only thing in town. Go crazy. |
| 71 | ALLOW_ANYTHING, // Venti. |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | class GlobalStateThatImpactsTilePriority { |
[email protected] | ffaa2a63 | 2012-11-11 14:47:50 | [diff] [blame] | 75 | public: |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 76 | GlobalStateThatImpactsTilePriority() |
| 77 | : memory_limit_policy(ALLOW_NOTHING) |
| 78 | , memory_limit_in_bytes(0) |
[email protected] | 0f0609c | 2012-11-16 10:00:47 | [diff] [blame^] | 79 | , smoothness_takes_priority(false) { |
[email protected] | 76858dd38 | 2012-11-10 09:38:07 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TileMemoryLimitPolicy memory_limit_policy; |
| 83 | |
| 84 | size_t memory_limit_in_bytes; |
| 85 | |
| 86 | // Set when scrolling. |
| 87 | bool smoothness_takes_priority; |
[email protected] | 18134fc | 2012-11-08 22:42:34 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace cc |
[email protected] | ffaa2a63 | 2012-11-11 14:47:50 | [diff] [blame] | 91 | |
| 92 | #endif // CC_TILE_PRIORITY_H_ |