OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/gpu/gpu_child_thread.h" | 5 #include "content/gpu/gpu_child_thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "content/child/child_process.h" | 17 #include "content/child/child_process.h" |
18 #include "content/child/thread_safe_sender.h" | 18 #include "content/child/thread_safe_sender.h" |
19 #include "content/common/establish_channel_params.h" | 19 #include "content/common/establish_channel_params.h" |
20 #include "content/common/gpu_host_messages.h" | 20 #include "content/common/gpu_host_messages.h" |
21 #include "content/common/process_control.mojom.h" | |
22 #include "content/gpu/gpu_process_control_impl.h" | 21 #include "content/gpu/gpu_process_control_impl.h" |
23 #include "content/gpu/gpu_watchdog_thread.h" | 22 #include "content/gpu/gpu_watchdog_thread.h" |
24 #include "content/public/common/connection_filter.h" | |
25 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
26 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/mojo_shell_connection.h" | |
28 #include "content/public/gpu/content_gpu_client.h" | 25 #include "content/public/gpu/content_gpu_client.h" |
29 #include "gpu/command_buffer/service/gpu_switches.h" | 26 #include "gpu/command_buffer/service/gpu_switches.h" |
30 #include "gpu/command_buffer/service/sync_point_manager.h" | 27 #include "gpu/command_buffer/service/sync_point_manager.h" |
31 #include "gpu/config/gpu_info_collector.h" | 28 #include "gpu/config/gpu_info_collector.h" |
32 #include "gpu/config/gpu_switches.h" | 29 #include "gpu/config/gpu_switches.h" |
33 #include "gpu/config/gpu_util.h" | 30 #include "gpu/config/gpu_util.h" |
34 #include "gpu/ipc/common/memory_stats.h" | 31 #include "gpu/ipc/common/memory_stats.h" |
35 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 32 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
36 #include "ipc/ipc_channel_handle.h" | 33 #include "ipc/ipc_channel_handle.h" |
37 #include "ipc/ipc_sync_message_filter.h" | 34 #include "ipc/ipc_sync_message_filter.h" |
38 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" | 35 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" |
39 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 36 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
40 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 37 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
41 #include "media/gpu/ipc/service/media_service.h" | 38 #include "media/gpu/ipc/service/media_service.h" |
42 #include "mojo/public/cpp/bindings/binding_set.h" | |
43 #include "services/shell/public/cpp/connection.h" | |
44 #include "services/shell/public/cpp/interface_factory.h" | |
45 #include "services/shell/public/cpp/interface_registry.h" | |
46 #include "ui/gl/gl_implementation.h" | 39 #include "ui/gl/gl_implementation.h" |
47 #include "ui/gl/gl_switches.h" | 40 #include "ui/gl/gl_switches.h" |
48 #include "ui/gl/gpu_switching_manager.h" | 41 #include "ui/gl/gpu_switching_manager.h" |
49 #include "ui/gl/init/gl_factory.h" | 42 #include "ui/gl/init/gl_factory.h" |
50 #include "url/gurl.h" | 43 #include "url/gurl.h" |
51 | 44 |
52 #if defined(USE_OZONE) | 45 #if defined(USE_OZONE) |
53 #include "ui/ozone/public/gpu_platform_support.h" | 46 #include "ui/ozone/public/gpu_platform_support.h" |
54 #include "ui/ozone/public/ozone_platform.h" | 47 #include "ui/ozone/public/ozone_platform.h" |
55 #endif | 48 #endif |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() | 133 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() |
141 ->GetGpuPlatformSupport() | 134 ->GetGpuPlatformSupport() |
142 ->GetMessageFilter(); | 135 ->GetMessageFilter(); |
143 if (message_filter) | 136 if (message_filter) |
144 builder.AddStartupFilter(message_filter); | 137 builder.AddStartupFilter(message_filter); |
145 #endif | 138 #endif |
146 | 139 |
147 return builder.Build(); | 140 return builder.Build(); |
148 } | 141 } |
149 | 142 |
150 // Connection filter for incoming connections from other shell clients. | |
151 class GpuConnectionFilter | |
152 : public ConnectionFilter, | |
153 public shell::InterfaceFactory<mojom::ProcessControl> { | |
154 public: | |
155 GpuConnectionFilter() {} | |
156 ~GpuConnectionFilter() override {} | |
157 | |
158 private: | |
159 // ConnectionFilter: | |
160 bool OnConnect(shell::Connection* connection, | |
161 shell::Connector* connector) override { | |
162 connection->AddInterface<mojom::ProcessControl>(this); | |
163 return true; | |
164 } | |
165 | |
166 // shell::InterfaceFactory<mojom::ProcessControl>: | |
167 void Create(shell::Connection* connection, | |
168 mojom::ProcessControlRequest request) override { | |
169 process_control_bindings_.AddBinding(&process_control_, std::move(request)); | |
170 } | |
171 | |
172 // Process control for Mojo application hosting. | |
173 // | |
174 // TODO(rockot): Remove this. To host mojo:media in the gpu process, we should | |
175 // simply package mojo:media in exe:content_gpu and use the ShellClientFactory | |
176 // idiom. | |
177 GpuProcessControlImpl process_control_; | |
178 | |
179 // Bindings to the mojom::ProcessControl impl. | |
180 mojo::BindingSet<mojom::ProcessControl> process_control_bindings_; | |
181 | |
182 DISALLOW_COPY_AND_ASSIGN(GpuConnectionFilter); | |
183 }; | |
184 | |
185 } // namespace | 143 } // namespace |
186 | 144 |
187 // static | 145 // static |
188 GpuChildThread* GpuChildThread::current() { | 146 GpuChildThread* GpuChildThread::current() { |
189 return g_lazy_tls.Pointer()->Get(); | 147 return g_lazy_tls.Pointer()->Get(); |
190 } | 148 } |
191 | 149 |
192 GpuChildThread::GpuChildThread( | 150 GpuChildThread::GpuChildThread( |
193 GpuWatchdogThread* watchdog_thread, | 151 GpuWatchdogThread* watchdog_thread, |
194 bool dead_on_arrival, | 152 bool dead_on_arrival, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 void GpuChildThread::Init(const base::Time& process_start_time) { | 211 void GpuChildThread::Init(const base::Time& process_start_time) { |
254 process_start_time_ = process_start_time; | 212 process_start_time_ = process_start_time; |
255 | 213 |
256 #if defined(OS_ANDROID) | 214 #if defined(OS_ANDROID) |
257 // When running in in-process mode, this has been set in the browser at | 215 // When running in in-process mode, this has been set in the browser at |
258 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 216 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
259 if (!in_browser_process_) | 217 if (!in_browser_process_) |
260 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 218 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
261 #endif | 219 #endif |
262 | 220 |
263 if (GetContentClient()->gpu()) { // NULL in tests. | 221 // Only set once per process instance. |
264 GetContentClient()->gpu()->ExposeInterfacesToBrowser( | 222 process_control_.reset(new GpuProcessControlImpl()); |
265 GetInterfaceRegistry()); | |
266 } | |
267 | |
268 // We don't want to process any incoming interface requests until | |
269 // OnInitialize() is invoked. | |
270 GetInterfaceRegistry()->PauseBinding(); | |
271 | 223 |
272 if (GetContentClient()->gpu()) // NULL in tests. | 224 if (GetContentClient()->gpu()) // NULL in tests. |
273 GetContentClient()->gpu()->Initialize(this); | 225 GetContentClient()->gpu()->Initialize(this); |
274 } | 226 } |
275 | 227 |
276 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, | 228 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, |
277 const std::string& group_name) { | 229 const std::string& group_name) { |
278 Send(new GpuHostMsg_FieldTrialActivated(trial_name)); | 230 Send(new GpuHostMsg_FieldTrialActivated(trial_name)); |
279 } | 231 } |
280 | 232 |
281 void GpuChildThread::AddConnectionFilters(MojoShellConnection* connection) { | |
282 connection->AddConnectionFilter(base::MakeUnique<GpuConnectionFilter>()); | |
283 } | |
284 | |
285 bool GpuChildThread::Send(IPC::Message* msg) { | 233 bool GpuChildThread::Send(IPC::Message* msg) { |
286 // The GPU process must never send a synchronous IPC message to the browser | 234 // The GPU process must never send a synchronous IPC message to the browser |
287 // process. This could result in deadlock. | 235 // process. This could result in deadlock. |
288 DCHECK(!msg->is_sync()); | 236 DCHECK(!msg->is_sync()); |
289 | 237 |
290 return ChildThreadImpl::Send(msg); | 238 return ChildThreadImpl::Send(msg); |
291 } | 239 } |
292 | 240 |
293 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) { | 241 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) { |
294 bool handled = true; | 242 bool handled = true; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 OnDestroyingVideoSurface); | 283 OnDestroyingVideoSurface); |
336 #endif | 284 #endif |
337 IPC_MESSAGE_UNHANDLED(handled = false) | 285 IPC_MESSAGE_UNHANDLED(handled = false) |
338 IPC_END_MESSAGE_MAP() | 286 IPC_END_MESSAGE_MAP() |
339 if (handled) | 287 if (handled) |
340 return true; | 288 return true; |
341 | 289 |
342 return false; | 290 return false; |
343 } | 291 } |
344 | 292 |
| 293 bool GpuChildThread::OnConnect(shell::Connection* connection) { |
| 294 // Use of base::Unretained(this) is safe here because |service_registry()| |
| 295 // will be destroyed before GpuChildThread is destructed. |
| 296 connection->GetInterfaceRegistry()->AddInterface(base::Bind( |
| 297 &GpuChildThread::BindProcessControlRequest, base::Unretained(this))); |
| 298 |
| 299 if (GetContentClient()->gpu()) { // NULL in tests. |
| 300 GetContentClient()->gpu()->ExposeInterfacesToBrowser( |
| 301 connection->GetInterfaceRegistry()); |
| 302 } |
| 303 |
| 304 // We don't want to process any incoming interface requests until |
| 305 // OnInitialize(). |
| 306 if (!gpu_channel_manager_) { |
| 307 connection->GetInterfaceRegistry()->PauseBinding(); |
| 308 resume_interface_bindings_callback_ = base::Bind( |
| 309 &shell::InterfaceRegistry::ResumeBinding, |
| 310 connection->GetInterfaceRegistry()->GetWeakPtr()); |
| 311 } |
| 312 |
| 313 return true; |
| 314 } |
| 315 |
| 316 shell::InterfaceRegistry* GpuChildThread::GetInterfaceRegistryForConnection() { |
| 317 return nullptr; |
| 318 } |
| 319 |
| 320 shell::InterfaceProvider* GpuChildThread::GetInterfaceProviderForConnection() { |
| 321 return nullptr; |
| 322 } |
| 323 |
345 void GpuChildThread::SetActiveURL(const GURL& url) { | 324 void GpuChildThread::SetActiveURL(const GURL& url) { |
346 GetContentClient()->SetActiveURL(url); | 325 GetContentClient()->SetActiveURL(url); |
347 } | 326 } |
348 | 327 |
349 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) { | 328 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) { |
350 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url)); | 329 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url)); |
351 } | 330 } |
352 | 331 |
353 void GpuChildThread::DidDestroyChannel(int client_id) { | 332 void GpuChildThread::DidDestroyChannel(int client_id) { |
354 media_service_->RemoveChannel(client_id); | 333 media_service_->RemoveChannel(client_id); |
(...skipping 23 matching lines...) Expand all Loading... |
378 } | 357 } |
379 #endif | 358 #endif |
380 | 359 |
381 void GpuChildThread::StoreShaderToDisk(int32_t client_id, | 360 void GpuChildThread::StoreShaderToDisk(int32_t client_id, |
382 const std::string& key, | 361 const std::string& key, |
383 const std::string& shader) { | 362 const std::string& shader) { |
384 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); | 363 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); |
385 } | 364 } |
386 | 365 |
387 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { | 366 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { |
388 GetInterfaceRegistry()->ResumeBinding(); | 367 if (!resume_interface_bindings_callback_.is_null()) |
| 368 base::ResetAndReturn(&resume_interface_bindings_callback_).Run(); |
389 | 369 |
390 gpu_preferences_ = gpu_preferences; | 370 gpu_preferences_ = gpu_preferences; |
391 | 371 |
392 gpu_info_.video_decode_accelerator_capabilities = | 372 gpu_info_.video_decode_accelerator_capabilities = |
393 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 373 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
394 gpu_info_.video_encode_accelerator_supported_profiles = | 374 gpu_info_.video_encode_accelerator_supported_profiles = |
395 media::GpuVideoEncodeAccelerator::GetSupportedProfiles( | 375 media::GpuVideoEncodeAccelerator::GetSupportedProfiles( |
396 gpu_preferences_); | 376 gpu_preferences_); |
397 gpu_info_.jpeg_decode_accelerator_supported = | 377 gpu_info_.jpeg_decode_accelerator_supported = |
398 media::GpuJpegDecodeAccelerator::IsSupported(); | 378 media::GpuJpegDecodeAccelerator::IsSupported(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 576 } |
597 #endif | 577 #endif |
598 | 578 |
599 void GpuChildThread::OnLoseAllContexts() { | 579 void GpuChildThread::OnLoseAllContexts() { |
600 if (gpu_channel_manager_) { | 580 if (gpu_channel_manager_) { |
601 gpu_channel_manager_->DestroyAllChannels(); | 581 gpu_channel_manager_->DestroyAllChannels(); |
602 media_service_->DestroyAllChannels(); | 582 media_service_->DestroyAllChannels(); |
603 } | 583 } |
604 } | 584 } |
605 | 585 |
| 586 void GpuChildThread::BindProcessControlRequest( |
| 587 mojo::InterfaceRequest<mojom::ProcessControl> request) { |
| 588 DVLOG(1) << "GPU: Binding ProcessControl request"; |
| 589 DCHECK(process_control_); |
| 590 process_control_bindings_.AddBinding(process_control_.get(), |
| 591 std::move(request)); |
| 592 } |
| 593 |
606 } // namespace content | 594 } // namespace content |
OLD | NEW |