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 { | |
11 | |
12 // TODO(qinmin): modify ui/gfx/range/range.h to support template so that we | |
13 // don't need to define this. | |
14 struct Range { | |
15 Range(float start, float end) : start_(start), end_(end) {} | |
16 bool IsEmpty(); | |
17 float start_; | |
18 float end_; | |
19 }; | |
20 | |
21 bool Range::IsEmpty() { | |
22 return start_ >= end_; | |
23 } | |
24 | |
25 inline void IntersectNegativeHalfplane(Range* out, | |
26 float previous, | |
27 float current, | |
28 float target, | |
29 float time_delta) { | |
30 float time_per_dist = time_delta / (current - previous); | |
31 float t = (target - current) * time_per_dist; | |
32 if (time_per_dist > 0.0f) | |
33 out->start_ = std::max(out->start_, t); | |
34 else | |
35 out->end_ = std::min(out->end_, t); | |
36 } | |
37 | |
38 inline void IntersectPositiveHalfplane(Range* out, | |
39 float previous, | |
40 float current, | |
41 float target, | |
42 float time_delta) { | |
43 float time_per_dist = time_delta / (current - previous); | |
44 float t = (target - current) * time_per_dist; | |
45 if (time_per_dist < 0.0f) | |
46 out->start_ = std::max(out->start_, t); | |
47 else | |
48 out->end_ = std::min(out->end_, t); | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 namespace cc { | 10 namespace cc { |
54 | 11 |
55 scoped_ptr<base::Value> WhichTreeAsValue(WhichTree tree) { | 12 scoped_ptr<base::Value> WhichTreeAsValue(WhichTree tree) { |
56 switch (tree) { | 13 switch (tree) { |
57 case ACTIVE_TREE: | 14 case ACTIVE_TREE: |
58 return scoped_ptr<base::Value>(new base::StringValue("ACTIVE_TREE")); | 15 return scoped_ptr<base::Value>(new base::StringValue("ACTIVE_TREE")); |
59 case PENDING_TREE: | 16 case PENDING_TREE: |
60 return scoped_ptr<base::Value>(new base::StringValue("PENDING_TREE")); | 17 return scoped_ptr<base::Value>(new base::StringValue("PENDING_TREE")); |
61 default: | 18 default: |
62 DCHECK(false) << "Unrecognized WhichTree value " << tree; | 19 DCHECK(false) << "Unrecognized WhichTree value " << tree; |
(...skipping 11 matching lines...) Expand all Loading... |
74 return scoped_ptr<base::Value>(new base::StringValue("HIGH_RESOLUTION")); | 31 return scoped_ptr<base::Value>(new base::StringValue("HIGH_RESOLUTION")); |
75 case NON_IDEAL_RESOLUTION: | 32 case NON_IDEAL_RESOLUTION: |
76 return scoped_ptr<base::Value>(new base::StringValue( | 33 return scoped_ptr<base::Value>(new base::StringValue( |
77 "NON_IDEAL_RESOLUTION")); | 34 "NON_IDEAL_RESOLUTION")); |
78 } | 35 } |
79 DCHECK(false) << "Unrecognized TileResolution value " << resolution; | 36 DCHECK(false) << "Unrecognized TileResolution value " << resolution; |
80 return scoped_ptr<base::Value>(new base::StringValue( | 37 return scoped_ptr<base::Value>(new base::StringValue( |
81 "<unknown TileResolution value>")); | 38 "<unknown TileResolution value>")); |
82 } | 39 } |
83 | 40 |
| 41 scoped_ptr<base::Value> TilePriorityBinAsValue(TilePriority::PriorityBin bin) { |
| 42 switch (bin) { |
| 43 case TilePriority::NOW: |
| 44 return scoped_ptr<base::Value>(base::Value::CreateStringValue("NOW")); |
| 45 case TilePriority::SOON: |
| 46 return scoped_ptr<base::Value>(base::Value::CreateStringValue("SOON")); |
| 47 case TilePriority::EVENTUALLY: |
| 48 return scoped_ptr<base::Value>( |
| 49 base::Value::CreateStringValue("EVENTUALLY")); |
| 50 } |
| 51 DCHECK(false) << "Unrecognized TilePriority::PriorityBin value " << bin; |
| 52 return scoped_ptr<base::Value>(base::Value::CreateStringValue( |
| 53 "<unknown TilePriority::PriorityBin value>")); |
| 54 } |
| 55 |
84 scoped_ptr<base::Value> TilePriority::AsValue() const { | 56 scoped_ptr<base::Value> TilePriority::AsValue() const { |
85 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 57 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
86 state->Set("resolution", TileResolutionAsValue(resolution).release()); | 58 state->Set("resolution", TileResolutionAsValue(resolution).release()); |
87 state->Set("time_to_visible_in_seconds", | 59 state->Set("priority_bin", TilePriorityBinAsValue(priority_bin).release()); |
88 MathUtil::AsValueSafely(time_to_visible_in_seconds).release()); | 60 state->Set("distance_to_visible", |
89 state->Set("distance_to_visible_in_pixels", | 61 MathUtil::AsValueSafely(distance_to_visible).release()); |
90 MathUtil::AsValueSafely(distance_to_visible_in_pixels).release()); | |
91 return state.PassAs<base::Value>(); | 62 return state.PassAs<base::Value>(); |
92 } | 63 } |
93 | 64 |
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( | 65 scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue( |
134 TileMemoryLimitPolicy policy) { | 66 TileMemoryLimitPolicy policy) { |
135 switch (policy) { | 67 switch (policy) { |
136 case ALLOW_NOTHING: | 68 case ALLOW_NOTHING: |
137 return scoped_ptr<base::Value>(new base::StringValue("ALLOW_NOTHING")); | 69 return scoped_ptr<base::Value>(new base::StringValue("ALLOW_NOTHING")); |
138 case ALLOW_ABSOLUTE_MINIMUM: | 70 case ALLOW_ABSOLUTE_MINIMUM: |
139 return scoped_ptr<base::Value>(new base::StringValue( | 71 return scoped_ptr<base::Value>(new base::StringValue( |
140 "ALLOW_ABSOLUTE_MINIMUM")); | 72 "ALLOW_ABSOLUTE_MINIMUM")); |
141 case ALLOW_PREPAINT_ONLY: | 73 case ALLOW_PREPAINT_ONLY: |
142 return scoped_ptr<base::Value>(new base::StringValue( | 74 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()); | 106 TileMemoryLimitPolicyAsValue(memory_limit_policy).release()); |
175 state->SetInteger("memory_limit_in_bytes", memory_limit_in_bytes); | 107 state->SetInteger("memory_limit_in_bytes", memory_limit_in_bytes); |
176 state->SetInteger("unused_memory_limit_in_bytes", | 108 state->SetInteger("unused_memory_limit_in_bytes", |
177 unused_memory_limit_in_bytes); | 109 unused_memory_limit_in_bytes); |
178 state->SetInteger("num_resources_limit", num_resources_limit); | 110 state->SetInteger("num_resources_limit", num_resources_limit); |
179 state->Set("tree_priority", TreePriorityAsValue(tree_priority).release()); | 111 state->Set("tree_priority", TreePriorityAsValue(tree_priority).release()); |
180 return state.PassAs<base::Value>(); | 112 return state.PassAs<base::Value>(); |
181 } | 113 } |
182 | 114 |
183 } // namespace cc | 115 } // namespace cc |
OLD | NEW |