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

Side by Side Diff: content/browser/gpu/gpu_process_host.cc

Issue 2820463002: gpu: Completely remove GpuProcessHostUIShim. (Closed)
Patch Set: . Created 3 years, 8 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
« no previous file with comments | « content/browser/gpu/gpu_process_host.h ('k') | content/browser/gpu/gpu_process_host_ui_shim.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/gpu/gpu_process_host.h" 5 #include "content/browser/gpu/gpu_process_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 11 matching lines...) Expand all
22 #include "base/metrics/field_trial.h" 22 #include "base/metrics/field_trial.h"
23 #include "base/metrics/histogram_macros.h" 23 #include "base/metrics/histogram_macros.h"
24 #include "base/sha1.h" 24 #include "base/sha1.h"
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "components/tracing/common/tracing_switches.h" 29 #include "components/tracing/common/tracing_switches.h"
30 #include "content/browser/browser_child_process_host_impl.h" 30 #include "content/browser/browser_child_process_host_impl.h"
31 #include "content/browser/browser_main_loop.h" 31 #include "content/browser/browser_main_loop.h"
32 #include "content/browser/field_trial_recorder.h"
32 #include "content/browser/gpu/compositor_util.h" 33 #include "content/browser/gpu/compositor_util.h"
33 #include "content/browser/gpu/gpu_data_manager_impl.h" 34 #include "content/browser/gpu/gpu_data_manager_impl.h"
34 #include "content/browser/gpu/gpu_main_thread_factory.h" 35 #include "content/browser/gpu/gpu_main_thread_factory.h"
35 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
36 #include "content/browser/gpu/shader_cache_factory.h" 36 #include "content/browser/gpu/shader_cache_factory.h"
37 #include "content/browser/service_manager/service_manager_context.h" 37 #include "content/browser/service_manager/service_manager_context.h"
38 #include "content/common/child_process_host_impl.h" 38 #include "content/common/child_process_host_impl.h"
39 #include "content/common/in_process_child_thread_params.h" 39 #include "content/common/in_process_child_thread_params.h"
40 #include "content/common/service_manager/child_connection.h" 40 #include "content/common/service_manager/child_connection.h"
41 #include "content/common/view_messages.h" 41 #include "content/common/view_messages.h"
42 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/content_browser_client.h" 43 #include "content/public/browser/content_browser_client.h"
44 #include "content/public/browser/gpu_utils.h" 44 #include "content/public/browser/gpu_utils.h"
45 #include "content/public/common/connection_filter.h" 45 #include "content/public/common/connection_filter.h"
(...skipping 18 matching lines...) Expand all
64 #include "services/service_manager/public/cpp/binder_registry.h" 64 #include "services/service_manager/public/cpp/binder_registry.h"
65 #include "services/service_manager/public/cpp/interface_provider.h" 65 #include "services/service_manager/public/cpp/interface_provider.h"
66 #include "services/service_manager/runner/common/client_util.h" 66 #include "services/service_manager/runner/common/client_util.h"
67 #include "ui/display/display_switches.h" 67 #include "ui/display/display_switches.h"
68 #include "ui/gfx/switches.h" 68 #include "ui/gfx/switches.h"
69 #include "ui/gl/gl_switches.h" 69 #include "ui/gl/gl_switches.h"
70 #include "ui/latency/latency_info.h" 70 #include "ui/latency/latency_info.h"
71 71
72 #if defined(OS_ANDROID) 72 #if defined(OS_ANDROID)
73 #include "base/android/build_info.h" 73 #include "base/android/build_info.h"
74 #include "content/public/browser/android/java_interfaces.h"
75 #include "media/mojo/interfaces/android_overlay.mojom.h"
74 #endif 76 #endif
75 77
76 #if defined(OS_WIN) 78 #if defined(OS_WIN)
77 #include "base/win/windows_version.h" 79 #include "base/win/windows_version.h"
78 #include "content/common/sandbox_win.h" 80 #include "content/common/sandbox_win.h"
79 #include "sandbox/win/src/sandbox_policy.h" 81 #include "sandbox/win/src/sandbox_policy.h"
80 #include "ui/gfx/switches.h" 82 #include "ui/gfx/switches.h"
81 #include "ui/gfx/win/rendering_window_manager.h" 83 #include "ui/gfx/win/rendering_window_manager.h"
82 #endif 84 #endif
83 85
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; 189 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT];
188 190
189 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, 191 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind,
190 bool force_create, 192 bool force_create,
191 const base::Callback<void(GpuProcessHost*)>& callback) { 193 const base::Callback<void(GpuProcessHost*)>& callback) {
192 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); 194 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create);
193 callback.Run(host); 195 callback.Run(host);
194 } 196 }
195 197
196 #if defined(USE_OZONE) 198 #if defined(USE_OZONE)
199 // The ozone platform use this callback to send IPC messages to the gpu process.
197 void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host, 200 void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host,
198 IPC::Message* message) { 201 IPC::Message* message) {
199 if (host) 202 if (host)
200 host->Send(message); 203 host->Send(message);
201 else 204 else
202 delete message; 205 delete message;
203 } 206 }
207
208 void RouteMessageToOzoneOnUI(const IPC::Message& message) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
210 ui::OzonePlatform::GetInstance()
211 ->GetGpuPlatformSupportHost()
212 ->OnMessageReceived(message);
213 }
214
204 #endif // defined(USE_OZONE) 215 #endif // defined(USE_OZONE)
205 216
217 void OnGpuProcessHostDestroyedOnUI(int host_id, const std::string& message) {
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
219 GpuDataManagerImpl::GetInstance()->AddLogMessage(
220 logging::LOG_ERROR, "GpuProcessHostUIShim", message);
221 #if defined(USE_OZONE)
222 ui::OzonePlatform::GetInstance()
223 ->GetGpuPlatformSupportHost()
224 ->OnChannelDestroyed(host_id);
225 #endif
226 }
227
206 // NOTE: changes to this class need to be reviewed by the security team. 228 // NOTE: changes to this class need to be reviewed by the security team.
207 class GpuSandboxedProcessLauncherDelegate 229 class GpuSandboxedProcessLauncherDelegate
208 : public SandboxedProcessLauncherDelegate { 230 : public SandboxedProcessLauncherDelegate {
209 public: 231 public:
210 explicit GpuSandboxedProcessLauncherDelegate( 232 explicit GpuSandboxedProcessLauncherDelegate(
211 const base::CommandLine& cmd_line) 233 const base::CommandLine& cmd_line)
212 #if defined(OS_WIN) 234 #if defined(OS_WIN)
213 : cmd_line_(cmd_line) 235 : cmd_line_(cmd_line)
214 #endif 236 #endif
215 { 237 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 SandboxType GetSandboxType() override { 321 SandboxType GetSandboxType() override {
300 return SANDBOX_TYPE_GPU; 322 return SANDBOX_TYPE_GPU;
301 } 323 }
302 324
303 private: 325 private:
304 #if defined(OS_WIN) 326 #if defined(OS_WIN)
305 base::CommandLine cmd_line_; 327 base::CommandLine cmd_line_;
306 #endif // OS_WIN 328 #endif // OS_WIN
307 }; 329 };
308 330
331 #if defined(OS_ANDROID)
332 template <typename Interface>
333 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) {
334 DCHECK_CURRENTLY_ON(BrowserThread::UI);
335 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request));
336 }
337 #endif // defined(OS_ANDROID)
338
309 } // anonymous namespace 339 } // anonymous namespace
310 340
311 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { 341 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter {
312 public: 342 public:
313 ConnectionFilterImpl() { 343 ConnectionFilterImpl() {
314 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(&registry_); 344 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
345 registry_.AddInterface(base::Bind(&FieldTrialRecorder::Create),
346 task_runner);
347 registry_.AddInterface(
348 base::Bind(
349 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest,
350 base::Unretained(
351 memory_instrumentation::CoordinatorImpl::GetInstance())),
352 task_runner);
353 #if defined(OS_ANDROID)
354 registry_.AddInterface(
355 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>),
356 task_runner);
357 #endif
315 } 358 }
316 359
317 private: 360 private:
318 // ConnectionFilter: 361 // ConnectionFilter:
319 void OnBindInterface(const service_manager::ServiceInfo& source_info, 362 void OnBindInterface(const service_manager::ServiceInfo& source_info,
320 const std::string& interface_name, 363 const std::string& interface_name,
321 mojo::ScopedMessagePipeHandle* interface_pipe, 364 mojo::ScopedMessagePipeHandle* interface_pipe,
322 service_manager::Connector* connector) override { 365 service_manager::Connector* connector) override {
323 if (registry_.CanBindInterface(interface_name)) { 366 if (registry_.CanBindInterface(interface_name)) {
324 registry_.BindInterface(source_info.identity, interface_name, 367 registry_.BindInterface(source_info.identity, interface_name,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 switches::kInProcessGPU)) { 502 switches::kInProcessGPU)) {
460 in_process_ = true; 503 in_process_ = true;
461 } 504 }
462 505
463 // If the 'single GPU process' policy ever changes, we still want to maintain 506 // If the 'single GPU process' policy ever changes, we still want to maintain
464 // it for 'gpu thread' mode and only create one instance of host and thread. 507 // it for 'gpu thread' mode and only create one instance of host and thread.
465 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); 508 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL);
466 509
467 g_gpu_process_hosts[kind] = this; 510 g_gpu_process_hosts[kind] = this;
468 511
469 // Post a task to create the corresponding GpuProcessHostUIShim. The
470 // GpuProcessHostUIShim will be destroyed when the GpuProcessHost is
471 // destroyed, which happens when the corresponding GPU process terminates or
472 // fails to launch. On browser exit, the shim can be leaked.
473 BrowserThread::PostTask(
474 BrowserThread::UI,
475 FROM_HERE,
476 base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id));
477
478 process_.reset(new BrowserChildProcessHostImpl( 512 process_.reset(new BrowserChildProcessHostImpl(
479 PROCESS_TYPE_GPU, this, mojom::kGpuServiceName)); 513 PROCESS_TYPE_GPU, this, mojom::kGpuServiceName));
480 } 514 }
481 515
482 GpuProcessHost::~GpuProcessHost() { 516 GpuProcessHost::~GpuProcessHost() {
483 DCHECK(CalledOnValidThread()); 517 DCHECK(CalledOnValidThread());
484 518
485 SendOutstandingReplies(); 519 SendOutstandingReplies();
486 520
487 // In case we never started, clean up. 521 // In case we never started, clean up.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 break; 589 break;
556 } 590 }
557 } 591 }
558 592
559 // If there are any remaining offscreen contexts at the point the 593 // If there are any remaining offscreen contexts at the point the
560 // GPU process exits, assume something went wrong, and block their 594 // GPU process exits, assume something went wrong, and block their
561 // URLs from accessing client 3D APIs without prompting. 595 // URLs from accessing client 3D APIs without prompting.
562 if (block_offscreen_contexts) 596 if (block_offscreen_contexts)
563 BlockLiveOffscreenContexts(); 597 BlockLiveOffscreenContexts();
564 598
565 BrowserThread::PostTask(BrowserThread::UI, 599 BrowserThread::PostTask(
566 FROM_HERE, 600 BrowserThread::UI, FROM_HERE,
567 base::Bind(&GpuProcessHostUIShim::Destroy, 601 base::Bind(&OnGpuProcessHostDestroyedOnUI, host_id_, message));
568 host_id_,
569 message));
570 } 602 }
571 603
572 bool GpuProcessHost::Init() { 604 bool GpuProcessHost::Init() {
573 init_start_time_ = base::TimeTicks::Now(); 605 init_start_time_ = base::TimeTicks::Now();
574 606
575 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); 607 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD);
576 608
577 // May be null during test execution. 609 // May be null during test execution.
578 if (ServiceManagerConnection::GetForProcess()) { 610 if (ServiceManagerConnection::GetForProcess()) {
579 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( 611 ServiceManagerConnection::GetForProcess()->AddConnectionFilter(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 gpu_main_ptr_->CreateGpuService( 644 gpu_main_ptr_->CreateGpuService(
613 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), 645 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(),
614 gpu_preferences, activity_flags_.CloneHandle()); 646 gpu_preferences, activity_flags_.CloneHandle());
615 647
616 #if defined(USE_OZONE) 648 #if defined(USE_OZONE)
617 // Ozone needs to send the primary DRM device to GPU process as early as 649 // Ozone needs to send the primary DRM device to GPU process as early as
618 // possible to ensure the latter always has a valid device. crbug.com/608839 650 // possible to ensure the latter always has a valid device. crbug.com/608839
619 ui::OzonePlatform::GetInstance() 651 ui::OzonePlatform::GetInstance()
620 ->GetGpuPlatformSupportHost() 652 ->GetGpuPlatformSupportHost()
621 ->OnGpuProcessLaunched( 653 ->OnGpuProcessLaunched(
622 host_id_, base::ThreadTaskRunnerHandle::Get(), 654 host_id_, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
655 base::ThreadTaskRunnerHandle::Get(),
623 base::Bind(&SendGpuProcessMessage, weak_ptr_factory_.GetWeakPtr())); 656 base::Bind(&SendGpuProcessMessage, weak_ptr_factory_.GetWeakPtr()));
624 #endif 657 #endif
625 658
626 return true; 659 return true;
627 } 660 }
628 661
629 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) {
630 BrowserThread::PostTask(
631 BrowserThread::UI,
632 FROM_HERE,
633 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message));
634 }
635
636 bool GpuProcessHost::Send(IPC::Message* msg) { 662 bool GpuProcessHost::Send(IPC::Message* msg) {
637 DCHECK(CalledOnValidThread()); 663 DCHECK(CalledOnValidThread());
638 if (process_->GetHost()->IsChannelOpening()) { 664 if (process_->GetHost()->IsChannelOpening()) {
639 queued_messages_.push(msg); 665 queued_messages_.push(msg);
640 return true; 666 return true;
641 } 667 }
642 668
643 bool result = process_->Send(msg); 669 bool result = process_->Send(msg);
644 if (!result) { 670 if (!result) {
645 // Channel is hosed, but we may not get destroyed for a while. Send 671 // Channel is hosed, but we may not get destroyed for a while. Send
646 // outstanding channel creation failures now so that the caller can restart 672 // outstanding channel creation failures now so that the caller can restart
647 // with a new process/channel without waiting. 673 // with a new process/channel without waiting.
648 SendOutstandingReplies(); 674 SendOutstandingReplies();
649 } 675 }
650 return result; 676 return result;
651 } 677 }
652 678
653 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { 679 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) {
654 DCHECK(CalledOnValidThread()); 680 DCHECK(CalledOnValidThread());
655 RouteOnUIThread(message); 681 #if defined(USE_OZONE)
682 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
683 base::Bind(&RouteMessageToOzoneOnUI, message));
684 #endif
656 return true; 685 return true;
657 } 686 }
658 687
659 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { 688 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) {
660 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); 689 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected");
661 690
662 while (!queued_messages_.empty()) { 691 while (!queued_messages_.empty()) {
663 Send(queued_messages_.front()); 692 Send(queued_messages_.front());
664 queued_messages_.pop(); 693 queued_messages_.pop();
665 } 694 }
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (!cache.get()) 1210 if (!cache.get())
1182 return; 1211 return;
1183 1212
1184 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader, 1213 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader,
1185 weak_ptr_factory_.GetWeakPtr())); 1214 weak_ptr_factory_.GetWeakPtr()));
1186 1215
1187 client_id_to_shader_cache_[client_id] = cache; 1216 client_id_to_shader_cache_[client_id] = cache;
1188 } 1217 }
1189 1218
1190 } // namespace content 1219 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.h ('k') | content/browser/gpu/gpu_process_host_ui_shim.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698