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/shell.h" | 13 #include "ash/shell.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
18 #include "ui/compositor/layer_animation_observer.h" | 19 #include "ui/compositor/layer_animation_observer.h" |
19 #include "ui/compositor/layer_animation_sequence.h" | 20 #include "ui/compositor/layer_animation_sequence.h" |
20 #include "ui/compositor/layer_animator.h" | 21 #include "ui/compositor/layer_animator.h" |
21 #include "ui/compositor/layer_owner.h" | 22 #include "ui/compositor/layer_owner.h" |
22 #include "ui/compositor/layer_tree_owner.h" | 23 #include "ui/compositor/layer_tree_owner.h" |
23 #include "ui/display/display.h" | 24 #include "ui/display/display.h" |
24 #include "ui/display/manager/display_manager.h" | 25 #include "ui/display/manager/display_manager.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // layer was added as a child to |root_window|'s layer so that it will be | 190 // layer was added as a child to |root_window|'s layer so that it will be |
190 // rendered. | 191 // rendered. |
191 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and | 192 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and |
192 // its current children so that we only need to initiate two | 193 // its current children so that we only need to initiate two |
193 // LayerAnimationSequences. One for the new layers and one for the old layer. | 194 // LayerAnimationSequences. One for the new layers and one for the old layer. |
194 for (ui::Layer* child_layer : root_window->layer()->children()) { | 195 for (ui::Layer* child_layer : root_window->layer()->children()) { |
195 // Skip the cloned layer because it has a different animation. | 196 // Skip the cloned layer because it has a different animation. |
196 if (child_layer == layer_cleanup_observer->GetRootLayer()) | 197 if (child_layer == layer_cleanup_observer->GetRootLayer()) |
197 continue; | 198 continue; |
198 | 199 |
199 std::unique_ptr<ScreenRotationAnimation> screen_rotation( | 200 std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
200 new ScreenRotationAnimation( | 201 base::MakeUnique<ScreenRotationAnimation>( |
201 child_layer, kRotationDegrees * rotation_factor, | 202 child_layer, kRotationDegrees * rotation_factor, |
202 0 /* end_degrees */, child_layer->opacity(), | 203 0 /* end_degrees */, child_layer->opacity(), |
203 1.0f /* target_opacity */, pivot, duration, tween_type)); | 204 1.0f /* target_opacity */, pivot, duration, tween_type); |
204 | 205 |
205 ui::LayerAnimator* animator = child_layer->GetAnimator(); | 206 ui::LayerAnimator* animator = child_layer->GetAnimator(); |
206 animator->set_preemption_strategy( | 207 animator->set_preemption_strategy( |
207 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 208 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
208 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence( | 209 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
209 new ui::LayerAnimationSequence(screen_rotation.release())); | 210 base::MakeUnique<ui::LayerAnimationSequence>( |
| 211 std::move(screen_rotation)); |
210 animator->StartAnimation(animation_sequence.release()); | 212 animator->StartAnimation(animation_sequence.release()); |
211 } | 213 } |
212 | 214 |
213 // The old layer will also be transformed into the new orientation. We will | 215 // The old layer will also be transformed into the new orientation. We will |
214 // translate it so that the old layer's center point aligns with the new | 216 // translate it so that the old layer's center point aligns with the new |
215 // orientation's center point and use that center point as the pivot for the | 217 // orientation's center point and use that center point as the pivot for the |
216 // rotation animation. | 218 // rotation animation. |
217 gfx::Transform translate_transform; | 219 gfx::Transform translate_transform; |
218 translate_transform.Translate( | 220 translate_transform.Translate( |
219 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, | 221 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, |
220 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); | 222 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); |
221 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform); | 223 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform); |
222 | 224 |
223 std::unique_ptr<ScreenRotationAnimation> screen_rotation( | 225 std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
224 new ScreenRotationAnimation( | 226 base::MakeUnique<ScreenRotationAnimation>( |
225 layer_cleanup_observer->GetRootLayer(), | 227 layer_cleanup_observer->GetRootLayer(), |
226 old_layer_initial_rotation_degrees * rotation_factor, | 228 old_layer_initial_rotation_degrees * rotation_factor, |
227 (old_layer_initial_rotation_degrees - kRotationDegrees) * | 229 (old_layer_initial_rotation_degrees - kRotationDegrees) * |
228 rotation_factor, | 230 rotation_factor, |
229 layer_cleanup_observer->GetRootLayer()->opacity(), | 231 layer_cleanup_observer->GetRootLayer()->opacity(), |
230 0.0f /* target_opacity */, pivot, duration, tween_type)); | 232 0.0f /* target_opacity */, pivot, duration, tween_type); |
231 | 233 |
232 ui::LayerAnimator* animator = | 234 ui::LayerAnimator* animator = |
233 layer_cleanup_observer->GetRootLayer()->GetAnimator(); | 235 layer_cleanup_observer->GetRootLayer()->GetAnimator(); |
234 animator->set_preemption_strategy( | 236 animator->set_preemption_strategy( |
235 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 237 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
236 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence( | 238 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
237 new ui::LayerAnimationSequence(screen_rotation.release())); | 239 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
238 // Add an observer so that the cloned layers can be cleaned up with the | 240 // Add an observer so that the cloned layers can be cleaned up with the |
239 // animation completes/aborts. | 241 // animation completes/aborts. |
240 animation_sequence->AddObserver(layer_cleanup_observer.release()); | 242 animation_sequence->AddObserver(layer_cleanup_observer.release()); |
241 animator->StartAnimation(animation_sequence.release()); | 243 animator->StartAnimation(animation_sequence.release()); |
242 } | 244 } |
243 | 245 |
244 } // namespace | 246 } // namespace |
245 | 247 |
246 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) | 248 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) |
247 : display_id_(display_id) {} | 249 : display_id_(display_id) {} |
(...skipping 12 matching lines...) Expand all Loading... |
260 const display::Display::Rotation current_rotation = | 262 const display::Display::Rotation current_rotation = |
261 GetCurrentRotation(display_id_); | 263 GetCurrentRotation(display_id_); |
262 | 264 |
263 if (current_rotation == new_rotation) | 265 if (current_rotation == new_rotation) |
264 return; | 266 return; |
265 | 267 |
266 RotateScreen(display_id_, new_rotation, source); | 268 RotateScreen(display_id_, new_rotation, source); |
267 } | 269 } |
268 | 270 |
269 } // namespace ash | 271 } // namespace ash |
OLD | NEW |