Chromium Code Reviews| 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" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "services/ui/ws/user_display_manager.h" | 35 #include "services/ui/ws/user_display_manager.h" |
| 36 #include "services/ui/ws/window_server.h" | 36 #include "services/ui/ws/window_server.h" |
| 37 #include "services/ui/ws/window_server_test_impl.h" | 37 #include "services/ui/ws/window_server_test_impl.h" |
| 38 #include "services/ui/ws/window_tree.h" | 38 #include "services/ui/ws/window_tree.h" |
| 39 #include "services/ui/ws/window_tree_binding.h" | 39 #include "services/ui/ws/window_tree_binding.h" |
| 40 #include "services/ui/ws/window_tree_factory.h" | 40 #include "services/ui/ws/window_tree_factory.h" |
| 41 #include "services/ui/ws/window_tree_host_factory.h" | 41 #include "services/ui/ws/window_tree_host_factory.h" |
| 42 #include "ui/base/platform_window_defaults.h" | 42 #include "ui/base/platform_window_defaults.h" |
| 43 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
| 44 #include "ui/base/ui_base_paths.h" | 44 #include "ui/base/ui_base_paths.h" |
| 45 #include "ui/display/screen_base.h" | |
| 45 #include "ui/events/event_switches.h" | 46 #include "ui/events/event_switches.h" |
| 46 #include "ui/events/platform/platform_event_source.h" | 47 #include "ui/events/platform/platform_event_source.h" |
| 47 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
| 48 #include "ui/gl/gl_surface.h" | 49 #include "ui/gl/gl_surface.h" |
| 49 | 50 |
| 50 #if defined(USE_X11) | 51 #if defined(USE_X11) |
| 51 #include <X11/Xlib.h> | 52 #include <X11/Xlib.h> |
| 52 #include "ui/base/x/x11_util.h" // nogncheck | 53 #include "ui/base/x/x11_util.h" // nogncheck |
| 53 #include "ui/platform_window/x11/x11_window.h" | 54 #include "ui/platform_window/x11/x11_window.h" |
| 54 #elif defined(USE_OZONE) | 55 #elif defined(USE_OZONE) |
| 56 #include "services/ui/display/screen_manager_forwarding.h" | |
| 55 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 57 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 56 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 58 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 57 #include "ui/ozone/public/ozone_platform.h" | 59 #include "ui/ozone/public/ozone_platform.h" |
| 58 #endif | 60 #endif |
| 59 | 61 |
| 60 using mojo::InterfaceRequest; | 62 using mojo::InterfaceRequest; |
| 61 using ui::mojom::WindowServerTest; | 63 using ui::mojom::WindowServerTest; |
| 62 using ui::mojom::WindowTreeHostFactory; | 64 using ui::mojom::WindowTreeHostFactory; |
| 63 | 65 |
| 64 namespace ui { | 66 namespace ui { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 struct Service::UserState { | 83 struct Service::UserState { |
| 82 std::unique_ptr<clipboard::ClipboardImpl> clipboard; | 84 std::unique_ptr<clipboard::ClipboardImpl> clipboard; |
| 83 std::unique_ptr<ws::AccessibilityManager> accessibility; | 85 std::unique_ptr<ws::AccessibilityManager> accessibility; |
| 84 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 86 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 Service::Service() | 89 Service::Service() |
| 88 : test_config_(false), | 90 : test_config_(false), |
| 89 screen_manager_(display::ScreenManager::Create()), | |
| 90 ime_registrar_(&ime_server_) {} | 91 ime_registrar_(&ime_server_) {} |
| 91 | 92 |
| 92 Service::~Service() { | 93 Service::~Service() { |
| 93 // Destroy |window_server_| first, since it depends on |event_source_|. | 94 // Destroy |window_server_| first, since it depends on |event_source_|. |
| 94 // WindowServer (or more correctly its Displays) may have state that needs to | 95 // WindowServer (or more correctly its Displays) may have state that needs to |
| 95 // be destroyed before GpuState as well. | 96 // be destroyed before GpuState as well. |
| 96 window_server_.reset(); | 97 window_server_.reset(); |
| 97 | 98 |
| 98 #if defined(USE_OZONE) | 99 #if defined(USE_OZONE) |
| 99 OzonePlatform::Shutdown(); | 100 OzonePlatform::Shutdown(); |
| 100 #endif | 101 #endif |
| 102 | |
| 103 if (screen_) | |
| 104 display::Screen::SetScreenInstance(nullptr); | |
| 101 } | 105 } |
| 102 | 106 |
| 103 void Service::InitializeResources(service_manager::Connector* connector) { | 107 void Service::InitializeResources(service_manager::Connector* connector) { |
| 104 if (ui::ResourceBundle::HasSharedInstance()) | 108 if (ui::ResourceBundle::HasSharedInstance()) |
| 105 return; | 109 return; |
| 106 | 110 |
| 107 std::set<std::string> resource_paths; | 111 std::set<std::string> resource_paths; |
| 108 resource_paths.insert(kResourceFileStrings); | 112 resource_paths.insert(kResourceFileStrings); |
| 109 resource_paths.insert(kResourceFile100); | 113 resource_paths.insert(kResourceFile100); |
| 110 resource_paths.insert(kResourceFile200); | 114 resource_paths.insert(kResourceFile200); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 .AddInterface<discardable_memory::mojom::DiscardableSharedMemoryManager>( | 217 .AddInterface<discardable_memory::mojom::DiscardableSharedMemoryManager>( |
| 214 this); | 218 this); |
| 215 if (test_config_) | 219 if (test_config_) |
| 216 registry_.AddInterface<WindowServerTest>(this); | 220 registry_.AddInterface<WindowServerTest>(this); |
| 217 | 221 |
| 218 // On non-Linux platforms there will be no DeviceDataManager instance and no | 222 // On non-Linux platforms there will be no DeviceDataManager instance and no |
| 219 // purpose in adding the Mojo interface to connect to. | 223 // purpose in adding the Mojo interface to connect to. |
| 220 if (input_device_server_.IsRegisteredAsObserver()) | 224 if (input_device_server_.IsRegisteredAsObserver()) |
| 221 input_device_server_.AddInterface(®istry_); | 225 input_device_server_.AddInterface(®istry_); |
| 222 | 226 |
| 223 screen_manager_->AddInterfaces(®istry_); | |
| 224 | |
| 225 #if defined(USE_OZONE) | 227 #if defined(USE_OZONE) |
| 226 ui::OzonePlatform::GetInstance()->AddInterfaces(®istry_); | 228 ui::OzonePlatform::GetInstance()->AddInterfaces(®istry_); |
| 227 #endif | 229 #endif |
| 228 } | 230 } |
| 229 | 231 |
| 230 void Service::OnBindInterface(const service_manager::ServiceInfo& source_info, | 232 void Service::OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 231 const std::string& interface_name, | 233 const std::string& interface_name, |
| 232 mojo::ScopedMessagePipeHandle interface_pipe) { | 234 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 233 registry_.BindInterface(source_info.identity, interface_name, | 235 registry_.BindInterface(source_info.identity, interface_name, |
| 234 std::move(interface_pipe)); | 236 std::move(interface_pipe)); |
| 235 } | 237 } |
| 236 | 238 |
| 237 void Service::StartDisplayInit() { | 239 void Service::StartDisplayInit() { |
| 238 screen_manager_->Init(window_server_->display_manager()); | 240 DCHECK(!is_gpu_ready_); // This should only be called once. |
| 241 is_gpu_ready_ = true; | |
| 242 if (screen_manager_) | |
| 243 screen_manager_->Init(window_server_->display_manager()); | |
| 239 } | 244 } |
| 240 | 245 |
| 241 void Service::OnFirstDisplayReady() { | 246 void Service::OnFirstDisplayReady() { |
| 242 PendingRequests requests; | 247 PendingRequests requests; |
| 243 requests.swap(pending_requests_); | 248 requests.swap(pending_requests_); |
| 244 for (auto& request : requests) { | 249 for (auto& request : requests) { |
| 245 if (request->wtf_request) | 250 if (request->wtf_request) |
| 246 Create(request->remote_identity, std::move(*request->wtf_request)); | 251 Create(request->remote_identity, std::move(*request->wtf_request)); |
| 247 else | 252 else |
| 248 Create(request->remote_identity, std::move(*request->dm_request)); | 253 Create(request->remote_identity, std::move(*request->dm_request)); |
| 249 } | 254 } |
| 250 } | 255 } |
| 251 | 256 |
| 252 void Service::OnNoMoreDisplays() { | 257 void Service::OnNoMoreDisplays() { |
| 253 // We may get here from the destructor, in which case there is no messageloop. | 258 // We may get here from the destructor, in which case there is no messageloop. |
| 254 if (base::MessageLoop::current() && | 259 if (base::MessageLoop::current() && |
| 255 base::MessageLoop::current()->is_running()) { | 260 base::MessageLoop::current()->is_running()) { |
| 256 base::MessageLoop::current()->QuitWhenIdle(); | 261 base::MessageLoop::current()->QuitWhenIdle(); |
| 257 } | 262 } |
| 258 } | 263 } |
| 259 | 264 |
| 260 bool Service::IsTestConfig() const { | 265 bool Service::IsTestConfig() const { |
| 261 return test_config_; | 266 return test_config_; |
| 262 } | 267 } |
| 263 | 268 |
| 269 void Service::OnWillCreateTreeForWindowManager( | |
|
kylechar
2017/04/19 18:06:08
What's the expected order that StartDisplayInit()
sky
2017/04/19 19:30:03
You are correct. One is not guaranteed to be calle
| |
| 270 bool automatically_create_display_roots) { | |
| 271 if (screen_manager_config_ != ScreenManagerConfig::UNKNOWN) | |
| 272 return; | |
| 273 | |
| 274 DVLOG(3) << "OnWillCreateTreeForWindowManager " | |
| 275 << automatically_create_display_roots; | |
| 276 screen_manager_config_ = automatically_create_display_roots | |
| 277 ? ScreenManagerConfig::INTERNAL | |
| 278 : ScreenManagerConfig::FORWARDING; | |
| 279 if (screen_manager_config_ == ScreenManagerConfig::FORWARDING) { | |
| 280 screen_ = base::MakeUnique<display::ScreenBase>(); | |
| 281 display::Screen::SetScreenInstance(screen_.get()); | |
| 282 #if defined(USE_OZONE) | |
| 283 screen_manager_ = base::MakeUnique<display::ScreenManagerForwarding>(); | |
| 284 #else | |
| 285 CHECK(false); | |
| 286 #endif | |
| 287 } else { | |
| 288 screen_manager_ = display::ScreenManager::Create(); | |
| 289 } | |
| 290 screen_manager_->AddInterfaces(®istry_); | |
| 291 if (is_gpu_ready_) | |
| 292 screen_manager_->Init(window_server_->display_manager()); | |
| 293 } | |
| 294 | |
| 295 display::ScreenBase* Service::GetScreen() { | |
| 296 return screen_.get(); | |
| 297 } | |
| 298 | |
| 264 void Service::Create(const service_manager::Identity& remote_identity, | 299 void Service::Create(const service_manager::Identity& remote_identity, |
| 265 mojom::AccessibilityManagerRequest request) { | 300 mojom::AccessibilityManagerRequest request) { |
| 266 UserState* user_state = GetUserState(remote_identity); | 301 UserState* user_state = GetUserState(remote_identity); |
| 267 if (!user_state->accessibility) { | 302 if (!user_state->accessibility) { |
| 268 const ws::UserId& user_id = remote_identity.user_id(); | 303 const ws::UserId& user_id = remote_identity.user_id(); |
| 269 user_state->accessibility.reset( | 304 user_state->accessibility.reset( |
| 270 new ws::AccessibilityManager(window_server_.get(), user_id)); | 305 new ws::AccessibilityManager(window_server_.get(), user_id)); |
| 271 } | 306 } |
| 272 user_state->accessibility->Bind(std::move(request)); | 307 user_state->accessibility->Bind(std::move(request)); |
| 273 } | 308 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 mojom::WindowServerTestRequest request) { | 404 mojom::WindowServerTestRequest request) { |
| 370 if (!test_config_) | 405 if (!test_config_) |
| 371 return; | 406 return; |
| 372 mojo::MakeStrongBinding( | 407 mojo::MakeStrongBinding( |
| 373 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), | 408 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), |
| 374 std::move(request)); | 409 std::move(request)); |
| 375 } | 410 } |
| 376 | 411 |
| 377 | 412 |
| 378 } // namespace ui | 413 } // namespace ui |
| OLD | NEW |