| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_UI_WS_DISPLAY_MANAGER_H_ | 5 #ifndef SERVICES_UI_WS_DISPLAY_MANAGER_H_ |
| 6 #define SERVICES_UI_WS_DISPLAY_MANAGER_H_ | 6 #define SERVICES_UI_WS_DISPLAY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "services/ui/display/screen_manager_delegate.h" | 13 #include "services/ui/display/screen_manager_delegate.h" |
| 14 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 14 #include "services/ui/ws/ids.h" | 15 #include "services/ui/ws/ids.h" |
| 15 #include "services/ui/ws/user_id.h" | 16 #include "services/ui/ws/user_id.h" |
| 16 #include "services/ui/ws/user_id_tracker_observer.h" | 17 #include "services/ui/ws/user_id_tracker_observer.h" |
| 17 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 class EventRewriter; | 21 class EventRewriter; |
| 21 namespace ws { | 22 namespace ws { |
| 22 | 23 |
| 23 class CursorLocationManager; | 24 class CursorLocationManager; |
| 24 class Display; | 25 class Display; |
| 25 class ServerWindow; | 26 class ServerWindow; |
| 26 class UserDisplayManager; | 27 class UserDisplayManager; |
| 27 class UserIdTracker; | 28 class UserIdTracker; |
| 28 class WindowManagerDisplayRoot; | 29 class WindowManagerDisplayRoot; |
| 29 class WindowServer; | 30 class WindowServer; |
| 30 | 31 |
| 31 // DisplayManager manages the set of Displays. DisplayManager distinguishes | 32 // DisplayManager manages the set of Displays. DisplayManager distinguishes |
| 32 // between displays that do not yet have an accelerated widget (pending), vs | 33 // between displays that do not yet have an accelerated widget (pending), vs |
| 33 // those that do. | 34 // those that do. |
| 34 class DisplayManager : public UserIdTrackerObserver, | 35 class DisplayManager : public UserIdTrackerObserver, |
| 35 public display::ScreenManagerDelegate { | 36 public display::ScreenManagerDelegate { |
| 36 public: | 37 public: |
| 37 DisplayManager(WindowServer* window_server, UserIdTracker* user_id_tracker); | 38 DisplayManager(WindowServer* window_server, UserIdTracker* user_id_tracker); |
| 38 ~DisplayManager() override; | 39 ~DisplayManager() override; |
| 39 | 40 |
| 41 // Called once WindowServer::display_creation_config() has been determined. |
| 42 void OnDisplayCreationConfigSet(); |
| 43 |
| 44 // Indicates the display configuration is valid. Set to true when the |
| 45 // display_creation_config() has been determined and the config is |
| 46 // AUTOMATIC, or MANUAL and the SetDisplayConfiguration() has been called. |
| 47 bool got_initial_config_from_window_manager() const { |
| 48 return got_initial_config_from_window_manager_; |
| 49 } |
| 50 |
| 51 // Sets the display configuration from the window manager. Returns true |
| 52 // on success, false if the arguments aren't valid. |
| 53 bool SetDisplayConfiguration( |
| 54 const std::vector<display::Display>& displays, |
| 55 std::vector<ui::mojom::WmViewportMetricsPtr> viewport_metrics, |
| 56 int64_t primary_display_id); |
| 57 |
| 40 // Returns the UserDisplayManager for |user_id|. DisplayManager owns the | 58 // Returns the UserDisplayManager for |user_id|. DisplayManager owns the |
| 41 // return value. | 59 // return value. |
| 42 UserDisplayManager* GetUserDisplayManager(const UserId& user_id); | 60 UserDisplayManager* GetUserDisplayManager(const UserId& user_id); |
| 43 | 61 |
| 44 // Returns the CursorLocationManager for |user_id|. | 62 // Returns the CursorLocationManager for |user_id|. |
| 45 CursorLocationManager* GetCursorLocationManager(const UserId& user_id); | 63 CursorLocationManager* GetCursorLocationManager(const UserId& user_id); |
| 46 | 64 |
| 47 // Adds/removes a Display. DisplayManager owns the Displays. | 65 // Adds/removes a Display. DisplayManager owns the Displays. |
| 48 // TODO(sky): make add take a scoped_ptr. | 66 // TODO(sky): make add take a scoped_ptr. |
| 49 void AddDisplay(Display* display); | 67 void AddDisplay(Display* display); |
| 50 // Called when the window manager explicitly adds a new display. | 68 // Called when the window manager explicitly adds a new display. |
| 51 void AddDisplayForWindowManager(const display::Display& display, | 69 Display* AddDisplayForWindowManager(bool is_primary_display, |
| 52 const display::ViewportMetrics& metrics); | 70 const display::Display& display, |
| 71 const display::ViewportMetrics& metrics); |
| 53 void DestroyDisplay(Display* display); | 72 void DestroyDisplay(Display* display); |
| 54 void DestroyAllDisplays(); | 73 void DestroyAllDisplays(); |
| 55 const std::set<Display*>& displays() { return displays_; } | 74 const std::set<Display*>& displays() { return displays_; } |
| 56 std::set<const Display*> displays() const; | 75 std::set<const Display*> displays() const; |
| 57 | 76 |
| 58 // Notifies when something about the Display changes. | 77 // Notifies when something about the Display changes. |
| 59 void OnDisplayUpdated(const display::Display& display); | 78 void OnDisplayUpdated(const display::Display& display); |
| 60 | 79 |
| 61 // Returns the Display that contains |window|, or null if |window| is not | 80 // Returns the Display that contains |window|, or null if |window| is not |
| 62 // attached to a display. | 81 // attached to a display. |
| 63 Display* GetDisplayContaining(const ServerWindow* window); | 82 Display* GetDisplayContaining(const ServerWindow* window); |
| 64 const Display* GetDisplayContaining(const ServerWindow* window) const; | 83 const Display* GetDisplayContaining(const ServerWindow* window) const; |
| 65 | 84 |
| 66 // Returns the display with the specified display id, or null if there is no | 85 // Returns the display with the specified display id, or null if there is no |
| 67 // display with that id. | 86 // display with that id. |
| 68 Display* GetDisplayById(int64_t display_id); | 87 Display* GetDisplayById(int64_t display_id); |
| 69 | 88 |
| 70 const WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( | 89 const WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( |
| 71 const ServerWindow* window) const; | 90 const ServerWindow* window) const; |
| 72 // TODO(sky): constness here is wrong! fix! | 91 // TODO(sky): constness here is wrong! fix! |
| 73 WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( | 92 WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( |
| 74 const ServerWindow* window); | 93 const ServerWindow* window); |
| 75 | 94 |
| 76 bool has_displays() const { return !displays_.empty(); } | 95 bool IsReady() const { |
| 96 return !displays_.empty() && got_initial_config_from_window_manager_; |
| 97 } |
| 77 bool has_active_or_pending_displays() const { | 98 bool has_active_or_pending_displays() const { |
| 78 return !displays_.empty() || !pending_displays_.empty(); | 99 return !displays_.empty() || !pending_displays_.empty(); |
| 79 } | 100 } |
| 80 | 101 |
| 81 // Returns the id for the next root window (both for the root of a Display | 102 // Returns the id for the next root window (both for the root of a Display |
| 82 // as well as the root of WindowManagers). | 103 // as well as the root of WindowManagers). |
| 83 WindowId GetAndAdvanceNextRootId(); | 104 WindowId GetAndAdvanceNextRootId(); |
| 84 | 105 |
| 85 // Called when the AcceleratedWidget is available for |display|. | 106 // Called when the AcceleratedWidget is available for |display|. |
| 86 void OnDisplayAcceleratedWidgetAvailable(Display* display); | 107 void OnDisplayAcceleratedWidgetAvailable(Display* display); |
| 87 | 108 |
| 88 // Switch the high contrast mode of all Displays to |enabled|. | 109 // Switch the high contrast mode of all Displays to |enabled|. |
| 89 void SetHighContrastMode(bool enabled); | 110 void SetHighContrastMode(bool enabled); |
| 90 | 111 |
| 91 private: | 112 private: |
| 92 // UserIdTrackerObserver: | 113 // UserIdTrackerObserver: |
| 93 void OnActiveUserIdChanged(const UserId& previously_active_id, | 114 void OnActiveUserIdChanged(const UserId& previously_active_id, |
| 94 const UserId& active_id) override; | 115 const UserId& active_id) override; |
| 95 | 116 |
| 117 void CreateDisplay(const display::Display& display, |
| 118 const display::ViewportMetrics& metrics); |
| 119 |
| 120 // NOTE: these functions are *not* called when the WindowManager manually |
| 121 // creates roots. |
| 96 // display::ScreenManagerDelegate: | 122 // display::ScreenManagerDelegate: |
| 97 void OnDisplayAdded(const display::Display& display, | 123 void OnDisplayAdded(const display::Display& display, |
| 98 const display::ViewportMetrics& metrics) override; | 124 const display::ViewportMetrics& metrics) override; |
| 99 void OnDisplayRemoved(int64_t id) override; | 125 void OnDisplayRemoved(int64_t id) override; |
| 100 void OnDisplayModified(const display::Display& display, | 126 void OnDisplayModified(const display::Display& display, |
| 101 const display::ViewportMetrics& metrics) override; | 127 const display::ViewportMetrics& metrics) override; |
| 102 void OnPrimaryDisplayChanged(int64_t primary_display_id) override; | 128 void OnPrimaryDisplayChanged(int64_t primary_display_id) override; |
| 103 | 129 |
| 104 WindowServer* window_server_; | 130 WindowServer* window_server_; |
| 105 UserIdTracker* user_id_tracker_; | 131 UserIdTracker* user_id_tracker_; |
| 106 | 132 |
| 107 // For rewriting ChromeOS function keys. | 133 // For rewriting ChromeOS function keys. |
| 108 std::unique_ptr<ui::EventRewriter> event_rewriter_; | 134 std::unique_ptr<ui::EventRewriter> event_rewriter_; |
| 109 | 135 |
| 110 // Displays are initially added to |pending_displays_|. When the display is | 136 // Displays are initially added to |pending_displays_|. When the display is |
| 111 // initialized it is moved to |displays_|. WindowServer owns the Displays. | 137 // initialized it is moved to |displays_|. WindowServer owns the Displays. |
| 112 std::set<Display*> pending_displays_; | 138 std::set<Display*> pending_displays_; |
| 113 std::set<Display*> displays_; | 139 std::set<Display*> displays_; |
| 114 | 140 |
| 115 std::map<UserId, std::unique_ptr<UserDisplayManager>> user_display_managers_; | 141 std::map<UserId, std::unique_ptr<UserDisplayManager>> user_display_managers_; |
| 116 | 142 |
| 117 std::map<UserId, std::unique_ptr<CursorLocationManager>> | 143 std::map<UserId, std::unique_ptr<CursorLocationManager>> |
| 118 cursor_location_managers_; | 144 cursor_location_managers_; |
| 119 | 145 |
| 120 // ID to use for next root node. | 146 // ID to use for next root node. |
| 121 ClientSpecificId next_root_id_; | 147 ClientSpecificId next_root_id_; |
| 122 | 148 |
| 149 bool got_initial_config_from_window_manager_ = false; |
| 150 |
| 123 DISALLOW_COPY_AND_ASSIGN(DisplayManager); | 151 DISALLOW_COPY_AND_ASSIGN(DisplayManager); |
| 124 }; | 152 }; |
| 125 | 153 |
| 126 } // namespace ws | 154 } // namespace ws |
| 127 } // namespace ui | 155 } // namespace ui |
| 128 | 156 |
| 129 #endif // SERVICES_UI_WS_DISPLAY_MANAGER_H_ | 157 #endif // SERVICES_UI_WS_DISPLAY_MANAGER_H_ |
| OLD | NEW |