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

Side by Side Diff: services/ui/launcher/launcher_app.cc

Issue 1552043002: Make Mozart view manager use the new compositor. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-12
Patch Set: Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/launcher/launcher_app.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
5 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
6 #include "mojo/application/application_runner_chromium.h" 10 #include "mojo/application/application_runner_chromium.h"
7 #include "mojo/common/tracing_impl.h" 11 #include "mojo/common/tracing_impl.h"
8 #include "mojo/public/c/system/main.h" 12 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_connection.h" 13 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_impl.h" 14 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/services/surfaces/cpp/surfaces_utils.h"
12 #include "mojo/services/surfaces/interfaces/quads.mojom.h"
13 #include "services/ui/launcher/launcher_app.h"
14 #include "services/ui/launcher/launcher_view_tree.h" 15 #include "services/ui/launcher/launcher_view_tree.h"
15 16
16 namespace launcher { 17 namespace launcher {
17 18
18 LauncherApp::LauncherApp() 19 LauncherApp::LauncherApp()
19 : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {} 20 : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {}
20 21
21 LauncherApp::~LauncherApp() {} 22 LauncherApp::~LauncherApp() {}
22 23
23 void LauncherApp::Initialize(mojo::ApplicationImpl* app) { 24 void LauncherApp::Initialize(mojo::ApplicationImpl* app_impl) {
24 app_impl_ = app; 25 app_impl_ = app_impl;
25 tracing_.Initialize(app); 26
27 auto command_line = base::CommandLine::ForCurrentProcess();
28 command_line->InitFromArgv(app_impl_->args());
abarth 2016/01/10 01:42:54 Woah. I guess that works.
jeffbrown 2016/01/26 05:59:12 (Nothing else does.)
29 logging::LoggingSettings settings;
30 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
31 logging::InitLogging(settings);
32
33 tracing_.Initialize(app_impl_);
26 TRACE_EVENT0("launcher", __func__); 34 TRACE_EVENT0("launcher", __func__);
27 35
28 if (app->args().size() != 2) { 36 if (command_line->GetArgs().size() != 1) {
29 LOG(ERROR) << "Invalid arguments.\n\n" 37 LOG(ERROR) << "Invalid arguments.\n\n"
30 "Usage: mojo_shell \"mojo:launcher <app url>\""; 38 "Usage: mojo_shell \"mojo:launcher <app url>\"";
31 app->Terminate(); 39 app_impl_->Terminate();
32 return; 40 return;
33 } 41 }
34 42
43 app_impl_->ConnectToService("mojo:compositor_service", &compositor_);
44 compositor_.set_connection_error_handler(base::Bind(
45 &LauncherApp::OnCompositorConnectionError, base::Unretained(this)));
46
47 app_impl_->ConnectToService("mojo:view_manager_service", &view_manager_);
48 view_manager_.set_connection_error_handler(base::Bind(
49 &LauncherApp::OnViewManagerConnectionError, base::Unretained(this)));
50
35 InitViewport(); 51 InitViewport();
36 LaunchClient(app->args()[1]); 52 LaunchClient(command_line->GetArgs()[0]);
53 }
54
55 void LauncherApp::OnCompositorConnectionError() {
56 LOG(ERROR) << "Exiting due to compositor connection error.";
57 Shutdown();
58 }
59
60 void LauncherApp::OnViewManagerConnectionError() {
61 LOG(ERROR) << "Exiting due to view manager connection error.";
62 Shutdown();
37 } 63 }
38 64
39 void LauncherApp::InitViewport() { 65 void LauncherApp::InitViewport() {
40 app_impl_->ConnectToService("mojo:native_viewport_service", 66 app_impl_->ConnectToService("mojo:native_viewport_service", &viewport_);
41 &viewport_service_); 67 viewport_.set_connection_error_handler(base::Bind(
42 viewport_service_.set_connection_error_handler(base::Bind(
43 &LauncherApp::OnViewportConnectionError, base::Unretained(this))); 68 &LauncherApp::OnViewportConnectionError, base::Unretained(this)));
44 69
45 mojo::NativeViewportEventDispatcherPtr dispatcher; 70 mojo::NativeViewportEventDispatcherPtr dispatcher;
46 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher)); 71 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher));
47 viewport_service_->SetEventDispatcher(dispatcher.Pass()); 72 viewport_->SetEventDispatcher(dispatcher.Pass());
48 73
49 // Match the Nexus 5 aspect ratio initially. 74 // Match the Nexus 5 aspect ratio initially.
50 auto size = mojo::Size::New(); 75 auto size = mojo::Size::New();
51 size->width = 320; 76 size->width = 320;
52 size->height = 640; 77 size->height = 640;
53 78
54 auto requested_configuration = mojo::SurfaceConfiguration::New(); 79 auto requested_configuration = mojo::SurfaceConfiguration::New();
55 viewport_service_->Create( 80 viewport_->Create(
56 size.Clone(), requested_configuration.Pass(), 81 size.Clone(), requested_configuration.Pass(),
57 base::Bind(&LauncherApp::OnViewportCreated, base::Unretained(this))); 82 base::Bind(&LauncherApp::OnViewportCreated, base::Unretained(this)));
58 } 83 }
59 84
60 void LauncherApp::OnViewportConnectionError() { 85 void LauncherApp::OnViewportConnectionError() {
61 LOG(ERROR) << "Exiting due to viewport connection error."; 86 LOG(ERROR) << "Exiting due to viewport connection error.";
62 app_impl_->Terminate(); 87 Shutdown();
63 } 88 }
64 89
65 void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) { 90 void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) {
66 viewport_service_->Show(); 91 viewport_->Show();
92
67 mojo::ContextProviderPtr context_provider; 93 mojo::ContextProviderPtr context_provider;
68 viewport_service_->GetContextProvider(GetProxy(&context_provider)); 94 viewport_->GetContextProvider(GetProxy(&context_provider));
69 95
70 mojo::DisplayFactoryPtr display_factory; 96 view_tree_.reset(new LauncherViewTree(
71 app_impl_->ConnectToService("mojo:surfaces_service", &display_factory); 97 compositor_.get(), view_manager_.get(), context_provider.Pass(),
72 98 metrics.Pass(),
73 mojo::DisplayPtr display; 99 base::Bind(&LauncherApp::Shutdown, base::Unretained(this))));
74 display_factory->Create(context_provider.Pass(), nullptr, GetProxy(&display));
75
76 view_tree_.reset(
77 new LauncherViewTree(app_impl_, display.Pass(), metrics.Pass()));
78 UpdateClientView(); 100 UpdateClientView();
79 RequestUpdatedViewportMetrics(); 101 RequestUpdatedViewportMetrics();
80 } 102 }
81 103
82 void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) { 104 void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) {
83 if (view_tree_) { 105 if (view_tree_) {
84 view_tree_->SetViewportMetrics(metrics.Pass()); 106 view_tree_->SetViewportMetrics(metrics.Pass());
85 RequestUpdatedViewportMetrics(); 107 RequestUpdatedViewportMetrics();
86 } 108 }
87 } 109 }
88 110
89 void LauncherApp::RequestUpdatedViewportMetrics() { 111 void LauncherApp::RequestUpdatedViewportMetrics() {
90 viewport_service_->RequestMetrics(base::Bind( 112 viewport_->RequestMetrics(base::Bind(&LauncherApp::OnViewportMetricsChanged,
91 &LauncherApp::OnViewportMetricsChanged, base::Unretained(this))); 113 base::Unretained(this)));
92 } 114 }
93 115
94 void LauncherApp::OnEvent(mojo::EventPtr event, 116 void LauncherApp::OnEvent(mojo::EventPtr event,
95 const mojo::Callback<void()>& callback) { 117 const mojo::Callback<void()>& callback) {
96 if (view_tree_) 118 if (view_tree_)
97 view_tree_->DispatchEvent(event.Pass()); 119 view_tree_->DispatchEvent(event.Pass());
98 callback.Run(); 120 callback.Run();
99 } 121 }
100 122
101 void LauncherApp::LaunchClient(std::string app_url) { 123 void LauncherApp::LaunchClient(std::string app_url) {
102 DVLOG(1) << "Launching " << app_url; 124 DVLOG(1) << "Launching " << app_url;
103 125
104 app_impl_->ConnectToService(app_url, &client_view_provider_); 126 app_impl_->ConnectToService(app_url, &client_view_provider_);
105 client_view_provider_.set_connection_error_handler(base::Bind( 127 client_view_provider_.set_connection_error_handler(base::Bind(
106 &LauncherApp::OnClientConnectionError, base::Unretained(this))); 128 &LauncherApp::OnClientConnectionError, base::Unretained(this)));
107 129
108 client_view_provider_->CreateView( 130 client_view_provider_->CreateView(
109 nullptr, nullptr, 131 nullptr, nullptr,
110 base::Bind(&LauncherApp::OnClientViewCreated, base::Unretained(this))); 132 base::Bind(&LauncherApp::OnClientViewCreated, base::Unretained(this)));
111 } 133 }
112 134
113 void LauncherApp::OnClientConnectionError() { 135 void LauncherApp::OnClientConnectionError() {
114 LOG(ERROR) << "Exiting due to client application connection error."; 136 LOG(ERROR) << "Exiting due to client application connection error.";
115 app_impl_->Terminate(); 137 Shutdown();
116 } 138 }
117 139
118 void LauncherApp::OnClientViewCreated(mojo::ui::ViewTokenPtr view_token) { 140 void LauncherApp::OnClientViewCreated(mojo::ui::ViewTokenPtr view_token) {
119 client_view_token_ = view_token.Pass(); 141 client_view_token_ = view_token.Pass();
120 UpdateClientView(); 142 UpdateClientView();
121 } 143 }
122 144
123 void LauncherApp::UpdateClientView() { 145 void LauncherApp::UpdateClientView() {
124 if (view_tree_) 146 if (view_tree_)
125 view_tree_->SetRoot(client_view_token_.Clone()); 147 view_tree_->SetRoot(client_view_token_.Clone());
126 } 148 }
127 149
150 void LauncherApp::Shutdown() {
151 app_impl_->Terminate();
152 }
153
128 } // namespace launcher 154 } // namespace launcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698