Chromium Code Reviews| 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 (CanAnimateScreenRotation(display_id) && |
|
bruthig
2017/03/08 22:35:59
Would it make sense to return early if GetCurrentS
wutao
2017/03/09 22:09:19
I cannot think of a reason why we still need to ca
| |
| 108 if (screen_rotation_animator.CanAnimate()) | 108 GetCurrentScreenRotation(display_id) != rotation) { |
| 109 screen_rotation_animator.Rotate(rotation, source); | 109 ScreenRotationAnimator* screen_rotation_animator = |
| 110 else | 110 GetScreenRotationAnimatorForDisplay(display_id); |
| 111 screen_rotation_animator->Rotate(rotation, source); | |
| 112 } else { | |
| 111 display_manager_->SetDisplayRotation(display_id, rotation, source); | 113 display_manager_->SetDisplayRotation(display_id, rotation, source); |
|
bruthig
2017/03/08 22:35:59
It might be worth having a DCHECK in this else bra
wutao
2017/03/09 22:09:19
Done.
| |
| 114 } | |
| 112 } | 115 } |
| 113 | 116 |
| 114 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, | 117 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, |
| 115 bool user_action) { | 118 bool user_action) { |
| 116 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 119 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
| 117 return; | 120 return; |
| 118 | 121 |
| 119 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 122 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
| 120 if (user_action && display_animator_) { | 123 if (user_action && display_animator_) { |
| 121 display_animator_->StartFadeOutAnimation( | 124 display_animator_->StartFadeOutAnimation( |
| 122 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, | 125 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, |
| 123 weak_ptr_factory_.GetWeakPtr(), display_id)); | 126 weak_ptr_factory_.GetWeakPtr(), display_id)); |
| 124 } else { | 127 } else { |
| 125 SetPrimaryDisplayIdImpl(display_id); | 128 SetPrimaryDisplayIdImpl(display_id); |
| 126 } | 129 } |
| 127 } | 130 } |
| 128 | 131 |
| 129 void DisplayConfigurationController::OnDisplayConfigurationChanged() { | 132 void DisplayConfigurationController::OnDisplayConfigurationChanged() { |
| 130 // TODO(oshima): Stop all animations. | 133 // TODO(oshima): Stop all animations. |
| 131 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 134 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 132 } | 135 } |
| 133 | 136 |
| 137 void DisplayConfigurationController::OnEndedOrAbortedAnimation( | |
| 138 ScreenRotationAnimator* screen_rotation_animator) { | |
| 139 if (!screen_rotation_animator) | |
|
bruthig
2017/03/08 22:35:59
When is it a valid use case that |screen_rotation_
wutao
2017/03/09 22:09:19
DisplayConfigurationController should maintain the
| |
| 140 return; | |
| 141 | |
| 142 const int64_t display_id = screen_rotation_animator->display_id(); | |
| 143 | |
| 144 DCHECK(display_animator_map_.count(display_id)); | |
| 145 | |
| 146 if (screen_rotation_animator->last_pending_request()) { | |
|
bruthig
2017/03/08 22:35:59
I think the it would be better to move the queue o
wutao
2017/03/09 22:09:19
Good suggestion. I will work on it.
bruthig
2017/03/10 22:34:07
Thanks, I think this re-work is a big improvement
| |
| 147 const ScreenRotationAnimator::ScreenRotationRequest pending_request = | |
| 148 *screen_rotation_animator->last_pending_request(); | |
| 149 const display::Display::Rotation new_rotation = | |
| 150 pending_request.new_rotation; | |
| 151 if (GetCurrentScreenRotation(display_id) != new_rotation) { | |
| 152 screen_rotation_animator->Rotate(new_rotation, pending_request.source); | |
| 153 return; | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 screen_rotation_animator->RemoveObserver(); | |
| 158 display_animator_map_.erase(screen_rotation_animator->display_id()); | |
| 159 } | |
| 160 | |
| 134 // Protected | 161 // Protected |
| 135 | 162 |
| 136 void DisplayConfigurationController::ResetAnimatorForTest() { | 163 void DisplayConfigurationController::ResetAnimatorForTest() { |
| 137 if (!display_animator_) | 164 if (!display_animator_) |
| 138 return; | 165 return; |
| 139 display_animator_.reset(); | 166 display_animator_.reset(); |
| 140 } | 167 } |
| 141 | 168 |
| 142 // Private | 169 // Private |
| 143 | 170 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 163 display_animator_->StartFadeInAnimation(); | 190 display_animator_->StartFadeInAnimation(); |
| 164 } | 191 } |
| 165 | 192 |
| 166 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( | 193 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( |
| 167 int64_t display_id) { | 194 int64_t display_id) { |
| 168 window_tree_host_manager_->SetPrimaryDisplayId(display_id); | 195 window_tree_host_manager_->SetPrimaryDisplayId(display_id); |
| 169 if (display_animator_) | 196 if (display_animator_) |
| 170 display_animator_->StartFadeInAnimation(); | 197 display_animator_->StartFadeInAnimation(); |
| 171 } | 198 } |
| 172 | 199 |
| 200 bool DisplayConfigurationController::CanAnimateScreenRotation( | |
| 201 int64_t display_id) const { | |
| 202 return display_manager_->GetDisplayForId(display_id).is_valid(); | |
| 203 } | |
| 204 | |
| 205 display::Display::Rotation | |
| 206 DisplayConfigurationController::GetCurrentScreenRotation( | |
| 207 int64_t display_id) const { | |
| 208 return display_manager_->GetDisplayInfo(display_id).GetActiveRotation(); | |
| 209 } | |
| 210 | |
| 211 ScreenRotationAnimator* | |
| 212 DisplayConfigurationController::GetScreenRotationAnimatorForDisplay( | |
| 213 int64_t display_id) { | |
| 214 auto iter = display_animator_map_.find(display_id); | |
| 215 if (iter != display_animator_map_.end()) | |
| 216 return iter->second.get(); | |
| 217 | |
| 218 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); | |
| 219 animator->SetObserver(this); | |
| 220 ScreenRotationAnimator* result = animator.get(); | |
| 221 display_animator_map_.insert(std::make_pair(display_id, std::move(animator))); | |
| 222 return result; | |
| 223 } | |
| 224 | |
| 173 } // namespace ash | 225 } // namespace ash |
| OLD | NEW |