Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 LayerCleanupObserver::~LayerCleanupObserver() { | 137 LayerCleanupObserver::~LayerCleanupObserver() { |
| 137 // We must eplicitly detach from |sequence_| because we return true from | 138 // We must eplicitly detach from |sequence_| because we return true from |
| 138 // RequiresNotificationWhenAnimatorDestroyed. | 139 // RequiresNotificationWhenAnimatorDestroyed. |
| 139 if (sequence_) | 140 if (sequence_) |
| 140 sequence_->RemoveObserver(this); | 141 sequence_->RemoveObserver(this); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void LayerCleanupObserver::OnLayerAnimationEnded( | 144 void LayerCleanupObserver::OnLayerAnimationEnded( |
| 144 ui::LayerAnimationSequence* sequence) { | 145 ui::LayerAnimationSequence* sequence) { |
| 145 if (animator_) | 146 if (animator_) |
| 146 animator_->OnLayerAnimationEnded(); | 147 animator_->ProcessAnimationQueue(); |
| 147 | 148 |
| 148 delete this; | 149 delete this; |
| 149 } | 150 } |
| 150 | 151 |
| 151 void LayerCleanupObserver::OnLayerAnimationAborted( | 152 void LayerCleanupObserver::OnLayerAnimationAborted( |
| 152 ui::LayerAnimationSequence* sequence) { | 153 ui::LayerAnimationSequence* sequence) { |
| 153 if (animator_) | 154 if (animator_) |
| 154 animator_->OnLayerAnimationAborted(); | 155 animator_->ProcessAnimationQueue(); |
| 155 | 156 |
| 156 delete this; | 157 delete this; |
| 157 } | 158 } |
| 158 | 159 |
| 159 void LayerCleanupObserver::OnAttachedToSequence( | 160 void LayerCleanupObserver::OnAttachedToSequence( |
| 160 ui::LayerAnimationSequence* sequence) { | 161 ui::LayerAnimationSequence* sequence) { |
| 161 sequence_ = sequence; | 162 sequence_ = sequence; |
| 162 } | 163 } |
| 163 | 164 |
| 164 void LayerCleanupObserver::OnDetachedFromSequence( | 165 void LayerCleanupObserver::OnDetachedFromSequence( |
| 165 ui::LayerAnimationSequence* sequence) { | 166 ui::LayerAnimationSequence* sequence) { |
| 166 DCHECK_EQ(sequence, sequence_); | 167 DCHECK_EQ(sequence, sequence_); |
| 167 sequence_ = nullptr; | 168 sequence_ = nullptr; |
| 168 } | 169 } |
| 169 | 170 |
| 170 } // namespace | 171 } // namespace |
| 171 | 172 |
| 172 struct ScreenRotationAnimator::ScreenRotationRequest { | 173 struct ScreenRotationAnimator::ScreenRotationRequest { |
| 173 ScreenRotationRequest(display::Display::Rotation to_rotation, | 174 ScreenRotationRequest(display::Display::Rotation to_rotation, |
| 174 display::Display::RotationSource from_source) | 175 display::Display::RotationSource from_source) |
| 175 : new_rotation(to_rotation), source(from_source) {} | 176 : new_rotation(to_rotation), source(from_source) {} |
| 176 display::Display::Rotation new_rotation; | 177 display::Display::Rotation new_rotation; |
| 177 display::Display::RotationSource source; | 178 display::Display::RotationSource source; |
| 178 }; | 179 }; |
| 179 | 180 |
| 181 class ScreenRotationAnimator::ScreenRotationAnimationMetricsReporter | |
| 182 : public ui::AnimationMetricsReporter { | |
| 183 void Report(int value) override { | |
|
oshima
2017/03/24 22:46:00
nit: define public ctor/dtor, then DISALLOW_COPY_A
wutao
2017/03/24 23:50:55
Done.
| |
| 184 UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value); | |
| 185 } | |
| 186 }; | |
| 187 | |
| 180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) | 188 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) |
| 181 : display_id_(display_id), | 189 : display_id_(display_id), |
| 182 is_rotating_(false), | 190 is_rotating_(false), |
| 191 metrics_reporter_( | |
| 192 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), | |
| 183 disable_animation_timers_for_test_(false), | 193 disable_animation_timers_for_test_(false), |
| 184 weak_factory_(this) {} | 194 weak_factory_(this) {} |
| 185 | 195 |
| 186 ScreenRotationAnimator::~ScreenRotationAnimator() {} | 196 ScreenRotationAnimator::~ScreenRotationAnimator() { |
| 197 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from | |
| 198 // calling a method on the |animator_|. | |
| 199 weak_factory_.InvalidateWeakPtrs(); | |
| 200 | |
| 201 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in | |
| 202 // order to make sure |metrics_reporter_| outlives the attached animation | |
| 203 // sequence. | |
| 204 old_layer_tree_owner_.reset(); | |
| 205 metrics_reporter_.reset(); | |
| 206 } | |
| 187 | 207 |
| 188 void ScreenRotationAnimator::AnimateRotation( | 208 void ScreenRotationAnimator::AnimateRotation( |
| 189 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 209 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 190 aura::Window* root_window = GetRootWindow(display_id_); | 210 aura::Window* root_window = GetRootWindow(display_id_); |
| 191 | 211 |
| 192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); | 212 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); |
| 193 | 213 |
| 194 const int rotation_factor = GetRotationFactor( | 214 const int rotation_factor = GetRotationFactor( |
| 195 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); | 215 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); |
| 196 | 216 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 291 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = | 292 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
| 273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); | 293 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
| 274 // Add an observer so that the cloned layers can be cleaned up with the | 294 // Add an observer so that the cloned layers can be cleaned up with the |
| 275 // animation completes/aborts. | 295 // animation completes/aborts. |
| 276 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); | 296 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); |
| 277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to | 297 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to |
| 278 // control the animation. | 298 // control the animation. |
| 279 if (disable_animation_timers_for_test_) | 299 if (disable_animation_timers_for_test_) |
| 280 animator->set_disable_timer_for_test(true); | 300 animator->set_disable_timer_for_test(true); |
| 301 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get()); | |
| 281 animator->StartAnimation(animation_sequence.release()); | 302 animator->StartAnimation(animation_sequence.release()); |
| 282 | 303 |
| 283 rotation_request.reset(); | 304 rotation_request.reset(); |
| 284 } | 305 } |
| 285 | 306 |
| 286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, | 307 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, |
| 287 display::Display::RotationSource source) { | 308 display::Display::RotationSource source) { |
| 288 if (GetCurrentScreenRotation(display_id_) == new_rotation) | 309 if (GetCurrentScreenRotation(display_id_) == new_rotation) |
| 289 return; | 310 return; |
| 290 | 311 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 306 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( | 327 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( |
| 307 ScreenRotationAnimatorObserver* observer) { | 328 ScreenRotationAnimatorObserver* observer) { |
| 308 screen_rotation_animator_observers_.AddObserver(observer); | 329 screen_rotation_animator_observers_.AddObserver(observer); |
| 309 } | 330 } |
| 310 | 331 |
| 311 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( | 332 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
| 312 ScreenRotationAnimatorObserver* observer) { | 333 ScreenRotationAnimatorObserver* observer) { |
| 313 screen_rotation_animator_observers_.RemoveObserver(observer); | 334 screen_rotation_animator_observers_.RemoveObserver(observer); |
| 314 } | 335 } |
| 315 | 336 |
| 316 void ScreenRotationAnimator::OnLayerAnimationEnded() { | |
| 317 ProcessAnimationQueue(); | |
| 318 } | |
| 319 | |
| 320 void ScreenRotationAnimator::OnLayerAnimationAborted() { | |
| 321 AbortAnimations(old_layer_tree_owner_->root()); | |
| 322 ProcessAnimationQueue(); | |
| 323 } | |
| 324 | |
| 325 void ScreenRotationAnimator::ProcessAnimationQueue() { | 337 void ScreenRotationAnimator::ProcessAnimationQueue() { |
| 326 is_rotating_ = false; | 338 is_rotating_ = false; |
| 327 old_layer_tree_owner_.reset(); | 339 old_layer_tree_owner_.reset(); |
| 328 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { | 340 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { |
| 329 std::unique_ptr<ScreenRotationRequest> rotation_request = | 341 std::unique_ptr<ScreenRotationRequest> rotation_request = |
| 330 std::move(last_pending_request_); | 342 std::move(last_pending_request_); |
| 331 Rotate(rotation_request->new_rotation, rotation_request->source); | 343 Rotate(rotation_request->new_rotation, rotation_request->source); |
| 332 rotation_request.reset(); | 344 rotation_request.reset(); |
| 333 return; | 345 return; |
| 334 } | 346 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 348 if (child_layer == old_layer_tree_owner_->root()) | 360 if (child_layer == old_layer_tree_owner_->root()) |
| 349 continue; | 361 continue; |
| 350 | 362 |
| 351 child_layer->GetAnimator()->StopAnimating(); | 363 child_layer->GetAnimator()->StopAnimating(); |
| 352 } | 364 } |
| 353 | 365 |
| 354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 366 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 355 } | 367 } |
| 356 | 368 |
| 357 } // namespace ash | 369 } // namespace ash |
| OLD | NEW |