Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/mus/ws/connection_manager.h

Issue 1766943002: Refators display related functionality into own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/ws/BUILD.gn ('k') | components/mus/ws/connection_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CONNECTION_MANAGER_H_ 5 #ifndef COMPONENTS_MUS_WS_CONNECTION_MANAGER_H_
6 #define COMPONENTS_MUS_WS_CONNECTION_MANAGER_H_ 6 #define COMPONENTS_MUS_WS_CONNECTION_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "components/mus/public/interfaces/display.mojom.h" 17 #include "components/mus/public/interfaces/display.mojom.h"
18 #include "components/mus/public/interfaces/window_manager_factory.mojom.h" 18 #include "components/mus/public/interfaces/window_manager_factory.mojom.h"
19 #include "components/mus/public/interfaces/window_tree.mojom.h" 19 #include "components/mus/public/interfaces/window_tree.mojom.h"
20 #include "components/mus/public/interfaces/window_tree_host.mojom.h" 20 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
21 #include "components/mus/surfaces/surfaces_state.h" 21 #include "components/mus/surfaces/surfaces_state.h"
22 #include "components/mus/ws/display.h" 22 #include "components/mus/ws/display.h"
23 #include "components/mus/ws/display_manager_delegate.h"
23 #include "components/mus/ws/ids.h" 24 #include "components/mus/ws/ids.h"
24 #include "components/mus/ws/operation.h" 25 #include "components/mus/ws/operation.h"
25 #include "components/mus/ws/server_window_delegate.h" 26 #include "components/mus/ws/server_window_delegate.h"
26 #include "components/mus/ws/server_window_observer.h" 27 #include "components/mus/ws/server_window_observer.h"
27 #include "components/mus/ws/user_id_tracker.h" 28 #include "components/mus/ws/user_id_tracker.h"
28 #include "components/mus/ws/window_manager_factory_registry.h" 29 #include "components/mus/ws/window_manager_factory_registry.h"
29 #include "mojo/converters/surfaces/custom_surface_converter.h" 30 #include "mojo/converters/surfaces/custom_surface_converter.h"
30 #include "mojo/public/cpp/bindings/array.h" 31 #include "mojo/public/cpp/bindings/array.h"
31 #include "mojo/public/cpp/bindings/binding.h" 32 #include "mojo/public/cpp/bindings/binding.h"
32 #include "mojo/public/cpp/bindings/binding_set.h" 33 #include "mojo/public/cpp/bindings/binding_set.h"
33 #include "mojo/public/cpp/bindings/interface_ptr_set.h" 34 #include "mojo/public/cpp/bindings/interface_ptr_set.h"
34 35
35 namespace mus { 36 namespace mus {
36 namespace ws { 37 namespace ws {
37 38
38 class ConnectionManagerDelegate; 39 class ConnectionManagerDelegate;
40 class DisplayManager;
39 class ServerWindow; 41 class ServerWindow;
40 class WindowManagerState; 42 class WindowManagerState;
41 class WindowTree; 43 class WindowTree;
42 class WindowTreeBinding; 44 class WindowTreeBinding;
43 45
44 struct WindowManagerAndDisplay {
45 WindowManagerAndDisplay() : window_manager_state(nullptr), display(nullptr) {}
46
47 WindowManagerState* window_manager_state;
48 Display* display;
49 };
50
51 struct WindowManagerAndDisplayConst {
52 WindowManagerAndDisplayConst()
53 : window_manager_state(nullptr), display(nullptr) {}
54 const WindowManagerState* window_manager_state;
55 const Display* display;
56 };
57
58 // ConnectionManager manages the set of connections to the window server (all 46 // ConnectionManager manages the set of connections to the window server (all
59 // the WindowTrees) as well as providing the root of the hierarchy. 47 // the WindowTrees) as well as providing the root of the hierarchy.
60 // 48 //
61 // TODO(sky): this class is doing too much. Refactor to make responsibilities 49 // TODO(sky): this class is doing too much. Refactor to make responsibilities
62 // clearer. 50 // clearer.
63 class ConnectionManager : public ServerWindowDelegate, 51 class ConnectionManager : public ServerWindowDelegate,
64 public ServerWindowObserver, 52 public ServerWindowObserver,
65 public mojom::DisplayManager { 53 public mojom::DisplayManager,
54 public DisplayManagerDelegate {
66 public: 55 public:
67 ConnectionManager(ConnectionManagerDelegate* delegate, 56 ConnectionManager(ConnectionManagerDelegate* delegate,
68 const scoped_refptr<mus::SurfacesState>& surfaces_state); 57 const scoped_refptr<mus::SurfacesState>& surfaces_state);
69 ~ConnectionManager() override; 58 ~ConnectionManager() override;
70 59
71 ConnectionManagerDelegate* delegate() { return delegate_; } 60 ConnectionManagerDelegate* delegate() { return delegate_; }
72 61
73 UserIdTracker* user_id_tracker() { return &user_id_tracker_; } 62 UserIdTracker* user_id_tracker() { return &user_id_tracker_; }
74 63
75 // Adds/removes a Display. ConnectionManager owns the Displays. 64 ws::DisplayManager* display_manager() { return display_manager_.get(); }
76 void AddDisplay(Display* display); 65 const ws::DisplayManager* display_manager() const {
77 void DestroyDisplay(Display* display); 66 return display_manager_.get();
78 std::set<Display*> displays() { return displays_; } 67 }
79 68
80 // Creates a new ServerWindow. The return value is owned by the caller, but 69 // Creates a new ServerWindow. The return value is owned by the caller, but
81 // must be destroyed before ConnectionManager. 70 // must be destroyed before ConnectionManager.
82 ServerWindow* CreateServerWindow( 71 ServerWindow* CreateServerWindow(
83 const WindowId& id, 72 const WindowId& id,
84 const std::map<std::string, std::vector<uint8_t>>& properties); 73 const std::map<std::string, std::vector<uint8_t>>& properties);
85 74
86 // Returns the id for the next WindowTree. 75 // Returns the id for the next WindowTree.
87 ConnectionSpecificId GetAndAdvanceNextConnectionId(); 76 ConnectionSpecificId GetAndAdvanceNextConnectionId();
88 77
89 // Returns the id for the next root window (both for the root of a Display
90 // as well as the root of WindowManagers).
91 uint16_t GetAndAdvanceNextRootId();
92
93 // See description of WindowTree::Embed() for details. This assumes 78 // See description of WindowTree::Embed() for details. This assumes
94 // |transport_window_id| is valid. 79 // |transport_window_id| is valid.
95 WindowTree* EmbedAtWindow(ServerWindow* root, 80 WindowTree* EmbedAtWindow(ServerWindow* root,
96 uint32_t policy_bitmask, 81 uint32_t policy_bitmask,
97 mojom::WindowTreeClientPtr client); 82 mojom::WindowTreeClientPtr client);
98 83
99 // Adds |tree_impl_ptr| to the set of known trees. Use DestroyTree() to 84 // Adds |tree_impl_ptr| to the set of known trees. Use DestroyTree() to
100 // destroy the tree. 85 // destroy the tree.
101 WindowTree* AddTree(scoped_ptr<WindowTree> tree_impl_ptr, 86 WindowTree* AddTree(scoped_ptr<WindowTree> tree_impl_ptr,
102 scoped_ptr<WindowTreeBinding> binding, 87 scoped_ptr<WindowTreeBinding> binding,
103 mojom::WindowTreePtr tree_ptr); 88 mojom::WindowTreePtr tree_ptr);
104 WindowTree* CreateTreeForWindowManager(Display* display, 89 WindowTree* CreateTreeForWindowManager(Display* display,
105 mojom::WindowManagerFactory* factory, 90 mojom::WindowManagerFactory* factory,
106 ServerWindow* root); 91 ServerWindow* root);
107 // Invoked when a WindowTree's connection encounters an error. 92 // Invoked when a WindowTree's connection encounters an error.
108 void DestroyTree(WindowTree* tree); 93 void DestroyTree(WindowTree* tree);
109 94
110 // Returns the connection by id. 95 // Returns the connection by id.
111 WindowTree* GetTreeWithId(ConnectionSpecificId connection_id); 96 WindowTree* GetTreeWithId(ConnectionSpecificId connection_id);
112 97
113 size_t num_trees() const { return tree_map_.size(); } 98 size_t num_trees() const { return tree_map_.size(); }
114 99
115 // Returns the Window identified by |id|. 100 // Returns the Window identified by |id|.
116 ServerWindow* GetWindow(const WindowId& id); 101 ServerWindow* GetWindow(const WindowId& id);
117 102
118 // Schedules a paint for the specified region in the coordinates of |window|. 103 // Schedules a paint for the specified region in the coordinates of |window|.
119 void SchedulePaint(const ServerWindow* window, const gfx::Rect& bounds); 104 void SchedulePaint(ServerWindow* window, const gfx::Rect& bounds);
120 105
121 OperationType current_operation_type() const { 106 OperationType current_operation_type() const {
122 return current_operation_ ? current_operation_->type() 107 return current_operation_ ? current_operation_->type()
123 : OperationType::NONE; 108 : OperationType::NONE;
124 } 109 }
125 110
126 // Invoked when the Display's PlatformDisplay is closed.
127 void OnDisplayClosed();
128
129 // Called when the AcceleratedWidget is available for |display|.
130 void OnDisplayAcceleratedWidgetAvailable(Display* display);
131
132 // Invoked when a connection messages a client about the change. This is used 111 // Invoked when a connection messages a client about the change. This is used
133 // to avoid sending ServerChangeIdAdvanced() unnecessarily. 112 // to avoid sending ServerChangeIdAdvanced() unnecessarily.
134 void OnTreeMessagedClient(ConnectionSpecificId id); 113 void OnTreeMessagedClient(ConnectionSpecificId id);
135 114
136 // Returns true if OnTreeMessagedClient() was invoked for id. 115 // Returns true if OnTreeMessagedClient() was invoked for id.
137 bool DidTreeMessageClient(ConnectionSpecificId id) const; 116 bool DidTreeMessageClient(ConnectionSpecificId id) const;
138 117
139 // Returns the metrics of the viewport where the provided |window| is 118 // Returns the metrics of the viewport where the provided |window| is
140 // displayed. 119 // displayed.
141 mojom::ViewportMetricsPtr GetViewportMetricsForWindow( 120 mojom::ViewportMetricsPtr GetViewportMetricsForWindow(
142 const ServerWindow* window); 121 const ServerWindow* window);
143 122
144 // Returns the WindowTree that has |id| as a root. 123 // Returns the WindowTree that has |id| as a root.
145 WindowTree* GetTreeWithRoot(const ServerWindow* window) { 124 WindowTree* GetTreeWithRoot(const ServerWindow* window) {
146 return const_cast<WindowTree*>( 125 return const_cast<WindowTree*>(
147 const_cast<const ConnectionManager*>(this)->GetTreeWithRoot(window)); 126 const_cast<const ConnectionManager*>(this)->GetTreeWithRoot(window));
148 } 127 }
149 const WindowTree* GetTreeWithRoot(const ServerWindow* window) const; 128 const WindowTree* GetTreeWithRoot(const ServerWindow* window) const;
150 129
151 // Returns the Display that contains |window|, or null if |window| is not
152 // attached to a display.
153 Display* GetDisplayContaining(const ServerWindow* window);
154 const Display* GetDisplayContaining(const ServerWindow* window) const;
155
156 WindowManagerAndDisplayConst GetWindowManagerAndDisplay(
157 const ServerWindow* window) const;
158 WindowManagerAndDisplay GetWindowManagerAndDisplay(
159 const ServerWindow* window);
160
161 Display* GetActiveDisplay();
162
163 bool has_displays() const { return !displays_.empty(); }
164
165 void AddDisplayManagerBinding( 130 void AddDisplayManagerBinding(
166 mojo::InterfaceRequest<mojom::DisplayManager> request); 131 mojo::InterfaceRequest<mojom::DisplayManager> request);
167 132
168 void OnFirstWindowManagerFactorySet(); 133 void OnFirstWindowManagerFactorySet();
169 134
170 WindowManagerFactoryRegistry* window_manager_factory_registry() { 135 WindowManagerFactoryRegistry* window_manager_factory_registry() {
171 return &window_manager_factory_registry_; 136 return &window_manager_factory_registry_;
172 } 137 }
173 138
174 // Returns a change id for the window manager that is associated with 139 // Returns a change id for the window manager that is associated with
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 228
264 // Calls OnDisplays() on |observer|. 229 // Calls OnDisplays() on |observer|.
265 void CallOnDisplays(mojom::DisplayManagerObserver* observer); 230 void CallOnDisplays(mojom::DisplayManagerObserver* observer);
266 231
267 // Calls observer->OnDisplaysChanged() with the display for |display|. 232 // Calls observer->OnDisplaysChanged() with the display for |display|.
268 void CallOnDisplayChanged(mojom::DisplayManagerObserver* observer, 233 void CallOnDisplayChanged(mojom::DisplayManagerObserver* observer,
269 Display* display); 234 Display* display);
270 235
271 // Overridden from ServerWindowDelegate: 236 // Overridden from ServerWindowDelegate:
272 mus::SurfacesState* GetSurfacesState() override; 237 mus::SurfacesState* GetSurfacesState() override;
273 void OnScheduleWindowPaint(const ServerWindow* window) override; 238 void OnScheduleWindowPaint(ServerWindow* window) override;
274 const ServerWindow* GetRootWindow(const ServerWindow* window) const override; 239 const ServerWindow* GetRootWindow(const ServerWindow* window) const override;
275 void ScheduleSurfaceDestruction(ServerWindow* window) override; 240 void ScheduleSurfaceDestruction(ServerWindow* window) override;
276 ServerWindow* FindWindowForSurface( 241 ServerWindow* FindWindowForSurface(
277 const ServerWindow* ancestor, 242 const ServerWindow* ancestor,
278 mojom::SurfaceType surface_type, 243 mojom::SurfaceType surface_type,
279 const ClientWindowId& client_window_id) override; 244 const ClientWindowId& client_window_id) override;
280 245
281 // Overridden from ServerWindowObserver: 246 // Overridden from ServerWindowObserver:
282 void OnWindowDestroyed(ServerWindow* window) override; 247 void OnWindowDestroyed(ServerWindow* window) override;
283 void OnWillChangeWindowHierarchy(ServerWindow* window, 248 void OnWillChangeWindowHierarchy(ServerWindow* window,
(...skipping 22 matching lines...) Expand all
306 void OnWindowTextInputStateChanged(ServerWindow* window, 271 void OnWindowTextInputStateChanged(ServerWindow* window,
307 const ui::TextInputState& state) override; 272 const ui::TextInputState& state) override;
308 void OnTransientWindowAdded(ServerWindow* window, 273 void OnTransientWindowAdded(ServerWindow* window,
309 ServerWindow* transient_child) override; 274 ServerWindow* transient_child) override;
310 void OnTransientWindowRemoved(ServerWindow* window, 275 void OnTransientWindowRemoved(ServerWindow* window,
311 ServerWindow* transient_child) override; 276 ServerWindow* transient_child) override;
312 277
313 // Overriden from mojom::DisplayManager: 278 // Overriden from mojom::DisplayManager:
314 void AddObserver(mojom::DisplayManagerObserverPtr observer) override; 279 void AddObserver(mojom::DisplayManagerObserverPtr observer) override;
315 280
281 // DisplayManagerDelegate:
282 void OnWillDestroyDisplay(Display* display) override;
283 void OnFirstDisplayReady() override;
284 void OnNoMoreDisplays() override;
285
316 UserIdTracker user_id_tracker_; 286 UserIdTracker user_id_tracker_;
317 287
318 ConnectionManagerDelegate* delegate_; 288 ConnectionManagerDelegate* delegate_;
319 289
320 // State for rendering into a Surface. 290 // State for rendering into a Surface.
321 scoped_refptr<mus::SurfacesState> surfaces_state_; 291 scoped_refptr<mus::SurfacesState> surfaces_state_;
322 292
323 // ID to use for next WindowTree. 293 // ID to use for next WindowTree.
324 ConnectionSpecificId next_connection_id_; 294 ConnectionSpecificId next_connection_id_;
325 295
326 // ID to use for next root node. 296 scoped_ptr<ws::DisplayManager> display_manager_;
327 uint16_t next_root_id_;
328 297
329 // Set of WindowTrees. 298 // Set of WindowTrees.
330 WindowTreeMap tree_map_; 299 WindowTreeMap tree_map_;
331 300
332 // Displays are initially added to |pending_displays_|. When the display is
333 // initialized it is moved to |displays_|. ConnectionManager owns the
334 // Displays.
335 std::set<Display*> pending_displays_;
336 std::set<Display*> displays_;
337
338 // If non-null then we're processing a client operation. The Operation is 301 // If non-null then we're processing a client operation. The Operation is
339 // not owned by us (it's created on the stack by WindowTree). 302 // not owned by us (it's created on the stack by WindowTree).
340 Operation* current_operation_; 303 Operation* current_operation_;
341 304
342 bool in_destructor_; 305 bool in_destructor_;
343 306
344 // Maps from window manager change id to the client that initiated the 307 // Maps from window manager change id to the client that initiated the
345 // request. 308 // request.
346 InFlightWindowManagerChangeMap in_flight_wm_change_map_; 309 InFlightWindowManagerChangeMap in_flight_wm_change_map_;
347 310
(...skipping 10 matching lines...) Expand all
358 321
359 WindowManagerFactoryRegistry window_manager_factory_registry_; 322 WindowManagerFactoryRegistry window_manager_factory_registry_;
360 323
361 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); 324 DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
362 }; 325 };
363 326
364 } // namespace ws 327 } // namespace ws
365 } // namespace mus 328 } // namespace mus
366 329
367 #endif // COMPONENTS_MUS_WS_CONNECTION_MANAGER_H_ 330 #endif // COMPONENTS_MUS_WS_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « components/mus/ws/BUILD.gn ('k') | components/mus/ws/connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698