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/callback.h" | |
9 #include "base/event_types.h" | 10 #include "base/event_types.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
13 | 14 |
14 // Forward declarations for Xlib and Xrandr. | 15 // Forward declarations for Xlib and Xrandr. |
15 // This is so unused X definitions don't pollute the namespace. | 16 // This is so unused X definitions don't pollute the namespace. |
16 typedef unsigned long XID; | 17 typedef unsigned long XID; |
17 typedef XID Window; | 18 typedef XID Window; |
18 typedef XID RROutput; | 19 typedef XID RROutput; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 STATE_DUAL_PRIMARY_ONLY, | 51 STATE_DUAL_PRIMARY_ONLY, |
51 STATE_DUAL_SECONDARY_ONLY, | 52 STATE_DUAL_SECONDARY_ONLY, |
52 }; | 53 }; |
53 | 54 |
54 // This class interacts directly with the underlying Xrandr API to manipulate | 55 // 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 | 56 // 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 | 57 // Output info in other ways as more of the Chrome display code grows up around |
57 // it. | 58 // it. |
58 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { | 59 class CHROMEOS_EXPORT OutputConfigurator : public MessageLoop::Dispatcher { |
59 public: | 60 public: |
61 // AnimationDelegate is responsible for making visual effect around the change | |
62 // of output configurations. Typically it makes fade-out the displays before | |
63 // the transition and fade-in again after the transition finished. | |
64 class AnimationDelegate { | |
65 public: | |
66 virtual ~AnimationDelegate() {} | |
67 | |
68 // Called when the change of display mode is scheduled. It will usually | |
69 // start fading out the displays. It also has to run |callback| once | |
70 // the visual effect has finished. | |
71 virtual void WillDisplayModeChange(base::Closure callback) { | |
72 callback.Run(); | |
73 } | |
oshima
2012/07/26 14:08:17
move this to .cc, and forward decl base::Closure.
| |
74 | |
75 // Called when the change of the display mode finished. It will usually | |
76 // start the fading in the displays. | |
77 virtual void OnDisplayModeChanged() {} | |
78 }; | |
79 | |
60 OutputConfigurator(); | 80 OutputConfigurator(); |
61 virtual ~OutputConfigurator(); | 81 virtual ~OutputConfigurator(); |
62 | 82 |
63 State output_state() const { return output_state_; } | 83 State output_state() const { return output_state_; } |
64 | 84 |
85 void set_animation_delegate(AnimationDelegate* animation_delegate) { | |
86 animation_delegate_.reset(animation_delegate); | |
87 } | |
88 | |
65 // Called when the user hits ctrl-F4 to request a display mode change. | 89 // 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 | 90 // This method should only return false if it was called in a single-head or |
67 // headless mode. | 91 // headless mode. |
68 bool CycleDisplayMode(); | 92 bool CycleDisplayMode(); |
69 | 93 |
70 // Called when powerd notifies us that some set of displays should be turned | 94 // 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 | 95 // 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. | 96 // the display(s) in question so that the low power state is engaged. |
73 bool ScreenPowerSet(bool power_on, bool all_displays); | 97 bool ScreenPowerSet(bool power_on, bool all_displays); |
74 | 98 |
75 // Force switching the display mode to |new_state|. This method is used when | 99 // 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 | 100 // 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. | 101 // false if it was called in a single-head or headless mode. |
78 bool SetDisplayMode(State new_state); | 102 bool SetDisplayMode(State new_state); |
79 | 103 |
80 // Called when an RRNotify event is received. The implementation is | 104 // Called when an RRNotify event is received. The implementation is |
81 // interested in the cases of RRNotify events which correspond to output | 105 // 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 | 106 // add/remove events. Note that Output add/remove events are sent in response |
83 // to our own reconfiguration operations so spurious events are common. | 107 // to our own reconfiguration operations so spurious events are common. |
84 // Spurious events will have no effect. | 108 // Spurious events will have no effect. |
85 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 109 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
86 | 110 |
87 private: | 111 private: |
112 // The actual task of changing display mode. Usually this is called by the | |
113 // |animation_delegate_|. | |
114 void SetDisplayModeInternal(State new_state); | |
115 | |
88 // Updates |output_count_|, |output_cache_|, |mirror_supported_|, | 116 // Updates |output_count_|, |output_cache_|, |mirror_supported_|, |
89 // |primary_output_index_|, and |secondary_output_index_| with new data. | 117 // |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 | 118 // Returns true if the update succeeded or false if it was skipped since no |
91 // actual change was observed. | 119 // actual change was observed. |
92 // Note that |output_state_| is not updated by this call. | 120 // Note that |output_state_| is not updated by this call. |
93 bool TryRecacheOutputs(Display* display, XRRScreenResources* screen); | 121 bool TryRecacheOutputs(Display* display, XRRScreenResources* screen); |
94 | 122 |
95 // Uses the data stored in |output_cache_| and the given |new_state| to | 123 // 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 | 124 // configure the Xrandr interface and then updates |output_state_| to reflect |
97 // the new state. | 125 // the new state. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 int secondary_output_index_; | 177 int secondary_output_index_; |
150 | 178 |
151 // The base of the event numbers used to represent XRandr events used in | 179 // The base of the event numbers used to represent XRandr events used in |
152 // decoding events regarding output add/remove. | 180 // decoding events regarding output add/remove. |
153 int xrandr_event_base_; | 181 int xrandr_event_base_; |
154 | 182 |
155 // The display state as derived from the outputs observed in |output_cache_|. | 183 // The display state as derived from the outputs observed in |output_cache_|. |
156 // This is used for rotating display modes. | 184 // This is used for rotating display modes. |
157 State output_state_; | 185 State output_state_; |
158 | 186 |
187 scoped_ptr<AnimationDelegate> animation_delegate_; | |
188 | |
159 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 189 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
160 }; | 190 }; |
161 | 191 |
162 } // namespace chromeos | 192 } // namespace chromeos |
163 | 193 |
164 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 194 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
OLD | NEW |