Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: ui/display/chromeos/display_configurator.cc

Issue 1861593002: chromeos: Turn off displays on suspend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chromeos: Turn off displays on suspend Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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.
941 native_display_delegate_->SyncWithServer();
953 } 942 }
954 943
955 void DisplayConfigurator::ResumeDisplays() { 944 void DisplayConfigurator::ResumeDisplays() {
945 chromeos::DisplayPowerState power_state = chromeos::DISPLAY_POWER_ALL_ON;
946
947 if (requested_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF) {
948 power_state = requested_power_state_;
949 } else if (saved_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF) {
950 power_state = saved_power_state_;
951 }
952
956 displays_suspended_ = false; 953 displays_suspended_ = false;
957 954 SetDisplayPower(power_state, kSetDisplayPowerForceProbe,
958 configure_timer_.Start( 955 base::Bind(&DoNothing));
959 FROM_HERE,
960 base::TimeDelta::FromMilliseconds(kResumeDelayMs),
961 base::Bind(&DisplayConfigurator::RestoreRequestedPowerStateAfterResume,
962 base::Unretained(this)));
marcheu1 2016/04/06 20:21:50 I think this is still needed. The kernel makes no
dbasehore 2016/04/06 20:48:41 We're just doing this in the ResumeDisplays functi
963 } 956 }
964 957
965 void DisplayConfigurator::ConfigureDisplays() { 958 void DisplayConfigurator::ConfigureDisplays() {
966 if (!configure_display_ || display_externally_controlled_) 959 if (!configure_display_ || display_externally_controlled_)
967 return; 960 return;
968 961
969 force_configure_ = true; 962 force_configure_ = true;
970 RunPendingConfiguration(); 963 RunPendingConfiguration();
971 } 964 }
972 965
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 in_progress_configuration_callbacks_.clear(); 1075 in_progress_configuration_callbacks_.clear();
1083 } 1076 }
1084 1077
1085 void DisplayConfigurator::CallAndClearQueuedCallbacks(bool success) { 1078 void DisplayConfigurator::CallAndClearQueuedCallbacks(bool success) {
1086 for (const auto& callback : queued_configuration_callbacks_) 1079 for (const auto& callback : queued_configuration_callbacks_)
1087 callback.Run(success); 1080 callback.Run(success);
1088 1081
1089 queued_configuration_callbacks_.clear(); 1082 queued_configuration_callbacks_.clear();
1090 } 1083 }
1091 1084
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( 1085 void DisplayConfigurator::NotifyDisplayStateObservers(
1100 bool success, 1086 bool success,
1101 MultipleDisplayState attempted_state) { 1087 MultipleDisplayState attempted_state) {
1102 if (success) { 1088 if (success) {
1103 FOR_EACH_OBSERVER( 1089 FOR_EACH_OBSERVER(
1104 Observer, observers_, OnDisplayModeChanged(cached_displays_)); 1090 Observer, observers_, OnDisplayModeChanged(cached_displays_));
1105 } else { 1091 } else {
1106 FOR_EACH_OBSERVER( 1092 FOR_EACH_OBSERVER(
1107 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, 1093 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_,
1108 attempted_state)); 1094 attempted_state));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 last_virtual_display_id_ = max_display_id & 0xff; 1137 last_virtual_display_id_ = max_display_id & 0xff;
1152 1138
1153 return true; 1139 return true;
1154 } 1140 }
1155 1141
1156 bool DisplayConfigurator::IsDisplayOn() const { 1142 bool DisplayConfigurator::IsDisplayOn() const {
1157 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; 1143 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF;
1158 } 1144 }
1159 1145
1160 } // namespace ui 1146 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698