| 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 COMPONENTS_MUS_WS_DISPLAY_MANAGER_H_ | 5 #ifndef COMPONENTS_MUS_WS_DISPLAY_MANAGER_H_ |
| 6 #define COMPONENTS_MUS_WS_DISPLAY_MANAGER_H_ | 6 #define COMPONENTS_MUS_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 "components/mus/ws/ids.h" | 13 #include "components/mus/ws/ids.h" |
| 14 #include "components/mus/ws/user_id.h" | 14 #include "components/mus/ws/user_id.h" |
| 15 #include "components/mus/ws/user_id_tracker_observer.h" |
| 15 | 16 |
| 16 namespace mus { | 17 namespace mus { |
| 17 namespace ws { | 18 namespace ws { |
| 18 | 19 |
| 19 class Display; | 20 class Display; |
| 20 class DisplayManagerDelegate; | 21 class DisplayManagerDelegate; |
| 21 class ServerWindow; | 22 class ServerWindow; |
| 22 class UserDisplayManager; | 23 class UserDisplayManager; |
| 23 class WindowManagerState; | 24 class UserIdTracker; |
| 25 class WindowManagerDisplayRoot; |
| 24 | 26 |
| 25 struct WindowManagerAndDisplay { | 27 // DisplayManager manages the set of Displays. DisplayManager distinguishes |
| 26 WindowManagerAndDisplay() : window_manager_state(nullptr), display(nullptr) {} | 28 // between displays that do yet have an accelerated widget (pending), vs |
| 27 | 29 // those that do. |
| 28 WindowManagerState* window_manager_state; | 30 class DisplayManager : public UserIdTrackerObserver { |
| 29 Display* display; | |
| 30 }; | |
| 31 | |
| 32 struct WindowManagerAndDisplayConst { | |
| 33 WindowManagerAndDisplayConst() | |
| 34 : window_manager_state(nullptr), display(nullptr) {} | |
| 35 const WindowManagerState* window_manager_state; | |
| 36 const Display* display; | |
| 37 }; | |
| 38 | |
| 39 class DisplayManager { | |
| 40 public: | 31 public: |
| 41 explicit DisplayManager(DisplayManagerDelegate* delegate); | 32 DisplayManager(DisplayManagerDelegate* delegate, |
| 42 ~DisplayManager(); | 33 UserIdTracker* user_id_tracker); |
| 34 ~DisplayManager() override; |
| 43 | 35 |
| 44 // Returns the UserDisplayManager for |user_id|. DisplayManager owns the | 36 // Returns the UserDisplayManager for |user_id|. DisplayManager owns the |
| 45 // return value. | 37 // return value. |
| 46 UserDisplayManager* GetUserDisplayManager(const UserId& user_id); | 38 UserDisplayManager* GetUserDisplayManager(const UserId& user_id); |
| 47 | 39 |
| 48 // Adds/removes a Display. DisplayManager owns the Displays. | 40 // Adds/removes a Display. DisplayManager owns the Displays. |
| 49 // TODO(sky): make add take a scoped_ptr. | 41 // TODO(sky): make add take a scoped_ptr. |
| 50 void AddDisplay(Display* display); | 42 void AddDisplay(Display* display); |
| 51 void DestroyDisplay(Display* display); | 43 void DestroyDisplay(Display* display); |
| 52 void DestroyAllDisplays(); | 44 void DestroyAllDisplays(); |
| 53 const std::set<Display*>& displays() { return displays_; } | 45 const std::set<Display*>& displays() { return displays_; } |
| 54 std::set<const Display*> displays() const; | 46 std::set<const Display*> displays() const; |
| 55 | 47 |
| 56 // Notifies when something about the Display changes. | 48 // Notifies when something about the Display changes. |
| 57 void OnDisplayUpdate(Display* display); | 49 void OnDisplayUpdate(Display* display); |
| 58 | 50 |
| 59 // Returns the Display that contains |window|, or null if |window| is not | 51 // Returns the Display that contains |window|, or null if |window| is not |
| 60 // attached to a display. | 52 // attached to a display. |
| 61 Display* GetDisplayContaining(ServerWindow* window); | 53 Display* GetDisplayContaining(ServerWindow* window); |
| 62 const Display* GetDisplayContaining(const ServerWindow* window) const; | 54 const Display* GetDisplayContaining(const ServerWindow* window) const; |
| 63 | 55 |
| 64 WindowManagerAndDisplayConst GetWindowManagerAndDisplay( | 56 const WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( |
| 65 const ServerWindow* window) const; | 57 const ServerWindow* window) const; |
| 66 WindowManagerAndDisplay GetWindowManagerAndDisplay( | 58 // TODO(sky): constness here is wrong! fix! |
| 59 WindowManagerDisplayRoot* GetWindowManagerDisplayRoot( |
| 67 const ServerWindow* window); | 60 const ServerWindow* window); |
| 68 | 61 |
| 69 bool has_displays() const { return !displays_.empty(); } | 62 bool has_displays() const { return !displays_.empty(); } |
| 70 bool has_active_or_pending_displays() const { | 63 bool has_active_or_pending_displays() const { |
| 71 return !displays_.empty() || !pending_displays_.empty(); | 64 return !displays_.empty() || !pending_displays_.empty(); |
| 72 } | 65 } |
| 73 | 66 |
| 74 // Returns the id for the next root window (both for the root of a Display | 67 // Returns the id for the next root window (both for the root of a Display |
| 75 // as well as the root of WindowManagers). | 68 // as well as the root of WindowManagers). |
| 76 WindowId GetAndAdvanceNextRootId(); | 69 WindowId GetAndAdvanceNextRootId(); |
| 77 | 70 |
| 78 uint32_t GetAndAdvanceNextDisplayId(); | 71 uint32_t GetAndAdvanceNextDisplayId(); |
| 79 | 72 |
| 80 // Called when the AcceleratedWidget is available for |display|. | 73 // Called when the AcceleratedWidget is available for |display|. |
| 81 void OnDisplayAcceleratedWidgetAvailable(Display* display); | 74 void OnDisplayAcceleratedWidgetAvailable(Display* display); |
| 82 | 75 |
| 83 private: | 76 private: |
| 77 // UserIdTrackerObserver: |
| 78 void OnActiveUserIdChanged(const UserId& previously_active_id, |
| 79 const UserId& active_id) override; |
| 80 |
| 84 DisplayManagerDelegate* delegate_; | 81 DisplayManagerDelegate* delegate_; |
| 82 UserIdTracker* user_id_tracker_; |
| 85 | 83 |
| 86 // Displays are initially added to |pending_displays_|. When the display is | 84 // Displays are initially added to |pending_displays_|. When the display is |
| 87 // initialized it is moved to |displays_|. WindowServer owns the Displays. | 85 // initialized it is moved to |displays_|. WindowServer owns the Displays. |
| 88 std::set<Display*> pending_displays_; | 86 std::set<Display*> pending_displays_; |
| 89 std::set<Display*> displays_; | 87 std::set<Display*> displays_; |
| 90 | 88 |
| 91 std::map<UserId, std::unique_ptr<UserDisplayManager>> user_display_managers_; | 89 std::map<UserId, std::unique_ptr<UserDisplayManager>> user_display_managers_; |
| 92 | 90 |
| 93 // ID to use for next root node. | 91 // ID to use for next root node. |
| 94 ClientSpecificId next_root_id_; | 92 ClientSpecificId next_root_id_; |
| 95 | 93 |
| 96 uint32_t next_display_id_; | 94 uint32_t next_display_id_; |
| 97 | 95 |
| 98 DISALLOW_COPY_AND_ASSIGN(DisplayManager); | 96 DISALLOW_COPY_AND_ASSIGN(DisplayManager); |
| 99 }; | 97 }; |
| 100 | 98 |
| 101 } // namespace ws | 99 } // namespace ws |
| 102 } // namespace mus | 100 } // namespace mus |
| 103 | 101 |
| 104 #endif // COMPONENTS_MUS_WS_DISPLAY_MANAGER_H_ | 102 #endif // COMPONENTS_MUS_WS_DISPLAY_MANAGER_H_ |
| OLD | NEW |