| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Used to describe the state of a multi-display configuration. | 30 // Used to describe the state of a multi-display configuration. |
| 31 enum OutputState { | 31 enum OutputState { |
| 32 STATE_INVALID, | 32 STATE_INVALID, |
| 33 STATE_HEADLESS, | 33 STATE_HEADLESS, |
| 34 STATE_SINGLE, | 34 STATE_SINGLE, |
| 35 STATE_DUAL_MIRROR, | 35 STATE_DUAL_MIRROR, |
| 36 STATE_DUAL_EXTENDED, | 36 STATE_DUAL_EXTENDED, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Video output types. |
| 40 enum OutputType { |
| 41 OUTPUT_TYPE_NONE = 0, |
| 42 OUTPUT_TYPE_UNKNOWN = 1 << 0, |
| 43 OUTPUT_TYPE_INTERNAL = 1 << 1, |
| 44 OUTPUT_TYPE_VGA = 1 << 2, |
| 45 OUTPUT_TYPE_HDMI = 1 << 3, |
| 46 OUTPUT_TYPE_DVI = 1 << 4, |
| 47 OUTPUT_TYPE_DISPLAYPORT = 1 << 5, |
| 48 }; |
| 49 |
| 50 // Content protection methods applied on video output. |
| 51 enum OutputProtectionMethod { |
| 52 OUTPUT_PROTECTION_METHOD_NONE = 0, |
| 53 OUTPUT_PROTECTION_METHOD_HDCP = 1 << 0, |
| 54 }; |
| 55 |
| 56 // HDCP protection state. |
| 57 enum HDCPState { |
| 58 HDCP_STATE_UNDESIRED, |
| 59 HDCP_STATE_DESIRED, |
| 60 HDCP_STATE_ENABLED |
| 61 }; |
| 62 |
| 39 // This class interacts directly with the underlying Xrandr API to manipulate | 63 // This class interacts directly with the underlying Xrandr API to manipulate |
| 40 // CTRCs and Outputs. | 64 // CTRCs and Outputs. |
| 41 class CHROMEOS_EXPORT OutputConfigurator | 65 class CHROMEOS_EXPORT OutputConfigurator |
| 42 : public base::MessageLoop::Dispatcher, | 66 : public base::MessageLoop::Dispatcher, |
| 43 public base::MessagePumpObserver { | 67 public base::MessagePumpObserver { |
| 44 public: | 68 public: |
| 69 typedef uint64_t OutputProtectionClientId; |
| 70 |
| 45 struct ModeInfo { | 71 struct ModeInfo { |
| 46 ModeInfo(); | 72 ModeInfo(); |
| 47 ModeInfo(int width, int height, bool interlaced, float refresh_rate); | 73 ModeInfo(int width, int height, bool interlaced, float refresh_rate); |
| 48 | 74 |
| 49 int width; | 75 int width; |
| 50 int height; | 76 int height; |
| 51 bool interlaced; | 77 bool interlaced; |
| 52 float refresh_rate; | 78 float refresh_rate; |
| 53 }; | 79 }; |
| 54 | 80 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 RRMode selected_mode; | 114 RRMode selected_mode; |
| 89 | 115 |
| 90 // Output's origin on the framebuffer. | 116 // Output's origin on the framebuffer. |
| 91 int x; | 117 int x; |
| 92 int y; | 118 int y; |
| 93 | 119 |
| 94 // Output's physical dimensions. | 120 // Output's physical dimensions. |
| 95 uint64 width_mm; | 121 uint64 width_mm; |
| 96 uint64 height_mm; | 122 uint64 height_mm; |
| 97 | 123 |
| 124 // TODO(kcwu): Remove this. Check type == OUTPUT_TYPE_INTERNAL instead. |
| 98 bool is_internal; | 125 bool is_internal; |
| 99 bool is_aspect_preserving_scaling; | 126 bool is_aspect_preserving_scaling; |
| 100 | 127 |
| 128 // The type of output. |
| 129 OutputType type; |
| 130 |
| 101 // Map from mode IDs to details about the corresponding modes. | 131 // Map from mode IDs to details about the corresponding modes. |
| 102 ModeInfoMap mode_infos; | 132 ModeInfoMap mode_infos; |
| 103 | 133 |
| 104 // XInput device ID or 0 if this output isn't a touchscreen. | 134 // XInput device ID or 0 if this output isn't a touchscreen. |
| 105 int touch_device_id; | 135 int touch_device_id; |
| 106 | 136 |
| 107 CoordinateTransformation transform; | 137 CoordinateTransformation transform; |
| 108 | 138 |
| 109 // Display id for this output. | 139 // Display id for this output. |
| 110 int64 display_id; | 140 int64 display_id; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // |touch_device_id| the ID of the touchscreen device to configure. | 246 // |touch_device_id| the ID of the touchscreen device to configure. |
| 217 // |ctm| contains the desired transformation parameters. The offsets | 247 // |ctm| contains the desired transformation parameters. The offsets |
| 218 // in it should be normalized so that 1 corresponds to the X or Y axis | 248 // in it should be normalized so that 1 corresponds to the X or Y axis |
| 219 // size for the corresponding offset. | 249 // size for the corresponding offset. |
| 220 virtual void ConfigureCTM(int touch_device_id, | 250 virtual void ConfigureCTM(int touch_device_id, |
| 221 const CoordinateTransformation& ctm) = 0; | 251 const CoordinateTransformation& ctm) = 0; |
| 222 | 252 |
| 223 // Sends a D-Bus message to the power manager telling it that the | 253 // Sends a D-Bus message to the power manager telling it that the |
| 224 // machine is or is not projecting. | 254 // machine is or is not projecting. |
| 225 virtual void SendProjectingStateToPowerManager(bool projecting) = 0; | 255 virtual void SendProjectingStateToPowerManager(bool projecting) = 0; |
| 256 |
| 257 // Gets HDCP state of output. |
| 258 virtual bool GetHDCPState(RROutput id, HDCPState* state) = 0; |
| 259 |
| 260 // Sets HDCP state of output. |
| 261 virtual bool SetHDCPState(RROutput id, HDCPState state) = 0; |
| 226 }; | 262 }; |
| 227 | 263 |
| 228 // Helper class used by tests. | 264 // Helper class used by tests. |
| 229 class TestApi { | 265 class TestApi { |
| 230 public: | 266 public: |
| 231 TestApi(OutputConfigurator* configurator, int xrandr_event_base) | 267 TestApi(OutputConfigurator* configurator, int xrandr_event_base) |
| 232 : configurator_(configurator), | 268 : configurator_(configurator), |
| 233 xrandr_event_base_(xrandr_event_base) {} | 269 xrandr_event_base_(xrandr_event_base) {} |
| 234 ~TestApi() {} | 270 ~TestApi() {} |
| 235 | 271 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 void ResumeDisplays(); | 391 void ResumeDisplays(); |
| 356 | 392 |
| 357 const std::map<int, float>& GetMirroredDisplayAreaRatioMap() { | 393 const std::map<int, float>& GetMirroredDisplayAreaRatioMap() { |
| 358 return mirrored_display_area_ratio_map_; | 394 return mirrored_display_area_ratio_map_; |
| 359 } | 395 } |
| 360 | 396 |
| 361 // Configure outputs with |kConfigureDelayMs| delay, | 397 // Configure outputs with |kConfigureDelayMs| delay, |
| 362 // so that time-consuming ConfigureOutputs() won't be called multiple times. | 398 // so that time-consuming ConfigureOutputs() won't be called multiple times. |
| 363 void ScheduleConfigureOutputs(); | 399 void ScheduleConfigureOutputs(); |
| 364 | 400 |
| 401 // Registers a client for output protection and requests a client id. Returns |
| 402 // 0 if requesting failed. |
| 403 OutputProtectionClientId RegisterOutputProtectionClient(); |
| 404 |
| 405 // Unregisters the client. |
| 406 void UnregisterOutputProtectionClient(OutputProtectionClientId client_id); |
| 407 |
| 408 // Queries link status and protection status. |
| 409 // |link_mask| is the type of connected output links, which is a bitmask of |
| 410 // OutputType values. |protection_mask| is the desired protection methods, |
| 411 // which is a bitmask of the OutputProtectionMethod values. |
| 412 // Returns true on success. |
| 413 bool QueryOutputProtectionStatus( |
| 414 OutputProtectionClientId client_id, |
| 415 uint32_t* link_mask, |
| 416 uint32_t* protection_mask); |
| 417 |
| 418 // Requests the desired protection methods. |
| 419 // |protection_mask| is the desired protection methods, which is a bitmask |
| 420 // of the OutputProtectionMethod values. |
| 421 // Returns true when the protection request has been made. |
| 422 bool EnableOutputProtection( |
| 423 OutputProtectionClientId client_id, |
| 424 uint32_t desired_protection_mask); |
| 425 |
| 365 private: | 426 private: |
| 427 // Mapping a client to its protection request bitmask. |
| 428 typedef std::map<chromeos::OutputConfigurator::OutputProtectionClientId, |
| 429 uint32_t> ProtectionRequests; |
| 430 |
| 366 // Updates |cached_outputs_| to contain currently-connected outputs. Calls | 431 // Updates |cached_outputs_| to contain currently-connected outputs. Calls |
| 367 // |delegate_->GetOutputs()| and then does additional work, like finding the | 432 // |delegate_->GetOutputs()| and then does additional work, like finding the |
| 368 // mirror mode and setting user-preferred modes. Note that the server must be | 433 // mirror mode and setting user-preferred modes. Note that the server must be |
| 369 // grabbed via |delegate_->GrabServer()| first. | 434 // grabbed via |delegate_->GrabServer()| first. |
| 370 void UpdateCachedOutputs(); | 435 void UpdateCachedOutputs(); |
| 371 | 436 |
| 372 // Helper method for UpdateCachedOutputs() that initializes the passed-in | 437 // Helper method for UpdateCachedOutputs() that initializes the passed-in |
| 373 // outputs' |mirror_mode| fields by looking for a mode in |internal_output| | 438 // outputs' |mirror_mode| fields by looking for a mode in |internal_output| |
| 374 // and |external_output| having the same resolution. Returns false if a shared | 439 // and |external_output| having the same resolution. Returns false if a shared |
| 375 // mode wasn't found or created. | 440 // mode wasn't found or created. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // Most-recently-used output configuration. Note that the actual | 521 // Most-recently-used output configuration. Note that the actual |
| 457 // configuration changes asynchronously. | 522 // configuration changes asynchronously. |
| 458 std::vector<OutputSnapshot> cached_outputs_; | 523 std::vector<OutputSnapshot> cached_outputs_; |
| 459 | 524 |
| 460 ObserverList<Observer> observers_; | 525 ObserverList<Observer> observers_; |
| 461 | 526 |
| 462 // The timer to delay configuring outputs. See also the comments in | 527 // The timer to delay configuring outputs. See also the comments in |
| 463 // Dispatch(). | 528 // Dispatch(). |
| 464 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; | 529 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; |
| 465 | 530 |
| 531 // Id for next output protection client. |
| 532 OutputProtectionClientId next_output_protection_client_id_; |
| 533 |
| 534 // Output protection requests of each client. |
| 535 ProtectionRequests client_protection_requests_; |
| 536 |
| 466 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); | 537 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); |
| 467 }; | 538 }; |
| 468 | 539 |
| 469 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; | 540 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; |
| 470 | 541 |
| 471 } // namespace chromeos | 542 } // namespace chromeos |
| 472 | 543 |
| 473 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ | 544 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ |
| OLD | NEW |