Index: ash/rotator/screen_rotation_animator.cc |
diff --git a/ash/rotator/screen_rotation_animator.cc b/ash/rotator/screen_rotation_animator.cc |
index 102b8d0e7b3082f7ff25656d2f1243ecad206e22..41c1651026c5c8045c62db83e503d81a7b00de7b 100644 |
--- a/ash/rotator/screen_rotation_animator.cc |
+++ b/ash/rotator/screen_rotation_animator.cc |
@@ -49,13 +49,8 @@ const int kRotationDurationInMs = 250; |
const int kCounterClockWiseRotationFactor = 1; |
const int kClockWiseRotationFactor = -1; |
-// Aborts the active animations of the layer, and recurses upon its child |
-// layers. |
-void AbortAnimations(ui::Layer* layer) { |
- for (ui::Layer* child_layer : layer->children()) |
- AbortAnimations(child_layer); |
- layer->GetAnimator()->AbortAllAnimations(); |
-} |
+// The delegate root layer name. |
+const std::string kDelegateRootLayerName = "DelegateRootLayer"; |
display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { |
return Shell::GetInstance() |
@@ -82,6 +77,15 @@ aura::Window* GetRootWindow(int64_t display_id) { |
->GetRootWindowForDisplayId(display_id); |
} |
+ui::Layer* GetChildLayerByName(ui::Layer* parent, const std::string& name) { |
+ for (ui::Layer* child_layer : parent->children()) { |
+ if (child_layer->name() == name) |
+ return child_layer; |
+ } |
+ NOTREACHED(); |
+ return nullptr; |
+} |
+ |
// Returns true if the rotation between |initial_rotation| and |new_rotation| is |
// 180 degrees. |
bool Is180DegreeFlip(display::Display::Rotation initial_rotation, |
@@ -249,33 +253,26 @@ void ScreenRotationAnimator::AnimateRotation( |
const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, |
rotated_screen_bounds.height() / 2); |
- ui::Layer* old_root_layer = old_layer_tree_owner_->root(); |
- // We must animate each non-cloned child layer individually because the cloned |
- // layer was added as a child to |root_window|'s layer so that it will be |
- // rendered. |
- // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and |
- // its current children so that we only need to initiate two |
- // LayerAnimationSequences. One for the new layers and one for the old layer. |
- for (ui::Layer* child_layer : root_window->layer()->children()) { |
- // Skip the cloned layer because it has a different animation. |
- if (child_layer == old_root_layer) |
- continue; |
- |
- std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
- base::MakeUnique<ScreenRotationAnimation>( |
- child_layer, kRotationDegrees * rotation_factor, |
- 0 /* end_degrees */, child_layer->opacity(), |
- 1.0f /* target_opacity */, pivot, duration, tween_type); |
- |
- ui::LayerAnimator* animator = child_layer->GetAnimator(); |
- animator->set_preemption_strategy( |
- ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
- std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
- base::MakeUnique<ui::LayerAnimationSequence>( |
- std::move(screen_rotation)); |
- animator->StartAnimation(animation_sequence.release()); |
- } |
+ ui::Layer* delegate_root_layer = |
+ GetChildLayerByName(root_window->layer(), kDelegateRootLayerName); |
oshima
2017/04/05 20:26:51
can't you just find the window by id and get layer
wutao
2017/04/05 23:37:34
Done.
|
+ std::unique_ptr<ScreenRotationAnimation> current_layer_screen_rotation = |
+ base::MakeUnique<ScreenRotationAnimation>( |
+ delegate_root_layer, kRotationDegrees * rotation_factor, |
+ 0 /* end_degrees */, 0.0f, |
+ delegate_root_layer->opacity() /* target_opacity */, pivot, duration, |
+ tween_type); |
+ ui::LayerAnimator* current_layer_animator = |
+ delegate_root_layer->GetAnimator(); |
+ current_layer_animator->set_preemption_strategy( |
+ ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
+ std::unique_ptr<ui::LayerAnimationSequence> current_layer_animation_sequence = |
+ base::MakeUnique<ui::LayerAnimationSequence>( |
+ std::move(current_layer_screen_rotation)); |
+ current_layer_animator->StartAnimation( |
+ current_layer_animation_sequence.release()); |
+ |
+ ui::Layer* old_root_layer = old_layer_tree_owner_->root(); |
// The old layer will also be transformed into the new orientation. We will |
// translate it so that the old layer's center point aligns with the new |
// orientation's center point and use that center point as the pivot for the |
@@ -286,7 +283,7 @@ void ScreenRotationAnimator::AnimateRotation( |
(rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); |
old_root_layer->SetTransform(translate_transform); |
- std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
+ std::unique_ptr<ScreenRotationAnimation> old_layer_screen_rotation = |
base::MakeUnique<ScreenRotationAnimation>( |
old_root_layer, old_layer_initial_rotation_degrees * rotation_factor, |
(old_layer_initial_rotation_degrees - kRotationDegrees) * |
@@ -294,20 +291,23 @@ void ScreenRotationAnimator::AnimateRotation( |
old_root_layer->opacity(), 0.0f /* target_opacity */, pivot, duration, |
tween_type); |
- ui::LayerAnimator* animator = old_root_layer->GetAnimator(); |
- animator->set_preemption_strategy( |
+ ui::LayerAnimator* old_layer_animator = old_root_layer->GetAnimator(); |
+ old_layer_animator->set_preemption_strategy( |
ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
- std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
- base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
+ std::unique_ptr<ui::LayerAnimationSequence> old_layer_animation_sequence = |
+ base::MakeUnique<ui::LayerAnimationSequence>( |
+ std::move(old_layer_screen_rotation)); |
// Add an observer so that the cloned layers can be cleaned up with the |
// animation completes/aborts. |
- animation_sequence->AddObserver(old_layer_cleanup_observer.release()); |
+ old_layer_animation_sequence->AddObserver( |
+ old_layer_cleanup_observer.release()); |
// In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to |
// control the animation. |
if (disable_animation_timers_for_test_) |
- animator->set_disable_timer_for_test(true); |
- animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get()); |
- animator->StartAnimation(animation_sequence.release()); |
+ old_layer_animator->set_disable_timer_for_test(true); |
+ old_layer_animation_sequence->SetAnimationMetricsReporter( |
+ metrics_reporter_.get()); |
+ old_layer_animator->StartAnimation(old_layer_animation_sequence.release()); |
rotation_request.reset(); |
} |
@@ -363,14 +363,10 @@ void ScreenRotationAnimator::set_disable_animation_timers_for_test( |
} |
void ScreenRotationAnimator::StopAnimating() { |
- aura::Window* root_window = GetRootWindow(display_id_); |
- for (ui::Layer* child_layer : root_window->layer()->children()) { |
- if (child_layer == old_layer_tree_owner_->root()) |
- continue; |
- |
- child_layer->GetAnimator()->StopAnimating(); |
- } |
- |
+ GetChildLayerByName(GetRootWindow(display_id_)->layer(), |
+ kDelegateRootLayerName) |
+ ->GetAnimator() |
+ ->StopAnimating(); |
old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); |
} |