| 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/mus/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/mus/client_connection.h" | 11 #include "components/mus/client_connection.h" |
| 12 #include "components/mus/connection_manager_delegate.h" | 12 #include "components/mus/connection_manager_delegate.h" |
| 13 #include "components/mus/server_view.h" | 13 #include "components/mus/server_view.h" |
| 14 #include "components/mus/view_coordinate_conversions.h" | 14 #include "components/mus/view_coordinate_conversions.h" |
| 15 #include "components/mus/view_tree_host_connection.h" | 15 #include "components/mus/view_tree_host_connection.h" |
| 16 #include "components/mus/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 namespace mus { |
| 24 | |
| 25 namespace view_manager { | |
| 26 | 24 |
| 27 ConnectionManager::ScopedChange::ScopedChange( | 25 ConnectionManager::ScopedChange::ScopedChange( |
| 28 ViewTreeImpl* connection, | 26 ViewTreeImpl* connection, |
| 29 ConnectionManager* connection_manager, | 27 ConnectionManager* connection_manager, |
| 30 bool is_delete_view) | 28 bool is_delete_view) |
| 31 : connection_manager_(connection_manager), | 29 : connection_manager_(connection_manager), |
| 32 connection_id_(connection->id()), | 30 connection_id_(connection->id()), |
| 33 is_delete_view_(is_delete_view) { | 31 is_delete_view_(is_delete_view) { |
| 34 connection_manager_->PrepareForChange(this); | 32 connection_manager_->PrepareForChange(this); |
| 35 } | 33 } |
| 36 | 34 |
| 37 ConnectionManager::ScopedChange::~ScopedChange() { | 35 ConnectionManager::ScopedChange::~ScopedChange() { |
| 38 connection_manager_->FinishChange(); | 36 connection_manager_->FinishChange(); |
| 39 } | 37 } |
| 40 | 38 |
| 41 ConnectionManager::ConnectionManager( | 39 ConnectionManager::ConnectionManager( |
| 42 ConnectionManagerDelegate* delegate, | 40 ConnectionManagerDelegate* delegate, |
| 43 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) | 41 const scoped_refptr<SurfacesState>& surfaces_state) |
| 44 : delegate_(delegate), | 42 : delegate_(delegate), |
| 45 surfaces_state_(surfaces_state), | 43 surfaces_state_(surfaces_state), |
| 46 next_connection_id_(1), | 44 next_connection_id_(1), |
| 47 next_host_id_(0), | 45 next_host_id_(0), |
| 48 current_change_(nullptr), | 46 current_change_(nullptr), |
| 49 in_destructor_(false) {} | 47 in_destructor_(false) {} |
| 50 | 48 |
| 51 ConnectionManager::~ConnectionManager() { | 49 ConnectionManager::~ConnectionManager() { |
| 52 in_destructor_ = true; | 50 in_destructor_ = true; |
| 53 | 51 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // observer pattern to do this. Each ViewTreeImpl should track its | 120 // observer pattern to do this. Each ViewTreeImpl should track its |
| 123 // parent's lifetime. | 121 // parent's lifetime. |
| 124 host_connection_map_.erase(it); | 122 host_connection_map_.erase(it); |
| 125 OnConnectionError(service_connection_it->second); | 123 OnConnectionError(service_connection_it->second); |
| 126 | 124 |
| 127 // If we have no more roots left, let the app know so it can terminate. | 125 // If we have no more roots left, let the app know so it can terminate. |
| 128 if (!host_connection_map_.size()) | 126 if (!host_connection_map_.size()) |
| 129 delegate_->OnNoMoreRootConnections(); | 127 delegate_->OnNoMoreRootConnections(); |
| 130 } | 128 } |
| 131 | 129 |
| 132 void ConnectionManager::EmbedAtView(mojo::ConnectionSpecificId creator_id, | 130 void ConnectionManager::EmbedAtView(ConnectionSpecificId creator_id, |
| 133 const ViewId& view_id, | 131 const ViewId& view_id, |
| 134 mojo::URLRequestPtr request) { | 132 mojo::URLRequestPtr request) { |
| 135 mojo::ViewTreePtr service_ptr; | 133 mojo::ViewTreePtr service_ptr; |
| 136 ClientConnection* client_connection = | 134 ClientConnection* client_connection = |
| 137 delegate_->CreateClientConnectionForEmbedAtView( | 135 delegate_->CreateClientConnectionForEmbedAtView( |
| 138 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id); | 136 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id); |
| 139 AddConnection(client_connection); | 137 AddConnection(client_connection); |
| 140 client_connection->service()->Init(client_connection->client(), | 138 client_connection->service()->Init(client_connection->client(), |
| 141 service_ptr.Pass()); | 139 service_ptr.Pass()); |
| 142 OnConnectionMessagedClient(client_connection->service()->id()); | 140 OnConnectionMessagedClient(client_connection->service()->id()); |
| 143 } | 141 } |
| 144 | 142 |
| 145 ViewTreeImpl* ConnectionManager::EmbedAtView( | 143 ViewTreeImpl* ConnectionManager::EmbedAtView(ConnectionSpecificId creator_id, |
| 146 mojo::ConnectionSpecificId creator_id, | 144 const ViewId& view_id, |
| 147 const ViewId& view_id, | 145 mojo::ViewTreeClientPtr client) { |
| 148 mojo::ViewTreeClientPtr client) { | |
| 149 mojo::ViewTreePtr service_ptr; | 146 mojo::ViewTreePtr service_ptr; |
| 150 ClientConnection* client_connection = | 147 ClientConnection* client_connection = |
| 151 delegate_->CreateClientConnectionForEmbedAtView( | 148 delegate_->CreateClientConnectionForEmbedAtView( |
| 152 this, GetProxy(&service_ptr), creator_id, view_id, client.Pass()); | 149 this, GetProxy(&service_ptr), creator_id, view_id, client.Pass()); |
| 153 AddConnection(client_connection); | 150 AddConnection(client_connection); |
| 154 client_connection->service()->Init(client_connection->client(), | 151 client_connection->service()->Init(client_connection->client(), |
| 155 service_ptr.Pass()); | 152 service_ptr.Pass()); |
| 156 OnConnectionMessagedClient(client_connection->service()->id()); | 153 OnConnectionMessagedClient(client_connection->service()->id()); |
| 157 | 154 |
| 158 return client_connection->service(); | 155 return client_connection->service(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 DCHECK_EQ(0u, connection_map_.count(connection->service()->id())); | 321 DCHECK_EQ(0u, connection_map_.count(connection->service()->id())); |
| 325 connection_map_[connection->service()->id()] = connection; | 322 connection_map_[connection->service()->id()] = connection; |
| 326 } | 323 } |
| 327 | 324 |
| 328 scoped_ptr<cc::CompositorFrame> | 325 scoped_ptr<cc::CompositorFrame> |
| 329 ConnectionManager::UpdateViewTreeFromCompositorFrame( | 326 ConnectionManager::UpdateViewTreeFromCompositorFrame( |
| 330 const mojo::CompositorFramePtr& input) { | 327 const mojo::CompositorFramePtr& input) { |
| 331 return ConvertToCompositorFrame(input, this); | 328 return ConvertToCompositorFrame(input, this); |
| 332 } | 329 } |
| 333 | 330 |
| 334 surfaces::SurfacesState* ConnectionManager::GetSurfacesState() { | 331 SurfacesState* ConnectionManager::GetSurfacesState() { |
| 335 return surfaces_state_.get(); | 332 return surfaces_state_.get(); |
| 336 } | 333 } |
| 337 | 334 |
| 338 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { | 335 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { |
| 339 if (!in_destructor_) | 336 if (!in_destructor_) |
| 340 SchedulePaint(view, gfx::Rect(view->bounds().size())); | 337 SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 341 } | 338 } |
| 342 | 339 |
| 343 const ServerView* ConnectionManager::GetRootView(const ServerView* view) const { | 340 const ServerView* ConnectionManager::GetRootView(const ServerView* view) const { |
| 344 const ViewTreeHostImpl* host = GetViewTreeHostByView(view); | 341 const ViewTreeHostImpl* host = GetViewTreeHostByView(view); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 bounds.set_origin(p); | 450 bounds.set_origin(p); |
| 454 // TODO(fsamuel): This seems like a crude way to set the size that probably | 451 // TODO(fsamuel): This seems like a crude way to set the size that probably |
| 455 // doesn't work correctly in the general case. We need to get transforms | 452 // doesn't work correctly in the general case. We need to get transforms |
| 456 // working correctly in the general case. | 453 // working correctly in the general case. |
| 457 bounds.set_size(gfx::ToRoundedSize( | 454 bounds.set_size(gfx::ToRoundedSize( |
| 458 gfx::ScaleSize(bounds.size(), metadata->device_scale_factor))); | 455 gfx::ScaleSize(bounds.size(), metadata->device_scale_factor))); |
| 459 view->SetBounds(bounds); | 456 view->SetBounds(bounds); |
| 460 return true; | 457 return true; |
| 461 } | 458 } |
| 462 | 459 |
| 463 } // namespace view_manager | 460 } // namespace mus |
| OLD | NEW |