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" |
9 #include "components/view_manager/client_connection.h" | 10 #include "components/view_manager/client_connection.h" |
10 #include "components/view_manager/connection_manager_delegate.h" | 11 #include "components/view_manager/connection_manager_delegate.h" |
11 #include "components/view_manager/focus_controller.h" | 12 #include "components/view_manager/focus_controller.h" |
12 #include "components/view_manager/server_view.h" | 13 #include "components/view_manager/server_view.h" |
13 #include "components/view_manager/view_coordinate_conversions.h" | 14 #include "components/view_manager/view_coordinate_conversions.h" |
14 #include "components/view_manager/view_manager_root_connection.h" | 15 #include "components/view_manager/view_manager_root_connection.h" |
15 #include "components/view_manager/view_manager_service_impl.h" | 16 #include "components/view_manager/view_manager_service_impl.h" |
16 #include "mojo/application/public/cpp/application_connection.h" | 17 #include "mojo/application/public/cpp/application_connection.h" |
17 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 18 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
18 #include "mojo/converters/geometry/geometry_type_converters.h" | 19 #include "mojo/converters/geometry/geometry_type_converters.h" |
19 #include "mojo/converters/input_events/input_events_type_converters.h" | 20 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 21 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
20 | 22 |
21 using mojo::ConnectionSpecificId; | 23 using mojo::ConnectionSpecificId; |
22 | 24 |
23 namespace view_manager { | 25 namespace view_manager { |
24 namespace { | 26 namespace { |
25 | 27 |
| 28 namespace { |
| 29 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { |
| 30 callback.Run(); |
| 31 } |
| 32 } |
| 33 |
26 // Creates a copy of |view|. The copied view has |delegate| as its delegate. | 34 // Creates a copy of |view|. The copied view has |delegate| as its delegate. |
27 // This does not recurse. | 35 // This does not recurse. |
28 ServerView* CloneView(const ServerView* view, ServerViewDelegate* delegate) { | 36 ServerView* CloneView(const ServerView* view, ServerViewDelegate* delegate) { |
29 ServerView* clone = new ServerView(delegate, ClonedViewId()); | 37 ServerView* clone = new ServerView(delegate, ClonedViewId()); |
30 clone->SetBounds(view->bounds()); | 38 clone->SetBounds(view->bounds()); |
31 clone->SetSurfaceId(view->surface_id()); | 39 clone->SetSurfaceId(view->surface_id()); |
32 clone->SetOpacity(view->opacity()); | 40 clone->SetOpacity(view->opacity()); |
33 return clone; | 41 return clone; |
34 } | 42 } |
35 | 43 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 : connection_manager_(connection_manager), | 112 : connection_manager_(connection_manager), |
105 connection_id_(connection->id()), | 113 connection_id_(connection->id()), |
106 is_delete_view_(is_delete_view) { | 114 is_delete_view_(is_delete_view) { |
107 connection_manager_->PrepareForChange(this); | 115 connection_manager_->PrepareForChange(this); |
108 } | 116 } |
109 | 117 |
110 ConnectionManager::ScopedChange::~ScopedChange() { | 118 ConnectionManager::ScopedChange::~ScopedChange() { |
111 connection_manager_->FinishChange(); | 119 connection_manager_->FinishChange(); |
112 } | 120 } |
113 | 121 |
114 ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate) | 122 ConnectionManager::ConnectionManager( |
| 123 ConnectionManagerDelegate* delegate, |
| 124 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) |
115 : delegate_(delegate), | 125 : delegate_(delegate), |
| 126 surfaces_state_(surfaces_state), |
| 127 surface_factory_(surfaces_state->manager(), this), |
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( |
| 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::SubmitFrame(ServerView* view, |
| 519 mojo::CompositorFramePtr frame, |
| 520 const mojo::Closure& callback) { |
| 521 if (view->surface_id().is_null()) { |
| 522 // TODO(fsamuel): This is a hack. Do something sensible. |
| 523 cc::SurfaceId surface_id( |
| 524 (static_cast<uint64_t>(surfaces_state_->next_id_namespace()) << 32) | |
| 525 view->id().view_id); |
| 526 surface_factory_.Create(surface_id); |
| 527 view->SetSurfaceId(surface_id); |
| 528 } else { |
| 529 gfx::Size frame_size = |
| 530 frame->passes[0]->output_rect.To<gfx::Rect>().size(); |
| 531 if (frame_size != view->last_submitted_frame_size()) { |
| 532 surface_factory_.Destroy(view->surface_id()); |
| 533 // Allocated a new Surface ID that is incremented by one. |
| 534 cc::SurfaceId surface_id(view->surface_id()); |
| 535 surface_id = cc::SurfaceId((surface_id.id & 0xffffffff00000000) | |
| 536 ((surface_id.id & 0x00000000ffffffff) + 1)); |
| 537 surface_factory_.Create(surface_id); |
| 538 view->SetSurfaceId(surface_id); |
| 539 } |
| 540 } |
| 541 |
| 542 surface_factory_.SubmitFrame(view->surface_id(), |
| 543 frame.To<scoped_ptr<cc::CompositorFrame>>(), |
| 544 base::Bind(&CallCallback, callback)); |
| 545 surfaces_state_->scheduler()->SetNeedsDraw(); |
| 546 } |
| 547 |
501 void ConnectionManager::PrepareToDestroyView(ServerView* view) { | 548 void ConnectionManager::PrepareToDestroyView(ServerView* view) { |
502 if (!in_destructor_ && IsViewAttachedToRoot(view) && | 549 if (!in_destructor_ && IsViewAttachedToRoot(view) && |
503 view->id() != ClonedViewId()) { | 550 view->id() != ClonedViewId()) { |
504 // We're about to destroy a view. Any cloned views need to be reparented | 551 // 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 | 552 // else the animation would no longer be visible. By moving to a visible |
506 // view, view->parent(), we ensure the animation is still visible. | 553 // view, view->parent(), we ensure the animation is still visible. |
507 ServerView* parent_above = view; | 554 ServerView* parent_above = view; |
508 ReparentClonedViews(view->parent(), &parent_above, view); | 555 ReparentClonedViews(view->parent(), &parent_above, view); |
509 } | 556 } |
510 | 557 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 759 |
713 if (new_view_manager_root) { | 760 if (new_view_manager_root) { |
714 new_view_manager_root->UpdateTextInputState( | 761 new_view_manager_root->UpdateTextInputState( |
715 new_focused_view->text_input_state()); | 762 new_focused_view->text_input_state()); |
716 } else if (old_view_manager_root) { | 763 } else if (old_view_manager_root) { |
717 old_view_manager_root->UpdateTextInputState(ui::TextInputState()); | 764 old_view_manager_root->UpdateTextInputState(ui::TextInputState()); |
718 } | 765 } |
719 } | 766 } |
720 | 767 |
721 } // namespace view_manager | 768 } // namespace view_manager |
OLD | NEW |