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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 }; | 75 }; |
76 | 76 |
77 struct Service::UserState { | 77 struct Service::UserState { |
78 std::unique_ptr<ws::AccessibilityManager> accessibility; | 78 std::unique_ptr<ws::AccessibilityManager> accessibility; |
79 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 79 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
80 }; | 80 }; |
81 | 81 |
82 Service::Service() | 82 Service::Service() |
83 : test_config_(false), | 83 : test_config_(false), |
84 platform_screen_(display::PlatformScreen::Create()), | 84 platform_screen_(display::PlatformScreen::Create()), |
85 ime_registrar_(&ime_server_), | 85 ime_registrar_(&ime_server_) {} |
86 weak_ptr_factory_(this) {} | |
87 | 86 |
88 Service::~Service() { | 87 Service::~Service() { |
89 // Destroy |window_server_| first, since it depends on |event_source_|. | 88 // Destroy |window_server_| first, since it depends on |event_source_|. |
90 // WindowServer (or more correctly its Displays) may have state that needs to | 89 // WindowServer (or more correctly its Displays) may have state that needs to |
91 // be destroyed before GpuState as well. | 90 // be destroyed before GpuState as well. |
92 window_server_.reset(); | 91 window_server_.reset(); |
93 } | 92 } |
94 | 93 |
95 void Service::InitializeResources(shell::Connector* connector) { | 94 void Service::InitializeResources(shell::Connector* connector) { |
96 if (ui::ResourceBundle::HasSharedInstance()) | 95 if (ui::ResourceBundle::HasSharedInstance()) |
(...skipping 30 matching lines...) Expand all Loading... |
127 return it->second.get(); | 126 return it->second.get(); |
128 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); | 127 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); |
129 return user_id_to_user_state_[user_id].get(); | 128 return user_id_to_user_state_[user_id].get(); |
130 } | 129 } |
131 | 130 |
132 void Service::AddUserIfNecessary(const shell::Identity& remote_identity) { | 131 void Service::AddUserIfNecessary(const shell::Identity& remote_identity) { |
133 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); | 132 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); |
134 } | 133 } |
135 | 134 |
136 void Service::OnStart(const shell::Identity& identity) { | 135 void Service::OnStart(const shell::Identity& identity) { |
137 platform_display_init_params_.surfaces_state = new SurfacesState; | |
138 | |
139 base::PlatformThread::SetName("mus"); | 136 base::PlatformThread::SetName("mus"); |
140 tracing_.Initialize(connector(), identity.name()); | 137 tracing_.Initialize(connector(), identity.name()); |
141 TRACE_EVENT0("mus", "Service::Initialize started"); | 138 TRACE_EVENT0("mus", "Service::Initialize started"); |
142 | 139 |
143 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 140 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
144 switches::kUseTestConfig); | 141 switches::kUseTestConfig); |
145 #if defined(USE_X11) | 142 #if defined(USE_X11) |
146 XInitThreads(); | 143 XInitThreads(); |
147 if (test_config_) | 144 if (test_config_) |
148 ui::test::SetUseOverrideRedirectWindowByDefault(true); | 145 ui::test::SetUseOverrideRedirectWindowByDefault(true); |
(...skipping 30 matching lines...) Expand all Loading... |
179 | 176 |
180 // This needs to happen after DeviceDataManager has been constructed. That | 177 // This needs to happen after DeviceDataManager has been constructed. That |
181 // happens either during OzonePlatform or PlatformEventSource initialization, | 178 // happens either during OzonePlatform or PlatformEventSource initialization, |
182 // so keep this line below both of those. | 179 // so keep this line below both of those. |
183 input_device_server_.RegisterAsObserver(); | 180 input_device_server_.RegisterAsObserver(); |
184 | 181 |
185 GpuServiceMus::GetInstance(); | 182 GpuServiceMus::GetInstance(); |
186 | 183 |
187 // Gpu must be running before the PlatformScreen can be initialized. | 184 // Gpu must be running before the PlatformScreen can be initialized. |
188 platform_screen_->Init(); | 185 platform_screen_->Init(); |
189 window_server_.reset( | 186 window_server_.reset(new ws::WindowServer(this)); |
190 new ws::WindowServer(this, platform_display_init_params_.surfaces_state)); | |
191 | 187 |
192 // DeviceDataManager must be initialized before TouchController. On non-Linux | 188 // DeviceDataManager must be initialized before TouchController. On non-Linux |
193 // platforms there is no DeviceDataManager so don't create touch controller. | 189 // platforms there is no DeviceDataManager so don't create touch controller. |
194 if (ui::DeviceDataManager::HasInstance()) | 190 if (ui::DeviceDataManager::HasInstance()) |
195 touch_controller_.reset( | 191 touch_controller_.reset( |
196 new ws::TouchController(window_server_->display_manager())); | 192 new ws::TouchController(window_server_->display_manager())); |
197 } | 193 } |
198 | 194 |
199 bool Service::OnConnect(const shell::Identity& remote_identity, | 195 bool Service::OnConnect(const shell::Identity& remote_identity, |
200 shell::InterfaceRegistry* registry) { | 196 shell::InterfaceRegistry* registry) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void Service::OnNoMoreDisplays() { | 234 void Service::OnNoMoreDisplays() { |
239 // We may get here from the destructor, in which case there is no messageloop. | 235 // We may get here from the destructor, in which case there is no messageloop. |
240 if (base::MessageLoop::current()) | 236 if (base::MessageLoop::current()) |
241 base::MessageLoop::current()->QuitWhenIdle(); | 237 base::MessageLoop::current()->QuitWhenIdle(); |
242 } | 238 } |
243 | 239 |
244 bool Service::IsTestConfig() const { | 240 bool Service::IsTestConfig() const { |
245 return test_config_; | 241 return test_config_; |
246 } | 242 } |
247 | 243 |
| 244 void Service::UpdateTouchTransforms() { |
| 245 if (touch_controller_) |
| 246 touch_controller_->UpdateTouchTransforms(); |
| 247 } |
| 248 |
248 void Service::CreateDefaultDisplays() { | 249 void Service::CreateDefaultDisplays() { |
249 // An asynchronous callback will create the Displays once the physical | 250 // An asynchronous callback will create the Displays once the physical |
250 // displays are ready. | 251 // displays are ready. |
251 platform_screen_->ConfigurePhysicalDisplay(base::Bind( | 252 platform_screen_->ConfigureDisplays(window_server_->display_manager()); |
252 &Service::OnCreatedPhysicalDisplay, weak_ptr_factory_.GetWeakPtr())); | |
253 } | 253 } |
254 | 254 |
255 void Service::Create(const shell::Identity& remote_identity, | 255 void Service::Create(const shell::Identity& remote_identity, |
256 mojom::AccessibilityManagerRequest request) { | 256 mojom::AccessibilityManagerRequest request) { |
257 UserState* user_state = GetUserState(remote_identity); | 257 UserState* user_state = GetUserState(remote_identity); |
258 if (!user_state->accessibility) { | 258 if (!user_state->accessibility) { |
259 const ws::UserId& user_id = remote_identity.user_id(); | 259 const ws::UserId& user_id = remote_identity.user_id(); |
260 user_state->accessibility.reset( | 260 user_state->accessibility.reset( |
261 new ws::AccessibilityManager(window_server_.get(), user_id)); | 261 new ws::AccessibilityManager(window_server_.get(), user_id)); |
262 } | 262 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 AddUserIfNecessary(remote_identity); | 334 AddUserIfNecessary(remote_identity); |
335 new ws::WindowTreeFactory(window_server_.get(), remote_identity.user_id(), | 335 new ws::WindowTreeFactory(window_server_.get(), remote_identity.user_id(), |
336 remote_identity.name(), std::move(request)); | 336 remote_identity.name(), std::move(request)); |
337 } | 337 } |
338 | 338 |
339 void Service::Create(const shell::Identity& remote_identity, | 339 void Service::Create(const shell::Identity& remote_identity, |
340 mojom::WindowTreeHostFactoryRequest request) { | 340 mojom::WindowTreeHostFactoryRequest request) { |
341 UserState* user_state = GetUserState(remote_identity); | 341 UserState* user_state = GetUserState(remote_identity); |
342 if (!user_state->window_tree_host_factory) { | 342 if (!user_state->window_tree_host_factory) { |
343 user_state->window_tree_host_factory.reset(new ws::WindowTreeHostFactory( | 343 user_state->window_tree_host_factory.reset(new ws::WindowTreeHostFactory( |
344 window_server_.get(), remote_identity.user_id(), | 344 window_server_.get(), remote_identity.user_id())); |
345 platform_display_init_params_)); | |
346 } | 345 } |
347 user_state->window_tree_host_factory->AddBinding(std::move(request)); | 346 user_state->window_tree_host_factory->AddBinding(std::move(request)); |
348 } | 347 } |
349 | 348 |
350 void Service::Create(const shell::Identity& remote_identity, | 349 void Service::Create(const shell::Identity& remote_identity, |
351 mojom::WindowServerTestRequest request) { | 350 mojom::WindowServerTestRequest request) { |
352 if (!test_config_) | 351 if (!test_config_) |
353 return; | 352 return; |
354 new ws::WindowServerTestImpl(window_server_.get(), std::move(request)); | 353 new ws::WindowServerTestImpl(window_server_.get(), std::move(request)); |
355 } | 354 } |
356 | 355 |
357 void Service::OnCreatedPhysicalDisplay(int64_t id, const gfx::Rect& bounds) { | |
358 platform_display_init_params_.display_bounds = bounds; | |
359 platform_display_init_params_.display_id = id; | |
360 platform_display_init_params_.platform_screen = platform_screen_.get(); | |
361 | |
362 // Display manages its own lifetime. | |
363 ws::Display* host_impl = | |
364 new ws::Display(window_server_.get(), platform_display_init_params_); | |
365 host_impl->Init(nullptr); | |
366 | |
367 if (touch_controller_) | |
368 touch_controller_->UpdateTouchTransforms(); | |
369 } | |
370 | 356 |
371 } // namespace ui | 357 } // namespace ui |
OLD | NEW |