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 13 matching lines...) Expand all Loading... |
24 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| | 24 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| |
25 // when the display change happens, so the actual timeout is much shorter. | 25 // when the display change happens, so the actual timeout is much shorter. |
26 const int64_t kAfterDisplayChangeThrottleTimeoutMs = 500; | 26 const int64_t kAfterDisplayChangeThrottleTimeoutMs = 500; |
27 const int64_t kCycleDisplayThrottleTimeoutMs = 4000; | 27 const int64_t kCycleDisplayThrottleTimeoutMs = 4000; |
28 const int64_t kSetPrimaryDisplayThrottleTimeoutMs = 500; | 28 const int64_t kSetPrimaryDisplayThrottleTimeoutMs = 500; |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 namespace ash { | 32 namespace ash { |
33 | 33 |
| 34 namespace { |
| 35 |
| 36 bool CanAnimate(ScreenRotationAnimator* animator) { |
| 37 return animator && animator->CanAnimate(); |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
34 class DisplayConfigurationController::DisplayChangeLimiter { | 42 class DisplayConfigurationController::DisplayChangeLimiter { |
35 public: | 43 public: |
36 DisplayChangeLimiter() : throttle_timeout_(base::Time::Now()) {} | 44 DisplayChangeLimiter() : throttle_timeout_(base::Time::Now()) {} |
37 | 45 |
38 void SetThrottleTimeout(int64_t throttle_ms) { | 46 void SetThrottleTimeout(int64_t throttle_ms) { |
39 throttle_timeout_ = | 47 throttle_timeout_ = |
40 base::Time::Now() + base::TimeDelta::FromMilliseconds(throttle_ms); | 48 base::Time::Now() + base::TimeDelta::FromMilliseconds(throttle_ms); |
41 } | 49 } |
42 | 50 |
43 bool IsThrottled() const { return base::Time::Now() < throttle_timeout_; } | 51 bool IsThrottled() const { return base::Time::Now() < throttle_timeout_; } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 105 } |
98 | 106 |
99 void DisplayConfigurationController::SetDisplayRotation( | 107 void DisplayConfigurationController::SetDisplayRotation( |
100 int64_t display_id, | 108 int64_t display_id, |
101 display::Display::Rotation rotation, | 109 display::Display::Rotation rotation, |
102 display::Display::RotationSource source) { | 110 display::Display::RotationSource source) { |
103 if (display_manager_->GetDisplayInfo(display_id).GetActiveRotation() == | 111 if (display_manager_->GetDisplayInfo(display_id).GetActiveRotation() == |
104 rotation) | 112 rotation) |
105 return; | 113 return; |
106 | 114 |
| 115 ScreenRotationAnimator* screen_rotation_animator = nullptr; |
107 if (display_manager_->IsDisplayIdValid(display_id)) { | 116 if (display_manager_->IsDisplayIdValid(display_id)) { |
108 ScreenRotationAnimator* screen_rotation_animator = | 117 screen_rotation_animator = GetScreenRotationAnimatorForDisplay(display_id); |
109 GetScreenRotationAnimatorForDisplay(display_id); | 118 } |
| 119 if (CanAnimate(screen_rotation_animator)) { |
110 screen_rotation_animator->Rotate(rotation, source); | 120 screen_rotation_animator->Rotate(rotation, source); |
111 } else { | 121 } else { |
112 DCHECK(!rotation_animator_map_.count(display_id)); | |
113 display_manager_->SetDisplayRotation(display_id, rotation, source); | 122 display_manager_->SetDisplayRotation(display_id, rotation, source); |
114 } | 123 } |
115 } | 124 } |
116 | 125 |
117 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { | 126 void DisplayConfigurationController::SetPrimaryDisplayId(int64_t display_id) { |
118 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) | 127 if (display_manager_->GetNumDisplays() <= 1 || IsLimited()) |
119 return; | 128 return; |
120 | 129 |
121 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); | 130 SetThrottleTimeout(kSetPrimaryDisplayThrottleTimeoutMs); |
122 if (display_animator_) { | 131 if (display_animator_) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return iter->second.get(); | 189 return iter->second.get(); |
181 | 190 |
182 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); | 191 auto animator = base::MakeUnique<ScreenRotationAnimator>(display_id); |
183 ScreenRotationAnimator* result = animator.get(); | 192 ScreenRotationAnimator* result = animator.get(); |
184 rotation_animator_map_.insert( | 193 rotation_animator_map_.insert( |
185 std::make_pair(display_id, std::move(animator))); | 194 std::make_pair(display_id, std::move(animator))); |
186 return result; | 195 return result; |
187 } | 196 } |
188 | 197 |
189 } // namespace ash | 198 } // namespace ash |
OLD | NEW |