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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/event_types.h" | 9 #include "base/event_types.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
13 | 13 |
14 // Forward declarations for Xlib and Xrandr. | 14 // Forward declarations for Xlib and Xrandr. |
15 // This is so unused X definitions don't pollute the namespace. | 15 // This is so unused X definitions don't pollute the namespace. |
16 typedef unsigned long XID; | 16 typedef unsigned long XID; |
17 typedef XID Window; | 17 typedef XID Window; |
18 typedef XID RROutput; | 18 typedef XID RROutput; |
19 typedef XID RRCrtc; | 19 typedef XID RRCrtc; |
20 typedef XID RRMode; | 20 typedef XID RRMode; |
21 | 21 |
22 struct _XRRScreenResources; | 22 struct _XRRScreenResources; |
23 typedef _XRRScreenResources XRRScreenResources; | 23 typedef _XRRScreenResources XRRScreenResources; |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 | 26 |
27 // The information we need to cache from an output to implement operations such | |
28 // as power state but also to eliminate duplicate operations within a given | |
29 // action (determining which CRTC to use for a given output, for example). | |
30 struct CachedOutputDescription { | |
31 RROutput output; | |
32 RRCrtc crtc; | |
33 RRMode mirror_mode; | |
34 RRMode ideal_mode; | |
35 int x; | |
36 int y; | |
37 bool is_connected; | |
38 bool is_powered_on; | |
39 bool is_internal; | |
40 unsigned long mm_width; | |
41 unsigned long mm_height; | |
42 }; | |
43 | |
44 // Used to describe the state of a multi-display configuration. | 27 // Used to describe the state of a multi-display configuration. |
45 enum State { | 28 enum OutputState { |
46 STATE_INVALID, | 29 STATE_INVALID, |
47 STATE_HEADLESS, | 30 STATE_HEADLESS, |
48 STATE_SINGLE, | 31 STATE_SINGLE, |
49 STATE_DUAL_MIRROR, | 32 STATE_DUAL_MIRROR, |
50 STATE_DUAL_PRIMARY_ONLY, | 33 STATE_DUAL_PRIMARY_ONLY, |
51 STATE_DUAL_SECONDARY_ONLY, | 34 STATE_DUAL_SECONDARY_ONLY, |
52 }; | 35 }; |
53 | 36 |
54 // This class interacts directly with the underlying Xrandr API to manipulate | 37 // This class interacts directly with the underlying Xrandr API to manipulate |
55 // CTRCs and Outputs. It will likely grow more state, over time, or expose | 38 // CTRCs and Outputs. It will likely grow more state, over time, or expose |
56 // Output info in other ways as more of the Chrome display code grows up around | 39 // Output info in other ways as more of the Chrome display code grows up around |
57 // it. | 40 // it. |
58 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { | 41 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { |
59 public: | 42 public: |
60 OutputConfigurator(); | 43 OutputConfigurator(); |
61 virtual ~OutputConfigurator(); | 44 virtual ~OutputConfigurator(); |
62 | 45 |
63 State output_state() const { return output_state_; } | 46 OutputState output_state() const { return output_state_; } |
64 | 47 |
65 // Called when the user hits ctrl-F4 to request a display mode change. | 48 // Called when the user hits ctrl-F4 to request a display mode change. |
66 // This method should only return false if it was called in a single-head or | 49 // This method should only return false if it was called in a single-head or |
67 // headless mode. | 50 // headless mode. |
68 bool CycleDisplayMode(bool extended_desktop_enabled); | 51 bool CycleDisplayMode(bool extended_desktop_enabled); |
69 | 52 |
70 // Called when powerd notifies us that some set of displays should be turned | 53 // Called when powerd notifies us that some set of displays should be turned |
71 // on or off. This requires enabling or disabling the CRTC associated with | 54 // on or off. This requires enabling or disabling the CRTC associated with |
72 // the display(s) in question so that the low power state is engaged. | 55 // the display(s) in question so that the low power state is engaged. |
73 bool ScreenPowerSet(bool power_on, bool all_displays); | 56 bool ScreenPowerSet(bool power_on, bool all_displays); |
74 | 57 |
75 // Force switching the display mode to |new_state|. This method is used when | 58 // Force switching the display mode to |new_state|. This method is used when |
76 // the user explicitly changes the display mode in the options UI. Returns | 59 // the user explicitly changes the display mode in the options UI. Returns |
77 // false if it was called in a single-head or headless mode. | 60 // false if it was called in a single-head or headless mode. |
78 bool SetDisplayMode(State new_state); | 61 bool SetDisplayMode(OutputState new_state); |
79 | 62 |
80 // Called when an RRNotify event is received. The implementation is | 63 // Called when an RRNotify event is received. The implementation is |
81 // interested in the cases of RRNotify events which correspond to output | 64 // interested in the cases of RRNotify events which correspond to output |
82 // add/remove events. Note that Output add/remove events are sent in response | 65 // add/remove events. Note that Output add/remove events are sent in response |
83 // to our own reconfiguration operations so spurious events are common. | 66 // to our own reconfiguration operations so spurious events are common. |
84 // Spurious events will have no effect. | 67 // Spurious events will have no effect. |
85 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 68 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
86 | 69 |
87 private: | 70 private: |
| 71 // The information we need to cache from an output to implement operations |
| 72 // such as power state but also to eliminate duplicate operations within a |
| 73 // given action (determining which CRTC to use for a given output, for |
| 74 // example). |
| 75 struct CachedOutputDescription { |
| 76 RROutput output; |
| 77 RRCrtc crtc; |
| 78 RRMode mirror_mode; |
| 79 RRMode ideal_mode; |
| 80 int x; |
| 81 int y; |
| 82 bool is_connected; |
| 83 bool is_powered_on; |
| 84 bool is_internal; |
| 85 unsigned long mm_width; |
| 86 unsigned long mm_height; |
| 87 }; |
| 88 |
88 // Updates |output_count_|, |output_cache_|, |mirror_supported_|, | 89 // Updates |output_count_|, |output_cache_|, |mirror_supported_|, |
89 // |primary_output_index_|, and |secondary_output_index_| with new data. | 90 // |primary_output_index_|, and |secondary_output_index_| with new data. |
90 // Returns true if the update succeeded or false if it was skipped since no | 91 // Returns true if the update succeeded or false if it was skipped since no |
91 // actual change was observed. | 92 // actual change was observed. |
92 // Note that |output_state_| is not updated by this call. | 93 // Note that |output_state_| is not updated by this call. |
93 bool TryRecacheOutputs(Display* display, XRRScreenResources* screen); | 94 bool TryRecacheOutputs(Display* display, XRRScreenResources* screen); |
94 | 95 |
95 // Uses the data stored in |output_cache_| and the given |new_state| to | 96 // Uses the data stored in |output_cache_| and the given |new_state| to |
96 // configure the Xrandr interface and then updates |output_state_| to reflect | 97 // configure the Xrandr interface and then updates |output_state_| to reflect |
97 // the new state. | 98 // the new state. |
98 void UpdateCacheAndXrandrToState(Display* display, | 99 void UpdateCacheAndXrandrToState(Display* display, |
99 XRRScreenResources* screen, | 100 XRRScreenResources* screen, |
100 Window window, | 101 Window window, |
101 State new_state); | 102 OutputState new_state); |
102 | 103 |
103 // A helper to re-cache instance variable state and transition into the | 104 // A helper to re-cache instance variable state and transition into the |
104 // appropriate default state for the observed displays. | 105 // appropriate default state for the observed displays. |
105 bool RecacheAndUseDefaultState(); | 106 bool RecacheAndUseDefaultState(); |
106 | 107 |
107 // Checks the |primary_output_index_|, |secondary_output_index_|, and | 108 // Checks the |primary_output_index_|, |secondary_output_index_|, and |
108 // |mirror_supported_| to see how many displays are currently connected and | 109 // |mirror_supported_| to see how many displays are currently connected and |
109 // returns the state which is most appropriate as a default state for those | 110 // returns the state which is most appropriate as a default state for those |
110 // displays. | 111 // displays. |
111 State GetDefaultState() const; | 112 OutputState GetDefaultState() const; |
112 | 113 |
113 // Called during start-up to determine what the current state of the displays | 114 // Called during start-up to determine what the current state of the displays |
114 // appears to be, by investigating how the outputs compare to the data stored | 115 // appears to be, by investigating how the outputs compare to the data stored |
115 // in |output_cache_|. Returns STATE_INVALID if the current display state | 116 // in |output_cache_|. Returns STATE_INVALID if the current display state |
116 // doesn't match any supported state. |output_cache_| must be up-to-date with | 117 // doesn't match any supported state. |output_cache_| must be up-to-date with |
117 // regards to the state of X or this method may return incorrect results. | 118 // regards to the state of X or this method may return incorrect results. |
118 State InferCurrentState(Display* display, XRRScreenResources* screen) const; | 119 OutputState InferCurrentState( |
| 120 Display* display, XRRScreenResources* screen) const; |
119 | 121 |
120 // Scans the |output_cache_| to determine whether or not we are in a | 122 // Scans the |output_cache_| to determine whether or not we are in a |
121 // "projecting" state and then calls the DBus kSetIsProjectingMethod on powerd | 123 // "projecting" state and then calls the DBus kSetIsProjectingMethod on powerd |
122 // with the result. | 124 // with the result. |
123 void CheckIsProjectingAndNotify(); | 125 void CheckIsProjectingAndNotify(); |
124 | 126 |
125 // This is detected by the constructor to determine whether or not we should | 127 // This is detected by the constructor to determine whether or not we should |
126 // be enabled. If we aren't running on ChromeOS, we can't assume that the | 128 // be enabled. If we aren't running on ChromeOS, we can't assume that the |
127 // Xrandr X11 extension is supported. | 129 // Xrandr X11 extension is supported. |
128 // If this flag is set to false, any attempts to change the output | 130 // If this flag is set to false, any attempts to change the output |
(...skipping 18 matching lines...) Expand all Loading... |
147 // there is no secondary output. This implies the machine currently has one | 149 // there is no secondary output. This implies the machine currently has one |
148 // output. | 150 // output. |
149 int secondary_output_index_; | 151 int secondary_output_index_; |
150 | 152 |
151 // The base of the event numbers used to represent XRandr events used in | 153 // The base of the event numbers used to represent XRandr events used in |
152 // decoding events regarding output add/remove. | 154 // decoding events regarding output add/remove. |
153 int xrandr_event_base_; | 155 int xrandr_event_base_; |
154 | 156 |
155 // The display state as derived from the outputs observed in |output_cache_|. | 157 // The display state as derived from the outputs observed in |output_cache_|. |
156 // This is used for rotating display modes. | 158 // This is used for rotating display modes. |
157 State output_state_; | 159 OutputState output_state_; |
158 | 160 |
159 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 161 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
160 }; | 162 }; |
161 | 163 |
162 } // namespace chromeos | 164 } // namespace chromeos |
163 | 165 |
164 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 166 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
OLD | NEW |