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

Side by Side Diff: components/view_manager/connection_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698