OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/display/chromeos/update_display_configuration_task.h" | 5 #include "ui/display/chromeos/update_display_configuration_task.h" |
6 | 6 |
7 #include "ui/display/chromeos/configure_displays_task.h" | 7 #include "ui/display/chromeos/configure_displays_task.h" |
8 #include "ui/display/chromeos/display_layout_manager.h" | 8 #include "ui/display/chromeos/display_layout_manager.h" |
9 #include "ui/display/chromeos/display_util.h" | 9 #include "ui/display/chromeos/display_util.h" |
10 #include "ui/display/types/display_snapshot.h" | 10 #include "ui/display/types/display_snapshot.h" |
11 #include "ui/display/types/native_display_delegate.h" | 11 #include "ui/display/types/native_display_delegate.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 UpdateDisplayConfigurationTask::UpdateDisplayConfigurationTask( | 15 UpdateDisplayConfigurationTask::UpdateDisplayConfigurationTask( |
16 NativeDisplayDelegate* delegate, | 16 NativeDisplayDelegate* delegate, |
17 DisplayLayoutManager* layout_manager, | 17 DisplayLayoutManager* layout_manager, |
18 MultipleDisplayState new_display_state, | 18 MultipleDisplayState new_display_state, |
19 chromeos::DisplayPowerState new_power_state, | 19 chromeos::DisplayPowerState new_power_state, |
20 int power_flags, | 20 int power_flags, |
21 uint32_t background_color_argb, | 21 uint32_t background_color_argb, |
22 bool force_configure, | 22 bool force_configure, |
| 23 bool configure_cached_displays, |
23 const ResponseCallback& callback) | 24 const ResponseCallback& callback) |
24 : delegate_(delegate), | 25 : delegate_(delegate), |
25 layout_manager_(layout_manager), | 26 layout_manager_(layout_manager), |
26 new_display_state_(new_display_state), | 27 new_display_state_(new_display_state), |
27 new_power_state_(new_power_state), | 28 new_power_state_(new_power_state), |
28 power_flags_(power_flags), | 29 power_flags_(power_flags), |
29 background_color_argb_(background_color_argb), | 30 background_color_argb_(background_color_argb), |
30 force_configure_(force_configure), | 31 force_configure_(force_configure), |
| 32 configure_cached_displays_(configure_cached_displays), |
31 callback_(callback), | 33 callback_(callback), |
32 force_dpms_(false), | 34 force_dpms_(false), |
33 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
34 delegate_->GrabServer(); | 36 delegate_->GrabServer(); |
35 } | 37 } |
36 | 38 |
37 UpdateDisplayConfigurationTask::~UpdateDisplayConfigurationTask() { | 39 UpdateDisplayConfigurationTask::~UpdateDisplayConfigurationTask() { |
38 delegate_->UngrabServer(); | 40 delegate_->UngrabServer(); |
39 } | 41 } |
40 | 42 |
| 43 void DoNothing(ConfigureDisplaysTask::Status status) { |
| 44 } |
| 45 |
41 void UpdateDisplayConfigurationTask::Run() { | 46 void UpdateDisplayConfigurationTask::Run() { |
| 47 // In the default case where the displays haven't changed, try to configure |
| 48 // without probing the display devices to speed things up. |
| 49 if (configure_cached_displays_) |
| 50 delegate_->GetCachedDisplays( |
| 51 base::Bind(&UpdateDisplayConfigurationTask::OnCachedDisplaysRetrieved, |
| 52 weak_ptr_factory_.GetWeakPtr())); |
| 53 |
42 delegate_->GetDisplays( | 54 delegate_->GetDisplays( |
43 base::Bind(&UpdateDisplayConfigurationTask::OnDisplaysUpdated, | 55 base::Bind(&UpdateDisplayConfigurationTask::OnDisplaysUpdated, |
44 weak_ptr_factory_.GetWeakPtr())); | 56 weak_ptr_factory_.GetWeakPtr())); |
45 } | 57 } |
46 | 58 |
| 59 void UpdateDisplayConfigurationTask::OnCachedDisplaysRetrieved( |
| 60 const std::vector<DisplaySnapshot*>& displays) { |
| 61 cached_displays_ = displays; |
| 62 |
| 63 if (cached_displays_.size() > 1 && background_color_argb_) |
| 64 delegate_->SetBackgroundColor(background_color_argb_); |
| 65 |
| 66 // If the user hasn't requested a display state, update it using the requested |
| 67 // power state. |
| 68 if (new_display_state_ == MULTIPLE_DISPLAY_STATE_INVALID) |
| 69 new_display_state_ = ChooseDisplayState(); |
| 70 |
| 71 // If there has been any change in the requested power state and the displays |
| 72 // aren't being turned off force a change in DPMS state. |
| 73 force_dpms_ = ShouldForceDpms() && ShouldConfigure(); |
| 74 |
| 75 if (ShouldConfigure()) |
| 76 EnterState(base::Bind(&DoNothing)); |
| 77 } |
| 78 |
47 void UpdateDisplayConfigurationTask::OnDisplaysUpdated( | 79 void UpdateDisplayConfigurationTask::OnDisplaysUpdated( |
48 const std::vector<DisplaySnapshot*>& displays) { | 80 const std::vector<DisplaySnapshot*>& displays) { |
49 cached_displays_ = displays; | 81 cached_displays_ = displays; |
50 | 82 |
51 // Add virtual displays after retrieving the physical displays from the NDD. | 83 // Add virtual displays after retrieving the physical displays from the NDD. |
52 cached_displays_.insert(cached_displays_.end(), | 84 cached_displays_.insert(cached_displays_.end(), |
53 virtual_display_snapshots_.begin(), | 85 virtual_display_snapshots_.begin(), |
54 virtual_display_snapshots_.end()); | 86 virtual_display_snapshots_.end()); |
55 | 87 |
56 if (cached_displays_.size() > 1 && background_color_argb_) | 88 if (cached_displays_.size() > 1 && background_color_argb_) |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 238 |
207 if (num_on_displays >= 3) { | 239 if (num_on_displays >= 3) { |
208 // 3+ displays are always extended | 240 // 3+ displays are always extended |
209 return MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED; | 241 return MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED; |
210 } | 242 } |
211 | 243 |
212 return MULTIPLE_DISPLAY_STATE_INVALID; | 244 return MULTIPLE_DISPLAY_STATE_INVALID; |
213 } | 245 } |
214 | 246 |
215 } // namespace ui | 247 } // namespace ui |
OLD | NEW |