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> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/event_types.h" | 14 #include "base/event_types.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
18 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 #include "ui/display/display_export.h" | 19 #include "ui/display/display_export.h" |
21 #include "ui/display/types/display_constants.h" | 20 #include "ui/display/types/display_constants.h" |
22 #include "ui/display/types/native_display_observer.h" | 21 #include "ui/display/types/native_display_observer.h" |
23 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
24 | 23 |
25 namespace gfx { | 24 namespace gfx { |
26 class Point; | 25 class Point; |
27 class Size; | 26 class Size; |
28 } | 27 } |
29 | 28 |
30 namespace ui { | 29 namespace ui { |
31 struct DisplayConfigureRequest; | 30 struct DisplayConfigureRequest; |
32 class DisplayMode; | 31 class DisplayMode; |
33 class DisplaySnapshot; | 32 class DisplaySnapshot; |
34 class NativeDisplayDelegate; | 33 class NativeDisplayDelegate; |
35 class UpdateDisplayConfigurationTask; | |
36 | 34 |
37 // This class interacts directly with the system display configurator. | 35 // This class interacts directly with the system display configurator. |
38 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { | 36 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { |
39 public: | 37 public: |
40 typedef uint64_t ContentProtectionClientId; | 38 typedef uint64_t ContentProtectionClientId; |
41 static const ContentProtectionClientId kInvalidClientId = 0; | 39 static const ContentProtectionClientId kInvalidClientId = 0; |
42 | 40 |
43 struct DisplayState { | 41 struct DisplayState { |
44 DisplayState(); | 42 DisplayState(); |
45 | 43 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 165 |
168 // Returns the mode within |display| that matches the given size with highest | 166 // Returns the mode within |display| that matches the given size with highest |
169 // refresh rate. Returns None if no matching display was found. | 167 // refresh rate. Returns None if no matching display was found. |
170 static const DisplayMode* FindDisplayModeMatchingSize( | 168 static const DisplayMode* FindDisplayModeMatchingSize( |
171 const DisplaySnapshot& display, | 169 const DisplaySnapshot& display, |
172 const gfx::Size& size); | 170 const gfx::Size& size); |
173 | 171 |
174 DisplayConfigurator(); | 172 DisplayConfigurator(); |
175 virtual ~DisplayConfigurator(); | 173 virtual ~DisplayConfigurator(); |
176 | 174 |
177 MultipleDisplayState display_state() const { return current_display_state_; } | 175 MultipleDisplayState display_state() const { return display_state_; } |
178 chromeos::DisplayPowerState requested_power_state() const { | 176 chromeos::DisplayPowerState requested_power_state() const { |
179 return requested_power_state_; | 177 return requested_power_state_; |
180 } | 178 } |
181 const gfx::Size framebuffer_size() const { return framebuffer_size_; } | 179 const gfx::Size framebuffer_size() const { return framebuffer_size_; } |
182 const std::vector<DisplayState>& cached_displays() const { | 180 const std::vector<DisplayState>& cached_displays() const { |
183 return cached_displays_; | 181 return cached_displays_; |
184 } | 182 } |
185 | 183 |
186 // Called when an external process no longer needs to control the display | 184 // Called when an external process no longer needs to control the display |
187 // and Chrome can take control. | 185 // and Chrome can take control. |
(...skipping 29 matching lines...) Expand all Loading... |
217 void ForceInitialConfigure(uint32_t background_color_argb); | 215 void ForceInitialConfigure(uint32_t background_color_argb); |
218 | 216 |
219 // Stop handling display configuration events/requests. | 217 // Stop handling display configuration events/requests. |
220 void PrepareForExit(); | 218 void PrepareForExit(); |
221 | 219 |
222 // Called when powerd notifies us that some set of displays should be turned | 220 // Called when powerd notifies us that some set of displays should be turned |
223 // on or off. This requires enabling or disabling the CRTC associated with | 221 // on or off. This requires enabling or disabling the CRTC associated with |
224 // the display(s) in question so that the low power state is engaged. | 222 // the display(s) in question so that the low power state is engaged. |
225 // |flags| contains bitwise-or-ed kSetDisplayPower* values. Returns true if | 223 // |flags| contains bitwise-or-ed kSetDisplayPower* values. Returns true if |
226 // the system successfully enters (or was already in) |power_state|. | 224 // the system successfully enters (or was already in) |power_state|. |
227 void SetDisplayPower(chromeos::DisplayPowerState power_state, int flags); | 225 bool SetDisplayPower(chromeos::DisplayPowerState power_state, int flags); |
228 | 226 |
229 // Force switching the display mode to |new_state|. Returns false if | 227 // Force switching the display mode to |new_state|. Returns false if |
230 // switching failed (possibly because |new_state| is invalid for the | 228 // switching failed (possibly because |new_state| is invalid for the |
231 // current set of connected displays). | 229 // current set of connected displays). |
232 void SetDisplayMode(MultipleDisplayState new_state); | 230 bool SetDisplayMode(MultipleDisplayState new_state); |
233 | 231 |
234 // NativeDisplayDelegate::Observer overrides: | 232 // NativeDisplayDelegate::Observer overrides: |
235 virtual void OnConfigurationChanged() override; | 233 virtual void OnConfigurationChanged() override; |
236 | 234 |
237 void AddObserver(Observer* observer); | 235 void AddObserver(Observer* observer); |
238 void RemoveObserver(Observer* observer); | 236 void RemoveObserver(Observer* observer); |
239 | 237 |
240 // Sets all the displays into pre-suspend mode; usually this means | 238 // Sets all the displays into pre-suspend mode; usually this means |
241 // configure them for their resume state. This allows faster resume on | 239 // configure them for their resume state. This allows faster resume on |
242 // machines where display configuration is slow. | 240 // machines where display configuration is slow. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Checks the available color profiles for |display_id| and fills the result | 272 // Checks the available color profiles for |display_id| and fills the result |
275 // into |profiles|. | 273 // into |profiles|. |
276 std::vector<ui::ColorCalibrationProfile> GetAvailableColorCalibrationProfiles( | 274 std::vector<ui::ColorCalibrationProfile> GetAvailableColorCalibrationProfiles( |
277 int64_t display_id); | 275 int64_t display_id); |
278 | 276 |
279 // Updates the color calibration to |new_profile|. | 277 // Updates the color calibration to |new_profile|. |
280 bool SetColorCalibrationProfile(int64_t display_id, | 278 bool SetColorCalibrationProfile(int64_t display_id, |
281 ui::ColorCalibrationProfile new_profile); | 279 ui::ColorCalibrationProfile new_profile); |
282 | 280 |
283 private: | 281 private: |
284 class DisplayLayoutManagerImpl; | |
285 | |
286 // Mapping a display_id to a protection request bitmask. | 282 // Mapping a display_id to a protection request bitmask. |
287 typedef std::map<int64_t, uint32_t> ContentProtections; | 283 typedef std::map<int64_t, uint32_t> ContentProtections; |
288 // Mapping a client to its protection request. | 284 // Mapping a client to its protection request. |
289 typedef std::map<ContentProtectionClientId, ContentProtections> | 285 typedef std::map<ContentProtectionClientId, ContentProtections> |
290 ProtectionRequests; | 286 ProtectionRequests; |
291 | 287 |
292 // Performs platform specific delegate initialization. | 288 // Performs platform specific delegate initialization. |
293 scoped_ptr<NativeDisplayDelegate> CreatePlatformNativeDisplayDelegate(); | 289 scoped_ptr<NativeDisplayDelegate> CreatePlatformNativeDisplayDelegate(); |
294 | 290 |
| 291 // Updates |cached_displays_| to contain currently-connected displays. Calls |
| 292 // |delegate_->GetDisplays()| and then does additional work, like finding the |
| 293 // mirror mode and setting user-preferred modes. Note that the server must be |
| 294 // grabbed via |delegate_->GrabServer()| first. |
| 295 void UpdateCachedDisplays(); |
| 296 |
| 297 // Helper method for UpdateCachedDisplays() that initializes the passed-in |
| 298 // displays' |mirror_mode| fields by looking for a mode in |internal_display| |
| 299 // and |external_display| having the same resolution. Returns false if a |
| 300 // shared |
| 301 // mode wasn't found or created. |
| 302 // |
| 303 // |try_panel_fitting| allows creating a panel-fitting mode for |
| 304 // |internal_display| instead of only searching for a matching mode (note that |
| 305 // it may lead to a crash if |internal_info| is not capable of panel fitting). |
| 306 // |
| 307 // |preserve_aspect| limits the search/creation only to the modes having the |
| 308 // native aspect ratio of |external_display|. |
| 309 bool FindMirrorMode(DisplayState* internal_display, |
| 310 DisplayState* external_display, |
| 311 bool try_panel_fitting, |
| 312 bool preserve_aspect); |
| 313 |
295 // Configures displays. Invoked by |configure_timer_|. | 314 // Configures displays. Invoked by |configure_timer_|. |
296 void ConfigureDisplays(); | 315 void ConfigureDisplays(); |
297 | 316 |
298 // Restores |requested_power_state_| after the system has resumed, | 317 // Restores |requested_power_state_| after the system has resumed, |
299 // additionally forcing a probe. Invoked by |configure_timer_|. | 318 // additionally forcing a probe. Invoked by |configure_timer_|. |
300 void RestoreRequestedPowerStateAfterResume(); | 319 void RestoreRequestedPowerStateAfterResume(); |
301 | 320 |
302 // Notifies observers about an attempted state change. | 321 // Notifies observers about an attempted state change. |
303 void NotifyObservers(bool success, MultipleDisplayState attempted_state); | 322 void NotifyObservers(bool success, MultipleDisplayState attempted_state); |
304 | 323 |
| 324 // Switches to the state specified in |display_state| and |power_state|. |
| 325 // If the hardware mirroring failed and |mirroring_controller_| is set, |
| 326 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()| |
| 327 // to enable software based mirroring. |
| 328 // On success, updates |display_state_|, |power_state_|, and |
| 329 // |cached_displays_| and returns true. |
| 330 bool EnterStateOrFallBackToSoftwareMirroring( |
| 331 MultipleDisplayState display_state, |
| 332 chromeos::DisplayPowerState power_state); |
| 333 |
| 334 // Switches to the state specified in |display_state| and |power_state|. |
| 335 // On success, updates |display_state_|, |power_state_|, and |
| 336 // |cached_displays_| and returns true. |
| 337 bool EnterState(MultipleDisplayState display_state, |
| 338 chromeos::DisplayPowerState power_state); |
| 339 |
305 // Returns the display state that should be used with |cached_displays_| while | 340 // Returns the display state that should be used with |cached_displays_| while |
306 // in |power_state|. | 341 // in |power_state|. |
307 MultipleDisplayState ChooseDisplayState( | 342 MultipleDisplayState ChooseDisplayState( |
308 chromeos::DisplayPowerState power_state) const; | 343 chromeos::DisplayPowerState power_state) const; |
309 | 344 |
310 // Returns the ratio between mirrored mode area and native mode area: | 345 // Returns the ratio between mirrored mode area and native mode area: |
311 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) | 346 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) |
312 float GetMirroredDisplayAreaRatio(const DisplayState& display); | 347 float GetMirroredDisplayAreaRatio(const DisplayState& display); |
313 | 348 |
314 // Returns true if in either hardware or software mirroring mode. | 349 // Returns true if in either hardware or software mirroring mode. |
315 bool IsMirroring() const; | 350 bool IsMirroring() const; |
316 | 351 |
317 // Applies display protections according to requests. | 352 // Applies display protections according to requests. |
318 bool ApplyProtections(const ContentProtections& requests); | 353 bool ApplyProtections(const ContentProtections& requests); |
319 | 354 |
320 // If |configuration_task_| isn't initialized, initializes it and starts the | |
321 // configuration task. | |
322 void RunPendingConfiguration(); | |
323 | |
324 // Callback for |configuration_taks_|. When the configuration process finishes | |
325 // this is called with the result (|success|) and the updated display state. | |
326 void OnConfigured(bool success, | |
327 const std::vector<DisplayState>& displays, | |
328 const gfx::Size& framebuffer_size, | |
329 MultipleDisplayState new_display_state, | |
330 chromeos::DisplayPowerState new_power_state); | |
331 | |
332 // Helps in identifying if a configuration task needs to be scheduled. | |
333 // Return true if any of the |requested_*| parameters have been updated. False | |
334 // otherwise. | |
335 bool ShouldRunConfigurationTask() const; | |
336 | |
337 StateController* state_controller_; | 355 StateController* state_controller_; |
338 SoftwareMirroringController* mirroring_controller_; | 356 SoftwareMirroringController* mirroring_controller_; |
339 scoped_ptr<NativeDisplayDelegate> native_display_delegate_; | 357 scoped_ptr<NativeDisplayDelegate> native_display_delegate_; |
340 | 358 |
341 // Used to enable modes which rely on panel fitting. | 359 // Used to enable modes which rely on panel fitting. |
342 bool is_panel_fitting_enabled_; | 360 bool is_panel_fitting_enabled_; |
343 | 361 |
344 // This is detected by the constructor to determine whether or not we should | 362 // This is detected by the constructor to determine whether or not we should |
345 // be enabled. If we aren't running on ChromeOS, we can't assume that the | 363 // be enabled. If we aren't running on ChromeOS, we can't assume that the |
346 // Xrandr X11 extension is supported. | 364 // Xrandr X11 extension is supported. |
347 // If this flag is set to false, any attempts to change the display | 365 // If this flag is set to false, any attempts to change the display |
348 // configuration to immediately fail without changing the state. | 366 // configuration to immediately fail without changing the state. |
349 bool configure_display_; | 367 bool configure_display_; |
350 | 368 |
351 // Current configuration state. | 369 // The current display state. |
352 MultipleDisplayState current_display_state_; | 370 MultipleDisplayState display_state_; |
| 371 |
| 372 gfx::Size framebuffer_size_; |
| 373 |
| 374 // The last-requested and current power state. These may differ if |
| 375 // configuration fails: SetDisplayMode() needs the last-requested state while |
| 376 // SetDisplayPower() needs the current state. |
| 377 chromeos::DisplayPowerState requested_power_state_; |
353 chromeos::DisplayPowerState current_power_state_; | 378 chromeos::DisplayPowerState current_power_state_; |
354 | 379 |
355 // Pending requests. These values are used when triggering the next display | |
356 // configuration. | |
357 // | |
358 // Stores the user requested state or INVALID if nothing was requested. | |
359 MultipleDisplayState requested_display_state_; | |
360 | |
361 // Stores the requested power state. | |
362 chromeos::DisplayPowerState requested_power_state_; | |
363 | |
364 // True if |requested_power_state_| has been changed due to a user request. | |
365 bool requested_power_state_change_; | |
366 | |
367 // Bitwise-or value of the |kSetDisplayPower*| flags defined above. | |
368 int requested_power_flags_; | |
369 | |
370 // True if the caller wants to force the display configuration process. | |
371 bool force_configure_; | |
372 | |
373 // Most-recently-used display configuration. Note that the actual | 380 // Most-recently-used display configuration. Note that the actual |
374 // configuration changes asynchronously. | 381 // configuration changes asynchronously. |
375 DisplayStateList cached_displays_; | 382 DisplayStateList cached_displays_; |
376 | 383 |
377 // Most-recently-used framebuffer size. | |
378 gfx::Size framebuffer_size_; | |
379 | |
380 ObserverList<Observer> observers_; | 384 ObserverList<Observer> observers_; |
381 | 385 |
382 // The timer to delay configuring displays. This is used to aggregate multiple | 386 // The timer to delay configuring displays. This is used to aggregate multiple |
383 // display configuration events when they are reported in short time spans. | 387 // display configuration events when they are reported in short time spans. |
384 // See comment for NativeDisplayEventDispatcherX11 for more details. | 388 // See comment for NativeDisplayEventDispatcherX11 for more details. |
385 base::OneShotTimer<DisplayConfigurator> configure_timer_; | 389 base::OneShotTimer<DisplayConfigurator> configure_timer_; |
386 | 390 |
387 // Id for next display protection client. | 391 // Id for next display protection client. |
388 ContentProtectionClientId next_display_protection_client_id_; | 392 ContentProtectionClientId next_display_protection_client_id_; |
389 | 393 |
390 // Display protection requests of each client. | 394 // Display protection requests of each client. |
391 ProtectionRequests client_protection_requests_; | 395 ProtectionRequests client_protection_requests_; |
392 | 396 |
393 // Display controlled by an external entity. | 397 // Display controlled by an external entity. |
394 bool display_externally_controlled_; | 398 bool display_externally_controlled_; |
395 | 399 |
396 scoped_ptr<DisplayLayoutManager> layout_manager_; | |
397 | |
398 scoped_ptr<UpdateDisplayConfigurationTask> configuration_task_; | |
399 | |
400 // This must be the last variable. | |
401 base::WeakPtrFactory<DisplayConfigurator> weak_ptr_factory_; | |
402 | |
403 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); | 400 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); |
404 }; | 401 }; |
405 | 402 |
406 } // namespace ui | 403 } // namespace ui |
407 | 404 |
408 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 405 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
OLD | NEW |