| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/display/display_configuration_controller.h" | 5 #include "ash/display/display_configuration_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_animator.h" | 7 #include "ash/display/display_animator.h" |
| 8 #include "ash/display/display_animator_chromeos.h" | 8 #include "ash/display/display_animator_chromeos.h" |
| 9 #include "ash/display/display_util.h" | 9 #include "ash/display/display_util.h" |
| 10 #include "ash/rotator/screen_rotation_animator.h" | 10 #include "ash/rotator/screen_rotation_animator.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 weak_ptr_factory_.GetWeakPtr(), mirror)); | 97 weak_ptr_factory_.GetWeakPtr(), mirror)); |
| 98 } else { | 98 } else { |
| 99 SetMirrorModeImpl(mirror); | 99 SetMirrorModeImpl(mirror); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void DisplayConfigurationController::SetDisplayRotation( | 103 void DisplayConfigurationController::SetDisplayRotation( |
| 104 int64_t display_id, | 104 int64_t display_id, |
| 105 display::Display::Rotation rotation, | 105 display::Display::Rotation rotation, |
| 106 display::Display::RotationSource source) { | 106 display::Display::RotationSource source) { |
| 107 ash::ScreenRotationAnimator screen_rotation_animator(display_id); | 107 if (GetCurrentScreenRotation(display_id) == rotation) |
| 108 if (screen_rotation_animator.CanAnimate()) | 108 return; |
| 109 screen_rotation_animator.Rotate(rotation, source); | 109 |
| 110 else | 110 if (CanAnimateScreenRotation(display_id)) { |
| 111 ScreenRotationAnimator* screen_rotation_animator = |
| 112 GetScreenRotationAnimatorForDisplay(display_id); |
| 113 screen_rotation_animator->Rotate(rotation, source); |
| 114 } else { |
| 115 DCHECK(!rotation_animator_map_.count(display_id)); |
| 111 display_manager_->SetDisplayRotation(display_id, rotation, source); | 116 display_manager_->SetDisplayRotation(display_id, rotation, source); |
| 117 } |
| 112 } | 118 } |
| 113 | 119 |
| 114 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, | 120 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, |
| 115 bool user_action) { | 121 bool user_action) { |
| 116 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 122 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
| 117 return; | 123 return; |
| 118 | 124 |
| 119 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 125 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
| 120 if (user_action && display_animator_) { | 126 if (user_action && display_animator_) { |
| 121 display_animator_->StartFadeOutAnimation( | 127 display_animator_->StartFadeOutAnimation( |
| 122 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, | 128 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, |
| 123 weak_ptr_factory_.GetWeakPtr(), display_id)); | 129 weak_ptr_factory_.GetWeakPtr(), display_id)); |
| 124 } else { | 130 } else { |
| 125 SetPrimaryDisplayIdImpl(display_id); | 131 SetPrimaryDisplayIdImpl(display_id); |
| 126 } | 132 } |
| 127 } | 133 } |
| 128 | 134 |
| 129 void DisplayConfigurationController::OnDisplayConfigurationChanged() { | 135 void DisplayConfigurationController::OnDisplayConfigurationChanged() { |
| 130 // TODO(oshima): Stop all animations. | 136 // TODO(oshima): Stop all animations. |
| 131 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 137 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 132 } | 138 } |
| 133 | 139 |
| 140 void DisplayConfigurationController::OnEndedOrAbortedScreenRotationAnimation( |
| 141 ScreenRotationAnimator* screen_rotation_animator) { |
| 142 const int64_t display_id = screen_rotation_animator->display_id(); |
| 143 |
| 144 DCHECK(rotation_animator_map_.count(display_id)); |
| 145 |
| 146 screen_rotation_animator->RemoveScreenRotationAnimatorObserver(); |
| 147 rotation_animator_map_.erase(screen_rotation_animator->display_id()); |
| 148 } |
| 149 |
| 134 // Protected | 150 // Protected |
| 135 | 151 |
| 136 void DisplayConfigurationController::ResetAnimatorForTest() { | 152 void DisplayConfigurationController::ResetAnimatorForTest() { |
| 137 if (!display_animator_) | 153 if (!display_animator_) |
| 138 return; | 154 return; |
| 139 display_animator_.reset(); | 155 display_animator_.reset(); |
| 140 } | 156 } |
| 141 | 157 |
| 142 // Private | 158 // Private |
| 143 | 159 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 163 display_animator_->StartFadeInAnimation(); | 179 display_animator_->StartFadeInAnimation(); |
| 164 } | 180 } |
| 165 | 181 |
| 166 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( | 182 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( |
| 167 int64_t display_id) { | 183 int64_t display_id) { |
| 168 window_tree_host_manager_->SetPrimaryDisplayId(display_id); | 184 window_tree_host_manager_->SetPrimaryDisplayId(display_id); |
| 169 if (display_animator_) | 185 if (display_animator_) |
| 170 display_animator_->StartFadeInAnimation(); | 186 display_animator_->StartFadeInAnimation(); |
| 171 } | 187 } |
| 172 | 188 |
| 189 bool DisplayConfigurationController::CanAnimateScreenRotation( |
| 190 int64_t display_id) const { |
| 191 return display_manager_->GetDisplayForId(display_id).is_valid(); |
| 192 } |
| 193 |
| 194 display::Display::Rotation |
| 195 DisplayConfigurationController::GetCurrentScreenRotation( |
| 196 int64_t display_id) const { |
| 197 return display_manager_->GetDisplayInfo(display_id).GetActiveRotation(); |
| 198 } |
| 199 |
| 200 ScreenRotationAnimator* |
| 201 DisplayConfigurationController::GetScreenRotationAnimatorForDisplay( |
| 202 int64_t display_id) { |
| 203 auto iter = rotation_animator_map_.find(display_id); |
| 204 if (iter != rotation_animator_map_.end()) |
| 205 return iter->second.get(); |
| 206 |
| 207 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); |
| 208 animator->SetScreenRotationAnimatorObserver(this); |
| 209 ScreenRotationAnimator* result = animator.get(); |
| 210 rotation_animator_map_.insert( |
| 211 std::make_pair(display_id, std::move(animator))); |
| 212 return result; |
| 213 } |
| 214 |
| 173 } // namespace ash | 215 } // namespace ash |
| OLD | NEW |