| 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 #include "cc/resources/tile_priority.h" | 5 #include "cc/resources/tile_priority.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return scoped_ptr<base::Value>(new base::StringValue("HIGH_RESOLUTION")); | 74 return scoped_ptr<base::Value>(new base::StringValue("HIGH_RESOLUTION")); |
| 75 case NON_IDEAL_RESOLUTION: | 75 case NON_IDEAL_RESOLUTION: |
| 76 return scoped_ptr<base::Value>(new base::StringValue( | 76 return scoped_ptr<base::Value>(new base::StringValue( |
| 77 "NON_IDEAL_RESOLUTION")); | 77 "NON_IDEAL_RESOLUTION")); |
| 78 } | 78 } |
| 79 DCHECK(false) << "Unrecognized TileResolution value " << resolution; | 79 DCHECK(false) << "Unrecognized TileResolution value " << resolution; |
| 80 return scoped_ptr<base::Value>(new base::StringValue( | 80 return scoped_ptr<base::Value>(new base::StringValue( |
| 81 "<unknown TileResolution value>")); | 81 "<unknown TileResolution value>")); |
| 82 } | 82 } |
| 83 | 83 |
| 84 scoped_ptr<base::Value> TilePriorityBinAsValue(TilePriority::PriorityBin bin) { |
| 85 switch (bin) { |
| 86 case TilePriority::NOW: |
| 87 return scoped_ptr<base::Value>(base::Value::CreateStringValue("NOW")); |
| 88 case TilePriority::SOON: |
| 89 return scoped_ptr<base::Value>(base::Value::CreateStringValue("SOON")); |
| 90 case TilePriority::EVENTUALLY: |
| 91 return scoped_ptr<base::Value>( |
| 92 base::Value::CreateStringValue("EVENTUALLY")); |
| 93 } |
| 94 DCHECK(false) << "Unrecognized TilePriority::PriorityBin value " << bin; |
| 95 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
| 96 "<unknown TilePriority::PriorityBin value>")); |
| 97 } |
| 98 |
| 84 scoped_ptr<base::Value> TilePriority::AsValue() const { | 99 scoped_ptr<base::Value> TilePriority::AsValue() const { |
| 85 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 100 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 86 state->Set("resolution", TileResolutionAsValue(resolution).release()); | 101 state->Set("resolution", TileResolutionAsValue(resolution).release()); |
| 87 state->Set("time_to_visible_in_seconds", | 102 state->Set("priority_bin", TilePriorityBinAsValue(priority_bin).release()); |
| 88 MathUtil::AsValueSafely(time_to_visible_in_seconds).release()); | 103 state->Set("distance_to_visible", |
| 89 state->Set("distance_to_visible_in_pixels", | 104 MathUtil::AsValueSafely(distance_to_visible).release()); |
| 90 MathUtil::AsValueSafely(distance_to_visible_in_pixels).release()); | |
| 91 return state.PassAs<base::Value>(); | 105 return state.PassAs<base::Value>(); |
| 92 } | 106 } |
| 93 | 107 |
| 94 float TilePriority::TimeForBoundsToIntersect(const gfx::RectF& previous_bounds, | |
| 95 const gfx::RectF& current_bounds, | |
| 96 float time_delta, | |
| 97 const gfx::RectF& target_bounds) { | |
| 98 // Perform an intersection test explicitly between current and target. | |
| 99 if (current_bounds.x() < target_bounds.right() && | |
| 100 current_bounds.y() < target_bounds.bottom() && | |
| 101 target_bounds.x() < current_bounds.right() && | |
| 102 target_bounds.y() < current_bounds.bottom()) | |
| 103 return 0.0f; | |
| 104 | |
| 105 const float kMaxTimeToVisibleInSeconds = | |
| 106 std::numeric_limits<float>::infinity(); | |
| 107 | |
| 108 if (time_delta == 0.0f) | |
| 109 return kMaxTimeToVisibleInSeconds; | |
| 110 | |
| 111 // As we are trying to solve the case of both scaling and scrolling, using | |
| 112 // a single coordinate with velocity is not enough. The logic here is to | |
| 113 // calculate the velocity for each edge. Then we calculate the time range that | |
| 114 // each edge will stay on the same side of the target bounds. If there is an | |
| 115 // overlap between these time ranges, the bounds must have intersect with | |
| 116 // each other during that period of time. | |
| 117 Range range(0.0f, kMaxTimeToVisibleInSeconds); | |
| 118 IntersectPositiveHalfplane( | |
| 119 &range, previous_bounds.x(), current_bounds.x(), | |
| 120 target_bounds.right(), time_delta); | |
| 121 IntersectNegativeHalfplane( | |
| 122 &range, previous_bounds.right(), current_bounds.right(), | |
| 123 target_bounds.x(), time_delta); | |
| 124 IntersectPositiveHalfplane( | |
| 125 &range, previous_bounds.y(), current_bounds.y(), | |
| 126 target_bounds.bottom(), time_delta); | |
| 127 IntersectNegativeHalfplane( | |
| 128 &range, previous_bounds.bottom(), current_bounds.bottom(), | |
| 129 target_bounds.y(), time_delta); | |
| 130 return range.IsEmpty() ? kMaxTimeToVisibleInSeconds : range.start_; | |
| 131 } | |
| 132 | |
| 133 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue( | 108 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue( |
| 134 TileMemoryLimitPolicy policy) { | 109 TileMemoryLimitPolicy policy) { |
| 135 switch (policy) { | 110 switch (policy) { |
| 136 case ALLOW_NOTHING: | 111 case ALLOW_NOTHING: |
| 137 return scoped_ptr<base::Value>(new base::StringValue("ALLOW_NOTHING")); | 112 return scoped_ptr<base::Value>(new base::StringValue("ALLOW_NOTHING")); |
| 138 case ALLOW_ABSOLUTE_MINIMUM: | 113 case ALLOW_ABSOLUTE_MINIMUM: |
| 139 return scoped_ptr<base::Value>(new base::StringValue( | 114 return scoped_ptr<base::Value>(new base::StringValue( |
| 140 "ALLOW_ABSOLUTE_MINIMUM")); | 115 "ALLOW_ABSOLUTE_MINIMUM")); |
| 141 case ALLOW_PREPAINT_ONLY: | 116 case ALLOW_PREPAINT_ONLY: |
| 142 return scoped_ptr<base::Value>(new base::StringValue( | 117 return scoped_ptr<base::Value>(new base::StringValue( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 TileMemoryLimitPolicyAsValue(memory_limit_policy).release()); | 149 TileMemoryLimitPolicyAsValue(memory_limit_policy).release()); |
| 175 state->SetInteger("memory_limit_in_bytes", memory_limit_in_bytes); | 150 state->SetInteger("memory_limit_in_bytes", memory_limit_in_bytes); |
| 176 state->SetInteger("unused_memory_limit_in_bytes", | 151 state->SetInteger("unused_memory_limit_in_bytes", |
| 177 unused_memory_limit_in_bytes); | 152 unused_memory_limit_in_bytes); |
| 178 state->SetInteger("num_resources_limit", num_resources_limit); | 153 state->SetInteger("num_resources_limit", num_resources_limit); |
| 179 state->Set("tree_priority", TreePriorityAsValue(tree_priority).release()); | 154 state->Set("tree_priority", TreePriorityAsValue(tree_priority).release()); |
| 180 return state.PassAs<base::Value>(); | 155 return state.PassAs<base::Value>(); |
| 181 } | 156 } |
| 182 | 157 |
| 183 } // namespace cc | 158 } // namespace cc |
| OLD | NEW |