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/view_manager/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" | |
10 #include "cc/surfaces/surface_id_allocator.h" | |
9 #include "components/view_manager/client_connection.h" | 11 #include "components/view_manager/client_connection.h" |
10 #include "components/view_manager/connection_manager_delegate.h" | 12 #include "components/view_manager/connection_manager_delegate.h" |
11 #include "components/view_manager/focus_controller.h" | 13 #include "components/view_manager/focus_controller.h" |
12 #include "components/view_manager/server_view.h" | 14 #include "components/view_manager/server_view.h" |
13 #include "components/view_manager/view_coordinate_conversions.h" | 15 #include "components/view_manager/view_coordinate_conversions.h" |
14 #include "components/view_manager/view_manager_root_connection.h" | 16 #include "components/view_manager/view_manager_root_connection.h" |
15 #include "components/view_manager/view_manager_service_impl.h" | 17 #include "components/view_manager/view_manager_service_impl.h" |
16 #include "mojo/application/public/cpp/application_connection.h" | 18 #include "mojo/application/public/cpp/application_connection.h" |
17 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 19 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
18 #include "mojo/converters/geometry/geometry_type_converters.h" | 20 #include "mojo/converters/geometry/geometry_type_converters.h" |
19 #include "mojo/converters/input_events/input_events_type_converters.h" | 21 #include "mojo/converters/input_events/input_events_type_converters.h" |
22 #include "mojo/converters/surfaces/surfaces_type_converters.h" | |
20 | 23 |
21 using mojo::ConnectionSpecificId; | 24 using mojo::ConnectionSpecificId; |
22 | 25 |
23 namespace view_manager { | 26 namespace view_manager { |
24 namespace { | 27 namespace { |
25 | 28 |
29 namespace { | |
30 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { | |
31 callback.Run(); | |
32 } | |
33 } | |
34 | |
26 // Creates a copy of |view|. The copied view has |delegate| as its delegate. | 35 // Creates a copy of |view|. The copied view has |delegate| as its delegate. |
27 // This does not recurse. | 36 // This does not recurse. |
28 ServerView* CloneView(const ServerView* view, ServerViewDelegate* delegate) { | 37 ServerView* CloneView(const ServerView* view, ServerViewDelegate* delegate) { |
29 ServerView* clone = new ServerView(delegate, ClonedViewId()); | 38 ServerView* clone = new ServerView(delegate, ClonedViewId()); |
30 clone->SetBounds(view->bounds()); | 39 clone->SetBounds(view->bounds()); |
31 clone->SetSurfaceId(view->surface_id()); | 40 clone->SetSurfaceId(view->surface_id()); |
32 clone->SetOpacity(view->opacity()); | 41 clone->SetOpacity(view->opacity()); |
33 return clone; | 42 return clone; |
34 } | 43 } |
35 | 44 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 : connection_manager_(connection_manager), | 113 : connection_manager_(connection_manager), |
105 connection_id_(connection->id()), | 114 connection_id_(connection->id()), |
106 is_delete_view_(is_delete_view) { | 115 is_delete_view_(is_delete_view) { |
107 connection_manager_->PrepareForChange(this); | 116 connection_manager_->PrepareForChange(this); |
108 } | 117 } |
109 | 118 |
110 ConnectionManager::ScopedChange::~ScopedChange() { | 119 ConnectionManager::ScopedChange::~ScopedChange() { |
111 connection_manager_->FinishChange(); | 120 connection_manager_->FinishChange(); |
112 } | 121 } |
113 | 122 |
114 ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate) | 123 ConnectionManager::ConnectionManager( |
124 ConnectionManagerDelegate* delegate, | |
125 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) | |
115 : delegate_(delegate), | 126 : delegate_(delegate), |
127 surfaces_state_(surfaces_state), | |
116 next_connection_id_(1), | 128 next_connection_id_(1), |
117 next_root_id_(0), | 129 next_root_id_(0), |
118 event_dispatcher_(this), | 130 event_dispatcher_(this), |
119 current_change_(nullptr), | 131 current_change_(nullptr), |
120 in_destructor_(false), | 132 in_destructor_(false), |
121 animation_runner_(base::TimeTicks::Now()), | 133 animation_runner_(base::TimeTicks::Now()), |
122 focus_controller_(new FocusController(this)) { | 134 focus_controller_(new FocusController(this)) { |
123 } | 135 } |
124 | 136 |
125 ConnectionManager::~ConnectionManager() { | 137 ConnectionManager::~ConnectionManager() { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 } | 456 } |
445 } | 457 } |
446 | 458 |
447 void ConnectionManager::ProcessViewDeleted(const ViewId& view) { | 459 void ConnectionManager::ProcessViewDeleted(const ViewId& view) { |
448 for (auto& pair : connection_map_) { | 460 for (auto& pair : connection_map_) { |
449 pair.second->service()->ProcessViewDeleted(view, | 461 pair.second->service()->ProcessViewDeleted(view, |
450 IsChangeSource(pair.first)); | 462 IsChangeSource(pair.first)); |
451 } | 463 } |
452 } | 464 } |
453 | 465 |
466 void ConnectionManager::ReturnResources( | |
rjkroege
2015/08/19 23:45:44
this is not how I plumbed it
Fady Samuel
2015/08/20 16:22:44
Feel free to change. This boilerplate code exists
| |
467 const cc::ReturnedResourceArray& resources) { | |
468 // TODO(fsamuel): Implement this. | |
469 } | |
470 | |
454 void ConnectionManager::ProcessViewportMetricsChanged( | 471 void ConnectionManager::ProcessViewportMetricsChanged( |
455 const mojo::ViewportMetrics& old_metrics, | 472 const mojo::ViewportMetrics& old_metrics, |
456 const mojo::ViewportMetrics& new_metrics) { | 473 const mojo::ViewportMetrics& new_metrics) { |
457 for (auto& pair : connection_map_) { | 474 for (auto& pair : connection_map_) { |
458 pair.second->service()->ProcessViewportMetricsChanged( | 475 pair.second->service()->ProcessViewportMetricsChanged( |
459 old_metrics, new_metrics, IsChangeSource(pair.first)); | 476 old_metrics, new_metrics, IsChangeSource(pair.first)); |
460 } | 477 } |
461 } | 478 } |
462 | 479 |
463 void ConnectionManager::PrepareForChange(ScopedChange* change) { | 480 void ConnectionManager::PrepareForChange(ScopedChange* change) { |
(...skipping 27 matching lines...) Expand all Loading... | |
491 const ServerView* view) const { | 508 const ServerView* view) const { |
492 while (view && view->parent()) | 509 while (view && view->parent()) |
493 view = view->parent(); | 510 view = view->parent(); |
494 for (auto& pair : root_connection_map_) { | 511 for (auto& pair : root_connection_map_) { |
495 if (view == pair.first->root_view()) | 512 if (view == pair.first->root_view()) |
496 return pair.first; | 513 return pair.first; |
497 } | 514 } |
498 return nullptr; | 515 return nullptr; |
499 } | 516 } |
500 | 517 |
518 void ConnectionManager::SubmitCompositorFrame(ServerView* view, | |
519 mojo::CompositorFramePtr frame, | |
520 const mojo::Closure& callback) { | |
521 // Create Surfaces state on demand. | |
522 if (!surface_factory_) { | |
523 surface_factory_.reset( | |
524 new cc::SurfaceFactory(surfaces_state_->manager(), this)); | |
525 } | |
526 | |
527 if (!surface_id_allocator_) { | |
528 surface_id_allocator_.reset( | |
529 new cc::SurfaceIdAllocator(surfaces_state_->next_id_namespace())); | |
530 } | |
531 | |
532 | |
533 if (view->surface_id().is_null()) { | |
534 // Create a Surface ID for the first time for this view. | |
535 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId()); | |
536 surface_factory_->Create(surface_id); | |
537 view->SetSurfaceId(surface_id); | |
538 } else { | |
539 // If the size of the CompostiorFrame has changed then destroy the existing | |
540 // Surface and create a new one of the appropriate size. | |
541 gfx::Size frame_size = | |
542 frame->passes[0]->output_rect.To<gfx::Rect>().size(); | |
543 if (frame_size != view->last_submitted_frame_size()) { | |
544 surface_factory_->Destroy(view->surface_id()); | |
545 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId()); | |
546 surface_factory_->Create(surface_id); | |
547 view->SetSurfaceId(surface_id); | |
548 } | |
549 } | |
550 | |
551 surface_factory_->SubmitFrame(view->surface_id(), | |
552 frame.To<scoped_ptr<cc::CompositorFrame>>(), | |
553 base::Bind(&CallCallback, callback)); | |
554 surfaces_state_->scheduler()->SetNeedsDraw(); | |
555 } | |
556 | |
501 void ConnectionManager::PrepareToDestroyView(ServerView* view) { | 557 void ConnectionManager::PrepareToDestroyView(ServerView* view) { |
502 if (!in_destructor_ && IsViewAttachedToRoot(view) && | 558 if (!in_destructor_ && IsViewAttachedToRoot(view) && |
503 view->id() != ClonedViewId()) { | 559 view->id() != ClonedViewId()) { |
504 // We're about to destroy a view. Any cloned views need to be reparented | 560 // We're about to destroy a view. Any cloned views need to be reparented |
505 // else the animation would no longer be visible. By moving to a visible | 561 // else the animation would no longer be visible. By moving to a visible |
506 // view, view->parent(), we ensure the animation is still visible. | 562 // view, view->parent(), we ensure the animation is still visible. |
507 ServerView* parent_above = view; | 563 ServerView* parent_above = view; |
508 ReparentClonedViews(view->parent(), &parent_above, view); | 564 ReparentClonedViews(view->parent(), &parent_above, view); |
509 } | 565 } |
510 | 566 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 | 768 |
713 if (new_view_manager_root) { | 769 if (new_view_manager_root) { |
714 new_view_manager_root->UpdateTextInputState( | 770 new_view_manager_root->UpdateTextInputState( |
715 new_focused_view->text_input_state()); | 771 new_focused_view->text_input_state()); |
716 } else if (old_view_manager_root) { | 772 } else if (old_view_manager_root) { |
717 old_view_manager_root->UpdateTextInputState(ui::TextInputState()); | 773 old_view_manager_root->UpdateTextInputState(ui::TextInputState()); |
718 } | 774 } |
719 } | 775 } |
720 | 776 |
721 } // namespace view_manager | 777 } // namespace view_manager |
OLD | NEW |