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

Side by Side Diff: services/ui/service.cc

Issue 2194893002: services/ui: Revert CLs that broke Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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
« no previous file with comments | « services/ui/service.h ('k') | services/ui/surfaces/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "services/ui/service.h" 5 #include "services/ui/service.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "mojo/public/c/system/main.h" 15 #include "mojo/public/c/system/main.h"
16 #include "services/catalog/public/cpp/resource_loader.h" 16 #include "services/catalog/public/cpp/resource_loader.h"
17 #include "services/shell/public/cpp/connection.h" 17 #include "services/shell/public/cpp/connection.h"
18 #include "services/shell/public/cpp/connector.h" 18 #include "services/shell/public/cpp/connector.h"
19 #include "services/tracing/public/cpp/tracing_impl.h" 19 #include "services/tracing/public/cpp/tracing_impl.h"
20 #include "services/ui/clipboard/clipboard_impl.h" 20 #include "services/ui/clipboard/clipboard_impl.h"
21 #include "services/ui/common/switches.h" 21 #include "services/ui/common/switches.h"
22 #include "services/ui/display/platform_screen.h" 22 #include "services/ui/display/platform_screen.h"
23 #include "services/ui/gles2/gpu_impl.h"
23 #include "services/ui/gpu/gpu_service_impl.h" 24 #include "services/ui/gpu/gpu_service_impl.h"
24 #include "services/ui/gpu/gpu_service_mus.h" 25 #include "services/ui/gpu/gpu_service_mus.h"
25 #include "services/ui/ws/accessibility_manager.h" 26 #include "services/ui/ws/accessibility_manager.h"
26 #include "services/ui/ws/display.h" 27 #include "services/ui/ws/display.h"
27 #include "services/ui/ws/display_binding.h" 28 #include "services/ui/ws/display_binding.h"
28 #include "services/ui/ws/display_manager.h" 29 #include "services/ui/ws/display_manager.h"
29 #include "services/ui/ws/user_activity_monitor.h" 30 #include "services/ui/ws/user_activity_monitor.h"
30 #include "services/ui/ws/user_display_manager.h" 31 #include "services/ui/ws/user_display_manager.h"
31 #include "services/ui/ws/window_server.h" 32 #include "services/ui/ws/window_server.h"
32 #include "services/ui/ws/window_server_test_impl.h" 33 #include "services/ui/ws/window_server_test_impl.h"
(...skipping 12 matching lines...) Expand all
45 #include <X11/Xlib.h> 46 #include <X11/Xlib.h>
46 #include "ui/platform_window/x11/x11_window.h" 47 #include "ui/platform_window/x11/x11_window.h"
47 #elif defined(USE_OZONE) 48 #elif defined(USE_OZONE)
48 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 49 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
49 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" 50 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
50 #include "ui/ozone/public/ozone_platform.h" 51 #include "ui/ozone/public/ozone_platform.h"
51 #endif 52 #endif
52 53
53 using shell::Connection; 54 using shell::Connection;
54 using mojo::InterfaceRequest; 55 using mojo::InterfaceRequest;
56 using ui::mojom::Gpu;
55 using ui::mojom::WindowServerTest; 57 using ui::mojom::WindowServerTest;
56 using ui::mojom::WindowTreeHostFactory; 58 using ui::mojom::WindowTreeHostFactory;
57 59
58 namespace ui { 60 namespace ui {
59 61
60 namespace { 62 namespace {
61 63
62 const char kResourceFileStrings[] = "mus_app_resources_strings.pak"; 64 const char kResourceFileStrings[] = "mus_app_resources_strings.pak";
63 const char kResourceFile100[] = "mus_app_resources_100.pak"; 65 const char kResourceFile100[] = "mus_app_resources_100.pak";
64 const char kResourceFile200[] = "mus_app_resources_200.pak"; 66 const char kResourceFile200[] = "mus_app_resources_200.pak";
65 67
66 } // namespace 68 } // namespace
67 69
68 // TODO(sky): this is a pretty typical pattern, make it easier to do. 70 // TODO(sky): this is a pretty typical pattern, make it easier to do.
69 struct Service::PendingRequest { 71 struct Service::PendingRequest {
70 shell::Identity remote_identity; 72 shell::Identity remote_identity;
71 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; 73 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request;
72 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; 74 std::unique_ptr<mojom::DisplayManagerRequest> dm_request;
73 }; 75 };
74 76
75 struct Service::UserState { 77 struct Service::UserState {
76 std::unique_ptr<ws::AccessibilityManager> accessibility; 78 std::unique_ptr<ws::AccessibilityManager> accessibility;
77 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; 79 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory;
78 }; 80 };
79 81
80 Service::Service() 82 Service::Service()
81 : test_config_(false), 83 : test_config_(false),
84 // TODO(penghuang): Kludge: Use mojo command buffer when running on
85 // Windows since chrome command buffer breaks unit tests
86 #if defined(OS_WIN)
87 use_chrome_gpu_command_buffer_(false),
88 #else
89 use_chrome_gpu_command_buffer_(true),
90 #endif
82 platform_screen_(display::PlatformScreen::Create()), 91 platform_screen_(display::PlatformScreen::Create()),
83 weak_ptr_factory_(this) { 92 weak_ptr_factory_(this) {
84 } 93 }
85 94
86 Service::~Service() { 95 Service::~Service() {
87 // Destroy |window_server_| first, since it depends on |event_source_|. 96 // Destroy |window_server_| first, since it depends on |event_source_|.
88 // WindowServer (or more correctly its Displays) may have state that needs to 97 // WindowServer (or more correctly its Displays) may have state that needs to
89 // be destroyed before GpuState as well. 98 // be destroyed before GpuState as well.
90 window_server_.reset(); 99 window_server_.reset();
100
101 if (platform_display_init_params_.gpu_state)
102 platform_display_init_params_.gpu_state->StopThreads();
91 } 103 }
92 104
93 void Service::InitializeResources(shell::Connector* connector) { 105 void Service::InitializeResources(shell::Connector* connector) {
94 if (ui::ResourceBundle::HasSharedInstance()) 106 if (ui::ResourceBundle::HasSharedInstance())
95 return; 107 return;
96 108
97 std::set<std::string> resource_paths; 109 std::set<std::string> resource_paths;
98 resource_paths.insert(kResourceFileStrings); 110 resource_paths.insert(kResourceFileStrings);
99 resource_paths.insert(kResourceFile100); 111 resource_paths.insert(kResourceFile100);
100 resource_paths.insert(kResourceFile200); 112 resource_paths.insert(kResourceFile200);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 145
134 void Service::OnStart(const shell::Identity& identity) { 146 void Service::OnStart(const shell::Identity& identity) {
135 platform_display_init_params_.surfaces_state = new SurfacesState; 147 platform_display_init_params_.surfaces_state = new SurfacesState;
136 148
137 base::PlatformThread::SetName("mus"); 149 base::PlatformThread::SetName("mus");
138 tracing_.Initialize(connector(), identity.name()); 150 tracing_.Initialize(connector(), identity.name());
139 TRACE_EVENT0("mus", "Service::Initialize started"); 151 TRACE_EVENT0("mus", "Service::Initialize started");
140 152
141 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( 153 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
142 switches::kUseTestConfig); 154 switches::kUseTestConfig);
155 // TODO(penghuang): Kludge: use mojo command buffer when running on Windows
156 // since Chrome command buffer breaks unit tests
157 #if defined(OS_WIN)
158 use_chrome_gpu_command_buffer_ = false;
159 #else
160 use_chrome_gpu_command_buffer_ =
161 !base::CommandLine::ForCurrentProcess()->HasSwitch(
162 switches::kUseMojoGpuCommandBufferInMus);
163 #endif
143 #if defined(USE_X11) 164 #if defined(USE_X11)
144 XInitThreads(); 165 XInitThreads();
145 if (test_config_) 166 if (test_config_)
146 ui::test::SetUseOverrideRedirectWindowByDefault(true); 167 ui::test::SetUseOverrideRedirectWindowByDefault(true);
147 #endif 168 #endif
148 169
149 InitializeResources(connector()); 170 InitializeResources(connector());
150 171
151 #if defined(USE_OZONE) 172 #if defined(USE_OZONE)
152 // The ozone platform can provide its own event source. So initialize the 173 // The ozone platform can provide its own event source. So initialize the
(...skipping 21 matching lines...) Expand all
174 195
175 #if !defined(OS_ANDROID) 196 #if !defined(OS_ANDROID)
176 event_source_ = ui::PlatformEventSource::CreateDefault(); 197 event_source_ = ui::PlatformEventSource::CreateDefault();
177 #endif 198 #endif
178 199
179 // This needs to happen after DeviceDataManager has been constructed. That 200 // This needs to happen after DeviceDataManager has been constructed. That
180 // happens either during OzonePlatform or PlatformEventSource initialization, 201 // happens either during OzonePlatform or PlatformEventSource initialization,
181 // so keep this line below both of those. 202 // so keep this line below both of those.
182 input_device_server_.RegisterAsObserver(); 203 input_device_server_.RegisterAsObserver();
183 204
184 GpuServiceMus::GetInstance(); 205 if (use_chrome_gpu_command_buffer_) {
206 GpuServiceMus::GetInstance();
207 } else {
208 // TODO(rjkroege): It is possible that we might want to generalize the
209 // GpuState object.
210 platform_display_init_params_.gpu_state = new GpuState();
211 }
185 212
186 // Gpu must be running before the PlatformScreen can be initialized. 213 // Gpu must be running before the PlatformScreen can be initialized.
187 platform_screen_->Init(); 214 platform_screen_->Init();
188 window_server_.reset( 215 window_server_.reset(
189 new ws::WindowServer(this, platform_display_init_params_.surfaces_state)); 216 new ws::WindowServer(this, platform_display_init_params_.surfaces_state));
190 217
191 // DeviceDataManager must be initialized before TouchController. On non-Linux 218 // DeviceDataManager must be initialized before TouchController. On non-Linux
192 // platforms there is no DeviceDataManager so don't create touch controller. 219 // platforms there is no DeviceDataManager so don't create touch controller.
193 if (ui::DeviceDataManager::HasInstance()) 220 if (ui::DeviceDataManager::HasInstance())
194 touch_controller_.reset( 221 touch_controller_.reset(
195 new ws::TouchController(window_server_->display_manager())); 222 new ws::TouchController(window_server_->display_manager()));
196 } 223 }
197 224
198 bool Service::OnConnect(Connection* connection) { 225 bool Service::OnConnect(Connection* connection) {
199 connection->AddInterface<mojom::AccessibilityManager>(this); 226 connection->AddInterface<mojom::AccessibilityManager>(this);
200 connection->AddInterface<mojom::Clipboard>(this); 227 connection->AddInterface<mojom::Clipboard>(this);
201 connection->AddInterface<mojom::DisplayManager>(this); 228 connection->AddInterface<mojom::DisplayManager>(this);
202 connection->AddInterface<mojom::GpuService>(this);
203 connection->AddInterface<mojom::UserAccessManager>(this); 229 connection->AddInterface<mojom::UserAccessManager>(this);
204 connection->AddInterface<mojom::UserActivityMonitor>(this); 230 connection->AddInterface<mojom::UserActivityMonitor>(this);
205 connection->AddInterface<WindowTreeHostFactory>(this); 231 connection->AddInterface<WindowTreeHostFactory>(this);
206 connection->AddInterface<mojom::WindowManagerWindowTreeFactory>(this); 232 connection->AddInterface<mojom::WindowManagerWindowTreeFactory>(this);
207 connection->AddInterface<mojom::WindowTreeFactory>(this); 233 connection->AddInterface<mojom::WindowTreeFactory>(this);
208 if (test_config_) 234 if (test_config_)
209 connection->AddInterface<WindowServerTest>(this); 235 connection->AddInterface<WindowServerTest>(this);
210 236
237 if (use_chrome_gpu_command_buffer_) {
238 connection->AddInterface<mojom::GpuService>(this);
239 } else {
240 connection->AddInterface<Gpu>(this);
241 }
242
211 // On non-Linux platforms there will be no DeviceDataManager instance and no 243 // On non-Linux platforms there will be no DeviceDataManager instance and no
212 // purpose in adding the Mojo interface to connect to. 244 // purpose in adding the Mojo interface to connect to.
213 if (input_device_server_.IsRegisteredAsObserver()) 245 if (input_device_server_.IsRegisteredAsObserver())
214 input_device_server_.AddInterface(connection); 246 input_device_server_.AddInterface(connection);
215 247
216 #if defined(USE_OZONE) 248 #if defined(USE_OZONE)
217 ui::OzonePlatform::GetInstance()->AddInterfaces(connection); 249 ui::OzonePlatform::GetInstance()->AddInterfaces(connection);
218 #endif 250 #endif
219 251
220 return true; 252 return true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 new mojom::DisplayManagerRequest(std::move(request))); 307 new mojom::DisplayManagerRequest(std::move(request)));
276 pending_requests_.push_back(std::move(pending_request)); 308 pending_requests_.push_back(std::move(pending_request));
277 return; 309 return;
278 } 310 }
279 window_server_->display_manager() 311 window_server_->display_manager()
280 ->GetUserDisplayManager(remote_identity.user_id()) 312 ->GetUserDisplayManager(remote_identity.user_id())
281 ->AddDisplayManagerBinding(std::move(request)); 313 ->AddDisplayManagerBinding(std::move(request));
282 } 314 }
283 315
284 void Service::Create(const shell::Identity& remote_identity, 316 void Service::Create(const shell::Identity& remote_identity,
317 mojom::GpuRequest request) {
318 if (use_chrome_gpu_command_buffer_)
319 return;
320 DCHECK(platform_display_init_params_.gpu_state);
321 new GpuImpl(std::move(request), platform_display_init_params_.gpu_state);
322 }
323
324 void Service::Create(const shell::Identity& remote_identity,
285 mojom::GpuServiceRequest request) { 325 mojom::GpuServiceRequest request) {
326 if (!use_chrome_gpu_command_buffer_)
327 return;
286 new GpuServiceImpl(std::move(request)); 328 new GpuServiceImpl(std::move(request));
287 } 329 }
288 330
289 void Service::Create(const shell::Identity& remote_identity, 331 void Service::Create(const shell::Identity& remote_identity,
290 mojom::UserAccessManagerRequest request) { 332 mojom::UserAccessManagerRequest request) {
291 window_server_->user_id_tracker()->Bind(std::move(request)); 333 window_server_->user_id_tracker()->Bind(std::move(request));
292 } 334 }
293 335
294 void Service::Create(const shell::Identity& remote_identity, 336 void Service::Create(const shell::Identity& remote_identity,
295 mojom::UserActivityMonitorRequest request) { 337 mojom::UserActivityMonitorRequest request) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Display manages its own lifetime. 389 // Display manages its own lifetime.
348 ws::Display* host_impl = 390 ws::Display* host_impl =
349 new ws::Display(window_server_.get(), platform_display_init_params_); 391 new ws::Display(window_server_.get(), platform_display_init_params_);
350 host_impl->Init(nullptr); 392 host_impl->Init(nullptr);
351 393
352 if (touch_controller_) 394 if (touch_controller_)
353 touch_controller_->UpdateTouchTransforms(); 395 touch_controller_->UpdateTouchTransforms();
354 } 396 }
355 397
356 } // namespace ui 398 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/service.h ('k') | services/ui/surfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698