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 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter); | 185 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 } // namespace | 188 } // namespace |
| 189 | 189 |
| 190 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) | 190 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) |
| 191 : display_id_(display_id), | 191 : display_id_(display_id), |
| 192 screen_rotation_state_(IDLE), | 192 screen_rotation_state_(IDLE), |
| 193 rotation_request_id_(0), | |
| 193 metrics_reporter_( | 194 metrics_reporter_( |
| 194 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), | 195 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), |
| 195 disable_animation_timers_for_test_(false), | 196 disable_animation_timers_for_test_(false), |
| 196 weak_factory_(this) {} | 197 weak_factory_(this) {} |
| 197 | 198 |
| 198 ScreenRotationAnimator::~ScreenRotationAnimator() { | 199 ScreenRotationAnimator::~ScreenRotationAnimator() { |
| 199 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from | 200 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from |
| 200 // calling a method on the |animator_|. | 201 // calling a method on the |animator_|. |
| 201 weak_factory_.InvalidateWeakPtrs(); | 202 weak_factory_.InvalidateWeakPtrs(); |
| 202 | 203 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 ScreenRotationAnimator::CreateAfterCopyCallback( | 235 ScreenRotationAnimator::CreateAfterCopyCallback( |
| 235 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 236 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 236 return base::Bind(&ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, | 237 return base::Bind(&ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, |
| 237 weak_factory_.GetWeakPtr(), | 238 weak_factory_.GetWeakPtr(), |
| 238 base::Passed(&rotation_request)); | 239 base::Passed(&rotation_request)); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( | 242 void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( |
| 242 std::unique_ptr<ScreenRotationRequest> rotation_request, | 243 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 243 std::unique_ptr<cc::CopyOutputResult> result) { | 244 std::unique_ptr<cc::CopyOutputResult> result) { |
| 245 // The |rotation_request_id_| changed since last copy request, which means a | |
| 246 // new rotation stated, we need to ignore this copy result. | |
| 247 if (rotation_request->id != rotation_request_id_) { | |
|
oshima
2017/04/13 17:24:41
it's probably better to have DCHECK
rotation_requ
wutao
2017/04/13 17:51:12
Done.
| |
| 248 rotation_request.reset(); | |
|
oshima
2017/04/13 17:24:41
it'll be reset upon return (sorry I missed others
wutao
2017/04/13 17:51:12
I removed this reset at 3 places. Please check it
| |
| 249 return; | |
| 250 } | |
| 251 | |
| 244 // In the following cases, abort rotation: | 252 // In the following cases, abort rotation: |
| 245 // 1) if the display was removed, | 253 // 1) if the display was removed, |
| 246 // 2) the copy request has been canceled or failed. It would fail if, | 254 // 2) the copy request has been canceled or failed. It would fail if, |
| 247 // for examples: a) The layer is removed from the compositor and destroye | 255 // for examples: a) The layer is removed from the compositor and destroye |
| 248 // before committing the request to the compositor. b) The compositor is | 256 // before committing the request to the compositor. b) The compositor is |
| 249 // shutdown. | 257 // shutdown. |
| 250 if (!IsDisplayIdValid(display_id_) || result->IsEmpty()) { | 258 if (!IsDisplayIdValid(display_id_) || result->IsEmpty()) { |
| 251 ProcessAnimationQueue(); | 259 ProcessAnimationQueue(); |
| 252 rotation_request.reset(); | 260 rotation_request.reset(); |
| 253 return; | 261 return; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 animator->StartAnimation(animation_sequence.release()); | 379 animator->StartAnimation(animation_sequence.release()); |
| 372 | 380 |
| 373 rotation_request.reset(); | 381 rotation_request.reset(); |
| 374 } | 382 } |
| 375 | 383 |
| 376 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, | 384 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, |
| 377 display::Display::RotationSource source) { | 385 display::Display::RotationSource source) { |
| 378 if (GetCurrentScreenRotation(display_id_) == new_rotation) | 386 if (GetCurrentScreenRotation(display_id_) == new_rotation) |
| 379 return; | 387 return; |
| 380 | 388 |
| 389 rotation_request_id_++; | |
| 381 std::unique_ptr<ScreenRotationRequest> rotation_request = | 390 std::unique_ptr<ScreenRotationRequest> rotation_request = |
| 382 base::MakeUnique<ScreenRotationRequest>(new_rotation, source); | 391 base::MakeUnique<ScreenRotationRequest>(rotation_request_id_, |
| 392 new_rotation, source); | |
| 383 | 393 |
| 384 switch (screen_rotation_state_) { | 394 switch (screen_rotation_state_) { |
| 385 case IDLE: | 395 case IDLE: |
| 396 case COPY_REQUESTED: | |
| 386 StartRotationAnimation(std::move(rotation_request)); | 397 StartRotationAnimation(std::move(rotation_request)); |
| 387 break; | 398 break; |
| 388 case ROTATING: | 399 case ROTATING: |
| 389 last_pending_request_ = std::move(rotation_request); | 400 last_pending_request_ = std::move(rotation_request); |
| 390 // The pending request will be processed when the | 401 // The pending request will be processed when the |
| 391 // OnLayerAnimation(Ended|Aborted) methods should be called after | 402 // OnLayerAnimation(Ended|Aborted) methods should be called after |
| 392 // |StopAnimating()|. | 403 // |StopAnimating()|. |
| 393 StopAnimating(); | 404 StopAnimating(); |
| 394 break; | 405 break; |
| 395 case COPY_REQUESTED: | 406 default: |
|
oshima
2017/04/13 17:24:41
remove default (so that compiler can catch an erro
wutao
2017/04/13 17:51:12
Done.
| |
| 396 // TODO(wutao): We need to handle this otherwise the device will be in | 407 NOTREACHED(); |
| 397 // inconsistent state. | |
| 398 break; | |
| 399 } | 408 } |
| 400 } | 409 } |
| 401 | 410 |
| 402 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( | 411 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( |
| 403 ScreenRotationAnimatorObserver* observer) { | 412 ScreenRotationAnimatorObserver* observer) { |
| 404 screen_rotation_animator_observers_.AddObserver(observer); | 413 screen_rotation_animator_observers_.AddObserver(observer); |
| 405 } | 414 } |
| 406 | 415 |
| 407 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( | 416 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
| 408 ScreenRotationAnimatorObserver* observer) { | 417 ScreenRotationAnimatorObserver* observer) { |
| 409 screen_rotation_animator_observers_.RemoveObserver(observer); | 418 screen_rotation_animator_observers_.RemoveObserver(observer); |
| 410 } | 419 } |
| 411 | 420 |
| 412 void ScreenRotationAnimator::ProcessAnimationQueue() { | 421 void ScreenRotationAnimator::ProcessAnimationQueue() { |
| 413 screen_rotation_state_ = IDLE; | 422 screen_rotation_state_ = IDLE; |
| 414 old_layer_tree_owner_.reset(); | 423 old_layer_tree_owner_.reset(); |
| 415 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { | 424 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { |
| 416 std::unique_ptr<ScreenRotationRequest> rotation_request = | 425 ScreenRotationRequest rotation_request = *last_pending_request_.get(); |
|
oshima
2017/04/13 17:24:41
can you just keep the new_rotation and source on s
wutao
2017/04/13 17:51:12
Done.
| |
| 417 std::move(last_pending_request_); | 426 last_pending_request_.reset(); |
| 418 Rotate(rotation_request->new_rotation, rotation_request->source); | 427 Rotate(rotation_request.new_rotation, rotation_request.source); |
| 419 rotation_request.reset(); | |
| 420 return; | 428 return; |
| 421 } | 429 } |
| 422 | 430 |
| 423 for (auto& observer : screen_rotation_animator_observers_) | 431 for (auto& observer : screen_rotation_animator_observers_) |
| 424 observer.OnScreenRotationAnimationFinished(this); | 432 observer.OnScreenRotationAnimationFinished(this); |
| 425 } | 433 } |
| 426 | 434 |
| 427 void ScreenRotationAnimator::set_disable_animation_timers_for_test( | 435 void ScreenRotationAnimator::set_disable_animation_timers_for_test( |
| 428 bool disable_timers) { | 436 bool disable_timers) { |
| 429 disable_animation_timers_for_test_ = disable_timers; | 437 disable_animation_timers_for_test_ = disable_timers; |
| 430 } | 438 } |
| 431 | 439 |
| 432 void ScreenRotationAnimator::StopAnimating() { | 440 void ScreenRotationAnimator::StopAnimating() { |
| 433 aura::Window* root_window = GetRootWindow(display_id_); | 441 aura::Window* root_window = GetRootWindow(display_id_); |
| 434 for (ui::Layer* child_layer : root_window->layer()->children()) { | 442 for (ui::Layer* child_layer : root_window->layer()->children()) { |
| 435 if (child_layer == old_layer_tree_owner_->root()) | 443 if (child_layer == old_layer_tree_owner_->root()) |
| 436 continue; | 444 continue; |
| 437 | 445 |
| 438 child_layer->GetAnimator()->StopAnimating(); | 446 child_layer->GetAnimator()->StopAnimating(); |
| 439 } | 447 } |
| 440 | 448 |
| 441 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 449 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 442 } | 450 } |
| 443 | 451 |
| 444 } // namespace ash | 452 } // namespace ash |
| OLD | NEW |