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

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

Issue 1775583002: Moves FrameDecorations from Display to WindowManagerState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: override 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/connection_manager.h ('k') | components/mus/ws/display.h » ('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 #include "components/mus/ws/connection_manager.h" 5 #include "components/mus/ws/connection_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "components/mus/ws/connection_manager_delegate.h" 9 #include "components/mus/ws/connection_manager_delegate.h"
10 #include "components/mus/ws/display.h" 10 #include "components/mus/ws/display.h"
(...skipping 14 matching lines...) Expand all
25 25
26 namespace mus { 26 namespace mus {
27 namespace ws { 27 namespace ws {
28 28
29 ConnectionManager::ConnectionManager( 29 ConnectionManager::ConnectionManager(
30 ConnectionManagerDelegate* delegate, 30 ConnectionManagerDelegate* delegate,
31 const scoped_refptr<mus::SurfacesState>& surfaces_state) 31 const scoped_refptr<mus::SurfacesState>& surfaces_state)
32 : delegate_(delegate), 32 : delegate_(delegate),
33 surfaces_state_(surfaces_state), 33 surfaces_state_(surfaces_state),
34 next_connection_id_(1), 34 next_connection_id_(1),
35 display_manager_(new ws::DisplayManager(this)), 35 display_manager_(new DisplayManager(this)),
36 current_operation_(nullptr), 36 current_operation_(nullptr),
37 in_destructor_(false), 37 in_destructor_(false),
38 next_wm_change_id_(0), 38 next_wm_change_id_(0),
39 got_valid_frame_decorations_(false),
40 window_manager_factory_registry_(this, &user_id_tracker_) {} 39 window_manager_factory_registry_(this, &user_id_tracker_) {}
41 40
42 ConnectionManager::~ConnectionManager() { 41 ConnectionManager::~ConnectionManager() {
43 in_destructor_ = true; 42 in_destructor_ = true;
44 43
45 // Destroys the window trees results in querying for the display. Tear down 44 // Destroys the window trees results in querying for the display. Tear down
46 // the displays first so that the trees are notified of the display going 45 // the displays first so that the trees are notified of the display going
47 // away while the display is still valid. 46 // away while the display is still valid.
48 display_manager_->DestroyAllDisplays(); 47 display_manager_->DestroyAllDisplays();
49 48
(...skipping 14 matching lines...) Expand all
64 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() { 63 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() {
65 const ConnectionSpecificId id = next_connection_id_++; 64 const ConnectionSpecificId id = next_connection_id_++;
66 DCHECK_LT(id, next_connection_id_); 65 DCHECK_LT(id, next_connection_id_);
67 return id; 66 return id;
68 } 67 }
69 68
70 WindowTree* ConnectionManager::EmbedAtWindow( 69 WindowTree* ConnectionManager::EmbedAtWindow(
71 ServerWindow* root, 70 ServerWindow* root,
72 uint32_t policy_bitmask, 71 uint32_t policy_bitmask,
73 mojom::WindowTreeClientPtr client) { 72 mojom::WindowTreeClientPtr client) {
74 scoped_ptr<WindowTree> tree_ptr( 73 scoped_ptr<WindowTree> tree_ptr(new WindowTree(this, root, policy_bitmask));
75 new ws::WindowTree(this, root, policy_bitmask));
76 WindowTree* tree = tree_ptr.get(); 74 WindowTree* tree = tree_ptr.get();
77 75
78 mojom::WindowTreePtr window_tree_ptr; 76 mojom::WindowTreePtr window_tree_ptr;
79 scoped_ptr<WindowTreeBinding> binding = 77 scoped_ptr<WindowTreeBinding> binding =
80 delegate_->CreateWindowTreeBindingForEmbedAtWindow( 78 delegate_->CreateWindowTreeBindingForEmbedAtWindow(
81 this, tree, GetProxy(&window_tree_ptr), std::move(client)); 79 this, tree, GetProxy(&window_tree_ptr), std::move(client));
82 80
83 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr)); 81 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr));
84 OnTreeMessagedClient(tree->id()); 82 OnTreeMessagedClient(tree->id());
85 return tree; 83 return tree;
86 } 84 }
87 85
88 WindowTree* ConnectionManager::AddTree(scoped_ptr<WindowTree> tree_impl_ptr, 86 WindowTree* ConnectionManager::AddTree(scoped_ptr<WindowTree> tree_impl_ptr,
89 scoped_ptr<WindowTreeBinding> binding, 87 scoped_ptr<WindowTreeBinding> binding,
90 mojom::WindowTreePtr tree_ptr) { 88 mojom::WindowTreePtr tree_ptr) {
91 CHECK_EQ(0u, tree_map_.count(tree_impl_ptr->id())); 89 CHECK_EQ(0u, tree_map_.count(tree_impl_ptr->id()));
92 WindowTree* tree = tree_impl_ptr.get(); 90 WindowTree* tree = tree_impl_ptr.get();
93 tree_map_[tree->id()] = std::move(tree_impl_ptr); 91 tree_map_[tree->id()] = std::move(tree_impl_ptr);
94 tree->Init(std::move(binding), std::move(tree_ptr)); 92 tree->Init(std::move(binding), std::move(tree_ptr));
95 return tree; 93 return tree;
96 } 94 }
97 95
98 WindowTree* ConnectionManager::CreateTreeForWindowManager( 96 WindowTree* ConnectionManager::CreateTreeForWindowManager(
99 Display* display, 97 Display* display,
100 mojom::WindowManagerFactory* factory, 98 mojom::WindowManagerFactory* factory,
101 ServerWindow* root) { 99 ServerWindow* root) {
102 mojom::DisplayPtr display_ptr = DisplayToMojomDisplay(display); 100 mojom::DisplayPtr display_ptr = display->ToMojomDisplay();
103 mojom::WindowTreeClientPtr tree_client; 101 mojom::WindowTreeClientPtr tree_client;
104 factory->CreateWindowManager(std::move(display_ptr), GetProxy(&tree_client)); 102 factory->CreateWindowManager(std::move(display_ptr), GetProxy(&tree_client));
105 scoped_ptr<ws::WindowTree> tree_ptr(new ws::WindowTree( 103 scoped_ptr<WindowTree> tree_ptr(
106 this, root, mojom::WindowTree::kAccessPolicyEmbedRoot)); 104 new WindowTree(this, root, mojom::WindowTree::kAccessPolicyEmbedRoot));
107 ws::WindowTree* tree = tree_ptr.get(); 105 WindowTree* tree = tree_ptr.get();
108 scoped_ptr<ws::DefaultWindowTreeBinding> binding( 106 scoped_ptr<DefaultWindowTreeBinding> binding(new DefaultWindowTreeBinding(
109 new ws::DefaultWindowTreeBinding(tree_ptr.get(), this, 107 tree_ptr.get(), this, std::move(tree_client)));
110 std::move(tree_client)));
111 mojom::WindowTreePtr window_tree_ptr = binding->CreateInterfacePtrAndBind(); 108 mojom::WindowTreePtr window_tree_ptr = binding->CreateInterfacePtrAndBind();
112 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr)); 109 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr));
113 tree->ConfigureWindowManager(); 110 tree->ConfigureWindowManager();
114 return tree; 111 return tree;
115 } 112 }
116 113
117 void ConnectionManager::DestroyTree(WindowTree* tree) { 114 void ConnectionManager::DestroyTree(WindowTree* tree) {
118 scoped_ptr<WindowTree> tree_ptr; 115 scoped_ptr<WindowTree> tree_ptr;
119 { 116 {
120 auto iter = tree_map_.find(tree->id()); 117 auto iter = tree_map_.find(tree->id());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const ServerWindow* window) const { 204 const ServerWindow* window) const {
208 if (!window) 205 if (!window)
209 return nullptr; 206 return nullptr;
210 for (auto& pair : tree_map_) { 207 for (auto& pair : tree_map_) {
211 if (pair.second->HasRoot(window)) 208 if (pair.second->HasRoot(window))
212 return pair.second.get(); 209 return pair.second.get();
213 } 210 }
214 return nullptr; 211 return nullptr;
215 } 212 }
216 213
217 void ConnectionManager::AddDisplayManagerBinding(
218 mojo::InterfaceRequest<mojom::DisplayManager> request) {
219 display_manager_bindings_.AddBinding(this, std::move(request));
220 }
221
222 void ConnectionManager::OnFirstWindowManagerFactorySet() { 214 void ConnectionManager::OnFirstWindowManagerFactorySet() {
223 if (display_manager_->has_active_or_pending_displays()) 215 if (display_manager_->has_active_or_pending_displays())
224 return; 216 return;
225 217
226 // We've been supplied a WindowManagerFactory and no displays have been 218 // We've been supplied a WindowManagerFactory and no displays have been
227 // created yet. Treat this as a signal to create a Display. 219 // created yet. Treat this as a signal to create a Display.
228 // TODO(sky): we need a better way to determine this, most likely a switch. 220 // TODO(sky): we need a better way to determine this, most likely a switch.
229 delegate_->CreateDefaultDisplays(); 221 delegate_->CreateDefaultDisplays();
230 } 222 }
231 223
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 !window || window->id().connection_id != wm_tree->id() || 263 !window || window->id().connection_id != wm_tree->id() ||
272 !window->children().empty() || GetTreeWithRoot(window)) { 264 !window->children().empty() || GetTreeWithRoot(window)) {
273 WindowManagerSentBogusMessage(); 265 WindowManagerSentBogusMessage();
274 return; 266 return;
275 } 267 }
276 268
277 tree->OnWindowManagerCreatedTopLevelWindow(window_manager_change_id, 269 tree->OnWindowManagerCreatedTopLevelWindow(window_manager_change_id,
278 change.client_change_id, window); 270 change.client_change_id, window);
279 } 271 }
280 272
281 mojom::DisplayPtr ConnectionManager::DisplayToMojomDisplay(Display* display) {
282 size_t i = 0;
283 int next_x = 0;
284 for (Display* display2 : display_manager_->displays()) {
285 const ServerWindow* root = display->root_window();
286 if (display == display2) {
287 mojom::DisplayPtr display_ptr = mojom::Display::New();
288 display_ptr = mojom::Display::New();
289 display_ptr->id = display->id();
290 display_ptr->bounds = mojo::Rect::New();
291 display_ptr->bounds->x = next_x;
292 display_ptr->bounds->y = 0;
293 display_ptr->bounds->width = root->bounds().size().width();
294 display_ptr->bounds->height = root->bounds().size().height();
295 // TODO(sky): window manager needs an API to set the work area.
296 display_ptr->work_area = display_ptr->bounds.Clone();
297 display_ptr->device_pixel_ratio =
298 display->GetViewportMetrics().device_pixel_ratio;
299 display_ptr->rotation = display->GetRotation();
300 // TODO(sky): make this real.
301 display_ptr->is_primary = i == 0;
302 // TODO(sky): make this real.
303 display_ptr->touch_support = mojom::TouchSupport::UNKNOWN;
304 display_ptr->frame_decoration_values =
305 display->frame_decoration_values().Clone();
306 return display_ptr;
307 }
308 next_x += root->bounds().size().width();
309 ++i;
310 }
311 NOTREACHED();
312 return mojom::Display::New();
313 }
314
315 void ConnectionManager::ProcessWindowBoundsChanged( 273 void ConnectionManager::ProcessWindowBoundsChanged(
316 const ServerWindow* window, 274 const ServerWindow* window,
317 const gfx::Rect& old_bounds, 275 const gfx::Rect& old_bounds,
318 const gfx::Rect& new_bounds) { 276 const gfx::Rect& new_bounds) {
319 for (auto& pair : tree_map_) { 277 for (auto& pair : tree_map_) {
320 pair.second->ProcessWindowBoundsChanged(window, old_bounds, new_bounds, 278 pair.second->ProcessWindowBoundsChanged(window, old_bounds, new_bounds,
321 IsOperationSource(pair.first)); 279 IsOperationSource(pair.first));
322 } 280 }
323 } 281 }
324 282
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 353 }
396 354
397 void ConnectionManager::ProcessViewportMetricsChanged( 355 void ConnectionManager::ProcessViewportMetricsChanged(
398 Display* display, 356 Display* display,
399 const mojom::ViewportMetrics& old_metrics, 357 const mojom::ViewportMetrics& old_metrics,
400 const mojom::ViewportMetrics& new_metrics) { 358 const mojom::ViewportMetrics& new_metrics) {
401 for (auto& pair : tree_map_) { 359 for (auto& pair : tree_map_) {
402 pair.second->ProcessViewportMetricsChanged( 360 pair.second->ProcessViewportMetricsChanged(
403 display, old_metrics, new_metrics, IsOperationSource(pair.first)); 361 display, old_metrics, new_metrics, IsOperationSource(pair.first));
404 } 362 }
405
406 if (!got_valid_frame_decorations_)
407 return;
408 }
409
410 void ConnectionManager::ProcessFrameDecorationValuesChanged(Display* display) {
411 if (!got_valid_frame_decorations_) {
412 got_valid_frame_decorations_ = true;
413 display_manager_observers_.ForAllPtrs([this](
414 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); });
415 return;
416 }
417
418 display_manager_observers_.ForAllPtrs(
419 [this, &display](mojom::DisplayManagerObserver* observer) {
420 CallOnDisplayChanged(observer, display);
421 });
422 } 363 }
423 364
424 bool ConnectionManager::GetAndClearInFlightWindowManagerChange( 365 bool ConnectionManager::GetAndClearInFlightWindowManagerChange(
425 uint32_t window_manager_change_id, 366 uint32_t window_manager_change_id,
426 InFlightWindowManagerChange* change) { 367 InFlightWindowManagerChange* change) {
427 // There are valid reasons as to why we wouldn't know about the id. The 368 // There are valid reasons as to why we wouldn't know about the id. The
428 // most likely is the client disconnected before the response from the window 369 // most likely is the client disconnected before the response from the window
429 // manager came back. 370 // manager came back.
430 auto iter = in_flight_wm_change_map_.find(window_manager_change_id); 371 auto iter = in_flight_wm_change_map_.find(window_manager_change_id);
431 if (iter == in_flight_wm_change_map_.end()) 372 if (iter == in_flight_wm_change_map_.end())
(...skipping 16 matching lines...) Expand all
448 current_operation_ = nullptr; 389 current_operation_ = nullptr;
449 } 390 }
450 391
451 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) { 392 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) {
452 // This can be null in unit tests. 393 // This can be null in unit tests.
453 Display* display = display_manager_->GetDisplayContaining(window); 394 Display* display = display_manager_->GetDisplayContaining(window);
454 if (display) 395 if (display)
455 display->MaybeChangeCursorOnWindowTreeChange(); 396 display->MaybeChangeCursorOnWindowTreeChange();
456 } 397 }
457 398
458 void ConnectionManager::CallOnDisplays(
459 mojom::DisplayManagerObserver* observer) {
460 std::set<Display*> displays = display_manager_->displays();
461 mojo::Array<mojom::DisplayPtr> display_ptrs(displays.size());
462 {
463 size_t i = 0;
464 // TODO(sky): need ordering!
465 for (Display* display : displays) {
466 display_ptrs[i] = DisplayToMojomDisplay(display);
467 ++i;
468 }
469 }
470 observer->OnDisplays(std::move(display_ptrs));
471 }
472
473 void ConnectionManager::CallOnDisplayChanged(
474 mojom::DisplayManagerObserver* observer,
475 Display* display) {
476 mojo::Array<mojom::DisplayPtr> displays(1);
477 displays[0] = DisplayToMojomDisplay(display);
478 display_manager_observers_.ForAllPtrs(
479 [&displays](mojom::DisplayManagerObserver* observer) {
480 observer->OnDisplaysChanged(displays.Clone());
481 });
482 }
483
484 mus::SurfacesState* ConnectionManager::GetSurfacesState() { 399 mus::SurfacesState* ConnectionManager::GetSurfacesState() {
485 return surfaces_state_.get(); 400 return surfaces_state_.get();
486 } 401 }
487 402
488 void ConnectionManager::OnScheduleWindowPaint(ServerWindow* window) { 403 void ConnectionManager::OnScheduleWindowPaint(ServerWindow* window) {
489 if (!in_destructor_) 404 if (!in_destructor_)
490 SchedulePaint(window, gfx::Rect(window->bounds().size())); 405 SchedulePaint(window, gfx::Rect(window->bounds().size()));
491 } 406 }
492 407
493 const ServerWindow* ConnectionManager::GetRootWindow( 408 const ServerWindow* ConnectionManager::GetRootWindow(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 ServerWindow* transient_child) { 565 ServerWindow* transient_child) {
651 // If we're deleting a window, then this is a superfluous message. 566 // If we're deleting a window, then this is a superfluous message.
652 if (current_operation_type() == OperationType::DELETE_WINDOW) 567 if (current_operation_type() == OperationType::DELETE_WINDOW)
653 return; 568 return;
654 for (auto& pair : tree_map_) { 569 for (auto& pair : tree_map_) {
655 pair.second->ProcessTransientWindowRemoved(window, transient_child, 570 pair.second->ProcessTransientWindowRemoved(window, transient_child,
656 IsOperationSource(pair.first)); 571 IsOperationSource(pair.first));
657 } 572 }
658 } 573 }
659 574
660 void ConnectionManager::AddObserver(mojom::DisplayManagerObserverPtr observer) {
661 // TODO(sky): this needs to be per user.
662
663 // Many clients key off the frame decorations to size widgets. Wait for frame
664 // decorations before notifying so that we don't have to worry about clients
665 // resizing appropriately.
666 if (!got_valid_frame_decorations_) {
667 display_manager_observers_.AddInterfacePtr(std::move(observer));
668 return;
669 }
670 CallOnDisplays(observer.get());
671 display_manager_observers_.AddInterfacePtr(std::move(observer));
672 }
673
674 void ConnectionManager::OnWillDestroyDisplay(Display* display) { 575 void ConnectionManager::OnWillDestroyDisplay(Display* display) {
675 for (auto& pair : tree_map_) 576 for (auto& pair : tree_map_)
676 pair.second->OnWillDestroyDisplay(display); 577 pair.second->OnWillDestroyDisplay(display);
677 } 578 }
678 579
679 void ConnectionManager::OnFirstDisplayReady() { 580 void ConnectionManager::OnFirstDisplayReady() {
680 delegate_->OnFirstDisplayReady(); 581 delegate_->OnFirstDisplayReady();
681 } 582 }
682 583
683 void ConnectionManager::OnNoMoreDisplays() { 584 void ConnectionManager::OnNoMoreDisplays() {
684 delegate_->OnNoMoreDisplays(); 585 delegate_->OnNoMoreDisplays();
685 } 586 }
686 587
687 } // namespace ws 588 } // namespace ws
688 } // namespace mus 589 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/connection_manager.h ('k') | components/mus/ws/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698