1 // Copyright 2013 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_CHANGE_OBSERVER_H_
6 #define UI_DISPLAY_MANAGER_DISPLAY_CHANGE_OBSERVER_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "base/macros.h"
14 #include "ui/display/manager/display_configurator.h"
15 #include "ui/display/manager/display_manager_export.h"
16 #include "ui/display/manager/managed_display_info.h"
17 #include "ui/events/devices/input_device_event_observer.h"
18 
19 namespace display {
20 
21 class DisplayManager;
22 class DisplaySnapshot;
23 
24 // An object that observes changes in display configuration and updates
25 // DisplayManager.
26 class DISPLAY_MANAGER_EXPORT DisplayChangeObserver
27     : public DisplayConfigurator::StateController,
28       public DisplayConfigurator::Observer,
29       public ui::InputDeviceEventObserver {
30  public:
31   // Returns the mode list for internal display.
32   DISPLAY_EXPORT static ManagedDisplayInfo::ManagedDisplayModeList
33   GetInternalManagedDisplayModeList(const ManagedDisplayInfo& display_info,
34                                     const DisplaySnapshot& output);
35 
36   // Returns the resolution list.
37   DISPLAY_EXPORT static ManagedDisplayInfo::ManagedDisplayModeList
38   GetExternalManagedDisplayModeList(const DisplaySnapshot& output);
39 
40   explicit DisplayChangeObserver(DisplayManager* display_manager);
41   ~DisplayChangeObserver() override;
42 
43   // DisplayConfigurator::StateController overrides:
44   MultipleDisplayState GetStateForDisplayIds(
45       const DisplayConfigurator::DisplayStateList& outputs) override;
46   bool GetSelectedModeForDisplayId(int64_t display_id,
47                                    ManagedDisplayMode* out_mode) const override;
48 
49   // Overriden from DisplayConfigurator::Observer:
50   void OnDisplayModeChanged(
51       const DisplayConfigurator::DisplayStateList& outputs) override;
52   void OnDisplayModeChangeFailed(
53       const DisplayConfigurator::DisplayStateList& displays,
54       MultipleDisplayState failed_new_state) override;
55 
56   // Overriden from ui::InputDeviceEventObserver:
57   void OnInputDeviceConfigurationChanged(uint8_t input_device_types) override;
58 
59   // Exposed for testing.
60   DISPLAY_EXPORT static float FindDeviceScaleFactor(float dpi);
61 
62  private:
63   void UpdateInternalDisplay(
64       const DisplayConfigurator::DisplayStateList& display_states);
65 
66   ManagedDisplayInfo CreateManagedDisplayInfo(const DisplaySnapshot* snapshot,
67                                               const DisplayMode* mode_info);
68 
69   // |display_manager_| is not owned and must outlive DisplayChangeObserver.
70   DisplayManager* display_manager_;
71 
72   DISALLOW_COPY_AND_ASSIGN(DisplayChangeObserver);
73 };
74 
75 }  // namespace display
76 
77 #endif  // UI_DISPLAY_MANAGER_DISPLAY_CHANGE_OBSERVER_H_
78