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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } | 182 } |
| 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 is_rotating_(false), | 192 screen_rotation_state_(IDLE), |
| 193 metrics_reporter_( | 193 metrics_reporter_( |
| 194 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), | 194 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), |
| 195 disable_animation_timers_for_test_(false), | 195 disable_animation_timers_for_test_(false), |
| 196 weak_factory_(this) {} | 196 weak_factory_(this) {} |
| 197 | 197 |
| 198 ScreenRotationAnimator::~ScreenRotationAnimator() { | 198 ScreenRotationAnimator::~ScreenRotationAnimator() { |
| 199 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from | 199 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from |
| 200 // calling a method on the |animator_|. | 200 // calling a method on the |animator_|. |
| 201 weak_factory_.InvalidateWeakPtrs(); | 201 weak_factory_.InvalidateWeakPtrs(); |
| 202 | 202 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 219 } | 219 } |
| 220 | 220 |
| 221 void ScreenRotationAnimator::RequestCopyRootLayerAndAnimateRotation( | 221 void ScreenRotationAnimator::RequestCopyRootLayerAndAnimateRotation( |
| 222 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 222 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 223 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 223 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
| 224 cc::CopyOutputRequest::CreateRequest( | 224 cc::CopyOutputRequest::CreateRequest( |
| 225 CreateAfterCopyCallback(std::move(rotation_request))); | 225 CreateAfterCopyCallback(std::move(rotation_request))); |
| 226 ui::Layer* layer = GetRootWindow(display_id_)->layer(); | 226 ui::Layer* layer = GetRootWindow(display_id_)->layer(); |
| 227 copy_output_request->set_area(gfx::Rect(layer->size())); | 227 copy_output_request->set_area(gfx::Rect(layer->size())); |
| 228 layer->RequestCopyOfOutput(std::move(copy_output_request)); | 228 layer->RequestCopyOfOutput(std::move(copy_output_request)); |
| 229 | |
| 230 screen_rotation_state_ = COPY_REQUESTED; | |
| 229 } | 231 } |
| 230 | 232 |
| 231 ScreenRotationAnimator::CopyCallback | 233 ScreenRotationAnimator::CopyCallback |
| 232 ScreenRotationAnimator::CreateAfterCopyCallback( | 234 ScreenRotationAnimator::CreateAfterCopyCallback( |
| 233 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 235 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 234 return base::Bind(&ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, | 236 return base::Bind(&ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, |
| 235 weak_factory_.GetWeakPtr(), | 237 weak_factory_.GetWeakPtr(), |
| 236 base::Passed(&rotation_request)); | 238 base::Passed(&rotation_request)); |
| 237 } | 239 } |
| 238 | 240 |
| 239 void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( | 241 void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( |
| 240 std::unique_ptr<ScreenRotationRequest> rotation_request, | 242 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 241 std::unique_ptr<cc::CopyOutputResult> result) { | 243 std::unique_ptr<cc::CopyOutputResult> result) { |
| 242 // If display was removed, should abort rotation. | 244 // In the following cases, abort rotation: |
| 243 if (!IsDisplayIdValid(display_id_)) { | 245 // 1) if the display was removed, |
| 246 // 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 | |
| 248 // before committing the request to the compositor. b) The compositor is | |
| 249 // shutdown. | |
| 250 if (!IsDisplayIdValid(display_id_) || result->IsEmpty()) { | |
| 244 ProcessAnimationQueue(); | 251 ProcessAnimationQueue(); |
| 252 rotation_request.reset(); | |
| 245 return; | 253 return; |
| 246 } | 254 } |
| 247 | 255 |
| 248 // Fall back to recreate layers solution when the copy request has been | 256 CopyOldLayerTree(std::move(result)); |
| 249 // canceled or failed. It would fail if, for examples: a) The layer is removed | |
| 250 // from the compositor and destroyed before committing the request to the | |
| 251 // compositor. b) The compositor is shutdown. | |
| 252 if (result->IsEmpty()) | |
| 253 CreateOldLayerTree(); | |
| 254 else | |
| 255 CopyOldLayerTree(std::move(result)); | |
| 256 AnimateRotation(std::move(rotation_request)); | 257 AnimateRotation(std::move(rotation_request)); |
| 257 } | 258 } |
| 258 | 259 |
| 259 void ScreenRotationAnimator::CreateOldLayerTree() { | 260 void ScreenRotationAnimator::CreateOldLayerTree() { |
| 260 old_layer_tree_owner_ = ::wm::RecreateLayers(GetRootWindow(display_id_)); | 261 old_layer_tree_owner_ = ::wm::RecreateLayers(GetRootWindow(display_id_)); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void ScreenRotationAnimator::CopyOldLayerTree( | 264 void ScreenRotationAnimator::CopyOldLayerTree( |
| 264 std::unique_ptr<cc::CopyOutputResult> result) { | 265 std::unique_ptr<cc::CopyOutputResult> result) { |
| 265 cc::TextureMailbox texture_mailbox; | 266 cc::TextureMailbox texture_mailbox; |
| 266 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 267 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
| 267 result->TakeTexture(&texture_mailbox, &release_callback); | 268 result->TakeTexture(&texture_mailbox, &release_callback); |
| 268 DCHECK(texture_mailbox.IsTexture()); | 269 DCHECK(texture_mailbox.IsTexture()); |
| 269 | 270 |
| 270 aura::Window* root_window = GetRootWindow(display_id_); | 271 aura::Window* root_window = GetRootWindow(display_id_); |
| 271 gfx::Rect rect(root_window->layer()->size()); | 272 gfx::Rect rect(root_window->layer()->size()); |
| 272 std::unique_ptr<ui::Layer> copy_layer = base::MakeUnique<ui::Layer>(); | 273 std::unique_ptr<ui::Layer> copy_layer = base::MakeUnique<ui::Layer>(); |
| 273 copy_layer->SetBounds(rect); | 274 copy_layer->SetBounds(rect); |
| 274 copy_layer->SetTextureMailbox(texture_mailbox, std::move(release_callback), | 275 copy_layer->SetTextureMailbox(texture_mailbox, std::move(release_callback), |
| 275 rect.size()); | 276 rect.size()); |
| 276 old_layer_tree_owner_ = | 277 old_layer_tree_owner_ = |
| 277 base::MakeUnique<ui::LayerTreeOwner>(std::move(copy_layer)); | 278 base::MakeUnique<ui::LayerTreeOwner>(std::move(copy_layer)); |
| 278 } | 279 } |
| 279 | 280 |
| 280 void ScreenRotationAnimator::AnimateRotation( | 281 void ScreenRotationAnimator::AnimateRotation( |
| 281 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 282 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 283 screen_rotation_state_ = ROTATING; | |
| 284 | |
| 282 aura::Window* root_window = GetRootWindow(display_id_); | 285 aura::Window* root_window = GetRootWindow(display_id_); |
| 283 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( | 286 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( |
| 284 new LayerCleanupObserver(weak_factory_.GetWeakPtr())); | 287 new LayerCleanupObserver(weak_factory_.GetWeakPtr())); |
| 285 ui::Layer* old_root_layer = old_layer_tree_owner_->root(); | 288 ui::Layer* old_root_layer = old_layer_tree_owner_->root(); |
| 286 old_root_layer->set_name("ScreenRotationAnimator:old_layer_tree"); | 289 old_root_layer->set_name("ScreenRotationAnimator:old_layer_tree"); |
| 287 // Add the cloned layer tree in to the root, so it will be rendered. | 290 // Add the cloned layer tree in to the root, so it will be rendered. |
| 288 root_window->layer()->Add(old_root_layer); | 291 root_window->layer()->Add(old_root_layer); |
| 289 root_window->layer()->StackAtTop(old_root_layer); | 292 root_window->layer()->StackAtTop(old_root_layer); |
| 290 | 293 |
| 291 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); | 294 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 } | 374 } |
| 372 | 375 |
| 373 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, | 376 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, |
| 374 display::Display::RotationSource source) { | 377 display::Display::RotationSource source) { |
| 375 if (GetCurrentScreenRotation(display_id_) == new_rotation) | 378 if (GetCurrentScreenRotation(display_id_) == new_rotation) |
| 376 return; | 379 return; |
| 377 | 380 |
| 378 std::unique_ptr<ScreenRotationRequest> rotation_request = | 381 std::unique_ptr<ScreenRotationRequest> rotation_request = |
| 379 base::MakeUnique<ScreenRotationRequest>(new_rotation, source); | 382 base::MakeUnique<ScreenRotationRequest>(new_rotation, source); |
| 380 | 383 |
| 381 if (is_rotating_) { | 384 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 382 last_pending_request_ = std::move(rotation_request); | 385 switches::kAshEnableSmoothScreenRotation); |
|
oshima
2017/04/10 22:56:59
was this for debugging?
wutao
2017/04/10 23:17:55
Thank you to find it out! Removed.
| |
| 383 // The pending request will be processed when the | 386 |
| 384 // OnLayerAnimation(Ended|Aborted) methods should be called after | 387 switch (screen_rotation_state_) { |
| 385 // StopAnimating(). | 388 case IDLE: |
| 386 StopAnimating(); | 389 StartRotationAnimation(std::move(rotation_request)); |
| 387 } else { | 390 break; |
| 388 is_rotating_ = true; | 391 case ROTATING: |
| 389 StartRotationAnimation(std::move(rotation_request)); | 392 last_pending_request_ = std::move(rotation_request); |
| 393 // The pending request will be processed when the | |
| 394 // OnLayerAnimation(Ended|Aborted) methods should be called after | |
| 395 // |StopAnimating()|. | |
| 396 StopAnimating(); | |
| 397 break; | |
| 398 case COPY_REQUESTED: | |
| 399 // ignore the new rotation request during this small time window. | |
| 400 // Otherwise, we need cancel the copy request and abort current rotation. | |
| 401 // This complicates the situation and gain little from it. | |
| 402 break; | |
|
oshima
2017/04/10 22:56:59
We still need to handle this otherwise the device
wutao
2017/04/10 23:17:55
Thanks, I will address this in a separate CL.
| |
| 390 } | 403 } |
| 391 } | 404 } |
| 392 | 405 |
| 393 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( | 406 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( |
| 394 ScreenRotationAnimatorObserver* observer) { | 407 ScreenRotationAnimatorObserver* observer) { |
| 395 screen_rotation_animator_observers_.AddObserver(observer); | 408 screen_rotation_animator_observers_.AddObserver(observer); |
| 396 } | 409 } |
| 397 | 410 |
| 398 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( | 411 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
| 399 ScreenRotationAnimatorObserver* observer) { | 412 ScreenRotationAnimatorObserver* observer) { |
| 400 screen_rotation_animator_observers_.RemoveObserver(observer); | 413 screen_rotation_animator_observers_.RemoveObserver(observer); |
| 401 } | 414 } |
| 402 | 415 |
| 403 void ScreenRotationAnimator::ProcessAnimationQueue() { | 416 void ScreenRotationAnimator::ProcessAnimationQueue() { |
| 404 is_rotating_ = false; | 417 screen_rotation_state_ = IDLE; |
| 405 old_layer_tree_owner_.reset(); | 418 old_layer_tree_owner_.reset(); |
| 406 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { | 419 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { |
| 407 std::unique_ptr<ScreenRotationRequest> rotation_request = | 420 std::unique_ptr<ScreenRotationRequest> rotation_request = |
| 408 std::move(last_pending_request_); | 421 std::move(last_pending_request_); |
| 409 Rotate(rotation_request->new_rotation, rotation_request->source); | 422 Rotate(rotation_request->new_rotation, rotation_request->source); |
| 410 rotation_request.reset(); | 423 rotation_request.reset(); |
| 411 return; | 424 return; |
| 412 } | 425 } |
| 413 | 426 |
| 414 for (auto& observer : screen_rotation_animator_observers_) | 427 for (auto& observer : screen_rotation_animator_observers_) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 426 if (child_layer == old_layer_tree_owner_->root()) | 439 if (child_layer == old_layer_tree_owner_->root()) |
| 427 continue; | 440 continue; |
| 428 | 441 |
| 429 child_layer->GetAnimator()->StopAnimating(); | 442 child_layer->GetAnimator()->StopAnimating(); |
| 430 } | 443 } |
| 431 | 444 |
| 432 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 445 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 433 } | 446 } |
| 434 | 447 |
| 435 } // namespace ash | 448 } // namespace ash |
| OLD | NEW |