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

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

Issue 2176303002: services/ui: Remove deprecated gpu code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 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
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::Connection* connection; 70 shell::Connection* connection;
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const shell::Identity& identity, 135 const shell::Identity& identity,
148 uint32_t id) { 136 uint32_t id) {
149 platform_display_init_params_.surfaces_state = new SurfacesState; 137 platform_display_init_params_.surfaces_state = new SurfacesState;
150 138
151 base::PlatformThread::SetName("mus"); 139 base::PlatformThread::SetName("mus");
152 tracing_.Initialize(connector, identity.name()); 140 tracing_.Initialize(connector, identity.name());
153 TRACE_EVENT0("mus", "Service::Initialize started"); 141 TRACE_EVENT0("mus", "Service::Initialize started");
154 142
155 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( 143 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
156 switches::kUseTestConfig); 144 switches::kUseTestConfig);
157 // TODO(penghuang): Kludge: use mojo command buffer when running on Windows
158 // since Chrome command buffer breaks unit tests
159 #if defined(OS_WIN)
160 use_chrome_gpu_command_buffer_ = false;
161 #else
162 use_chrome_gpu_command_buffer_ =
163 !base::CommandLine::ForCurrentProcess()->HasSwitch(
164 switches::kUseMojoGpuCommandBufferInMus);
165 #endif
166 #if defined(USE_X11) 145 #if defined(USE_X11)
167 XInitThreads(); 146 XInitThreads();
168 if (test_config_) 147 if (test_config_)
169 ui::test::SetUseOverrideRedirectWindowByDefault(true); 148 ui::test::SetUseOverrideRedirectWindowByDefault(true);
170 #endif 149 #endif
171 150
172 InitializeResources(connector); 151 InitializeResources(connector);
173 152
174 #if defined(USE_OZONE) 153 #if defined(USE_OZONE)
175 // The ozone platform can provide its own event source. So initialize the 154 // The ozone platform can provide its own event source. So initialize the
(...skipping 21 matching lines...) Expand all
197 176
198 #if !defined(OS_ANDROID) 177 #if !defined(OS_ANDROID)
199 event_source_ = ui::PlatformEventSource::CreateDefault(); 178 event_source_ = ui::PlatformEventSource::CreateDefault();
200 #endif 179 #endif
201 180
202 // This needs to happen after DeviceDataManager has been constructed. That 181 // This needs to happen after DeviceDataManager has been constructed. That
203 // happens either during OzonePlatform or PlatformEventSource initialization, 182 // happens either during OzonePlatform or PlatformEventSource initialization,
204 // so keep this line below both of those. 183 // so keep this line below both of those.
205 input_device_server_.RegisterAsObserver(); 184 input_device_server_.RegisterAsObserver();
206 185
207 if (use_chrome_gpu_command_buffer_) { 186 GpuServiceMus::GetInstance();
208 GpuServiceMus::GetInstance();
209 } else {
210 // TODO(rjkroege): It is possible that we might want to generalize the
211 // GpuState object.
212 platform_display_init_params_.gpu_state = new GpuState();
213 }
214 187
215 // Gpu must be running before the PlatformScreen can be initialized. 188 // Gpu must be running before the PlatformScreen can be initialized.
216 platform_screen_->Init(); 189 platform_screen_->Init();
217 window_server_.reset( 190 window_server_.reset(
218 new ws::WindowServer(this, platform_display_init_params_.surfaces_state)); 191 new ws::WindowServer(this, platform_display_init_params_.surfaces_state));
219 192
220 // DeviceDataManager must be initialized before TouchController. On non-Linux 193 // DeviceDataManager must be initialized before TouchController. On non-Linux
221 // platforms there is no DeviceDataManager so don't create touch controller. 194 // platforms there is no DeviceDataManager so don't create touch controller.
222 if (ui::DeviceDataManager::HasInstance()) 195 if (ui::DeviceDataManager::HasInstance())
223 touch_controller_.reset( 196 touch_controller_.reset(
224 new ws::TouchController(window_server_->display_manager())); 197 new ws::TouchController(window_server_->display_manager()));
225 } 198 }
226 199
227 bool Service::OnConnect(Connection* connection) { 200 bool Service::OnConnect(Connection* connection) {
228 connection->AddInterface<mojom::AccessibilityManager>(this); 201 connection->AddInterface<mojom::AccessibilityManager>(this);
229 connection->AddInterface<mojom::Clipboard>(this); 202 connection->AddInterface<mojom::Clipboard>(this);
230 connection->AddInterface<mojom::DisplayManager>(this); 203 connection->AddInterface<mojom::DisplayManager>(this);
231 connection->AddInterface<mojom::UserAccessManager>(this); 204 connection->AddInterface<mojom::UserAccessManager>(this);
232 connection->AddInterface<mojom::UserActivityMonitor>(this); 205 connection->AddInterface<mojom::UserActivityMonitor>(this);
233 connection->AddInterface<WindowTreeHostFactory>(this); 206 connection->AddInterface<WindowTreeHostFactory>(this);
234 connection->AddInterface<mojom::WindowManagerWindowTreeFactory>(this); 207 connection->AddInterface<mojom::WindowManagerWindowTreeFactory>(this);
235 connection->AddInterface<mojom::WindowTreeFactory>(this); 208 connection->AddInterface<mojom::WindowTreeFactory>(this);
236 if (test_config_) 209 if (test_config_)
237 connection->AddInterface<WindowServerTest>(this); 210 connection->AddInterface<WindowServerTest>(this);
238 211
239 if (use_chrome_gpu_command_buffer_) { 212 connection->AddInterface<mojom::GpuService>(this);
Peng 2016/07/26 15:47:03 Reorder interfaces?
sadrul 2016/07/26 16:13:04 Done.
240 connection->AddInterface<mojom::GpuService>(this);
241 } else {
242 connection->AddInterface<Gpu>(this);
243 }
244 213
245 // On non-Linux platforms there will be no DeviceDataManager instance and no 214 // On non-Linux platforms there will be no DeviceDataManager instance and no
246 // purpose in adding the Mojo interface to connect to. 215 // purpose in adding the Mojo interface to connect to.
247 if (input_device_server_.IsRegisteredAsObserver()) 216 if (input_device_server_.IsRegisteredAsObserver())
248 input_device_server_.AddInterface(connection); 217 input_device_server_.AddInterface(connection);
249 218
250 #if defined(USE_OZONE) 219 #if defined(USE_OZONE)
251 ui::OzonePlatform::GetInstance()->AddInterfaces(connection); 220 ui::OzonePlatform::GetInstance()->AddInterfaces(connection);
252 #endif 221 #endif
253 222
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 pending_request->dm_request.reset( 277 pending_request->dm_request.reset(
309 new mojom::DisplayManagerRequest(std::move(request))); 278 new mojom::DisplayManagerRequest(std::move(request)));
310 pending_requests_.push_back(std::move(pending_request)); 279 pending_requests_.push_back(std::move(pending_request));
311 return; 280 return;
312 } 281 }
313 window_server_->display_manager() 282 window_server_->display_manager()
314 ->GetUserDisplayManager(connection->GetRemoteIdentity().user_id()) 283 ->GetUserDisplayManager(connection->GetRemoteIdentity().user_id())
315 ->AddDisplayManagerBinding(std::move(request)); 284 ->AddDisplayManagerBinding(std::move(request));
316 } 285 }
317 286
318 void Service::Create(shell::Connection* connection, mojom::GpuRequest request) {
319 if (use_chrome_gpu_command_buffer_)
320 return;
321 DCHECK(platform_display_init_params_.gpu_state);
322 new GpuImpl(std::move(request), platform_display_init_params_.gpu_state);
323 }
324
325 void Service::Create(shell::Connection* connection, 287 void Service::Create(shell::Connection* connection,
326 mojom::GpuServiceRequest request) { 288 mojom::GpuServiceRequest request) {
327 if (!use_chrome_gpu_command_buffer_)
328 return;
329 new GpuServiceImpl(std::move(request), connection); 289 new GpuServiceImpl(std::move(request), connection);
330 } 290 }
331 291
332 void Service::Create(shell::Connection* connection, 292 void Service::Create(shell::Connection* connection,
333 mojom::UserAccessManagerRequest request) { 293 mojom::UserAccessManagerRequest request) {
334 window_server_->user_id_tracker()->Bind(std::move(request)); 294 window_server_->user_id_tracker()->Bind(std::move(request));
335 } 295 }
336 296
337 void Service::Create(shell::Connection* connection, 297 void Service::Create(shell::Connection* connection,
338 mojom::UserActivityMonitorRequest request) { 298 mojom::UserActivityMonitorRequest request) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // Display manages its own lifetime. 351 // Display manages its own lifetime.
392 ws::Display* host_impl = 352 ws::Display* host_impl =
393 new ws::Display(window_server_.get(), platform_display_init_params_); 353 new ws::Display(window_server_.get(), platform_display_init_params_);
394 host_impl->Init(nullptr); 354 host_impl->Init(nullptr);
395 355
396 if (touch_controller_) 356 if (touch_controller_)
397 touch_controller_->UpdateTouchTransforms(); 357 touch_controller_->UpdateTouchTransforms();
398 } 358 }
399 359
400 } // namespace ui 360 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698