| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 // The time it takes for the rotation animations to run. | 61 // The time it takes for the rotation animations to run. |
| 62 const int kRotationDurationInMs = 250; | 62 const int kRotationDurationInMs = 250; |
| 63 | 63 |
| 64 // Gets the current display rotation for the display with the specified | 64 // Gets the current display rotation for the display with the specified |
| 65 // |display_id|. | 65 // |display_id|. |
| 66 gfx::Display::Rotation GetCurrentRotation(int64 display_id) { | 66 gfx::Display::Rotation GetCurrentRotation(int64 display_id) { |
| 67 return Shell::GetInstance() | 67 return Shell::GetInstance() |
| 68 ->display_manager() | 68 ->display_manager() |
| 69 ->GetDisplayInfo(display_id) | 69 ->GetDisplayInfo(display_id) |
| 70 .rotation(); | 70 .GetActiveRotation(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Returns true if the rotation between |initial_rotation| and |new_rotation| is | 73 // Returns true if the rotation between |initial_rotation| and |new_rotation| is |
| 74 // 180 degrees. | 74 // 180 degrees. |
| 75 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation, | 75 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation, |
| 76 gfx::Display::Rotation new_rotation) { | 76 gfx::Display::Rotation new_rotation) { |
| 77 return (initial_rotation + 2) % 4 == new_rotation; | 77 return (initial_rotation + 2) % 4 == new_rotation; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when | 80 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void LayerCleanupObserver::OnDetachedFromSequence( | 147 void LayerCleanupObserver::OnDetachedFromSequence( |
| 148 ui::LayerAnimationSequence* sequence) { | 148 ui::LayerAnimationSequence* sequence) { |
| 149 DCHECK_EQ(sequence, sequence_); | 149 DCHECK_EQ(sequence, sequence_); |
| 150 sequence_ = nullptr; | 150 sequence_ = nullptr; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Set the screen orientation for the given |display| to |new_rotation| and | 153 // Set the screen orientation for the given |display| to |new_rotation| and |
| 154 // animate the change. | 154 // animate the change. |
| 155 void RotateScreen(int64 display_id, | 155 void RotateScreen(int64 display_id, |
| 156 gfx::Display::Rotation new_rotation, | 156 gfx::Display::Rotation new_rotation, |
| 157 gfx::Display::RotationSource source, |
| 157 base::TimeDelta duration, | 158 base::TimeDelta duration, |
| 158 int rotation_degrees, | 159 int rotation_degrees, |
| 159 int rotation_degree_offset, | 160 int rotation_degree_offset, |
| 160 gfx::Tween::Type tween_type, | 161 gfx::Tween::Type tween_type, |
| 161 bool should_scale) { | 162 bool should_scale) { |
| 162 aura::Window* root_window = | 163 aura::Window* root_window = |
| 163 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( | 164 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( |
| 164 display_id); | 165 display_id); |
| 165 | 166 |
| 166 const gfx::Display::Rotation initial_orientation = | 167 const gfx::Display::Rotation initial_orientation = |
| 167 GetCurrentRotation(display_id); | 168 GetCurrentRotation(display_id); |
| 168 | 169 |
| 169 const gfx::RectF original_screen_bounds = root_window->GetTargetBounds(); | 170 const gfx::RectF original_screen_bounds = root_window->GetTargetBounds(); |
| 170 // 180 degree rotations should animate clock-wise. | 171 // 180 degree rotations should animate clock-wise. |
| 171 const int rotation_factor = | 172 const int rotation_factor = |
| 172 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1; | 173 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1; |
| 173 | 174 |
| 174 scoped_ptr<ui::LayerTreeOwner> old_layer_tree = | 175 scoped_ptr<ui::LayerTreeOwner> old_layer_tree = |
| 175 wm::RecreateLayers(root_window); | 176 wm::RecreateLayers(root_window); |
| 176 | 177 |
| 177 // Add the cloned layer tree in to the root, so it will be rendered. | 178 // Add the cloned layer tree in to the root, so it will be rendered. |
| 178 root_window->layer()->Add(old_layer_tree->root()); | 179 root_window->layer()->Add(old_layer_tree->root()); |
| 179 root_window->layer()->StackAtTop(old_layer_tree->root()); | 180 root_window->layer()->StackAtTop(old_layer_tree->root()); |
| 180 | 181 |
| 181 scoped_ptr<LayerCleanupObserver> layer_cleanup_observer( | 182 scoped_ptr<LayerCleanupObserver> layer_cleanup_observer( |
| 182 new LayerCleanupObserver(old_layer_tree.Pass())); | 183 new LayerCleanupObserver(old_layer_tree.Pass())); |
| 183 | 184 |
| 184 Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id, | 185 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
| 185 new_rotation); | 186 display_id, new_rotation, source); |
| 186 | 187 |
| 187 const gfx::RectF rotated_screen_bounds = root_window->GetTargetBounds(); | 188 const gfx::RectF rotated_screen_bounds = root_window->GetTargetBounds(); |
| 188 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, | 189 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, |
| 189 rotated_screen_bounds.height() / 2); | 190 rotated_screen_bounds.height() / 2); |
| 190 | 191 |
| 191 gfx::Point3F new_layer_initial_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); | 192 gfx::Point3F new_layer_initial_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); |
| 192 gfx::Point3F old_layer_target_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); | 193 gfx::Point3F old_layer_target_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); |
| 193 | 194 |
| 194 if (should_scale) { | 195 if (should_scale) { |
| 195 new_layer_initial_scale = gfx::Point3F( | 196 new_layer_initial_scale = gfx::Point3F( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 261 |
| 261 } // namespace | 262 } // namespace |
| 262 | 263 |
| 263 ScreenRotationAnimator::ScreenRotationAnimator(int64 display_id) | 264 ScreenRotationAnimator::ScreenRotationAnimator(int64 display_id) |
| 264 : display_id_(display_id) { | 265 : display_id_(display_id) { |
| 265 } | 266 } |
| 266 | 267 |
| 267 ScreenRotationAnimator::~ScreenRotationAnimator() { | 268 ScreenRotationAnimator::~ScreenRotationAnimator() { |
| 268 } | 269 } |
| 269 | 270 |
| 270 void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) { | 271 void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation, |
| 272 gfx::Display::RotationSource source) { |
| 271 const gfx::Display::Rotation current_rotation = | 273 const gfx::Display::Rotation current_rotation = |
| 272 GetCurrentRotation(display_id_); | 274 GetCurrentRotation(display_id_); |
| 273 | 275 |
| 274 if (current_rotation == new_rotation) | 276 if (current_rotation == new_rotation) |
| 275 return; | 277 return; |
| 276 | 278 |
| 277 const std::string switch_value = | 279 const std::string switch_value = |
| 278 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 280 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 279 switches::kAshEnableScreenRotationAnimation); | 281 switches::kAshEnableScreenRotationAnimation); |
| 280 | 282 |
| 281 if (switch_value == kRotationAnimation_None) { | 283 if (switch_value == kRotationAnimation_None) { |
| 282 Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id_, | 284 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
| 283 new_rotation); | 285 display_id_, new_rotation, source); |
| 284 } else if (kRotationAnimation_Default == switch_value || | 286 } else if (kRotationAnimation_Default == switch_value || |
| 285 kRotationAnimation_Partial == switch_value) { | 287 kRotationAnimation_Partial == switch_value) { |
| 286 const int rotation_degree_offset = | 288 const int rotation_degree_offset = |
| 287 Is180DegreeFlip(current_rotation, new_rotation) | 289 Is180DegreeFlip(current_rotation, new_rotation) |
| 288 ? 180 - kPartialRotationDegrees | 290 ? 180 - kPartialRotationDegrees |
| 289 : 90 - kPartialRotationDegrees; | 291 : 90 - kPartialRotationDegrees; |
| 290 | 292 |
| 291 RotateScreen(display_id_, new_rotation, | 293 RotateScreen(display_id_, new_rotation, source, |
| 292 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), | 294 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), |
| 293 kPartialRotationDegrees, rotation_degree_offset, | 295 kPartialRotationDegrees, rotation_degree_offset, |
| 294 gfx::Tween::FAST_OUT_LINEAR_IN, false /* should_scale */); | 296 gfx::Tween::FAST_OUT_LINEAR_IN, false /* should_scale */); |
| 295 } else if (kRotationAnimation_Full == switch_value) { | 297 } else if (kRotationAnimation_Full == switch_value) { |
| 296 const int rotation_degrees = | 298 const int rotation_degrees = |
| 297 Is180DegreeFlip(current_rotation, new_rotation) ? 180 : 90; | 299 Is180DegreeFlip(current_rotation, new_rotation) ? 180 : 90; |
| 298 | 300 |
| 299 RotateScreen(display_id_, new_rotation, | 301 RotateScreen(display_id_, new_rotation, source, |
| 300 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), | 302 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), |
| 301 rotation_degrees, 0 /* rotation_degree_offset */, | 303 rotation_degrees, 0 /* rotation_degree_offset */, |
| 302 gfx::Tween::FAST_OUT_LINEAR_IN, true /* should_scale */); | 304 gfx::Tween::FAST_OUT_LINEAR_IN, true /* should_scale */); |
| 303 } else { | 305 } else { |
| 304 NOTREACHED(); | 306 NOTREACHED(); |
| 305 } | 307 } |
| 306 } | 308 } |
| 307 | 309 |
| 308 } // namespace ash | 310 } // namespace ash |
| OLD | NEW |