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