OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 5 #ifndef CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
6 #define CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 6 #define CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/event_types.h" | 11 #include "base/event_types.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "chromeos/chromeos_export.h" | 16 #include "chromeos/chromeos_export.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 | 18 |
18 // Forward declarations for Xlib and Xrandr. | 19 // Forward declarations for Xlib and Xrandr. |
19 // This is so unused X definitions don't pollute the namespace. | 20 // This is so unused X definitions don't pollute the namespace. |
20 typedef unsigned long XID; | 21 typedef unsigned long XID; |
21 typedef XID Window; | 22 typedef XID Window; |
22 typedef XID RROutput; | 23 typedef XID RROutput; |
23 typedef XID RRCrtc; | 24 typedef XID RRCrtc; |
24 typedef XID RRMode; | 25 typedef XID RRMode; |
25 | 26 |
26 struct _XDisplay; | 27 struct _XDisplay; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void Stop(); | 80 void Stop(); |
80 | 81 |
81 // Called when the user hits ctrl-F4 to request a display mode change. | 82 // Called when the user hits ctrl-F4 to request a display mode change. |
82 // This method should only return false if it was called in a single-head or | 83 // This method should only return false if it was called in a single-head or |
83 // headless mode. | 84 // headless mode. |
84 bool CycleDisplayMode(); | 85 bool CycleDisplayMode(); |
85 | 86 |
86 // Called when powerd notifies us that some set of displays should be turned | 87 // Called when powerd notifies us that some set of displays should be turned |
87 // on or off. This requires enabling or disabling the CRTC associated with | 88 // on or off. This requires enabling or disabling the CRTC associated with |
88 // the display(s) in question so that the low power state is engaged. | 89 // the display(s) in question so that the low power state is engaged. |
89 bool ScreenPowerSet(bool power_on, bool all_displays); | 90 // If |force_probe| is true, the displays will be configured even if |
| 91 // |power_state| matches |power_state_|. |
| 92 bool SetDisplayPower(DisplayPowerState power_state, bool force_probe); |
90 | 93 |
91 // Force switching the display mode to |new_state|. This method is used when | 94 // Force switching the display mode to |new_state|. This method is used when |
92 // the user explicitly changes the display mode in the options UI. Returns | 95 // the user explicitly changes the display mode in the options UI. Returns |
93 // false if it was called in a single-head or headless mode. | 96 // false if it was called in a single-head or headless mode. |
94 bool SetDisplayMode(OutputState new_state); | 97 bool SetDisplayMode(OutputState new_state); |
95 | 98 |
96 // Called when an RRNotify event is received. The implementation is | 99 // Called when an RRNotify event is received. The implementation is |
97 // interested in the cases of RRNotify events which correspond to output | 100 // interested in the cases of RRNotify events which correspond to output |
98 // add/remove events. Note that Output add/remove events are sent in response | 101 // add/remove events. Note that Output add/remove events are sent in response |
99 // to our own reconfiguration operations so spurious events are common. | 102 // to our own reconfiguration operations so spurious events are common. |
100 // Spurious events will have no effect. | 103 // Spurious events will have no effect. |
101 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 104 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
102 | 105 |
103 void AddObserver(Observer* observer); | 106 void AddObserver(Observer* observer); |
104 void RemoveObserver(Observer* observer); | 107 void RemoveObserver(Observer* observer); |
105 | 108 |
106 // Tells if the output specified by |name| is for internal display. | 109 // Tells if the output specified by |name| is for internal display. |
107 static bool IsInternalOutputName(const std::string& name); | 110 static bool IsInternalOutputName(const std::string& name); |
108 | 111 |
109 // Set all the displays into pre-suspend mode; usually this means configure | 112 // Sets all the displays into pre-suspend mode; usually this means |
110 // them for their resume state. This allows faster resume on machines where | 113 // configure them for their resume state. This allows faster resume on |
111 // display configuration is slow. | 114 // machines where display configuration is slow. |
112 void SuspendDisplays(); | 115 void SuspendDisplays(); |
113 | 116 |
| 117 // Reprobes displays to handle changes made while the system was |
| 118 // suspended. |
| 119 void ResumeDisplays(); |
| 120 |
114 private: | 121 private: |
115 // Configure outputs. | 122 // Configure outputs. |
116 void ConfigureOutputs(); | 123 void ConfigureOutputs(); |
117 | 124 |
118 // Fires OnDisplayModeChanged() event to the observers. | 125 // Fires OnDisplayModeChanged() event to the observers. |
119 void NotifyOnDisplayChanged(); | 126 void NotifyOnDisplayChanged(); |
120 | 127 |
121 // Returns a vector filled with properties of the first two connected outputs | 128 // Returns a vector filled with properties of the first two connected outputs |
122 // found on |display| and |screen|. | 129 // found on |display| and |screen|. |
123 std::vector<OutputSnapshot> GetDualOutputs(Display* display, | 130 std::vector<OutputSnapshot> GetDualOutputs(Display* display, |
(...skipping 25 matching lines...) Expand all Loading... |
149 // Searches for touchscreens among input devices, | 156 // Searches for touchscreens among input devices, |
150 // and tries to match them up to screens in |outputs|. | 157 // and tries to match them up to screens in |outputs|. |
151 // |display| and |screen| are used to make X calls. | 158 // |display| and |screen| are used to make X calls. |
152 // |outputs| is an array of detected screens. | 159 // |outputs| is an array of detected screens. |
153 // If a touchscreen with same resolution as an output's native mode | 160 // If a touchscreen with same resolution as an output's native mode |
154 // is detected, its id will be stored in this output. | 161 // is detected, its id will be stored in this output. |
155 void GetTouchscreens(Display* display, | 162 void GetTouchscreens(Display* display, |
156 XRRScreenResources* screen, | 163 XRRScreenResources* screen, |
157 std::vector<OutputSnapshot>& outputs); | 164 std::vector<OutputSnapshot>& outputs); |
158 | 165 |
159 // Configures X to the state specified in |new_state|. | 166 // Configures X to the state specified in |output_state| and |
160 // |display|, |screen| and |window| are used to change X configuration. | 167 // |power_state|. |display|, |screen| and |window| are used to change X |
161 // |new_state| is the state to enter. | 168 // configuration. |outputs| contains information on the currently |
162 // |outputs| contains information on the currently configured state, | 169 // configured state, as well as how to apply the new state. |
163 // as well as how to apply the new state. | |
164 bool EnterState(Display* display, | 170 bool EnterState(Display* display, |
165 XRRScreenResources* screen, | 171 XRRScreenResources* screen, |
166 Window window, | 172 Window window, |
167 OutputState new_state, | 173 OutputState output_state, |
| 174 DisplayPowerState power_state, |
168 const std::vector<OutputSnapshot>& outputs); | 175 const std::vector<OutputSnapshot>& outputs); |
169 | 176 |
170 // Outputs UMA metrics of previous state (the state that is being left). | 177 // Outputs UMA metrics of previous state (the state that is being left). |
171 // Updates |mirror_mode_preserved_aspect_| and |last_enter_state_time_|. | 178 // Updates |mirror_mode_preserved_aspect_| and |last_enter_state_time_|. |
172 void RecordPreviousStateUMA(); | 179 void RecordPreviousStateUMA(); |
173 | 180 |
174 // Tells if the output specified by |output_info| is for internal display. | 181 // Tells if the output specified by |output_info| is for internal display. |
175 static bool IsInternalOutput(const XRROutputInfo* output_info); | 182 static bool IsInternalOutput(const XRROutputInfo* output_info); |
176 | 183 |
177 // Returns output's native mode, None if not found. | 184 // Returns output's native mode, None if not found. |
(...skipping 14 matching lines...) Expand all Loading... |
192 int connected_output_count_; | 199 int connected_output_count_; |
193 | 200 |
194 // The base of the event numbers used to represent XRandr events used in | 201 // The base of the event numbers used to represent XRandr events used in |
195 // decoding events regarding output add/remove. | 202 // decoding events regarding output add/remove. |
196 int xrandr_event_base_; | 203 int xrandr_event_base_; |
197 | 204 |
198 // The display state as derived from the outputs observed in |output_cache_|. | 205 // The display state as derived from the outputs observed in |output_cache_|. |
199 // This is used for rotating display modes. | 206 // This is used for rotating display modes. |
200 OutputState output_state_; | 207 OutputState output_state_; |
201 | 208 |
| 209 // The current power state as set via SetDisplayPower(). |
| 210 DisplayPowerState power_state_; |
| 211 |
202 ObserverList<Observer> observers_; | 212 ObserverList<Observer> observers_; |
203 | 213 |
204 // The timer to delay configuring outputs. See also the comments in | 214 // The timer to delay configuring outputs. See also the comments in |
205 // |Dispatch()|. | 215 // |Dispatch()|. |
206 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; | 216 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; |
207 | 217 |
208 // Next 3 members are used for UMA of time spent in various states. | 218 // Next 3 members are used for UMA of time spent in various states. |
209 // Indicates that current OutputSnapshot has aspect preserving mirror mode. | 219 // Indicates that current OutputSnapshot has aspect preserving mirror mode. |
210 bool mirror_mode_will_preserve_aspect_; | 220 bool mirror_mode_will_preserve_aspect_; |
211 | 221 |
212 // Indicates that last entered mirror mode preserved aspect. | 222 // Indicates that last entered mirror mode preserved aspect. |
213 bool mirror_mode_preserved_aspect_; | 223 bool mirror_mode_preserved_aspect_; |
214 | 224 |
215 // Indicates the time at which |output_state_| was entered. | 225 // Indicates the time at which |output_state_| was entered. |
216 base::TimeTicks last_enter_state_time_; | 226 base::TimeTicks last_enter_state_time_; |
217 | 227 |
218 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 228 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
219 }; | 229 }; |
220 | 230 |
221 } // namespace chromeos | 231 } // namespace chromeos |
222 | 232 |
223 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 233 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
OLD | NEW |