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 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 (GetCurrentScreenRotation(display_id) == rotation) |
| 104 if (screen_rotation_animator.CanAnimate()) | 104 return; |
| 105 screen_rotation_animator.Rotate(rotation, source); | 105 |
| 106 else | 106 if (CanAnimateScreenRotation(display_id)) { |
| 107 ScreenRotationAnimator* screen_rotation_animator = | |
| 108 GetScreenRotationAnimatorForDisplay(display_id); | |
| 109 screen_rotation_animator->Rotate(rotation, source); | |
| 110 } else { | |
| 111 DCHECK(!rotation_animator_map_.count(display_id)); | |
| 107 display_manager_->SetDisplayRotation(display_id, rotation, source); | 112 display_manager_->SetDisplayRotation(display_id, rotation, source); |
| 113 } | |
| 108 } | 114 } |
| 109 | 115 |
| 110 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { | 116 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { |
| 111 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 117 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
| 112 return; | 118 return; |
| 113 | 119 |
| 114 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 120 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
| 115 if (display_animator_) { | 121 if (display_animator_) { |
| 116 display_animator_->StartFadeOutAnimation( | 122 display_animator_->StartFadeOutAnimation( |
| 117 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, | 123 base::Bind(&DisplayConfigurationController::SetPrimaryDisplayIdImpl, |
| 118 weak_ptr_factory_.GetWeakPtr(), display_id)); | 124 weak_ptr_factory_.GetWeakPtr(), display_id)); |
| 119 } else { | 125 } else { |
| 120 SetPrimaryDisplayIdImpl(display_id); | 126 SetPrimaryDisplayIdImpl(display_id); |
| 121 } | 127 } |
| 122 } | 128 } |
| 123 | 129 |
| 124 void DisplayConfigurationController::OnDisplayConfigurationChanged() { | 130 void DisplayConfigurationController::OnDisplayConfigurationChanged() { |
| 125 // TODO(oshima): Stop all animations. | 131 // TODO(oshima): Stop all animations. |
| 126 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 132 SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 127 } | 133 } |
| 128 | 134 |
| 135 void DisplayConfigurationController::OnEndedOrAbortedScreenRotationAnimation( | |
| 136 ScreenRotationAnimator* screen_rotation_animator) { | |
| 137 const int64_t display_id = screen_rotation_animator->display_id(); | |
| 138 | |
| 139 DCHECK(rotation_animator_map_.count(display_id)); | |
| 140 | |
| 141 screen_rotation_animator->RemoveScreenRotationAnimatorObserver(); | |
| 142 rotation_animator_map_.erase(screen_rotation_animator->display_id()); | |
| 143 } | |
| 144 | |
| 129 // Protected | 145 // Protected |
| 130 | 146 |
| 131 void DisplayConfigurationController::ResetAnimatorForTest() { | 147 void DisplayConfigurationController::ResetAnimatorForTest() { |
| 132 if (!display_animator_) | 148 if (!display_animator_) |
| 133 return; | 149 return; |
| 134 display_animator_.reset(); | 150 display_animator_.reset(); |
| 135 } | 151 } |
| 136 | 152 |
| 137 // Private | 153 // Private |
| 138 | 154 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 158 display_animator_->StartFadeInAnimation(); | 174 display_animator_->StartFadeInAnimation(); |
| 159 } | 175 } |
| 160 | 176 |
| 161 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( | 177 void DisplayConfigurationController::SetPrimaryDisplayIdImpl( |
| 162 int64_t display_id) { | 178 int64_t display_id) { |
| 163 window_tree_host_manager_->SetPrimaryDisplayId(display_id); | 179 window_tree_host_manager_->SetPrimaryDisplayId(display_id); |
| 164 if (display_animator_) | 180 if (display_animator_) |
| 165 display_animator_->StartFadeInAnimation(); | 181 display_animator_->StartFadeInAnimation(); |
| 166 } | 182 } |
| 167 | 183 |
| 184 bool DisplayConfigurationController::CanAnimateScreenRotation( | |
|
oshima
2017/03/16 20:13:09
instead of defining a method here, can you add IsA
wutao
2017/03/17 00:01:03
Done, name it IsDisplayValid(display_id)
Is there
| |
| 185 int64_t display_id) const { | |
| 186 return display_manager_->GetDisplayForId(display_id).is_valid(); | |
| 187 } | |
| 188 | |
| 189 display::Display::Rotation | |
| 190 DisplayConfigurationController::GetCurrentScreenRotation( | |
| 191 int64_t display_id) const { | |
| 192 return display_manager_->GetDisplayInfo(display_id).GetActiveRotation(); | |
|
oshima
2017/03/16 20:13:09
inline this
wutao
2017/03/17 00:01:03
Done.
| |
| 193 } | |
| 194 | |
| 195 ScreenRotationAnimator* | |
| 196 DisplayConfigurationController::GetScreenRotationAnimatorForDisplay( | |
| 197 int64_t display_id) { | |
| 198 auto iter = rotation_animator_map_.find(display_id); | |
| 199 if (iter != rotation_animator_map_.end()) | |
| 200 return iter->second.get(); | |
| 201 | |
| 202 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); | |
| 203 animator->SetScreenRotationAnimatorObserver(this); | |
| 204 ScreenRotationAnimator* result = animator.get(); | |
| 205 rotation_animator_map_.insert( | |
| 206 std::make_pair(display_id, std::move(animator))); | |
| 207 return result; | |
| 208 } | |
| 209 | |
| 168 } // namespace ash | 210 } // namespace ash |
| OLD | NEW |