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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 24 matching lines...) Expand all Loading... |
35 STATE_DUAL_MIRROR, | 35 STATE_DUAL_MIRROR, |
36 STATE_DUAL_EXTENDED, | 36 STATE_DUAL_EXTENDED, |
37 }; | 37 }; |
38 | 38 |
39 // This class interacts directly with the underlying Xrandr API to manipulate | 39 // This class interacts directly with the underlying Xrandr API to manipulate |
40 // CTRCs and Outputs. | 40 // CTRCs and Outputs. |
41 class CHROMEOS_EXPORT OutputConfigurator | 41 class CHROMEOS_EXPORT OutputConfigurator |
42 : public base::MessageLoop::Dispatcher, | 42 : public base::MessageLoop::Dispatcher, |
43 public base::MessagePumpObserver { | 43 public base::MessagePumpObserver { |
44 public: | 44 public: |
| 45 struct CoordinateTransformation { |
| 46 // Initialized to the identity transformation. |
| 47 CoordinateTransformation(); |
| 48 |
| 49 float x_scale; |
| 50 float x_offset; |
| 51 float y_scale; |
| 52 float y_offset; |
| 53 }; |
| 54 |
45 // Information about an output's current state. | 55 // Information about an output's current state. |
46 struct OutputSnapshot { | 56 struct OutputSnapshot { |
47 OutputSnapshot(); | 57 OutputSnapshot(); |
48 | 58 |
49 RROutput output; | 59 RROutput output; |
50 | 60 |
51 // CRTC that should be used for this output. Not necessarily the CRTC | 61 // CRTC that should be used for this output. Not necessarily the CRTC |
52 // that XRandR reports is currently being used. | 62 // that XRandR reports is currently being used. |
53 RRCrtc crtc; | 63 RRCrtc crtc; |
54 | 64 |
| 65 // Mode currently being used by the output. |
55 RRMode current_mode; | 66 RRMode current_mode; |
| 67 |
| 68 // "Best" mode supported by the output. |
56 RRMode native_mode; | 69 RRMode native_mode; |
| 70 |
| 71 // Mode used when displaying the same desktop on multiple outputs. |
57 RRMode mirror_mode; | 72 RRMode mirror_mode; |
| 73 |
| 74 // User-selected mode for the output. |
58 RRMode selected_mode; | 75 RRMode selected_mode; |
59 | 76 |
| 77 // Output's origin on the framebuffer. |
| 78 int x; |
60 int y; | 79 int y; |
61 int height; | |
62 | 80 |
63 bool is_internal; | 81 bool is_internal; |
64 bool is_aspect_preserving_scaling; | 82 bool is_aspect_preserving_scaling; |
65 | 83 |
66 // XInput device ID or 0 if this output isn't a touchscreen. | 84 // XInput device ID or 0 if this output isn't a touchscreen. |
67 int touch_device_id; | 85 int touch_device_id; |
68 | 86 |
| 87 CoordinateTransformation transform; |
| 88 |
69 // Display id for this output. | 89 // Display id for this output. |
70 int64 display_id; | 90 int64 display_id; |
71 | 91 |
72 bool has_display_id; | 92 bool has_display_id; |
73 }; | 93 }; |
74 | 94 |
75 struct CoordinateTransformation { | |
76 // Initialized to the identity transformation. | |
77 CoordinateTransformation(); | |
78 | |
79 float x_scale; | |
80 float x_offset; | |
81 float y_scale; | |
82 float y_offset; | |
83 }; | |
84 | |
85 struct CrtcConfig { | |
86 CrtcConfig(); | |
87 CrtcConfig(RRCrtc crtc, int x, int y, RRMode mode, RROutput output); | |
88 | |
89 RRCrtc crtc; | |
90 int x; | |
91 int y; | |
92 RRMode mode; | |
93 RROutput output; | |
94 }; | |
95 | |
96 class Observer { | 95 class Observer { |
97 public: | 96 public: |
98 virtual ~Observer() {} | 97 virtual ~Observer() {} |
99 | 98 |
100 // Called when the change of the display mode finished. It will usually | 99 // Called when the change of the display mode finished. It will usually |
101 // start the fading in the displays. | 100 // start the fading in the displays. |
102 virtual void OnDisplayModeChanged() {} | 101 virtual void OnDisplayModeChanged() {} |
103 | 102 |
104 // Called when the change of the display mode is issued but failed. | 103 // Called when the change of the display mode is issued but failed. |
105 // |failed_new_state| is the new state which the system failed to enter. | 104 // |failed_new_state| is the new state which the system failed to enter. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 virtual std::vector<OutputSnapshot> GetOutputs( | 168 virtual std::vector<OutputSnapshot> GetOutputs( |
170 const StateController* state_controller) = 0; | 169 const StateController* state_controller) = 0; |
171 | 170 |
172 // Gets details corresponding to |mode|. Parameters may be NULL. | 171 // Gets details corresponding to |mode|. Parameters may be NULL. |
173 // Returns true on success. | 172 // Returns true on success. |
174 virtual bool GetModeDetails(RRMode mode, | 173 virtual bool GetModeDetails(RRMode mode, |
175 int* width, | 174 int* width, |
176 int* height, | 175 int* height, |
177 bool* interlaced) = 0; | 176 bool* interlaced) = 0; |
178 | 177 |
179 // Calls XRRSetCrtcConfig() with the given options but some of our | 178 // Calls XRRSetCrtcConfig() with the given options but some of our default |
180 // default output count and rotation arguments. | 179 // output count and rotation arguments. Returns true on success. |
181 virtual void ConfigureCrtc(CrtcConfig* config) = 0; | 180 virtual bool ConfigureCrtc(RRCrtc crtc, |
| 181 RRMode mode, |
| 182 RROutput output, |
| 183 int x, |
| 184 int y) = 0; |
182 | 185 |
183 // Called to set the frame buffer (underlying XRR "screen") size. Has | 186 // Called to set the frame buffer (underlying XRR "screen") size. Has |
184 // a side-effect of disabling all CRTCs. | 187 // a side-effect of disabling all CRTCs. |
185 virtual void CreateFrameBuffer( | 188 virtual void CreateFrameBuffer( |
186 int width, | 189 int width, |
187 int height, | 190 int height, |
188 const std::vector<OutputConfigurator::CrtcConfig>& configs) = 0; | 191 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) = 0; |
189 | 192 |
190 // Configures XInput's Coordinate Transformation Matrix property. | 193 // Configures XInput's Coordinate Transformation Matrix property. |
191 // |touch_device_id| the ID of the touchscreen device to configure. | 194 // |touch_device_id| the ID of the touchscreen device to configure. |
192 // |ctm| contains the desired transformation parameters. The offsets | 195 // |ctm| contains the desired transformation parameters. The offsets |
193 // in it should be normalized so that 1 corresponds to the X or Y axis | 196 // in it should be normalized so that 1 corresponds to the X or Y axis |
194 // size for the corresponding offset. | 197 // size for the corresponding offset. |
195 virtual void ConfigureCTM(int touch_device_id, | 198 virtual void ConfigureCTM(int touch_device_id, |
196 const CoordinateTransformation& ctm) = 0; | 199 const CoordinateTransformation& ctm) = 0; |
197 | 200 |
198 // Sends a D-Bus message to the power manager telling it that the | 201 // Sends a D-Bus message to the power manager telling it that the |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 private: | 321 private: |
319 // Configure outputs. | 322 // Configure outputs. |
320 void ConfigureOutputs(); | 323 void ConfigureOutputs(); |
321 | 324 |
322 // Fires OnDisplayModeChanged() event to the observers. | 325 // Fires OnDisplayModeChanged() event to the observers. |
323 void NotifyOnDisplayChanged(); | 326 void NotifyOnDisplayChanged(); |
324 | 327 |
325 // Switches to the state specified in |output_state| and |power_state|. | 328 // Switches to the state specified in |output_state| and |power_state|. |
326 // If the hardware mirroring failed and |mirroring_controller_| is set, | 329 // If the hardware mirroring failed and |mirroring_controller_| is set, |
327 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()| | 330 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()| |
328 // to enable software based mirroing. | 331 // to enable software based mirroring. |
329 // On success, updates |output_state_| and |power_state_| and returns true. | 332 // On success, updates |output_state_|, |power_state_|, and |cached_outputs_| |
| 333 // and returns true. |
330 bool EnterStateOrFallBackToSoftwareMirroring( | 334 bool EnterStateOrFallBackToSoftwareMirroring( |
331 OutputState output_state, | 335 OutputState output_state, |
332 DisplayPowerState power_state, | 336 DisplayPowerState power_state, |
333 const std::vector<OutputSnapshot>& outputs); | 337 const std::vector<OutputSnapshot>& outputs); |
334 | 338 |
335 // Switches to the state specified in |output_state| and |power_state|. | 339 // Switches to the state specified in |output_state| and |power_state|. |
336 // On success, updates |output_state_| and |power_state_| and returns true. | 340 // On success, updates |output_state_|, |power_state_|, and |
| 341 // |cached_outputs_| and returns true. |
337 bool EnterState(OutputState output_state, | 342 bool EnterState(OutputState output_state, |
338 DisplayPowerState power_state, | 343 DisplayPowerState power_state, |
339 const std::vector<OutputSnapshot>& outputs); | 344 const std::vector<OutputSnapshot>& outputs); |
340 | 345 |
341 // Returns the output state that should be used with |outputs| connected | 346 // Returns the output state that should be used with |outputs| connected |
342 // while in |power_state|. | 347 // while in |power_state|. |
343 OutputState GetOutputState(const std::vector<OutputSnapshot>& outputs, | 348 OutputState GetOutputState(const std::vector<OutputSnapshot>& outputs, |
344 DisplayPowerState power_state) const; | 349 DisplayPowerState power_state) const; |
345 | 350 |
346 // Computes the relevant transformation for mirror mode. | 351 // Computes the relevant transformation for mirror mode. |
(...skipping 29 matching lines...) Expand all Loading... |
376 // The base of the event numbers used to represent XRandr events used in | 381 // The base of the event numbers used to represent XRandr events used in |
377 // decoding events regarding output add/remove. | 382 // decoding events regarding output add/remove. |
378 int xrandr_event_base_; | 383 int xrandr_event_base_; |
379 | 384 |
380 // The current display state. | 385 // The current display state. |
381 OutputState output_state_; | 386 OutputState output_state_; |
382 | 387 |
383 // The current power state. | 388 // The current power state. |
384 DisplayPowerState power_state_; | 389 DisplayPowerState power_state_; |
385 | 390 |
| 391 // Most-recently-used output configuration. Note that the actual |
| 392 // configuration changes asynchronously. |
| 393 std::vector<OutputSnapshot> cached_outputs_; |
| 394 |
386 ObserverList<Observer> observers_; | 395 ObserverList<Observer> observers_; |
387 | 396 |
388 // The timer to delay configuring outputs. See also the comments in | 397 // The timer to delay configuring outputs. See also the comments in |
389 // Dispatch(). | 398 // Dispatch(). |
390 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; | 399 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; |
391 | 400 |
392 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 401 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
393 }; | 402 }; |
394 | 403 |
395 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; | 404 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; |
396 | 405 |
397 } // namespace chromeos | 406 } // namespace chromeos |
398 | 407 |
399 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 408 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
OLD | NEW |