Chromium Code Reviews| 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 ModeInfo { | |
| 46 ModeInfo(); | |
| 47 | |
| 48 int width; | |
| 49 int height; | |
| 50 bool interlaced; | |
| 51 }; | |
| 52 | |
| 45 struct CoordinateTransformation { | 53 struct CoordinateTransformation { |
| 46 // Initialized to the identity transformation. | 54 // Initialized to the identity transformation. |
| 47 CoordinateTransformation(); | 55 CoordinateTransformation(); |
| 48 | 56 |
| 49 float x_scale; | 57 float x_scale; |
| 50 float x_offset; | 58 float x_offset; |
| 51 float y_scale; | 59 float y_scale; |
| 52 float y_offset; | 60 float y_offset; |
| 53 }; | 61 }; |
| 54 | 62 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 71 // Mode used when displaying the same desktop on multiple outputs. | 79 // Mode used when displaying the same desktop on multiple outputs. |
| 72 RRMode mirror_mode; | 80 RRMode mirror_mode; |
| 73 | 81 |
| 74 // User-selected mode for the output. | 82 // User-selected mode for the output. |
| 75 RRMode selected_mode; | 83 RRMode selected_mode; |
| 76 | 84 |
| 77 // Output's origin on the framebuffer. | 85 // Output's origin on the framebuffer. |
| 78 int x; | 86 int x; |
| 79 int y; | 87 int y; |
| 80 | 88 |
| 89 // Output's physical dimensions. | |
| 90 uint64 width_mm; | |
| 91 uint64 height_mm; | |
| 92 | |
| 81 bool is_internal; | 93 bool is_internal; |
| 82 bool is_aspect_preserving_scaling; | 94 bool is_aspect_preserving_scaling; |
| 83 | 95 |
| 96 // Map from mode IDs to details about the corresponding modes. | |
| 97 std::map<RRMode, ModeInfo> mode_infos; | |
|
oshima
2013/08/15 19:03:24
Does style-guide allow a class in a struct? (just
Daniel Erat
2013/08/15 19:29:26
Whoops, missed this question. Yes, I think this is
| |
| 98 | |
| 84 // XInput device ID or 0 if this output isn't a touchscreen. | 99 // XInput device ID or 0 if this output isn't a touchscreen. |
| 85 int touch_device_id; | 100 int touch_device_id; |
| 86 | 101 |
| 87 CoordinateTransformation transform; | 102 CoordinateTransformation transform; |
| 88 | 103 |
| 89 // Display id for this output. | 104 // Display id for this output. |
| 90 int64 display_id; | 105 int64 display_id; |
| 91 | 106 |
| 92 bool has_display_id; | 107 bool has_display_id; |
| 93 }; | 108 }; |
| 94 | 109 |
| 95 class Observer { | 110 class Observer { |
| 96 public: | 111 public: |
| 97 virtual ~Observer() {} | 112 virtual ~Observer() {} |
| 98 | 113 |
| 99 // Called when the change of the display mode finished. It will usually | 114 // Called after the display mode has been changed. |output| contains the |
| 100 // start the fading in the displays. | 115 // just-applied configuration. Note that the X server is no longer grabbed |
| 101 virtual void OnDisplayModeChanged() {} | 116 // when this method is called, so the actual configuration could've changed |
| 117 // already. | |
| 118 virtual void OnDisplayModeChanged( | |
| 119 const std::vector<OutputSnapshot>& outputs) {} | |
| 102 | 120 |
| 103 // Called when the change of the display mode is issued but failed. | 121 // Called after a display mode change attempt failed. |failed_new_state| is |
| 104 // |failed_new_state| is the new state which the system failed to enter. | 122 // the new state which the system failed to enter. |
| 105 virtual void OnDisplayModeChangeFailed(OutputState failed_new_state) {} | 123 virtual void OnDisplayModeChangeFailed(OutputState failed_new_state) {} |
| 106 }; | 124 }; |
| 107 | 125 |
| 108 // Interface for classes that make decisions about which output state | 126 // Interface for classes that make decisions about which output state |
| 109 // should be used. | 127 // should be used. |
| 110 class StateController { | 128 class StateController { |
| 111 public: | 129 public: |
| 112 virtual ~StateController() {} | 130 virtual ~StateController() {} |
| 113 | 131 |
| 114 // Called when displays are detected. | 132 // Called when displays are detected. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 virtual void SetBackgroundColor(uint32 color_argb) = 0; | 179 virtual void SetBackgroundColor(uint32 color_argb) = 0; |
| 162 | 180 |
| 163 // Enables DPMS and forces it to the "on" state. | 181 // Enables DPMS and forces it to the "on" state. |
| 164 virtual void ForceDPMSOn() = 0; | 182 virtual void ForceDPMSOn() = 0; |
| 165 | 183 |
| 166 // Returns information about the current outputs. | 184 // Returns information about the current outputs. |
| 167 // This method may block for 60 milliseconds or more. | 185 // This method may block for 60 milliseconds or more. |
| 168 virtual std::vector<OutputSnapshot> GetOutputs( | 186 virtual std::vector<OutputSnapshot> GetOutputs( |
| 169 const StateController* state_controller) = 0; | 187 const StateController* state_controller) = 0; |
| 170 | 188 |
| 171 // Gets details corresponding to |mode|. Parameters may be NULL. | |
| 172 // Returns true on success. | |
| 173 virtual bool GetModeDetails(RRMode mode, | |
| 174 int* width, | |
| 175 int* height, | |
| 176 bool* interlaced) = 0; | |
| 177 | |
| 178 // Calls XRRSetCrtcConfig() with the given options but some of our default | 189 // Calls XRRSetCrtcConfig() with the given options but some of our default |
| 179 // output count and rotation arguments. Returns true on success. | 190 // output count and rotation arguments. Returns true on success. |
| 180 virtual bool ConfigureCrtc(RRCrtc crtc, | 191 virtual bool ConfigureCrtc(RRCrtc crtc, |
| 181 RRMode mode, | 192 RRMode mode, |
| 182 RROutput output, | 193 RROutput output, |
| 183 int x, | 194 int x, |
| 184 int y) = 0; | 195 int y) = 0; |
| 185 | 196 |
| 186 // Called to set the frame buffer (underlying XRR "screen") size. Has | 197 // Called to set the frame buffer (underlying XRR "screen") size. Has |
| 187 // a side-effect of disabling all CRTCs. | 198 // a side-effect of disabling all CRTCs. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 | 253 |
| 243 // Gap between screens so cursor at bottom of active display doesn't | 254 // Gap between screens so cursor at bottom of active display doesn't |
| 244 // partially appear on top of inactive display. Higher numbers guard | 255 // partially appear on top of inactive display. Higher numbers guard |
| 245 // against larger cursors, but also waste more memory. | 256 // against larger cursors, but also waste more memory. |
| 246 // For simplicity, this is hard-coded to avoid the complexity of always | 257 // For simplicity, this is hard-coded to avoid the complexity of always |
| 247 // determining the DPI of the screen and rationalizing which screen we | 258 // determining the DPI of the screen and rationalizing which screen we |
| 248 // need to use for the DPI calculation. | 259 // need to use for the DPI calculation. |
| 249 // See crbug.com/130188 for initial discussion. | 260 // See crbug.com/130188 for initial discussion. |
| 250 static const int kVerticalGap = 60; | 261 static const int kVerticalGap = 60; |
| 251 | 262 |
| 263 // Returns a pointer to the ModeInfo struct in |output| corresponding to | |
| 264 // |mode|, or NULL if the struct isn't present. | |
| 265 static const ModeInfo* GetModeInfo(const OutputSnapshot& output, | |
| 266 RRMode mode); | |
| 267 | |
| 252 OutputConfigurator(); | 268 OutputConfigurator(); |
| 253 virtual ~OutputConfigurator(); | 269 virtual ~OutputConfigurator(); |
| 254 | 270 |
| 255 OutputState output_state() const { return output_state_; } | 271 OutputState output_state() const { return output_state_; } |
| 256 DisplayPowerState power_state() const { return power_state_; } | 272 DisplayPowerState power_state() const { return power_state_; } |
| 257 | 273 |
| 258 void set_state_controller(StateController* controller) { | 274 void set_state_controller(StateController* controller) { |
| 259 state_controller_ = controller; | 275 state_controller_ = controller; |
| 260 } | 276 } |
| 261 void set_mirroring_controller(SoftwareMirroringController* controller) { | 277 void set_mirroring_controller(SoftwareMirroringController* controller) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 369 |
| 354 // Returns the output state that should be used with |outputs| connected | 370 // Returns the output state that should be used with |outputs| connected |
| 355 // while in |power_state|. | 371 // while in |power_state|. |
| 356 OutputState GetOutputState(const std::vector<OutputSnapshot>& outputs, | 372 OutputState GetOutputState(const std::vector<OutputSnapshot>& outputs, |
| 357 DisplayPowerState power_state) const; | 373 DisplayPowerState power_state) const; |
| 358 | 374 |
| 359 // Computes the relevant transformation for mirror mode. | 375 // Computes the relevant transformation for mirror mode. |
| 360 // |output| is the output on which mirror mode is being applied. | 376 // |output| is the output on which mirror mode is being applied. |
| 361 // Returns the transformation or identity if computations fail. | 377 // Returns the transformation or identity if computations fail. |
| 362 CoordinateTransformation GetMirrorModeCTM( | 378 CoordinateTransformation GetMirrorModeCTM( |
| 363 const OutputConfigurator::OutputSnapshot* output); | 379 const OutputConfigurator::OutputSnapshot& output); |
| 364 | 380 |
| 365 // Returns the ratio between mirrored mode area and native mode area: | 381 // Returns the ratio between mirrored mode area and native mode area: |
| 366 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) | 382 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) |
| 367 float GetMirroredDisplayAreaRatio( | 383 float GetMirroredDisplayAreaRatio( |
| 368 const OutputConfigurator::OutputSnapshot* output); | 384 const OutputConfigurator::OutputSnapshot& output); |
| 369 | 385 |
| 370 StateController* state_controller_; | 386 StateController* state_controller_; |
| 371 SoftwareMirroringController* mirroring_controller_; | 387 SoftwareMirroringController* mirroring_controller_; |
| 372 scoped_ptr<Delegate> delegate_; | 388 scoped_ptr<Delegate> delegate_; |
| 373 | 389 |
| 374 // Key of the map is the touch display's id, and the value of the map is the | 390 // Key of the map is the touch display's id, and the value of the map is the |
| 375 // touch display's area ratio in mirror mode defined as : | 391 // touch display's area ratio in mirror mode defined as : |
| 376 // mirror_mode_area / native_mode_area. | 392 // mirror_mode_area / native_mode_area. |
| 377 // This is used for scaling touch event's radius when the touch display is in | 393 // This is used for scaling touch event's radius when the touch display is in |
| 378 // mirror mode : | 394 // mirror mode : |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 407 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; | 423 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; |
| 408 | 424 |
| 409 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 425 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
| 410 }; | 426 }; |
| 411 | 427 |
| 412 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; | 428 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; |
| 413 | 429 |
| 414 } // namespace chromeos | 430 } // namespace chromeos |
| 415 | 431 |
| 416 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 432 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
| OLD | NEW |