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