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