| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 weak_ptr_factory_.GetWeakPtr(), mirror)); | 93 weak_ptr_factory_.GetWeakPtr(), mirror)); |
| 94 } else { | 94 } else { |
| 95 SetMirrorModeImpl(mirror); | 95 SetMirrorModeImpl(mirror); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DisplayConfigurationController::SetDisplayRotation( | 99 void DisplayConfigurationController::SetDisplayRotation( |
| 100 int64_t display_id, | 100 int64_t display_id, |
| 101 display::Display::Rotation rotation, | 101 display::Display::Rotation rotation, |
| 102 display::Display::RotationSource source) { | 102 display::Display::RotationSource source) { |
| 103 ash::ScreenRotationAnimator screen_rotation_animator(display_id); | 103 if (display_manager_->GetDisplayInfo(display_id).GetActiveRotation() == |
| 104 if (screen_rotation_animator.CanAnimate()) | 104 rotation) |
| 105 screen_rotation_animator.Rotate(rotation, source); | 105 return; |
| 106 else | 106 |
| 107 if (display_manager_->IsDisplayIdValid(display_id)) { |
| 108 ScreenRotationAnimator* screen_rotation_animator = |
| 109 GetScreenRotationAnimatorForDisplay(display_id); |
| 110 screen_rotation_animator->Rotate(rotation, source); |
| 111 } else { |
| 112 DCHECK(!rotation_animator_map_.count(display_id)); |
| 107 display_manager_->SetDisplayRotation(display_id, rotation, source); | 113 display_manager_->SetDisplayRotation(display_id, rotation, source); |
| 114 } |
| 108 } | 115 } |
| 109 | 116 |
| 110 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { | 117 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { |
| 111 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 118 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
| 112 return; | 119 return; |
| 113 | 120 |
| 114 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 121 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
| 115 if (display_animator_) { | 122 if (display_animator_) { |
| 116 display_animator_->StartFadeOutAnimation( | 123 display_animator_->StartFadeOutAnimation( |
| 117 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, | 124 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, |
| 118 weak_ptr_factory_.GetWeakPtr(), display_id)); | 125 weak_ptr_factory_.GetWeakPtr(), display_id)); |
| 119 } else { | 126 } else { |
| 120 SetPrimaryDisplayIdImpl(display_id); | 127 SetPrimaryDisplayIdImpl(display_id); |
| 121 } | 128 } |
| 122 } | 129 } |
| 123 | 130 |
| 124 void DisplayConfigurationController::OnDisplayConfigurationChanged() { | 131 void DisplayConfigurationController::OnDisplayConfigurationChanged() { |
| 125 // TODO(oshima): Stop all animations. | 132 // TODO(oshima): Stop all animations. |
| 126 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 133 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 127 } | 134 } |
| 128 | 135 |
| 136 void DisplayConfigurationController::OnScreenRotationAnimationFinished( |
| 137 ScreenRotationAnimator* screen_rotation_animator) { |
| 138 const int64_t display_id = screen_rotation_animator->display_id(); |
| 139 |
| 140 DCHECK(rotation_animator_map_.count(display_id)); |
| 141 |
| 142 screen_rotation_animator->RemoveScreenRotationAnimatorObserver(this); |
| 143 rotation_animator_map_.erase(screen_rotation_animator->display_id()); |
| 144 } |
| 145 |
| 129 // Protected | 146 // Protected |
| 130 | 147 |
| 131 void DisplayConfigurationController::ResetAnimatorForTest() { | 148 void DisplayConfigurationController::ResetAnimatorForTest() { |
| 132 if (!display_animator_) | 149 if (!display_animator_) |
| 133 return; | 150 return; |
| 134 display_animator_.reset(); | 151 display_animator_.reset(); |
| 135 } | 152 } |
| 136 | 153 |
| 137 // Private | 154 // Private |
| 138 | 155 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 158 display_animator_->StartFadeInAnimation(); | 175 display_animator_->StartFadeInAnimation(); |
| 159 } | 176 } |
| 160 | 177 |
| 161 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( | 178 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( |
| 162 int64_t display_id) { | 179 int64_t display_id) { |
| 163 window_tree_host_manager_->SetPrimaryDisplayId(display_id); | 180 window_tree_host_manager_->SetPrimaryDisplayId(display_id); |
| 164 if (display_animator_) | 181 if (display_animator_) |
| 165 display_animator_->StartFadeInAnimation(); | 182 display_animator_->StartFadeInAnimation(); |
| 166 } | 183 } |
| 167 | 184 |
| 185 ScreenRotationAnimator* |
| 186 DisplayConfigurationController::GetScreenRotationAnimatorForDisplay( |
| 187 int64_t display_id) { |
| 188 auto iter = rotation_animator_map_.find(display_id); |
| 189 if (iter != rotation_animator_map_.end()) |
| 190 return iter->second.get(); |
| 191 |
| 192 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); |
| 193 animator->AddScreenRotationAnimatorObserver(this); |
| 194 ScreenRotationAnimator* result = animator.get(); |
| 195 rotation_animator_map_.insert( |
| 196 std::make_pair(display_id, std::move(animator))); |
| 197 return result; |
| 198 } |
| 199 |
| 168 } // namespace ash | 200 } // namespace ash |
| OLD | NEW |