Chromium Code Reviews| 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/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 namespace ui { | 28 namespace ui { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 typedef std::vector<const DisplayMode*> DisplayModeList; | 32 typedef std::vector<const DisplayMode*> DisplayModeList; |
| 33 | 33 |
| 34 // The delay to perform configuration after RRNotify. See the comment for | 34 // The delay to perform configuration after RRNotify. See the comment for |
| 35 // |configure_timer_|. | 35 // |configure_timer_|. |
| 36 const int kConfigureDelayMs = 500; | 36 const int kConfigureDelayMs = 500; |
| 37 | 37 |
| 38 // The delay spent before reading the display configuration after coming out of | |
| 39 // suspend. While coming out of suspend the display state may be updating. This | |
| 40 // is used to wait until the hardware had a chance to update the display state | |
| 41 // such that we read an up to date state. | |
| 42 const int kResumeDelayMs = 500; | |
| 43 | |
| 44 // The EDID specification marks the top bit of the manufacturer id as reserved. | 38 // The EDID specification marks the top bit of the manufacturer id as reserved. |
| 45 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); | 39 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); |
| 46 | 40 |
| 47 struct DisplayState { | 41 struct DisplayState { |
| 48 DisplaySnapshot* display = nullptr; // Not owned. | 42 DisplaySnapshot* display = nullptr; // Not owned. |
| 49 | 43 |
| 50 // User-selected mode for the display. | 44 // User-selected mode for the display. |
| 51 const DisplayMode* selected_mode = nullptr; | 45 const DisplayMode* selected_mode = nullptr; |
| 52 | 46 |
| 53 // Mode used when displaying the same desktop on multiple displays. | 47 // Mode used when displaying the same desktop on multiple displays. |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 | 463 |
| 470 DisplayConfigurator::DisplayConfigurator() | 464 DisplayConfigurator::DisplayConfigurator() |
| 471 : state_controller_(NULL), | 465 : state_controller_(NULL), |
| 472 mirroring_controller_(NULL), | 466 mirroring_controller_(NULL), |
| 473 is_panel_fitting_enabled_(false), | 467 is_panel_fitting_enabled_(false), |
| 474 configure_display_(base::SysInfo::IsRunningOnChromeOS()), | 468 configure_display_(base::SysInfo::IsRunningOnChromeOS()), |
| 475 current_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), | 469 current_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 476 current_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 470 current_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 477 requested_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), | 471 requested_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 478 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 472 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 473 saved_power_state_(chromeos::DISPLAY_POWER_ALL_OFF), | |
| 479 requested_power_state_change_(false), | 474 requested_power_state_change_(false), |
| 480 requested_power_flags_(kSetDisplayPowerNoFlags), | 475 requested_power_flags_(kSetDisplayPowerNoFlags), |
| 481 force_configure_(false), | 476 force_configure_(false), |
| 482 next_display_protection_client_id_(1), | 477 next_display_protection_client_id_(1), |
| 483 display_externally_controlled_(false), | 478 display_externally_controlled_(false), |
| 484 display_control_changing_(false), | 479 display_control_changing_(false), |
| 485 displays_suspended_(false), | 480 displays_suspended_(false), |
| 486 layout_manager_(new DisplayLayoutManagerImpl(this)), | 481 layout_manager_(new DisplayLayoutManagerImpl(this)), |
| 487 weak_ptr_factory_(this) { | 482 weak_ptr_factory_(this) { |
| 488 } | 483 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 void DisplayConfigurator::AddObserver(Observer* observer) { | 916 void DisplayConfigurator::AddObserver(Observer* observer) { |
| 922 observers_.AddObserver(observer); | 917 observers_.AddObserver(observer); |
| 923 } | 918 } |
| 924 | 919 |
| 925 void DisplayConfigurator::RemoveObserver(Observer* observer) { | 920 void DisplayConfigurator::RemoveObserver(Observer* observer) { |
| 926 observers_.RemoveObserver(observer); | 921 observers_.RemoveObserver(observer); |
| 927 } | 922 } |
| 928 | 923 |
| 929 void DisplayConfigurator::SuspendDisplays( | 924 void DisplayConfigurator::SuspendDisplays( |
| 930 const ConfigurationCallback& callback) { | 925 const ConfigurationCallback& callback) { |
| 931 // If the display is off due to user inactivity and there's only a single | |
| 932 // internal display connected, switch to the all-on state before | |
| 933 // suspending. This shouldn't be very noticeable to the user since the | |
| 934 // backlight is off at this point, and doing this lets us resume directly | |
| 935 // into the "on" state, which greatly reduces resume times. | |
| 936 if (requested_power_state_ == chromeos::DISPLAY_POWER_ALL_OFF) { | |
| 937 SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, | |
| 938 kSetDisplayPowerOnlyIfSingleInternalDisplay, callback); | |
| 939 | |
| 940 // We need to make sure that the monitor configuration we just did actually | |
| 941 // completes before we return, because otherwise the X message could be | |
| 942 // racing with the HandleSuspendReadiness message. | |
| 943 native_display_delegate_->SyncWithServer(); | |
| 944 } else { | |
| 945 callback.Run(true); | |
| 946 } | |
| 947 | |
| 948 displays_suspended_ = true; | 926 displays_suspended_ = true; |
| 949 | 927 |
| 950 // Stop |configure_timer_| because we will force probe and configure all the | 928 // Stop |configure_timer_| because we will force probe and configure all the |
| 951 // displays at resume time anyway. | 929 // displays at resume time anyway. |
| 952 configure_timer_.Stop(); | 930 configure_timer_.Stop(); |
| 931 | |
| 932 saved_power_state_ = requested_power_state_; | |
| 933 // Turn off the displays for suspend. This way, if we wake up for lucid sleep, | |
| 934 // the displays will not turn on (all displays should be off for lucid sleep | |
| 935 // unless explicitly requested by lucid sleep code). | |
| 936 SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, kSetDisplayPowerNoFlags, | |
| 937 callback); | |
| 938 | |
| 939 // We need to make sure that the monitor configuration we just did actually | |
| 940 // completes before we return, because otherwise the X message could be | |
|
Eric Caruso
2016/04/05 17:33:36
Aren't we not using X anymore?
dbasehore
2016/04/06 04:40:39
Done.
| |
| 941 // racing with the HandleSuspendReadiness message. | |
| 942 native_display_delegate_->SyncWithServer(); | |
| 953 } | 943 } |
| 954 | 944 |
| 955 void DisplayConfigurator::ResumeDisplays() { | 945 void DisplayConfigurator::ResumeDisplays() { |
| 946 chromeos::DisplayPowerState power_state = requested_power_state_; | |
| 947 | |
| 948 if (power_state == chromeos::DISPLAY_POWER_ALL_OFF) | |
| 949 power_state = saved_power_state_; | |
| 950 | |
| 956 displays_suspended_ = false; | 951 displays_suspended_ = false; |
| 957 | 952 saved_power_state_ = chromeos::DISPLAY_POWER_ALL_OFF; |
|
Daniel Erat
2016/04/05 14:40:03
what's the reason for resetting this here? doesn't
dbasehore
2016/04/06 04:40:39
Done.
| |
| 958 configure_timer_.Start( | 953 if (power_state == chromeos::DISPLAY_POWER_ALL_OFF) |
|
Daniel Erat
2016/04/05 14:40:04
add curly brackets for this if/else
dbasehore
2016/04/06 04:40:39
Done.
| |
| 959 FROM_HERE, | 954 SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
|
Daniel Erat
2016/04/05 14:40:03
what happens if the user sets the brightness to ze
dbasehore
2016/04/06 04:40:40
Don't know how, but it doesn't undo what the user
Daniel Erat
2016/04/06 15:04:19
i'm uneasy not knowing how/why this works. so you'
dbasehore
2016/04/06 20:44:45
This seems to be how it works:
-Backlight set to 0
dbasehore
2016/04/06 20:53:26
When we update the backlight state in powerd, we s
| |
| 960 base::TimeDelta::FromMilliseconds(kResumeDelayMs), | 955 kSetDisplayPowerOnlyIfSingleInternalDisplay, |
|
dnicoara
2016/04/05 16:56:57
I think you still want kSetDisplayPowerForceProbe
dbasehore
2016/04/06 04:40:40
I'm changing how this works for the next version.
| |
| 961 base::Bind(&DisplayConfigurator::RestoreRequestedPowerStateAfterResume, | 956 base::Bind(&DoNothing)); |
| 962 base::Unretained(this))); | 957 else |
| 958 SetDisplayPower(power_state, kSetDisplayPowerForceProbe, | |
| 959 base::Bind(&DoNothing)); | |
| 963 } | 960 } |
| 964 | 961 |
| 965 void DisplayConfigurator::ConfigureDisplays() { | 962 void DisplayConfigurator::ConfigureDisplays() { |
| 966 if (!configure_display_ || display_externally_controlled_) | 963 if (!configure_display_ || display_externally_controlled_) |
| 967 return; | 964 return; |
| 968 | 965 |
| 969 force_configure_ = true; | 966 force_configure_ = true; |
| 970 RunPendingConfiguration(); | 967 RunPendingConfiguration(); |
| 971 } | 968 } |
| 972 | 969 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 in_progress_configuration_callbacks_.clear(); | 1079 in_progress_configuration_callbacks_.clear(); |
| 1083 } | 1080 } |
| 1084 | 1081 |
| 1085 void DisplayConfigurator::CallAndClearQueuedCallbacks(bool success) { | 1082 void DisplayConfigurator::CallAndClearQueuedCallbacks(bool success) { |
| 1086 for (const auto& callback : queued_configuration_callbacks_) | 1083 for (const auto& callback : queued_configuration_callbacks_) |
| 1087 callback.Run(success); | 1084 callback.Run(success); |
| 1088 | 1085 |
| 1089 queued_configuration_callbacks_.clear(); | 1086 queued_configuration_callbacks_.clear(); |
| 1090 } | 1087 } |
| 1091 | 1088 |
| 1092 void DisplayConfigurator::RestoreRequestedPowerStateAfterResume() { | |
| 1093 // Force probing to ensure that we pick up any changes that were made while | |
| 1094 // the system was suspended. | |
| 1095 SetDisplayPower(requested_power_state_, kSetDisplayPowerForceProbe, | |
| 1096 base::Bind(&DoNothing)); | |
| 1097 } | |
| 1098 | |
| 1099 void DisplayConfigurator::NotifyDisplayStateObservers( | 1089 void DisplayConfigurator::NotifyDisplayStateObservers( |
| 1100 bool success, | 1090 bool success, |
| 1101 MultipleDisplayState attempted_state) { | 1091 MultipleDisplayState attempted_state) { |
| 1102 if (success) { | 1092 if (success) { |
| 1103 FOR_EACH_OBSERVER( | 1093 FOR_EACH_OBSERVER( |
| 1104 Observer, observers_, OnDisplayModeChanged(cached_displays_)); | 1094 Observer, observers_, OnDisplayModeChanged(cached_displays_)); |
| 1105 } else { | 1095 } else { |
| 1106 FOR_EACH_OBSERVER( | 1096 FOR_EACH_OBSERVER( |
| 1107 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, | 1097 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, |
| 1108 attempted_state)); | 1098 attempted_state)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 last_virtual_display_id_ = max_display_id & 0xff; | 1141 last_virtual_display_id_ = max_display_id & 0xff; |
| 1152 | 1142 |
| 1153 return true; | 1143 return true; |
| 1154 } | 1144 } |
| 1155 | 1145 |
| 1156 bool DisplayConfigurator::IsDisplayOn() const { | 1146 bool DisplayConfigurator::IsDisplayOn() const { |
| 1157 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; | 1147 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; |
| 1158 } | 1148 } |
| 1159 | 1149 |
| 1160 } // namespace ui | 1150 } // namespace ui |
| OLD | NEW |