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/common/ash_switches.h" | |
| 11 #include "ash/display/window_tree_host_manager.h" | 12 #include "ash/display/window_tree_host_manager.h" |
| 12 #include "ash/rotator/screen_rotation_animation.h" | 13 #include "ash/rotator/screen_rotation_animation.h" |
| 13 #include "ash/rotator/screen_rotation_animator_observer.h" | 14 #include "ash/rotator/screen_rotation_animator_observer.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "cc/output/copy_output_request.h" | |
| 21 #include "cc/output/copy_output_result.h" | |
| 19 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 20 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
| 21 #include "ui/compositor/layer_animation_element.h" | 24 #include "ui/compositor/layer_animation_element.h" |
| 22 #include "ui/compositor/layer_animation_observer.h" | 25 #include "ui/compositor/layer_animation_observer.h" |
| 23 #include "ui/compositor/layer_animation_sequence.h" | 26 #include "ui/compositor/layer_animation_sequence.h" |
| 24 #include "ui/compositor/layer_animator.h" | 27 #include "ui/compositor/layer_animator.h" |
| 25 #include "ui/compositor/layer_owner.h" | 28 #include "ui/compositor/layer_owner.h" |
| 26 #include "ui/compositor/layer_tree_owner.h" | 29 #include "ui/compositor/layer_tree_owner.h" |
| 27 #include "ui/display/display.h" | 30 #include "ui/display/display.h" |
| 28 #include "ui/display/manager/display_manager.h" | 31 #include "ui/display/manager/display_manager.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 // calling a method on the |animator_|. | 209 // calling a method on the |animator_|. |
| 207 weak_factory_.InvalidateWeakPtrs(); | 210 weak_factory_.InvalidateWeakPtrs(); |
| 208 | 211 |
| 209 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in | 212 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in |
| 210 // order to make sure |metrics_reporter_| outlives the attached animation | 213 // order to make sure |metrics_reporter_| outlives the attached animation |
| 211 // sequence. | 214 // sequence. |
| 212 old_layer_tree_owner_.reset(); | 215 old_layer_tree_owner_.reset(); |
| 213 metrics_reporter_.reset(); | 216 metrics_reporter_.reset(); |
| 214 } | 217 } |
| 215 | 218 |
| 219 void ScreenRotationAnimator::StartRotationAnimation( | |
| 220 std::unique_ptr<ScreenRotationRequest> rotation_request) { | |
| 221 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 222 switches::kAshEnableSmoothScreenRotationAnimation)) { | |
| 223 RequestCopyRootLayerAndAnimateRotation(std::move(rotation_request)); | |
| 224 } else { | |
| 225 CreateOldLayerTree(); | |
| 226 AnimateRotation(std::move(rotation_request)); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 void ScreenRotationAnimator::RequestCopyRootLayerAndAnimateRotation( | |
| 231 std::unique_ptr<ScreenRotationRequest> rotation_request) { | |
| 232 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | |
| 233 cc::CopyOutputRequest::CreateRequest(base::Bind( | |
| 234 &ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation, | |
| 235 weak_factory_.GetWeakPtr(), base::Passed(&rotation_request))); | |
|
oshima
2017/03/31 00:14:34
do we still need to use ::Passed? Didn't std::move
wutao
2017/04/03 16:16:03
Cannot, it prompts: 'unique_ptr' has been explicit
danakj
2017/04/03 16:25:04
Passed() changes behaviour of how the variable is
| |
| 236 ui::Layer* layer = GetRootWindow(display_id_)->layer(); | |
| 237 layer->RequestCopyOfOutput(std::move(copy_output_request)); | |
| 238 } | |
| 239 | |
| 240 void ScreenRotationAnimator::OnRootLayerCopiedBeforeRotation( | |
| 241 std::unique_ptr<ScreenRotationRequest> rotation_request, | |
| 242 std::unique_ptr<cc::CopyOutputResult> result) { | |
| 243 // If copy request does not succeeded, fall back to recreate layers solution. | |
|
oshima
2017/03/31 00:14:34
can you mention when and how it can fail?
wutao
2017/04/03 16:16:04
One situation is that the user cancel the request.
danakj
2017/04/03 16:23:30
It would fail if, for example..
- The layer is rem
| |
| 244 if (result->IsEmpty() || result->size().IsEmpty() || !result->HasTexture()) | |
| 245 CreateOldLayerTree(); | |
| 246 else | |
| 247 CopyOldLayerTree(std::move(result)); | |
| 248 AnimateRotation(std::move(rotation_request)); | |
| 249 } | |
| 250 | |
| 251 void ScreenRotationAnimator::CreateOldLayerTree() { | |
| 252 old_layer_tree_owner_ = ::wm::RecreateLayers(GetRootWindow(display_id_)); | |
| 253 } | |
| 254 | |
| 255 void ScreenRotationAnimator::CopyOldLayerTree( | |
| 256 std::unique_ptr<cc::CopyOutputResult> result) { | |
| 257 cc::TextureMailbox texture_mailbox; | |
| 258 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | |
| 259 result->TakeTexture(&texture_mailbox, &release_callback); | |
| 260 DCHECK(texture_mailbox.IsTexture()); | |
| 261 | |
| 262 aura::Window* root_window = GetRootWindow(display_id_); | |
| 263 gfx::Rect rect(0, 0, root_window->layer()->size().width(), | |
| 264 root_window->layer()->size().height()); | |
|
oshima
2017/03/31 00:14:34
gfx::Rect rect(..->size());
wutao
2017/04/03 16:16:04
Done.
| |
| 265 std::unique_ptr<ui::Layer> copy_layer = base::MakeUnique<ui::Layer>(); | |
| 266 copy_layer->SetBounds(rect); | |
|
oshima
2017/03/31 00:14:34
what happens if
a) the display bounds changed duri
wutao
2017/04/03 16:16:04
a) The display bounds changed during animation wil
oshima
2017/04/03 16:36:11
My concerns are:
1) it shouldn't crash or leave c
wutao
2017/04/03 17:53:38
I archive your comments and add TODO. We can add c
| |
| 267 copy_layer->SetTextureMailbox(texture_mailbox, std::move(release_callback), | |
| 268 rect.size()); | |
| 269 old_layer_tree_owner_ = | |
| 270 base::MakeUnique<ui::LayerTreeOwner>(std::move(copy_layer)); | |
| 271 } | |
| 272 | |
| 216 void ScreenRotationAnimator::AnimateRotation( | 273 void ScreenRotationAnimator::AnimateRotation( |
| 217 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 274 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 218 aura::Window* root_window = GetRootWindow(display_id_); | 275 aura::Window* root_window = GetRootWindow(display_id_); |
| 276 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( | |
| 277 new LayerCleanupObserver(weak_factory_.GetWeakPtr())); | |
| 278 ui::Layer* old_root_layer = old_layer_tree_owner_->root(); | |
| 279 old_root_layer->set_name("ScreenRotationAnimator:old_layer_tree"); | |
| 280 // Add the cloned layer tree in to the root, so it will be rendered. | |
| 281 root_window->layer()->Add(old_root_layer); | |
| 282 root_window->layer()->StackAtTop(old_root_layer); | |
| 219 | 283 |
| 220 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); | 284 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); |
| 221 | 285 |
| 222 const int rotation_factor = GetRotationFactor( | 286 const int rotation_factor = GetRotationFactor( |
| 223 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); | 287 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); |
| 224 | 288 |
| 225 const int old_layer_initial_rotation_degrees = GetInitialDegrees( | 289 const int old_layer_initial_rotation_degrees = GetInitialDegrees( |
| 226 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); | 290 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); |
| 227 | 291 |
| 228 const base::TimeDelta duration = | 292 const base::TimeDelta duration = |
| 229 base::TimeDelta::FromMilliseconds(kRotationDurationInMs); | 293 base::TimeDelta::FromMilliseconds(kRotationDurationInMs); |
| 230 | 294 |
| 231 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; | 295 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; |
| 232 | 296 |
| 233 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree = | |
| 234 ::wm::RecreateLayers(root_window); | |
| 235 old_layer_tree->root()->set_name("ScreenRotationAnimator:old_layer_tree"); | |
| 236 | |
| 237 // Add the cloned layer tree in to the root, so it will be rendered. | |
| 238 root_window->layer()->Add(old_layer_tree->root()); | |
| 239 root_window->layer()->StackAtTop(old_layer_tree->root()); | |
| 240 | |
| 241 old_layer_tree_owner_ = std::move(old_layer_tree); | |
| 242 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer( | |
| 243 new LayerCleanupObserver(weak_factory_.GetWeakPtr())); | |
| 244 | |
| 245 Shell::GetInstance()->display_manager()->SetDisplayRotation( | 297 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
| 246 display_id_, rotation_request->new_rotation, rotation_request->source); | 298 display_id_, rotation_request->new_rotation, rotation_request->source); |
| 247 | 299 |
| 248 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); | 300 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); |
| 249 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, | 301 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, |
| 250 rotated_screen_bounds.height() / 2); | 302 rotated_screen_bounds.height() / 2); |
| 251 | 303 |
| 252 ui::Layer* old_root_layer = old_layer_tree_owner_->root(); | |
| 253 // We must animate each non-cloned child layer individually because the cloned | 304 // We must animate each non-cloned child layer individually because the cloned |
| 254 // layer was added as a child to |root_window|'s layer so that it will be | 305 // layer was added as a child to |root_window|'s layer so that it will be |
| 255 // rendered. | 306 // rendered. |
| 256 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and | 307 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and |
| 257 // its current children so that we only need to initiate two | 308 // its current children so that we only need to initiate two |
| 258 // LayerAnimationSequences. One for the new layers and one for the old layer. | 309 // LayerAnimationSequences. One for the new layers and one for the old layer. |
| 259 for (ui::Layer* child_layer : root_window->layer()->children()) { | 310 for (ui::Layer* child_layer : root_window->layer()->children()) { |
| 260 // Skip the cloned layer because it has a different animation. | 311 // Skip the cloned layer because it has a different animation. |
| 261 if (child_layer == old_root_layer) | 312 if (child_layer == old_root_layer) |
| 262 continue; | 313 continue; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 base::MakeUnique<ScreenRotationRequest>(new_rotation, source); | 372 base::MakeUnique<ScreenRotationRequest>(new_rotation, source); |
| 322 | 373 |
| 323 if (is_rotating_) { | 374 if (is_rotating_) { |
| 324 last_pending_request_ = std::move(rotation_request); | 375 last_pending_request_ = std::move(rotation_request); |
| 325 // The pending request will be processed when the | 376 // The pending request will be processed when the |
| 326 // OnLayerAnimation(Ended|Aborted) methods should be called after | 377 // OnLayerAnimation(Ended|Aborted) methods should be called after |
| 327 // StopAnimating(). | 378 // StopAnimating(). |
| 328 StopAnimating(); | 379 StopAnimating(); |
| 329 } else { | 380 } else { |
| 330 is_rotating_ = true; | 381 is_rotating_ = true; |
| 331 AnimateRotation(std::move(rotation_request)); | 382 StartRotationAnimation(std::move(rotation_request)); |
| 332 } | 383 } |
| 333 } | 384 } |
| 334 | 385 |
| 335 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( | 386 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( |
| 336 ScreenRotationAnimatorObserver* observer) { | 387 ScreenRotationAnimatorObserver* observer) { |
| 337 screen_rotation_animator_observers_.AddObserver(observer); | 388 screen_rotation_animator_observers_.AddObserver(observer); |
| 338 } | 389 } |
| 339 | 390 |
| 340 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( | 391 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
| 341 ScreenRotationAnimatorObserver* observer) { | 392 ScreenRotationAnimatorObserver* observer) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 368 if (child_layer == old_layer_tree_owner_->root()) | 419 if (child_layer == old_layer_tree_owner_->root()) |
| 369 continue; | 420 continue; |
| 370 | 421 |
| 371 child_layer->GetAnimator()->StopAnimating(); | 422 child_layer->GetAnimator()->StopAnimating(); |
| 372 } | 423 } |
| 373 | 424 |
| 374 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); | 425 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
| 375 } | 426 } |
| 376 | 427 |
| 377 } // namespace ash | 428 } // namespace ash |
| OLD | NEW |