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