| OLD | NEW |
| 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/view_manager/connection_manager.h" | 5 #include "components/mus/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 "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/quads/shared_quad_state.h" | 10 #include "cc/quads/shared_quad_state.h" |
| 11 #include "components/view_manager/client_connection.h" | 11 #include "components/mus/client_connection.h" |
| 12 #include "components/view_manager/connection_manager_delegate.h" | 12 #include "components/mus/connection_manager_delegate.h" |
| 13 #include "components/view_manager/server_view.h" | 13 #include "components/mus/server_view.h" |
| 14 #include "components/view_manager/view_coordinate_conversions.h" | 14 #include "components/mus/view_coordinate_conversions.h" |
| 15 #include "components/view_manager/view_tree_host_connection.h" | 15 #include "components/mus/view_tree_host_connection.h" |
| 16 #include "components/view_manager/view_tree_impl.h" | 16 #include "components/mus/view_tree_impl.h" |
| 17 #include "mojo/application/public/cpp/application_connection.h" | 17 #include "mojo/application/public/cpp/application_connection.h" |
| 18 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 19 #include "mojo/converters/input_events/input_events_type_converters.h" | 19 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 20 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 20 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 21 #include "ui/gfx/geometry/size_conversions.h" | 21 #include "ui/gfx/geometry/size_conversions.h" |
| 22 | 22 |
| 23 using mojo::ConnectionSpecificId; | 23 using mojo::ConnectionSpecificId; |
| 24 | 24 |
| 25 namespace view_manager { | 25 namespace view_manager { |
| 26 | 26 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 ConnectionManager::ConnectionManager( | 41 ConnectionManager::ConnectionManager( |
| 42 ConnectionManagerDelegate* delegate, | 42 ConnectionManagerDelegate* delegate, |
| 43 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) | 43 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) |
| 44 : delegate_(delegate), | 44 : delegate_(delegate), |
| 45 surfaces_state_(surfaces_state), | 45 surfaces_state_(surfaces_state), |
| 46 next_connection_id_(1), | 46 next_connection_id_(1), |
| 47 next_host_id_(0), | 47 next_host_id_(0), |
| 48 current_change_(nullptr), | 48 current_change_(nullptr), |
| 49 in_destructor_(false) { | 49 in_destructor_(false) {} |
| 50 } | |
| 51 | 50 |
| 52 ConnectionManager::~ConnectionManager() { | 51 ConnectionManager::~ConnectionManager() { |
| 53 in_destructor_ = true; | 52 in_destructor_ = true; |
| 54 | 53 |
| 55 // Copy the HostConnectionMap because it will be mutated as the connections | 54 // Copy the HostConnectionMap because it will be mutated as the connections |
| 56 // are closed. | 55 // are closed. |
| 57 HostConnectionMap host_connection_map(host_connection_map_); | 56 HostConnectionMap host_connection_map(host_connection_map_); |
| 58 for (auto& pair : host_connection_map) | 57 for (auto& pair : host_connection_map) |
| 59 pair.second->CloseConnection(); | 58 pair.second->CloseConnection(); |
| 60 | 59 |
| 61 STLDeleteValues(&connection_map_); | 60 STLDeleteValues(&connection_map_); |
| 62 // All the connections should have been destroyed. | 61 // All the connections should have been destroyed. |
| 63 DCHECK(host_connection_map_.empty()); | 62 DCHECK(host_connection_map_.empty()); |
| 64 DCHECK(connection_map_.empty()); | 63 DCHECK(connection_map_.empty()); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void ConnectionManager::AddHost( | 66 void ConnectionManager::AddHost(ViewTreeHostConnection* host_connection) { |
| 68 ViewTreeHostConnection* host_connection) { | |
| 69 DCHECK_EQ(0u, host_connection_map_.count(host_connection->view_tree_host())); | 67 DCHECK_EQ(0u, host_connection_map_.count(host_connection->view_tree_host())); |
| 70 host_connection_map_[host_connection->view_tree_host()] = host_connection; | 68 host_connection_map_[host_connection->view_tree_host()] = host_connection; |
| 71 } | 69 } |
| 72 | 70 |
| 73 ServerView* ConnectionManager::CreateServerView(const ViewId& id) { | 71 ServerView* ConnectionManager::CreateServerView(const ViewId& id) { |
| 74 ServerView* view = new ServerView(this, id); | 72 ServerView* view = new ServerView(this, id); |
| 75 view->AddObserver(this); | 73 view->AddObserver(this); |
| 76 return view; | 74 return view; |
| 77 } | 75 } |
| 78 | 76 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 97 // the root connection goes away to cleanup. | 95 // the root connection goes away to cleanup. |
| 98 if (view && (GetRootView(view) == view)) | 96 if (view && (GetRootView(view) == view)) |
| 99 return; | 97 return; |
| 100 | 98 |
| 101 scoped_ptr<ClientConnection> connection_owner(connection); | 99 scoped_ptr<ClientConnection> connection_owner(connection); |
| 102 | 100 |
| 103 connection_map_.erase(connection->service()->id()); | 101 connection_map_.erase(connection->service()->id()); |
| 104 | 102 |
| 105 // Notify remaining connections so that they can cleanup. | 103 // Notify remaining connections so that they can cleanup. |
| 106 for (auto& pair : connection_map_) { | 104 for (auto& pair : connection_map_) { |
| 107 pair.second->service()->OnWillDestroyViewTreeImpl( | 105 pair.second->service()->OnWillDestroyViewTreeImpl(connection->service()); |
| 108 connection->service()); | |
| 109 } | 106 } |
| 110 } | 107 } |
| 111 | 108 |
| 112 void ConnectionManager::OnHostConnectionClosed( | 109 void ConnectionManager::OnHostConnectionClosed( |
| 113 ViewTreeHostConnection* connection) { | 110 ViewTreeHostConnection* connection) { |
| 114 auto it = host_connection_map_.find(connection->view_tree_host()); | 111 auto it = host_connection_map_.find(connection->view_tree_host()); |
| 115 DCHECK(it != host_connection_map_.end()); | 112 DCHECK(it != host_connection_map_.end()); |
| 116 | 113 |
| 117 // Get the ClientConnection by ViewTreeImpl ID. | 114 // Get the ClientConnection by ViewTreeImpl ID. |
| 118 ConnectionMap::iterator service_connection_it = | 115 ConnectionMap::iterator service_connection_it = |
| 119 connection_map_.find(it->first->GetViewTree()->id()); | 116 connection_map_.find(it->first->GetViewTree()->id()); |
| 120 DCHECK(service_connection_it != connection_map_.end()); | 117 DCHECK(service_connection_it != connection_map_.end()); |
| 121 | 118 |
| 122 // Tear down the associated ViewTree connection. | 119 // Tear down the associated ViewTree connection. |
| 123 // TODO(fsamuel): I don't think this is quite right, we should tear down all | 120 // TODO(fsamuel): I don't think this is quite right, we should tear down all |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (!in_destructor_) | 395 if (!in_destructor_) |
| 399 SchedulePaint(view, gfx::Rect(view->bounds().size())); | 396 SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 400 } | 397 } |
| 401 | 398 |
| 402 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { | 399 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { |
| 403 if (in_destructor_) | 400 if (in_destructor_) |
| 404 return; | 401 return; |
| 405 | 402 |
| 406 // Need to repaint if the view was drawn (which means it's in the process of | 403 // Need to repaint if the view was drawn (which means it's in the process of |
| 407 // hiding) or the view is transitioning to drawn. | 404 // hiding) or the view is transitioning to drawn. |
| 408 if (view->parent() && (view->IsDrawn() || | 405 if (view->parent() && |
| 409 (!view->visible() && view->parent()->IsDrawn()))) { | 406 (view->IsDrawn() || (!view->visible() && view->parent()->IsDrawn()))) { |
| 410 SchedulePaint(view->parent(), view->bounds()); | 407 SchedulePaint(view->parent(), view->bounds()); |
| 411 } | 408 } |
| 412 | 409 |
| 413 for (auto& pair : connection_map_) { | 410 for (auto& pair : connection_map_) { |
| 414 pair.second->service()->ProcessWillChangeViewVisibility( | 411 pair.second->service()->ProcessWillChangeViewVisibility( |
| 415 view, IsChangeSource(pair.first)); | 412 view, IsChangeSource(pair.first)); |
| 416 } | 413 } |
| 417 } | 414 } |
| 418 | 415 |
| 419 void ConnectionManager::OnViewSharedPropertyChanged( | 416 void ConnectionManager::OnViewSharedPropertyChanged( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 // TODO(fsamuel): This seems like a crude way to set the size that probably | 454 // TODO(fsamuel): This seems like a crude way to set the size that probably |
| 458 // doesn't work correctly in the general case. We need to get transforms | 455 // doesn't work correctly in the general case. We need to get transforms |
| 459 // working correctly in the general case. | 456 // working correctly in the general case. |
| 460 bounds.set_size(gfx::ToRoundedSize( | 457 bounds.set_size(gfx::ToRoundedSize( |
| 461 gfx::ScaleSize(bounds.size(), metadata->device_scale_factor))); | 458 gfx::ScaleSize(bounds.size(), metadata->device_scale_factor))); |
| 462 view->SetBounds(bounds); | 459 view->SetBounds(bounds); |
| 463 return true; | 460 return true; |
| 464 } | 461 } |
| 465 | 462 |
| 466 } // namespace view_manager | 463 } // namespace view_manager |
| OLD | NEW |