OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ash/rotator/screen_rotation_animator.h" | 5 #include "ash/rotator/screen_rotation_animator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
12 #include "ash/rotator/screen_rotation_animation.h" | 12 #include "ash/rotator/screen_rotation_animation.h" |
13 #include "ash/rotator/screen_rotation_animator_observer.h" | 13 #include "ash/rotator/screen_rotation_animator_observer.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/histogram_macros.h" | |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
20 #include "ui/compositor/layer_animation_observer.h" | 21 #include "ui/compositor/layer_animation_observer.h" |
21 #include "ui/compositor/layer_animation_sequence.h" | 22 #include "ui/compositor/layer_animation_sequence.h" |
22 #include "ui/compositor/layer_animator.h" | 23 #include "ui/compositor/layer_animator.h" |
23 #include "ui/compositor/layer_owner.h" | 24 #include "ui/compositor/layer_owner.h" |
24 #include "ui/compositor/layer_tree_owner.h" | 25 #include "ui/compositor/layer_tree_owner.h" |
25 #include "ui/display/display.h" | 26 #include "ui/display/display.h" |
26 #include "ui/display/manager/display_manager.h" | 27 #include "ui/display/manager/display_manager.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
40 // The number of degrees that the rotation animations animate through. | 41 // The number of degrees that the rotation animations animate through. |
41 const int kRotationDegrees = 20; | 42 const int kRotationDegrees = 20; |
42 | 43 |
43 // The time it takes for the rotation animations to run. | 44 // The time it takes for the rotation animations to run. |
44 const int kRotationDurationInMs = 250; | 45 const int kRotationDurationInMs = 250; |
45 | 46 |
46 // The rotation factors. | 47 // The rotation factors. |
47 const int kCounterClockWiseRotationFactor = 1; | 48 const int kCounterClockWiseRotationFactor = 1; |
48 const int kClockWiseRotationFactor = -1; | 49 const int kClockWiseRotationFactor = -1; |
49 | 50 |
51 // The percentage histogram boundary. | |
52 const int kPercentage_MIN = 1; | |
53 const int kPercentage_MAX = 101; | |
54 | |
50 // Aborts the active animations of the layer, and recurses upon its child | 55 // Aborts the active animations of the layer, and recurses upon its child |
51 // layers. | 56 // layers. |
52 void AbortAnimations(ui::Layer* layer) { | 57 void AbortAnimations(ui::Layer* layer) { |
53 for (ui::Layer* child_layer : layer->children()) | 58 for (ui::Layer* child_layer : layer->children()) |
54 AbortAnimations(child_layer); | 59 AbortAnimations(child_layer); |
55 layer->GetAnimator()->AbortAllAnimations(); | 60 layer->GetAnimator()->AbortAllAnimations(); |
56 } | 61 } |
57 | 62 |
58 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { | 63 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { |
59 return Shell::GetInstance() | 64 return Shell::GetInstance() |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 } // namespace | 175 } // namespace |
171 | 176 |
172 struct ScreenRotationAnimator::ScreenRotationRequest { | 177 struct ScreenRotationAnimator::ScreenRotationRequest { |
173 ScreenRotationRequest(display::Display::Rotation to_rotation, | 178 ScreenRotationRequest(display::Display::Rotation to_rotation, |
174 display::Display::RotationSource from_source) | 179 display::Display::RotationSource from_source) |
175 : new_rotation(to_rotation), source(from_source) {} | 180 : new_rotation(to_rotation), source(from_source) {} |
176 display::Display::Rotation new_rotation; | 181 display::Display::Rotation new_rotation; |
177 display::Display::RotationSource source; | 182 display::Display::RotationSource source; |
178 }; | 183 }; |
179 | 184 |
185 class ScreenRotationAnimator::ScreenRotationAnimationMetricsReporter | |
186 : public ui::AnimationMetricsReporter { | |
187 void Report(int value) override { | |
188 base::LinearHistogram::FactoryGet( | |
189 "Ash.Rotation.AnimationSmoothness", kPercentage_MIN, kPercentage_MAX, | |
bruthig
2017/03/24 14:25:39
FYI You will need to add an entry to histograms.xm
wutao
2017/03/24 20:24:37
Done.
| |
190 kPercentage_MAX + 1, base::HistogramBase::kUmaTargetedHistogramFlag) | |
191 ->Add(value); | |
192 } | |
193 }; | |
194 | |
180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) | 195 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) |
181 : display_id_(display_id), | 196 : display_id_(display_id), |
182 is_rotating_(false), | 197 is_rotating_(false), |
198 metrics_reporter_( | |
199 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), | |
183 disable_animation_timers_for_test_(false), | 200 disable_animation_timers_for_test_(false), |
184 weak_factory_(this) {} | 201 weak_factory_(this) {} |
185 | 202 |
186 ScreenRotationAnimator::~ScreenRotationAnimator() {} | 203 ScreenRotationAnimator::~ScreenRotationAnimator() {} |
187 | 204 |
188 void ScreenRotationAnimator::AnimateRotation( | 205 void ScreenRotationAnimator::AnimateRotation( |
189 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 206 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
190 aura::Window* root_window = GetRootWindow(display_id_); | 207 aura::Window* root_window = GetRootWindow(display_id_); |
191 | 208 |
192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); | 209 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 252 |
236 std::unique_ptr<ScreenRotationAnimation> screen_rotation = | 253 std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
237 base::MakeUnique<ScreenRotationAnimation>( | 254 base::MakeUnique<ScreenRotationAnimation>( |
238 child_layer, kRotationDegrees * rotation_factor, | 255 child_layer, kRotationDegrees * rotation_factor, |
239 0 /* end_degrees */, child_layer->opacity(), | 256 0 /* end_degrees */, child_layer->opacity(), |
240 1.0f /* target_opacity */, pivot, duration, tween_type); | 257 1.0f /* target_opacity */, pivot, duration, tween_type); |
241 | 258 |
242 ui::LayerAnimator* animator = child_layer->GetAnimator(); | 259 ui::LayerAnimator* animator = child_layer->GetAnimator(); |
243 animator->set_preemption_strategy( | 260 animator->set_preemption_strategy( |
244 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 261 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
245 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = | 262 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
bruthig
2017/03/24 14:25:39
Why don't we add the metric for this sequence?
varkha
2017/03/24 15:04:59
I think it would effectively be redundant given th
varkha
2017/03/24 16:49:32
Also, perhaps more importantly, the |child_layer|s
wutao
2017/03/24 20:24:37
Thank you to address this for me!
| |
246 base::MakeUnique<ui::LayerAnimationSequence>( | 263 base::MakeUnique<ui::LayerAnimationSequence>( |
247 std::move(screen_rotation)); | 264 std::move(screen_rotation)); |
248 animator->StartAnimation(animation_sequence.release()); | 265 animator->StartAnimation(animation_sequence.release()); |
249 } | 266 } |
250 | 267 |
251 // The old layer will also be transformed into the new orientation. We will | 268 // The old layer will also be transformed into the new orientation. We will |
252 // translate it so that the old layer's center point aligns with the new | 269 // translate it so that the old layer's center point aligns with the new |
253 // orientation's center point and use that center point as the pivot for the | 270 // orientation's center point and use that center point as the pivot for the |
254 // rotation animation. | 271 // rotation animation. |
255 gfx::Transform translate_transform; | 272 gfx::Transform translate_transform; |
(...skipping 13 matching lines...) Expand all Loading... | |
269 ui::LayerAnimator* animator = old_root_layer->GetAnimator(); | 286 ui::LayerAnimator* animator = old_root_layer->GetAnimator(); |
270 animator->set_preemption_strategy( | 287 animator->set_preemption_strategy( |
271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 288 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = | 289 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); | 290 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
274 // Add an observer so that the cloned layers can be cleaned up with the | 291 // Add an observer so that the cloned layers can be cleaned up with the |
275 // animation completes/aborts. | 292 // animation completes/aborts. |
276 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); | 293 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); |
277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to | 294 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to |
278 // control the animation. | 295 // control the animation. |
279 if (disable_animation_timers_for_test_) | 296 if (disable_animation_timers_for_test_) |
bruthig
2017/03/24 14:25:39
Not related to this change but shouldn't we be dis
wutao
2017/03/24 20:24:37
Ideally yes, but it will not affect the test resul
| |
280 animator->set_disable_timer_for_test(true); | 297 animator->set_disable_timer_for_test(true); |
298 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get()); | |
281 animator->StartAnimation(animation_sequence.release()); | 299 animator->StartAnimation(animation_sequence.release()); |
282 | 300 |
283 rotation_request.reset(); | 301 rotation_request.reset(); |
284 } | 302 } |
285 | 303 |
286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, | 304 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, |
287 display::Display::RotationSource source) { | 305 display::Display::RotationSource source) { |
288 if (GetCurrentScreenRotation(display_id_) == new_rotation) | 306 if (GetCurrentScreenRotation(display_id_) == new_rotation) |
289 return; | 307 return; |
290 | 308 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 if (child_layer == old_layer_tree_owner_->root()) | 366 if (child_layer == old_layer_tree_owner_->root()) |
349 continue; | 367 continue; |
350 | 368 |
351 child_layer->GetAnimator()->StopAnimating(); | 369 child_layer->GetAnimator()->StopAnimating(); |
352 } | 370 } |
353 | 371 |
354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 372 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
355 } | 373 } |
356 | 374 |
357 } // namespace ash | 375 } // namespace ash |
OLD | NEW |