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/common/strings/grit/ash_strings.h" | 7 #include "ash/common/strings/grit/ash_strings.h" |
| 8 #include "ash/display/display_animator.h" | 8 #include "ash/display/display_animator.h" |
| 9 #include "ash/display/display_animator_chromeos.h" | 9 #include "ash/display/display_animator_chromeos.h" |
| 10 #include "ash/display/display_util.h" | 10 #include "ash/display/display_util.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 (CanAnimate(display_id) && GetCurrentRotation(display_id) != rotation) { |
| 108 if (screen_rotation_animator.CanAnimate()) | 108 ScreenRotationAnimator* screen_rotation_animator = |
| 109 screen_rotation_animator.Rotate(rotation, source); | 109 GetOrMakeAnimatorByDisplayId(display_id); |
| 110 else | 110 screen_rotation_animator->Rotate(rotation, source); |
|
afakhry
2017/03/02 19:47:55
Do you need to check screen_rotation_animator->Can
wutao
2017/03/03 02:45:52
The consideration here is that, if we do not check
| |
| 111 } else { | |
| 111 display_manager_->SetDisplayRotation(display_id, rotation, source); | 112 display_manager_->SetDisplayRotation(display_id, rotation, source); |
| 113 } | |
| 112 } | 114 } |
| 113 | 115 |
| 114 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, | 116 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id, |
| 115 bool user_action) { | 117 bool user_action) { |
| 116 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 118 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
| 117 return; | 119 return; |
| 118 | 120 |
| 119 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 121 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
| 120 if (user_action && display_animator_) { | 122 if (user_action && display_animator_) { |
| 121 display_animator_->StartFadeOutAnimation( | 123 display_animator_->StartFadeOutAnimation( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 display_animator_->StartFadeInAnimation(); | 165 display_animator_->StartFadeInAnimation(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( | 168 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( |
| 167 int64_t display_id) { | 169 int64_t display_id) { |
| 168 window_tree_host_manager_->SetPrimaryDisplayId(display_id); | 170 window_tree_host_manager_->SetPrimaryDisplayId(display_id); |
| 169 if (display_animator_) | 171 if (display_animator_) |
| 170 display_animator_->StartFadeInAnimation(); | 172 display_animator_->StartFadeInAnimation(); |
| 171 } | 173 } |
| 172 | 174 |
| 175 bool DisplayConfigurationController::CanAnimate(int64_t display_id) const { | |
| 176 return display_manager_->GetDisplayForId(display_id).is_valid(); | |
| 177 } | |
| 178 | |
| 179 display::Display::Rotation DisplayConfigurationController::GetCurrentRotation( | |
| 180 int64_t display_id) const { | |
| 181 return display_manager_->GetDisplayInfo(display_id).GetActiveRotation(); | |
| 182 } | |
| 183 | |
| 184 ScreenRotationAnimator* | |
| 185 DisplayConfigurationController::GetOrMakeAnimatorByDisplayId( | |
| 186 int64_t display_id) { | |
| 187 if (display_animator_map_.find(display_id) == display_animator_map_.end()) { | |
| 188 display_animator_map_[display_id] = | |
| 189 base::MakeUnique<ScreenRotationAnimator>(display_id); | |
| 190 display_animator_map_[display_id]->SetObserver(this); | |
| 191 } | |
| 192 return display_animator_map_[display_id].get(); | |
|
afakhry
2017/03/02 19:47:55
This function has 4 map searches! This is very ine
wutao
2017/03/03 02:45:52
Nice catch! Changed accordingly.
| |
| 193 } | |
| 194 | |
| 195 void DisplayConfigurationController::OnEndedOrAbortedAnimation( | |
| 196 base::WeakPtr<ScreenRotationAnimator> screen_rotation_animator) { | |
| 197 if (!screen_rotation_animator) | |
|
bruthig
2017/03/02 18:25:45
Why do we need to support WeakPtrs here? If the D
wutao
2017/03/03 02:45:52
Right. I will make it a real ptr.
| |
| 198 return; | |
| 199 | |
| 200 DCHECK(display_animator_map_.find(screen_rotation_animator->display_id()) != | |
| 201 display_animator_map_.end()); | |
|
afakhry
2017/03/02 19:47:55
You can replace that with the simpler:
DCHECK(dis
wutao
2017/03/03 02:45:52
Cool! Thanks.
| |
| 202 | |
| 203 screen_rotation_animator->set_is_animating(false); | |
| 204 if (screen_rotation_animator->last_pending_request() && | |
| 205 GetCurrentRotation(screen_rotation_animator->display_id()) != | |
| 206 screen_rotation_animator->last_pending_request()->new_rotation) { | |
| 207 const display::Display::Rotation rotation = | |
| 208 screen_rotation_animator->last_pending_request()->new_rotation; | |
| 209 display::Display::RotationSource source = | |
| 210 screen_rotation_animator->last_pending_request()->source; | |
| 211 screen_rotation_animator->reset_last_pending_request(); | |
| 212 screen_rotation_animator->Rotate(rotation, source); | |
| 213 } else { | |
| 214 screen_rotation_animator->RemoveObserver(); | |
| 215 display_animator_map_.erase(screen_rotation_animator->display_id()); | |
|
afakhry
2017/03/02 19:47:55
Can you minimize the verbosity of this code a bit
wutao
2017/03/03 02:45:52
Done.
| |
| 216 } | |
| 217 } | |
| 218 | |
| 173 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |