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 3 // found in the LICENSE file. 4 5 #ifndef UI_DISPLAY_MANAGER_DISPLAY_MANAGER_H_ 6 #define UI_DISPLAY_MANAGER_DISPLAY_MANAGER_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include <algorithm> 12 #include <map> 13 #include <memory> 14 #include <string> 15 #include <utility> 16 #include <vector> 17 18 #include "base/callback.h" 19 #include "base/compiler_specific.h" 20 #include "base/gtest_prod_util.h" 21 #include "base/logging.h" 22 #include "base/macros.h" 23 #include "base/memory/ref_counted.h" 24 #include "base/memory/weak_ptr.h" 25 #include "base/observer_list.h" 26 #include "ui/display/display.h" 27 #include "ui/display/display_layout.h" 28 #include "ui/display/display_observer.h" 29 #include "ui/display/manager/display_manager_export.h" 30 #include "ui/display/manager/display_manager_utilities.h" 31 #include "ui/display/manager/managed_display_info.h" 32 #include "ui/display/types/display_constants.h" 33 #include "ui/display/unified_desktop_utils.h" 34 35 #if defined(OS_CHROMEOS) 36 #include "base/cancelable_callback.h" 37 #include "base/optional.h" 38 #include "ui/display/manager/display_configurator.h" 39 #include "ui/display/manager/touch_device_manager.h" 40 #endif 41 42 namespace gfx { 43 class Insets; 44 class Rect; 45 } // namespace gfx 46 47 namespace display { 48 class DisplayChangeObserver; 49 class DisplayLayoutStore; 50 class DisplayObserver; 51 class NativeDisplayDelegate; 52 class Screen; 53 54 namespace test { 55 class DisplayManagerTestApi; 56 } 57 58 // DisplayManager maintains the current display configurations, 59 // and notifies observers when configuration changes. 60 class DISPLAY_MANAGER_EXPORT DisplayManager 61 #if defined(OS_CHROMEOS) 62 : public DisplayConfigurator::SoftwareMirroringController 63 #endif 64 { 65 public: 66 class DISPLAY_MANAGER_EXPORT Delegate { 67 public: ~Delegate()68 virtual ~Delegate() {} 69 70 // Create or updates the mirroring window with |display_info_list|. 71 virtual void CreateOrUpdateMirroringDisplay( 72 const DisplayInfoList& display_info_list) = 0; 73 74 // Closes the mirror window if not necessary. 75 virtual void CloseMirroringDisplayIfNotNecessary() = 0; 76 77 // Sets the primary display by display id. 78 virtual void SetPrimaryDisplayId(int64_t id) = 0; 79 80 // Called before and after the display configuration changes. When 81 // |clear_focus| is true, the implementation should deactivate the active 82 // window and set the focus window to NULL. 83 virtual void PreDisplayConfigurationChange(bool clear_focus) = 0; 84 virtual void PostDisplayConfigurationChange() = 0; 85 }; 86 87 // How secondary displays will be used. 88 // 1) EXTENDED mode extends the desktop onto additional displays, creating one 89 // root window for each display. Each display has a shelf and status tray, 90 // and each user window is only rendered on a single display. 91 // 2) MIRRORING mode copies the content of the primary display to the second 92 // display via software mirroring. This only supports 2 displays for now. 93 // 3) UNIFIED mode creates a virtual desktop with a *single* root window that 94 // spans multiple physical displays via software mirroring. The primary 95 // physical display has a shelf and status tray, and user windows may 96 // render spanning across multiple displays. 97 // 98 // WARNING: These values are persisted to logs. Entries should not be 99 // renumbered and numeric values should never be reused. 100 enum MultiDisplayMode { 101 EXTENDED = 0, 102 MIRRORING = 1, 103 UNIFIED = 2, 104 105 // Always keep this the last item. 106 MULTI_DISPLAY_MODE_LAST = UNIFIED, 107 }; 108 109 explicit DisplayManager(std::unique_ptr<Screen> screen); 110 #if defined(OS_CHROMEOS) 111 ~DisplayManager() override; 112 #else 113 ~DisplayManager(); 114 #endif 115 layout_store()116 DisplayLayoutStore* layout_store() { return layout_store_.get(); } 117 set_delegate(Delegate * delegate)118 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 119 120 // When set to true, the DisplayManager calls OnDisplayMetricsChanged even if 121 // the display's bounds didn't change. Used to swap primary display. set_force_bounds_changed(bool force_bounds_changed)122 void set_force_bounds_changed(bool force_bounds_changed) { 123 force_bounds_changed_ = force_bounds_changed; 124 } 125 set_configure_displays(bool configure_displays)126 void set_configure_displays(bool configure_displays) { 127 configure_displays_ = configure_displays; 128 } 129 set_internal_display_has_accelerometer(bool has_accelerometer)130 void set_internal_display_has_accelerometer(bool has_accelerometer) { 131 internal_display_has_accelerometer_ = has_accelerometer; 132 } 133 134 // Returns the display id of the first display in the outupt list. first_display_id()135 int64_t first_display_id() const { return first_display_id_; } 136 137 #if defined(OS_CHROMEOS) touch_device_manager()138 TouchDeviceManager* touch_device_manager() const { 139 return touch_device_manager_.get(); 140 } 141 configurator()142 DisplayConfigurator* configurator() { return display_configurator_.get(); } 143 #endif 144 current_unified_desktop_matrix()145 const UnifiedDesktopLayoutMatrix& current_unified_desktop_matrix() const { 146 return current_unified_desktop_matrix_; 147 } 148 149 // Initializes displays using command line flag. Returns false if no command 150 // line flag was provided. 151 bool InitFromCommandLine(); 152 153 // Initialize default display. 154 void InitDefaultDisplay(); 155 156 // Update the internal display's display info. 157 void UpdateInternalDisplay(const ManagedDisplayInfo& display_info); 158 159 // Initializes font related params that depends on display configuration. 160 void RefreshFontParams(); 161 162 // Returns the display layout used for current displays. 163 const DisplayLayout& GetCurrentDisplayLayout() const; 164 165 // Returns the actual display layout after it has been resolved and applied. 166 const DisplayLayout& GetCurrentResolvedDisplayLayout() const; 167 168 // Returns the current display list. 169 DisplayIdList GetCurrentDisplayIdList() const; 170 171 // Sets the layout for the current display pair. The |layout| specifies the 172 // locaion of the displays relative to their parents. 173 void SetLayoutForCurrentDisplays(std::unique_ptr<DisplayLayout> layout); 174 175 // Returns display for given |display_id|. 176 const Display& GetDisplayForId(int64_t display_id) const; 177 178 // Checks the validity of given |display_id|. 179 bool IsDisplayIdValid(int64_t display_id) const; 180 181 // Finds the display that contains |point| in screeen coordinates. Returns 182 // invalid display if there is no display that can satisfy the condition. 183 const Display& FindDisplayContainingPoint( 184 const gfx::Point& point_in_screen) const; 185 186 // Sets the work area's |insets| to the display given by |display_id|. 187 bool UpdateWorkAreaOfDisplay(int64_t display_id, const gfx::Insets& insets); 188 189 // Registers the overscan insets for the display of the specified ID. Note 190 // that the insets size should be specified in DIP size. It also triggers the 191 // display's bounds change. 192 void SetOverscanInsets(int64_t display_id, const gfx::Insets& insets_in_dip); 193 194 // Sets the display's rotation for the given |source|. The new |rotation| will 195 // also become active. 196 void SetDisplayRotation(int64_t display_id, 197 Display::Rotation rotation, 198 Display::RotationSource source); 199 200 // Sets the external display's configuration, including resolution change and 201 // device scale factor change. Returns true if it changes the display 202 // resolution so that the caller needs to show a notification in case the new 203 // resolution actually doesn't work. 204 bool SetDisplayMode(int64_t display_id, 205 const ManagedDisplayMode& display_mode); 206 207 // Register per display properties. 208 // |overscan_insets| is null if the display has no custom overscan insets. 209 // |touch_calibration_data| is null if the display has no touch calibration 210 // associated data. 211 void RegisterDisplayProperty(int64_t display_id, 212 Display::Rotation rotation, 213 const gfx::Insets* overscan_insets, 214 const gfx::Size& resolution_in_pixels, 215 float device_scale_factor, 216 float display_zoom_factor, 217 float refresh_rate, 218 bool is_interlaced); 219 220 // Register stored rotation properties for the internal display. 221 void RegisterDisplayRotationProperties(bool rotation_lock, 222 Display::Rotation rotation); 223 224 // Returns the stored rotation lock preference if it has been loaded, 225 // otherwise false. registered_internal_display_rotation_lock()226 bool registered_internal_display_rotation_lock() const { 227 return registered_internal_display_rotation_lock_; 228 } 229 230 // Returns the stored rotation preference for the internal display if it has 231 // been loaded, otherwise |Display::Rotate_0|. registered_internal_display_rotation()232 Display::Rotation registered_internal_display_rotation() const { 233 return registered_internal_display_rotation_; 234 } 235 236 // Fills in the display |mode| currently in use in |display_id| if found, 237 // returning true in that case, otherwise false. 238 bool GetActiveModeForDisplayId(int64_t display_id, 239 ManagedDisplayMode* mode) const; 240 241 // Returns true and fills in the display's selected |mode| if found, or false. 242 bool GetSelectedModeForDisplayId(int64_t display_id, 243 ManagedDisplayMode* mode) const; 244 245 // Sets the selected mode of |display_id| to |display_mode| if it's a 246 // supported mode. This doesn't trigger reconfiguration or observers 247 // notifications. This is suitable to be used from within an observer 248 // notification to prevent reentrance to UpdateDisplaysWith(). 249 void SetSelectedModeForDisplayId(int64_t display_id, 250 const ManagedDisplayMode& display_mode); 251 252 // Tells if the virtual resolution feature is enabled. 253 bool IsDisplayUIScalingEnabled() const; 254 255 // Returns the current overscan insets for the specified |display_id|. 256 // Returns an empty insets (0, 0, 0, 0) if no insets are specified for the 257 // display. 258 gfx::Insets GetOverscanInsets(int64_t display_id) const; 259 260 // Called when display configuration has changed. The new display 261 // configurations is passed as a vector of Display object, which contains each 262 // display's new infomration. 263 void OnNativeDisplaysChanged( 264 const std::vector<ManagedDisplayInfo>& display_info_list); 265 266 // Updates the internal display data and notifies observers about the changes. 267 void UpdateDisplaysWith( 268 const std::vector<ManagedDisplayInfo>& display_info_list); 269 270 // Updates current displays using current |display_info_|. 271 void UpdateDisplays(); 272 273 // Returns the display at |index|. The display at 0 is no longer considered 274 // "primary". 275 const Display& GetDisplayAt(size_t index) const; 276 277 const Display& GetPrimaryDisplayCandidate() const; 278 279 // This is called by ScreenAsh when the primary display is requested, but 280 // there is no valid display. It provides a display that 281 // - has a non-empty screen rect 282 // - has a valid gfx::BufferFormat 283 // This exists to enable buggy observers assume that the primary display 284 // will always have non-zero size and a valid gfx::BufferFormat. The right 285 // solution to this problem is to fix those observers. 286 // https://crbug.com/866714, https://crbug.com/1057501 287 static const Display& GetFakePrimaryDisplay(); 288 289 // Returns the logical number of displays. This returns 1 when displays are 290 // mirrored. 291 size_t GetNumDisplays() const; 292 293 // Returns only the currently active displays. This list does not include the 294 // displays that will be removed if |UpdateDisplaysWith| is currently 295 // executing. 296 // See https://crbug.com/632755 active_only_display_list()297 const Displays& active_only_display_list() const { 298 return is_updating_display_list_ ? active_only_display_list_ 299 : active_display_list(); 300 } 301 active_display_list()302 const Displays& active_display_list() const { return active_display_list_; } 303 304 // Returns true if the display specified by |display_id| is currently 305 // connected and active. (mirroring display isn't active, for example). 306 bool IsActiveDisplayId(int64_t display_id) const; 307 308 // Returns the number of connected displays. This returns 2 when displays are 309 // mirrored. num_connected_displays()310 size_t num_connected_displays() const { return num_connected_displays_; } 311 312 // Returns true if either software or hardware mirror mode is active. 313 bool IsInMirrorMode() const; 314 315 // Returns true if software mirror mode is active. Note that when 316 // SoftwareMirroringEnabled() returns true, it only means software mirroring 317 // mode is requested, but it does not guarantee that the mode is active. The 318 // mode will be active after UpdateDisplaysWith() is called. 319 bool IsInSoftwareMirrorMode() const; 320 321 // Returns true if hardware mirror mode is active. 322 bool IsInHardwareMirrorMode() const; 323 mirroring_source_id()324 int64_t mirroring_source_id() const { return mirroring_source_id_; } 325 326 // Returns a list of mirroring destination display ids. 327 DisplayIdList GetMirroringDestinationDisplayIdList() const; 328 software_mirroring_display_list()329 const Displays& software_mirroring_display_list() const { 330 return software_mirroring_display_list_; 331 } 332 333 // Used in test to prevent previous mirror modes affecting current mode. set_disable_restoring_mirror_mode_for_test(bool disabled)334 void set_disable_restoring_mirror_mode_for_test(bool disabled) { 335 disable_restoring_mirror_mode_for_test_ = disabled; 336 } 337 external_display_mirror_info()338 const std::set<int64_t>& external_display_mirror_info() const { 339 return external_display_mirror_info_; 340 } 341 set_external_display_mirror_info(const std::set<int64_t> & external_display_mirror_info)342 void set_external_display_mirror_info( 343 const std::set<int64_t>& external_display_mirror_info) { 344 external_display_mirror_info_ = external_display_mirror_info; 345 } 346 set_should_restore_mirror_mode_from_display_prefs(bool value)347 void set_should_restore_mirror_mode_from_display_prefs(bool value) { 348 should_restore_mirror_mode_from_display_prefs_ = value; 349 } 350 mixed_mirror_mode_params()351 const base::Optional<MixedMirrorModeParams>& mixed_mirror_mode_params() 352 const { 353 return mixed_mirror_mode_params_; 354 } 355 356 // Set mixed mirror mode parameters. The parameters will be used to restore 357 // mixed mirror mode in the next display configuration. (Use SetMirrorMode() 358 // to immediately switch to mixed mirror mode.) set_mixed_mirror_mode_params(const base::Optional<MixedMirrorModeParams> mixed_params)359 void set_mixed_mirror_mode_params( 360 const base::Optional<MixedMirrorModeParams> mixed_params) { 361 mixed_mirror_mode_params_ = mixed_params; 362 } 363 dec_screen_capture_active_counter()364 void dec_screen_capture_active_counter() { 365 DCHECK_GT(screen_capture_active_counter_, 0); 366 screen_capture_active_counter_--; 367 } 368 inc_screen_capture_active_counter()369 void inc_screen_capture_active_counter() { ++screen_capture_active_counter_; } 370 screen_capture_is_active()371 bool screen_capture_is_active() const { 372 return screen_capture_active_counter_ > 0; 373 } 374 375 // Remove mirroring source and destination displays, so that they will be 376 // updated when UpdateDisplaysWith() is called. 377 void ClearMirroringSourceAndDestination(); 378 379 // Sets/gets if the unified desktop feature is enabled. 380 void SetUnifiedDesktopEnabled(bool enabled); unified_desktop_enabled()381 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } 382 383 // Returns true if it's in unified desktop mode. 384 bool IsInUnifiedMode() const; 385 386 // Sets the Unified Desktop layout using the given |matrix| and sets the 387 // current mode to Unified Desktop. 388 void SetUnifiedDesktopMatrix(const UnifiedDesktopLayoutMatrix& matrix); 389 390 // Returns the Unified Desktop mode mirroring display according to the 391 // supplied |cell_position| in the matrix. Returns invalid display if we're 392 // not in Unified mode. 393 Display GetMirroringDisplayForUnifiedDesktop( 394 DisplayPositionInUnifiedMatrix cell_position) const; 395 396 // Returns the index of the row in the Unified Mode layout matrix which 397 // contains the display with |display_id|. 398 int GetMirroringDisplayRowIndexInUnifiedMatrix(int64_t display_id) const; 399 400 // Returns the maximum display height of the row with |row_index| in the 401 // Unified Mode layout matrix. 402 int GetUnifiedDesktopRowMaxHeight(int row_index) const; 403 404 // Returns the display used for software mirrroring. Returns invalid display 405 // if not found. 406 const Display GetMirroringDisplayById(int64_t id) const; 407 408 // Retuns the display info associated with |display_id|. 409 const ManagedDisplayInfo& GetDisplayInfo(int64_t display_id) const; 410 411 // Returns the human-readable name for the display |id|. 412 std::string GetDisplayNameForId(int64_t id) const; 413 414 // Returns true if mirror mode should be set on for the specified displays. 415 // If |should_check_hardware_mirroring| is true, the state of 416 // IsInHardwareMirroringMode() will also be taken into account. 417 bool ShouldSetMirrorModeOn(const DisplayIdList& id_list, 418 bool should_check_hardware_mirroring); 419 420 // Change the mirror mode. |mixed_params| will be ignored if mirror mode is 421 // off or normal. When mirror mode is off, display mode will be set to default 422 // mode (either extended mode or unified desktop mode). When mirror mode is 423 // normal, the default source display will be mirrored to all other displays. 424 // When mirror mode is mixed, the specified source display will be mirrored to 425 // the specified destination displays and all other connected displays will be 426 // extended. 427 void SetMirrorMode(MirrorMode mode, 428 const base::Optional<MixedMirrorModeParams>& mixed_params); 429 430 // Used to emulate display change when run in a desktop environment instead 431 // of on a device. 432 void AddRemoveDisplay( 433 ManagedDisplayInfo::ManagedDisplayModeList display_modes = {}); 434 void ToggleDisplayScaleFactor(); 435 436 #if defined(OS_CHROMEOS) 437 void InitConfigurator(std::unique_ptr<NativeDisplayDelegate> delegate); 438 void ForceInitialConfigureWithObservers( 439 display::DisplayChangeObserver* display_change_observer, 440 display::DisplayConfigurator::Observer* display_error_observer); 441 442 // SoftwareMirroringController override: 443 void SetSoftwareMirroring(bool enabled) override; 444 bool SoftwareMirroringEnabled() const override; 445 bool IsSoftwareMirroringEnforced() const override; 446 void SetTouchCalibrationData( 447 int64_t display_id, 448 const TouchCalibrationData::CalibrationPointPairQuad& point_pair_quad, 449 const gfx::Size& display_bounds, 450 const TouchDeviceIdentifier& touch_device_identifier); 451 void ClearTouchCalibrationData( 452 int64_t display_id, 453 base::Optional<TouchDeviceIdentifier> touch_device_identifier); 454 void UpdateZoomFactor(int64_t display_id, float zoom_factor); 455 bool HasUnassociatedDisplay() const; 456 #endif 457 458 // Sets/gets default multi display mode. 459 void SetDefaultMultiDisplayModeForCurrentDisplays(MultiDisplayMode mode); current_default_multi_display_mode()460 MultiDisplayMode current_default_multi_display_mode() const { 461 return current_default_multi_display_mode_; 462 } 463 464 // Sets multi display mode. 465 void SetMultiDisplayMode(MultiDisplayMode mode); 466 467 // Reconfigure display configuration using the same physical display. 468 // TODO(oshima): Refactor and move this impl to |SetDefaultMultiDisplayMode|. 469 void ReconfigureDisplays(); 470 471 // Update the bounds of the display given by |display_id|. 472 bool UpdateDisplayBounds(int64_t display_id, const gfx::Rect& new_bounds); 473 474 // Creates mirror window asynchronously if the software mirror mode is 475 // enabled. 476 void CreateMirrorWindowAsyncIfAny(); 477 478 // A unit test may change the internal display id (which never happens on a 479 // real device). This will update the mode list for internal display for this 480 // test scenario. 481 void UpdateInternalManagedDisplayModeListForTest(); 482 483 // Zooms the display identified by |display_id| by increasing or decreasing 484 // its zoom factor value by 1 unit. Zooming in will have no effect on the 485 // display if it is already at its maximum zoom. Vice versa for zooming out. 486 bool ZoomDisplay(int64_t display_id, bool up); 487 488 // Resets the zoom value to 1 for the display identified by |display_id|. 489 void ResetDisplayZoom(int64_t display_id); 490 491 // Notifies observers of display configuration changes. 492 void NotifyMetricsChanged(const Display& display, uint32_t metrics); 493 void NotifyDisplayAdded(const Display& display); 494 void NotifyDisplayRemoved(const Display& display); 495 496 // Delegated from the Screen implementation. 497 void AddObserver(DisplayObserver* observer); 498 void RemoveObserver(DisplayObserver* observer); 499 500 private: 501 friend class test::DisplayManagerTestApi; 502 503 // See description above |notify_depth_| for details. 504 class BeginEndNotifier { 505 public: 506 explicit BeginEndNotifier(DisplayManager* display_manager); 507 ~BeginEndNotifier(); 508 509 private: 510 DisplayManager* display_manager_; 511 512 DISALLOW_COPY_AND_ASSIGN(BeginEndNotifier); 513 }; 514 set_change_display_upon_host_resize(bool value)515 void set_change_display_upon_host_resize(bool value) { 516 change_display_upon_host_resize_ = value; 517 } 518 519 // Creates software mirroring display related information. The display used to 520 // mirror the content is removed from the |display_info_list|. 521 void CreateSoftwareMirroringDisplayInfo(DisplayInfoList* display_info_list); 522 523 // Same as above but for Unified Desktop. 524 void CreateUnifiedDesktopDisplayInfo(DisplayInfoList* display_info_list); 525 526 // Finds an display for given |display_id|. Returns nullptr if not found. 527 Display* FindDisplayForId(int64_t display_id); 528 529 // Add the mirror display's display info if the software based mirroring is in 530 // use. This should only be called before UpdateDisplaysWith(). 531 void AddMirrorDisplayInfoIfAny(DisplayInfoList* display_info_list); 532 533 // Inserts and update the ManagedDisplayInfo according to the overscan state. 534 // Note that The ManagedDisplayInfo stored in the |internal_display_info_| can 535 // be different from |new_info| (due to overscan state), so you must use 536 // |GetDisplayInfo| to get the correct ManagedDisplayInfo for a display. 537 void InsertAndUpdateDisplayInfo(const ManagedDisplayInfo& new_info); 538 539 // Creates a display object from the ManagedDisplayInfo for 540 // |display_id|. 541 Display CreateDisplayFromDisplayInfoById(int64_t display_id); 542 543 // Creates a display object from the ManagedDisplayInfo for |display_id| for 544 // mirroring. The size of the display will be scaled using |scale| with the 545 // offset using |origin|. 546 Display CreateMirroringDisplayFromDisplayInfoById(int64_t display_id, 547 const gfx::Point& origin, 548 float scale); 549 550 // Updates the bounds of all non-primary displays in |display_list| and append 551 // the indices of displays updated to |updated_indices|. When the size of 552 // |display_list| equals 2, the bounds are updated using the layout registered 553 // for the display pair. For more than 2 displays, the bounds are updated 554 // using horizontal layout. 555 void UpdateNonPrimaryDisplayBoundsForLayout( 556 Displays* display_list, 557 std::vector<size_t>* updated_indices); 558 559 void CreateMirrorWindowIfAny(); 560 561 void RunPendingTasksForTest(); 562 563 // Applies the |layout| and updates the bounds of displays in |display_list|. 564 // |updated_ids| contains the ids for displays whose bounds have changed. 565 void ApplyDisplayLayout(DisplayLayout* layout, 566 Displays* display_list, 567 std::vector<int64_t>* updated_ids); 568 569 // Update the info used to restore mirror mode. 570 void UpdateInfoForRestoringMirrorMode(); 571 572 void UpdatePrimaryDisplayIdIfNecessary(); 573 574 Delegate* delegate_ = nullptr; // not owned. 575 576 // When set to true, DisplayManager will use DisplayConfigurator to configure 577 // displays. By default, this is set to true when running on device and false 578 // when running off device. 579 bool configure_displays_ = false; 580 581 std::unique_ptr<Screen> screen_; 582 583 std::unique_ptr<DisplayLayoutStore> layout_store_; 584 585 std::unique_ptr<DisplayLayout> current_resolved_layout_; 586 587 // The matrix that's used to layout the displays in Unified Desktop mode. 588 UnifiedDesktopLayoutMatrix current_unified_desktop_matrix_; 589 590 std::map<int64_t, int> mirroring_display_id_to_unified_matrix_row_; 591 592 std::vector<int> unified_display_rows_heights_; 593 594 int64_t first_display_id_ = kInvalidDisplayId; 595 596 // List of current active displays. 597 Displays active_display_list_; 598 // This list does not include the displays that will be removed if 599 // |UpdateDisplaysWith| is under execution. 600 // See https://crbug.com/632755 601 Displays active_only_display_list_; 602 603 // True if active_display_list is being modified and has displays that are not 604 // presently active. 605 // See https://crbug.com/632755 606 bool is_updating_display_list_ = false; 607 608 size_t num_connected_displays_ = 0; 609 610 bool force_bounds_changed_ = false; 611 612 // The mapping from the display ID to its internal data. 613 std::map<int64_t, ManagedDisplayInfo> display_info_; 614 615 // Selected display modes for displays. Key is the displays' ID. 616 std::map<int64_t, ManagedDisplayMode> display_modes_; 617 618 // When set to true, the host window's resize event updates the display's 619 // size. This is set to true when running on desktop environment (for 620 // debugging) so that resizing the host window will update the display 621 // properly. This is set to false on device as well as during the unit tests. 622 bool change_display_upon_host_resize_ = false; 623 624 MultiDisplayMode multi_display_mode_ = EXTENDED; 625 MultiDisplayMode current_default_multi_display_mode_ = EXTENDED; 626 627 // This is used in two distinct ways: 628 // 1. The source display id when software mirroring is active. 629 // 2. There's no source and destination display in hardware mirroring, so we 630 // treat the first mirroring display id as source id when hardware mirroring 631 // is active. 632 int64_t mirroring_source_id_ = kInvalidDisplayId; 633 634 // This is used in two distinct ways: 635 // 1. when software mirroring is active this contains the destination 636 // displays. 637 // 2. when unified mode is enabled this is the set of physical displays. 638 Displays software_mirroring_display_list_; 639 640 // There's no source and destination display in hardware mirroring, so we 641 // treat the first mirroring display as source and store its id in 642 // |mirroring_source_id_| and treat the rest of mirroring displays as 643 // destination and store their ids in this list. 644 DisplayIdList hardware_mirroring_display_id_list_; 645 646 // Stores external displays that were in mirror mode before. 647 std::set<int64_t> external_display_mirror_info_; 648 649 // This is set to true when the display prefs have been loaded from local 650 // state to signal that we should restore the mirror mode state from 651 // |external_display_mirror_info_| in the upcoming display re-configuration. 652 bool should_restore_mirror_mode_from_display_prefs_ = false; 653 654 // True if mirror mode should not be restored. Only used in test. 655 bool disable_restoring_mirror_mode_for_test_ = false; 656 657 // Cached mirror mode for metrics changed notification. 658 bool mirror_mode_for_metrics_ = false; 659 660 // User preference for rotation lock of the internal display. 661 bool registered_internal_display_rotation_lock_ = false; 662 663 // User preference for the rotation of the internal display. 664 Display::Rotation registered_internal_display_rotation_ = Display::ROTATE_0; 665 666 bool unified_desktop_enabled_ = false; 667 668 bool internal_display_has_accelerometer_ = false; 669 670 // Set during screen capture to enable software compositing of mouse cursor, 671 // this is a counter to enable multiple active sessions at once. 672 int screen_capture_active_counter_ = 0; 673 674 // Holds a callback to help RunPendingTasksForTest() to exit at the correct 675 // time. 676 base::OnceClosure created_mirror_window_; 677 678 base::ObserverList<DisplayObserver> observers_; 679 680 // Not empty if mixed mirror mode should be turned on (the specified source 681 // display is mirrored to the specified destination displays). Empty if mixed 682 // mirror mode is disabled. 683 base::Optional<MixedMirrorModeParams> mixed_mirror_mode_params_; 684 685 // This is incremented whenever a BeginEndNotifier is created and decremented 686 // when destroyed. BeginEndNotifier uses this to track when it should call 687 // OnWillProcessDisplayChanges() and OnDidProcessDisplayChanges(). 688 int notify_depth_ = 0; 689 690 #if defined(OS_CHROMEOS) 691 std::unique_ptr<display::DisplayConfigurator> display_configurator_; 692 693 std::unique_ptr<TouchDeviceManager> touch_device_manager_; 694 695 // A cancelable callback to trigger sending UMA metrics when display zoom is 696 // updated. The reason we need a cancelable callback is because we dont want 697 // to record UMA metrics for changes to the display zoom that are temporary. 698 // Temporary changes may include things like the user trying out different 699 // zoom levels before making the final decision. 700 base::CancelableCallback<void()> on_display_zoom_modify_timeout_; 701 #endif 702 703 base::WeakPtrFactory<DisplayManager> weak_ptr_factory_{this}; 704 705 DISALLOW_COPY_AND_ASSIGN(DisplayManager); 706 }; 707 708 } // namespace display 709 710 #endif // UI_DISPLAY_MANAGER_DISPLAY_MANAGER_H_ 711