Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: ash/rotator/screen_rotation_animator.cc

Issue 2786563003: Add a NOT_DRAWN window in between the root_window and its children. (Closed)
Patch Set: Fix the tests. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ash_switches.h" 11 #include "ash/ash_switches.h"
12 #include "ash/display/window_tree_host_manager.h" 12 #include "ash/display/window_tree_host_manager.h"
13 #include "ash/public/cpp/shell_window_ids.h"
13 #include "ash/rotator/screen_rotation_animation.h" 14 #include "ash/rotator/screen_rotation_animation.h"
14 #include "ash/rotator/screen_rotation_animator_observer.h" 15 #include "ash/rotator/screen_rotation_animator_observer.h"
15 #include "ash/shell.h" 16 #include "ash/shell.h"
16 #include "base/command_line.h" 17 #include "base/command_line.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "cc/output/copy_output_request.h" 21 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h" 22 #include "cc/output/copy_output_result.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
(...skipping 22 matching lines...) Expand all
45 // The number of degrees that the rotation animations animate through. 46 // The number of degrees that the rotation animations animate through.
46 const int kRotationDegrees = 20; 47 const int kRotationDegrees = 20;
47 48
48 // The time it takes for the rotation animations to run. 49 // The time it takes for the rotation animations to run.
49 const int kRotationDurationInMs = 250; 50 const int kRotationDurationInMs = 250;
50 51
51 // The rotation factors. 52 // The rotation factors.
52 const int kCounterClockWiseRotationFactor = 1; 53 const int kCounterClockWiseRotationFactor = 1;
53 const int kClockWiseRotationFactor = -1; 54 const int kClockWiseRotationFactor = -1;
54 55
55 // Aborts the active animations of the layer, and recurses upon its child
56 // layers.
57 void AbortAnimations(ui::Layer* layer) {
58 for (ui::Layer* child_layer : layer->children())
59 AbortAnimations(child_layer);
60 layer->GetAnimator()->AbortAllAnimations();
61 }
62
63 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { 56 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) {
64 return Shell::Get() 57 return Shell::Get()
65 ->display_manager() 58 ->display_manager()
66 ->GetDisplayInfo(display_id) 59 ->GetDisplayInfo(display_id)
67 .GetActiveRotation(); 60 .GetActiveRotation();
68 } 61 }
69 62
70 bool IsDisplayIdValid(int64_t display_id) { 63 bool IsDisplayIdValid(int64_t display_id) {
71 return Shell::Get()->display_manager()->IsDisplayIdValid(display_id); 64 return Shell::Get()->display_manager()->IsDisplayIdValid(display_id);
72 } 65 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 294
302 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;
303 296
304 Shell::Get()->display_manager()->SetDisplayRotation( 297 Shell::Get()->display_manager()->SetDisplayRotation(
305 display_id_, rotation_request->new_rotation, rotation_request->source); 298 display_id_, rotation_request->new_rotation, rotation_request->source);
306 299
307 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); 300 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds();
308 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, 301 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2,
309 rotated_screen_bounds.height() / 2); 302 rotated_screen_bounds.height() / 2);
310 303
311 // We must animate each non-cloned child layer individually because the cloned 304 ui::Layer* screen_rotation_container_layer =
312 // layer was added as a child to |root_window|'s layer so that it will be 305 root_window->GetChildById(kShellWindowId_ScreenRotationContainer)
313 // rendered. 306 ->layer();
314 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and 307 std::unique_ptr<ScreenRotationAnimation> current_layer_screen_rotation =
315 // its current children so that we only need to initiate two 308 base::MakeUnique<ScreenRotationAnimation>(
316 // LayerAnimationSequences. One for the new layers and one for the old layer. 309 screen_rotation_container_layer, kRotationDegrees * rotation_factor,
317 for (ui::Layer* child_layer : root_window->layer()->children()) { 310 0 /* end_degrees */, 0.0f,
318 // Skip the cloned layer because it has a different animation. 311 screen_rotation_container_layer->opacity() /* target_opacity */,
319 if (child_layer == old_root_layer) 312 pivot, duration, tween_type);
320 continue;
321 313
322 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 314 ui::LayerAnimator* current_layer_animator =
323 base::MakeUnique<ScreenRotationAnimation>( 315 screen_rotation_container_layer->GetAnimator();
324 child_layer, kRotationDegrees * rotation_factor, 316 current_layer_animator->set_preemption_strategy(
325 0 /* end_degrees */, child_layer->opacity(), 317 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
326 1.0f /* target_opacity */, pivot, duration, tween_type); 318 std::unique_ptr<ui::LayerAnimationSequence> current_layer_animation_sequence =
327 319 base::MakeUnique<ui::LayerAnimationSequence>(
328 ui::LayerAnimator* animator = child_layer->GetAnimator(); 320 std::move(current_layer_screen_rotation));
329 animator->set_preemption_strategy( 321 current_layer_animator->StartAnimation(
330 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 322 current_layer_animation_sequence.release());
331 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
332 base::MakeUnique<ui::LayerAnimationSequence>(
333 std::move(screen_rotation));
334 animator->StartAnimation(animation_sequence.release());
335 }
336 323
337 // The old layer will also be transformed into the new orientation. We will 324 // The old layer will also be transformed into the new orientation. We will
338 // translate it so that the old layer's center point aligns with the new 325 // translate it so that the old layer's center point aligns with the new
339 // orientation's center point and use that center point as the pivot for the 326 // orientation's center point and use that center point as the pivot for the
340 // rotation animation. 327 // rotation animation.
341 gfx::Transform translate_transform; 328 gfx::Transform translate_transform;
342 translate_transform.Translate( 329 translate_transform.Translate(
343 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, 330 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2,
344 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); 331 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2);
345 old_root_layer->SetTransform(translate_transform); 332 old_root_layer->SetTransform(translate_transform);
346 333
347 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 334 std::unique_ptr<ScreenRotationAnimation> old_layer_screen_rotation =
348 base::MakeUnique<ScreenRotationAnimation>( 335 base::MakeUnique<ScreenRotationAnimation>(
349 old_root_layer, old_layer_initial_rotation_degrees * rotation_factor, 336 old_root_layer, old_layer_initial_rotation_degrees * rotation_factor,
350 (old_layer_initial_rotation_degrees - kRotationDegrees) * 337 (old_layer_initial_rotation_degrees - kRotationDegrees) *
351 rotation_factor, 338 rotation_factor,
352 old_root_layer->opacity(), 0.0f /* target_opacity */, pivot, duration, 339 old_root_layer->opacity(), 0.0f /* target_opacity */, pivot, duration,
353 tween_type); 340 tween_type);
354 341
355 ui::LayerAnimator* animator = old_root_layer->GetAnimator(); 342 ui::LayerAnimator* old_layer_animator = old_root_layer->GetAnimator();
356 animator->set_preemption_strategy( 343 old_layer_animator->set_preemption_strategy(
357 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 344 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
358 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 345 std::unique_ptr<ui::LayerAnimationSequence> old_layer_animation_sequence =
359 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 346 base::MakeUnique<ui::LayerAnimationSequence>(
347 std::move(old_layer_screen_rotation));
360 // Add an observer so that the cloned layers can be cleaned up with the 348 // Add an observer so that the cloned layers can be cleaned up with the
361 // animation completes/aborts. 349 // animation completes/aborts.
362 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); 350 old_layer_animation_sequence->AddObserver(
351 old_layer_cleanup_observer.release());
363 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to 352 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to
364 // control the animation. 353 // control the animation.
365 if (disable_animation_timers_for_test_) 354 if (disable_animation_timers_for_test_)
366 animator->set_disable_timer_for_test(true); 355 old_layer_animator->set_disable_timer_for_test(true);
367 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get()); 356 old_layer_animation_sequence->SetAnimationMetricsReporter(
368 animator->StartAnimation(animation_sequence.release()); 357 metrics_reporter_.get());
358 old_layer_animator->StartAnimation(old_layer_animation_sequence.release());
369 359
370 rotation_request.reset(); 360 rotation_request.reset();
371 } 361 }
372 362
373 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 363 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
374 display::Display::RotationSource source) { 364 display::Display::RotationSource source) {
375 if (GetCurrentScreenRotation(display_id_) == new_rotation) 365 if (GetCurrentScreenRotation(display_id_) == new_rotation)
376 return; 366 return;
377 367
378 std::unique_ptr<ScreenRotationRequest> rotation_request = 368 std::unique_ptr<ScreenRotationRequest> rotation_request =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 for (auto& observer : screen_rotation_animator_observers_) 404 for (auto& observer : screen_rotation_animator_observers_)
415 observer.OnScreenRotationAnimationFinished(this); 405 observer.OnScreenRotationAnimationFinished(this);
416 } 406 }
417 407
418 void ScreenRotationAnimator::set_disable_animation_timers_for_test( 408 void ScreenRotationAnimator::set_disable_animation_timers_for_test(
419 bool disable_timers) { 409 bool disable_timers) {
420 disable_animation_timers_for_test_ = disable_timers; 410 disable_animation_timers_for_test_ = disable_timers;
421 } 411 }
422 412
423 void ScreenRotationAnimator::StopAnimating() { 413 void ScreenRotationAnimator::StopAnimating() {
424 aura::Window* root_window = GetRootWindow(display_id_); 414 GetRootWindow(display_id_)
425 for (ui::Layer* child_layer : root_window->layer()->children()) { 415 ->GetChildById(kShellWindowId_ScreenRotationContainer)
426 if (child_layer == old_layer_tree_owner_->root()) 416 ->layer()
427 continue; 417 ->GetAnimator()
428 418 ->StopAnimating();
429 child_layer->GetAnimator()->StopAnimating(); 419 if (old_layer_tree_owner_)
430 } 420 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
431
432 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
433 } 421 }
434 422
435 } // namespace ash 423 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698