| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 5 #ifndef UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
| 6 #define UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 6 #define UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class UpdateDisplayConfigurationTask; | 35 class UpdateDisplayConfigurationTask; |
| 36 | 36 |
| 37 // This class interacts directly with the system display configurator. | 37 // This class interacts directly with the system display configurator. |
| 38 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { | 38 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { |
| 39 public: | 39 public: |
| 40 typedef uint64_t ContentProtectionClientId; | 40 typedef uint64_t ContentProtectionClientId; |
| 41 static const ContentProtectionClientId kInvalidClientId = 0; | 41 static const ContentProtectionClientId kInvalidClientId = 0; |
| 42 | 42 |
| 43 typedef base::Callback<void(bool)> ConfigurationCallback; | 43 typedef base::Callback<void(bool)> ConfigurationCallback; |
| 44 | 44 |
| 45 struct DisplayState { | 45 typedef std::vector<DisplaySnapshot*> DisplayStateList; |
| 46 DisplayState(); | |
| 47 | |
| 48 DisplaySnapshot* display; // Not owned. | |
| 49 | |
| 50 // User-selected mode for the display. | |
| 51 const DisplayMode* selected_mode; | |
| 52 | |
| 53 // Mode used when displaying the same desktop on multiple displays. | |
| 54 const DisplayMode* mirror_mode; | |
| 55 }; | |
| 56 | |
| 57 typedef std::vector<DisplayState> DisplayStateList; | |
| 58 | 46 |
| 59 class Observer { | 47 class Observer { |
| 60 public: | 48 public: |
| 61 virtual ~Observer() {} | 49 virtual ~Observer() {} |
| 62 | 50 |
| 63 // Called after the display mode has been changed. |display| contains the | 51 // Called after the display mode has been changed. |display| contains the |
| 64 // just-applied configuration. Note that the X server is no longer grabbed | 52 // just-applied configuration. Note that the X server is no longer grabbed |
| 65 // when this method is called, so the actual configuration could've changed | 53 // when this method is called, so the actual configuration could've changed |
| 66 // already. | 54 // already. |
| 67 virtual void OnDisplayModeChanged( | 55 virtual void OnDisplayModeChanged( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const = 0; | 97 const = 0; |
| 110 | 98 |
| 111 virtual StateController* GetStateController() const = 0; | 99 virtual StateController* GetStateController() const = 0; |
| 112 | 100 |
| 113 // Returns the current display state. | 101 // Returns the current display state. |
| 114 virtual MultipleDisplayState GetDisplayState() const = 0; | 102 virtual MultipleDisplayState GetDisplayState() const = 0; |
| 115 | 103 |
| 116 // Returns the current power state. | 104 // Returns the current power state. |
| 117 virtual chromeos::DisplayPowerState GetPowerState() const = 0; | 105 virtual chromeos::DisplayPowerState GetPowerState() const = 0; |
| 118 | 106 |
| 119 // Parses the |displays| into a list of DisplayStates. This effectively adds | |
| 120 // |mirror_mode| and |selected_mode| to the returned results. | |
| 121 // TODO(dnicoara): This operation doesn't depend on state and could be done | |
| 122 // directly in |GetDisplayLayout()|. Though I need to make sure that there | |
| 123 // are no uses for those fields outside DisplayConfigurator. | |
| 124 virtual std::vector<DisplayState> ParseDisplays( | |
| 125 const std::vector<DisplaySnapshot*>& displays) const = 0; | |
| 126 | |
| 127 // Based on the given |displays|, display state and power state, it will | 107 // Based on the given |displays|, display state and power state, it will |
| 128 // create display configuration requests which will then be used to | 108 // create display configuration requests which will then be used to |
| 129 // configure the hardware. The requested configuration is stored in | 109 // configure the hardware. The requested configuration is stored in |
| 130 // |requests| and |framebuffer_size|. | 110 // |requests| and |framebuffer_size|. |
| 131 virtual bool GetDisplayLayout( | 111 virtual bool GetDisplayLayout( |
| 132 const std::vector<DisplayState>& displays, | 112 const std::vector<DisplaySnapshot*>& displays, |
| 133 MultipleDisplayState new_display_state, | 113 MultipleDisplayState new_display_state, |
| 134 chromeos::DisplayPowerState new_power_state, | 114 chromeos::DisplayPowerState new_power_state, |
| 135 std::vector<DisplayConfigureRequest>* requests, | 115 std::vector<DisplayConfigureRequest>* requests, |
| 136 gfx::Size* framebuffer_size) const = 0; | 116 gfx::Size* framebuffer_size) const = 0; |
| 137 }; | 117 }; |
| 138 | 118 |
| 139 // Helper class used by tests. | 119 // Helper class used by tests. |
| 140 class TestApi { | 120 class TestApi { |
| 141 public: | 121 public: |
| 142 TestApi(DisplayConfigurator* configurator) : configurator_(configurator) {} | 122 TestApi(DisplayConfigurator* configurator) : configurator_(configurator) {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 const gfx::Size& size); | 156 const gfx::Size& size); |
| 177 | 157 |
| 178 DisplayConfigurator(); | 158 DisplayConfigurator(); |
| 179 ~DisplayConfigurator() override; | 159 ~DisplayConfigurator() override; |
| 180 | 160 |
| 181 MultipleDisplayState display_state() const { return current_display_state_; } | 161 MultipleDisplayState display_state() const { return current_display_state_; } |
| 182 chromeos::DisplayPowerState requested_power_state() const { | 162 chromeos::DisplayPowerState requested_power_state() const { |
| 183 return requested_power_state_; | 163 return requested_power_state_; |
| 184 } | 164 } |
| 185 const gfx::Size framebuffer_size() const { return framebuffer_size_; } | 165 const gfx::Size framebuffer_size() const { return framebuffer_size_; } |
| 186 const std::vector<DisplayState>& cached_displays() const { | 166 const std::vector<DisplaySnapshot*>& cached_displays() const { |
| 187 return cached_displays_; | 167 return cached_displays_; |
| 188 } | 168 } |
| 189 | 169 |
| 190 // Called when an external process no longer needs to control the display | 170 // Called when an external process no longer needs to control the display |
| 191 // and Chrome can take control. | 171 // and Chrome can take control. |
| 192 void TakeControl(); | 172 void TakeControl(); |
| 193 | 173 |
| 194 // Called when an external process needs to control the display and thus | 174 // Called when an external process needs to control the display and thus |
| 195 // Chrome should relinquish it. | 175 // Chrome should relinquish it. |
| 196 void RelinquishControl(); | 176 void RelinquishControl(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 void RestoreRequestedPowerStateAfterResume(); | 287 void RestoreRequestedPowerStateAfterResume(); |
| 308 | 288 |
| 309 // Notifies observers about an attempted state change. | 289 // Notifies observers about an attempted state change. |
| 310 void NotifyObservers(bool success, MultipleDisplayState attempted_state); | 290 void NotifyObservers(bool success, MultipleDisplayState attempted_state); |
| 311 | 291 |
| 312 // Returns the display state that should be used with |cached_displays_| while | 292 // Returns the display state that should be used with |cached_displays_| while |
| 313 // in |power_state|. | 293 // in |power_state|. |
| 314 MultipleDisplayState ChooseDisplayState( | 294 MultipleDisplayState ChooseDisplayState( |
| 315 chromeos::DisplayPowerState power_state) const; | 295 chromeos::DisplayPowerState power_state) const; |
| 316 | 296 |
| 317 // Returns the ratio between mirrored mode area and native mode area: | |
| 318 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) | |
| 319 float GetMirroredDisplayAreaRatio(const DisplayState& display); | |
| 320 | |
| 321 // Returns true if in either hardware or software mirroring mode. | 297 // Returns true if in either hardware or software mirroring mode. |
| 322 bool IsMirroring() const; | 298 bool IsMirroring() const; |
| 323 | 299 |
| 324 // Applies display protections according to requests. | 300 // Applies display protections according to requests. |
| 325 bool ApplyProtections(const ContentProtections& requests); | 301 bool ApplyProtections(const ContentProtections& requests); |
| 326 | 302 |
| 327 // If |configuration_task_| isn't initialized, initializes it and starts the | 303 // If |configuration_task_| isn't initialized, initializes it and starts the |
| 328 // configuration task. | 304 // configuration task. |
| 329 void RunPendingConfiguration(); | 305 void RunPendingConfiguration(); |
| 330 | 306 |
| 331 // Callback for |configuration_taks_|. When the configuration process finishes | 307 // Callback for |configuration_taks_|. When the configuration process finishes |
| 332 // this is called with the result (|success|) and the updated display state. | 308 // this is called with the result (|success|) and the updated display state. |
| 333 void OnConfigured(bool success, | 309 void OnConfigured(bool success, |
| 334 const std::vector<DisplayState>& displays, | 310 const std::vector<DisplaySnapshot*>& displays, |
| 335 const gfx::Size& framebuffer_size, | 311 const gfx::Size& framebuffer_size, |
| 336 MultipleDisplayState new_display_state, | 312 MultipleDisplayState new_display_state, |
| 337 chromeos::DisplayPowerState new_power_state); | 313 chromeos::DisplayPowerState new_power_state); |
| 338 | 314 |
| 339 // Helps in identifying if a configuration task needs to be scheduled. | 315 // Helps in identifying if a configuration task needs to be scheduled. |
| 340 // Return true if any of the |requested_*| parameters have been updated. False | 316 // Return true if any of the |requested_*| parameters have been updated. False |
| 341 // otherwise. | 317 // otherwise. |
| 342 bool ShouldRunConfigurationTask() const; | 318 bool ShouldRunConfigurationTask() const; |
| 343 | 319 |
| 344 // Helper functions which will call the callbacks in | 320 // Helper functions which will call the callbacks in |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 402 |
| 427 // This must be the last variable. | 403 // This must be the last variable. |
| 428 base::WeakPtrFactory<DisplayConfigurator> weak_ptr_factory_; | 404 base::WeakPtrFactory<DisplayConfigurator> weak_ptr_factory_; |
| 429 | 405 |
| 430 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); | 406 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); |
| 431 }; | 407 }; |
| 432 | 408 |
| 433 } // namespace ui | 409 } // namespace ui |
| 434 | 410 |
| 435 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 411 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
| OLD | NEW |