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/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
15 | 15 |
16 // Forward declarations for Xlib and Xrandr. | 16 // Forward declarations for Xlib and Xrandr. |
17 // This is so unused X definitions don't pollute the namespace. | 17 // This is so unused X definitions don't pollute the namespace. |
18 typedef unsigned long XID; | 18 typedef unsigned long XID; |
19 typedef XID Window; | 19 typedef XID Window; |
20 typedef XID RROutput; | 20 typedef XID RROutput; |
21 typedef XID RRCrtc; | 21 typedef XID RRCrtc; |
22 typedef XID RRMode; | 22 typedef XID RRMode; |
23 | 23 |
| 24 struct _XDisplay; |
| 25 typedef struct _XDisplay Display; |
| 26 struct _XRROutputInfo; |
| 27 typedef _XRROutputInfo XRROutputInfo; |
24 struct _XRRScreenResources; | 28 struct _XRRScreenResources; |
25 typedef _XRRScreenResources XRRScreenResources; | 29 typedef _XRRScreenResources XRRScreenResources; |
26 | 30 |
27 namespace chromeos { | 31 namespace chromeos { |
28 | 32 |
| 33 struct OutputSnapshot; |
| 34 |
29 // Used to describe the state of a multi-display configuration. | 35 // Used to describe the state of a multi-display configuration. |
30 // TODO(oshima): remove DUAL_SECONDARY_ONLY | 36 // TODO(oshima): remove DUAL_SECONDARY_ONLY |
31 enum OutputState { | 37 enum OutputState { |
32 STATE_INVALID, | 38 STATE_INVALID, |
33 STATE_HEADLESS, | 39 STATE_HEADLESS, |
34 STATE_SINGLE, | 40 STATE_SINGLE, |
35 STATE_DUAL_MIRROR, | 41 STATE_DUAL_MIRROR, |
36 STATE_DUAL_PRIMARY_ONLY, | 42 STATE_DUAL_PRIMARY_ONLY, |
37 STATE_DUAL_SECONDARY_ONLY, | 43 STATE_DUAL_SECONDARY_ONLY, |
38 STATE_DUAL_UNKNOWN, | 44 STATE_DUAL_UNKNOWN, |
39 }; | 45 }; |
40 | 46 |
41 // This class interacts directly with the underlying Xrandr API to manipulate | 47 // This class interacts directly with the underlying Xrandr API to manipulate |
42 // CTRCs and Outputs. It will likely grow more state, over time, or expose | 48 // CTRCs and Outputs. It will likely grow more state, over time, or expose |
43 // Output info in other ways as more of the Chrome display code grows up around | 49 // Output info in other ways as more of the Chrome display code grows up around |
44 // it. | 50 // it. |
45 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { | 51 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { |
46 public: | 52 public: |
47 class Observer { | 53 class Observer { |
48 public: | 54 public: |
49 // Called when the change of the display mode finished. It will usually | 55 // Called when the change of the display mode finished. It will usually |
50 // start the fading in the displays. | 56 // start the fading in the displays. |
51 virtual void OnDisplayModeChanged() {}; | 57 virtual void OnDisplayModeChanged() {} |
52 | 58 |
53 // Called when the change of the display mode is issued but failed. | 59 // Called when the change of the display mode is issued but failed. |
54 virtual void OnDisplayModeChangeFailed() {}; | 60 virtual void OnDisplayModeChangeFailed() {} |
55 }; | 61 }; |
56 | 62 |
57 OutputConfigurator(); | 63 OutputConfigurator(); |
58 virtual ~OutputConfigurator(); | 64 virtual ~OutputConfigurator(); |
59 | 65 |
60 int connected_output_count() const { return connected_output_count_; } | 66 int connected_output_count() const { return connected_output_count_; } |
61 | 67 |
62 OutputState output_state() const { return output_state_; } | 68 OutputState output_state() const { return output_state_; } |
63 | 69 |
| 70 // Initialization, must be called right after constructor. |
| 71 // |is_panel_fitting_enabled| indicates hardware panel fitting support. |
| 72 void Init(bool is_panel_fitting_enabled); |
| 73 |
64 // Called when the user hits ctrl-F4 to request a display mode change. | 74 // Called when the user hits ctrl-F4 to request a display mode change. |
65 // This method should only return false if it was called in a single-head or | 75 // This method should only return false if it was called in a single-head or |
66 // headless mode. | 76 // headless mode. |
67 bool CycleDisplayMode(); | 77 bool CycleDisplayMode(); |
68 | 78 |
69 // Called when powerd notifies us that some set of displays should be turned | 79 // Called when powerd notifies us that some set of displays should be turned |
70 // on or off. This requires enabling or disabling the CRTC associated with | 80 // on or off. This requires enabling or disabling the CRTC associated with |
71 // the display(s) in question so that the low power state is engaged. | 81 // the display(s) in question so that the low power state is engaged. |
72 bool ScreenPowerSet(bool power_on, bool all_displays); | 82 bool ScreenPowerSet(bool power_on, bool all_displays); |
73 | 83 |
(...skipping 12 matching lines...) Expand all Loading... |
86 void AddObserver(Observer* observer); | 96 void AddObserver(Observer* observer); |
87 void RemoveObserver(Observer* observer); | 97 void RemoveObserver(Observer* observer); |
88 | 98 |
89 // Tells if the output specified by |name| is for internal display. | 99 // Tells if the output specified by |name| is for internal display. |
90 static bool IsInternalOutputName(const std::string& name); | 100 static bool IsInternalOutputName(const std::string& name); |
91 | 101 |
92 private: | 102 private: |
93 // Fires OnDisplayModeChanged() event to the observers. | 103 // Fires OnDisplayModeChanged() event to the observers. |
94 void NotifyOnDisplayChanged(); | 104 void NotifyOnDisplayChanged(); |
95 | 105 |
| 106 // Fills output parameters |one| and |two| with properties of |
| 107 // first two connected outputs found on |display| and |screen|. |
| 108 int GetDualOutputs(Display* display, |
| 109 XRRScreenResources* screen, |
| 110 OutputSnapshot* one, |
| 111 OutputSnapshot* two); |
| 112 |
| 113 // Should be called if the internal (built-in) output didn't advertise a mode |
| 114 // which would be capable to support mirror mode. |
| 115 // Relies on hardware panel fitting support, |
| 116 // returns immediately if it is not available. |
| 117 // Tries to add the native mode of the external output to the internal output, |
| 118 // assuming panel fitter hardware will take care of scaling and letterboxing. |
| 119 // The RROutput IDs |output_one| and |output_two| are used |
| 120 // to look up the modes and configure the internal output, |
| 121 // |output_one_mode| and |output_two_mode| are the out-parameters |
| 122 // for the modes on the two outputs which will have same resolution. |
| 123 // Returns false if it fails to configure the internal output appropriately. |
| 124 bool AddMirrorModeToInternalOutput(Display* display, |
| 125 XRRScreenResources* screen, |
| 126 RROutput output_one, |
| 127 RROutput output_two, |
| 128 RRMode* output_one_mode, |
| 129 RRMode* output_two_mode); |
| 130 |
| 131 // Tells if the output specified by |output_info| is for internal display. |
| 132 static bool IsInternalOutput(const XRROutputInfo* output_info); |
| 133 |
| 134 // Returns output's native mode, None if not found. |
| 135 static RRMode GetOutputNativeMode(const XRROutputInfo* output_info); |
| 136 |
96 // This is detected by the constructor to determine whether or not we should | 137 // This is detected by the constructor to determine whether or not we should |
97 // be enabled. If we aren't running on ChromeOS, we can't assume that the | 138 // be enabled. If we aren't running on ChromeOS, we can't assume that the |
98 // Xrandr X11 extension is supported. | 139 // Xrandr X11 extension is supported. |
99 // If this flag is set to false, any attempts to change the output | 140 // If this flag is set to false, any attempts to change the output |
100 // configuration to immediately fail without changing the state. | 141 // configuration to immediately fail without changing the state. |
101 bool is_running_on_chrome_os_; | 142 bool is_running_on_chrome_os_; |
102 | 143 |
| 144 // This is set externally in Init, |
| 145 // and is used to enable modes which rely on panel fitting. |
| 146 bool is_panel_fitting_enabled_; |
| 147 |
103 // The number of outputs that are connected. | 148 // The number of outputs that are connected. |
104 int connected_output_count_; | 149 int connected_output_count_; |
105 | 150 |
106 // The base of the event numbers used to represent XRandr events used in | 151 // The base of the event numbers used to represent XRandr events used in |
107 // decoding events regarding output add/remove. | 152 // decoding events regarding output add/remove. |
108 int xrandr_event_base_; | 153 int xrandr_event_base_; |
109 | 154 |
110 // The display state as derived from the outputs observed in |output_cache_|. | 155 // The display state as derived from the outputs observed in |output_cache_|. |
111 // This is used for rotating display modes. | 156 // This is used for rotating display modes. |
112 OutputState output_state_; | 157 OutputState output_state_; |
113 | 158 |
114 ObserverList<Observer> observers_; | 159 ObserverList<Observer> observers_; |
115 | 160 |
116 // The timer to delay sending the notification of OnDisplayChanged(). See also | 161 // The timer to delay sending the notification of OnDisplayChanged(). See also |
117 // the comments in Dispatch(). | 162 // the comments in Dispatch(). |
118 scoped_ptr<base::OneShotTimer<OutputConfigurator> > notification_timer_; | 163 scoped_ptr<base::OneShotTimer<OutputConfigurator> > notification_timer_; |
119 | 164 |
120 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 165 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
121 }; | 166 }; |
122 | 167 |
123 } // namespace chromeos | 168 } // namespace chromeos |
124 | 169 |
125 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 170 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
OLD | NEW |