blob: 6e584b05021e2cdf8ba3b9f93f57966c9b197701 [file] [log] [blame]
[email protected]f0918242012-02-18 00:30:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7a31f7c2011-03-21 23:22:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_GPU_GPU_CHILD_THREAD_H_
6#define CONTENT_GPU_GPU_CHILD_THREAD_H_
[email protected]7a31f7c2011-03-21 23:22:047
avi66a07722015-12-25 23:38:128#include <stdint.h>
9
dcheng6003e0b2016-04-09 18:42:3410#include <memory>
[email protected]ec4bda62013-06-14 15:51:0311#include <queue>
[email protected]7a31f7c2011-03-21 23:22:0412#include <string>
Ken Rockotb2928f32019-03-12 04:43:0313#include <vector>
[email protected]7a31f7c2011-03-21 23:22:0414
rockotcaccf782016-06-29 23:39:1615#include "base/callback.h"
[email protected]7a31f7c2011-03-21 23:22:0416#include "base/command_line.h"
avi66a07722015-12-25 23:38:1217#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1518#include "base/memory/ref_counted.h"
bend6234442017-04-24 22:51:1319#include "base/memory/weak_ptr.h"
[email protected]abb522162013-06-28 01:54:1620#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0421#include "build/build_config.h"
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:3822#include "components/viz/service/gl/gpu_service_impl.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0623#include "components/viz/service/main/viz_main_impl.h"
jam8a021512a2015-02-03 18:16:0824#include "content/child/child_thread_impl.h"
Jonah Ryan-Davisa70577c2019-06-26 18:54:3125#include "gpu/config/gpu_extra_info.h"
ericrk41a1579e2017-02-10 20:56:2826#include "gpu/config/gpu_feature_info.h"
[email protected]d7b5cc72013-05-23 20:05:0027#include "gpu/config/gpu_info.h"
Jonathan Backer0af509962018-05-30 16:05:0728#include "gpu/config/gpu_preferences.h"
markdittmerd88b8352016-04-08 15:28:4529#include "gpu/ipc/service/gpu_channel.h"
30#include "gpu/ipc/service/gpu_channel_manager.h"
31#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
32#include "gpu/ipc/service/gpu_config.h"
33#include "gpu/ipc/service/x_util.h"
liberato441ca702017-05-13 16:50:3834#include "media/base/android_overlay_mojo_factory.h"
sadrul72aae8a2017-01-24 04:52:3235#include "mojo/public/cpp/bindings/associated_binding_set.h"
Chris Watkins88a40002017-09-28 01:16:4236#include "services/service_manager/public/cpp/service_context_ref.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0637#include "services/viz/privileged/interfaces/viz_main.mojom.h"
Ken Rockot26e4e802018-07-31 15:03:3338#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
[email protected]7a31f7c2011-03-21 23:22:0439#include "ui/gfx/native_widget_types.h"
40
[email protected]eb398192012-10-22 20:16:1941namespace content {
ben507aa812016-08-10 23:26:1942class GpuServiceFactory;
[email protected]7a31f7c2011-03-21 23:22:0443
44// The main thread of the GPU child process. There will only ever be one of
45// these per process. It does process initialization and shutdown. It forwards
markdittmerd88b8352016-04-08 15:28:4546// IPC messages to gpu::GpuChannelManager, which is responsible for issuing
47// rendering commands to the GPU.
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0648class GpuChildThread : public ChildThreadImpl,
Takashi Sakamotobb074802018-10-15 07:35:2749 public viz::VizMainImpl::Delegate {
[email protected]7a31f7c2011-03-21 23:22:0450 public:
Wez6979109b2018-09-07 17:30:5651 GpuChildThread(base::RepeatingClosure quit_closure,
52 std::unique_ptr<gpu::GpuInit> gpu_init,
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0653 viz::VizMainImpl::LogMessages deferred_messages);
[email protected]7a31f7c2011-03-21 23:22:0454
sadrul3f8d0fa2016-09-08 17:47:4155 GpuChildThread(const InProcessChildThreadParams& params,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5756 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0457
dchenge933b3e2014-10-21 11:44:0958 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0459
60 void Init(const base::Time& process_start_time);
[email protected]7a31f7c2011-03-21 23:22:0461
penghuang7404df9882016-02-29 23:07:2962 private:
Wez6979109b2018-09-07 17:30:5663 GpuChildThread(base::RepeatingClosure quit_closure,
64 const ChildThreadImpl::Options& options,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5765 std::unique_ptr<gpu::GpuInit> gpu_init);
sadrul041ca722017-03-24 22:35:3566
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0667 void CreateVizMainService(viz::mojom::VizMainAssociatedRequest request);
sadrul6c5aed8c2017-01-11 23:11:4468
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1569 bool in_process_gpu() const;
70
Ken Rockotb2928f32019-03-12 04:43:0371 // ChildThreadImpl:
dchenge933b3e2014-10-21 11:44:0972 bool Send(IPC::Message* msg) override;
Ken Rockotb2928f32019-03-12 04:43:0373 void RunService(
74 const std::string& service_name,
75 mojo::PendingReceiver<service_manager::mojom::Service> receiver) override;
[email protected]7a31f7c2011-03-21 23:22:0476
sadrul72aae8a2017-01-24 04:52:3277 // IPC::Listener implementation via ChildThreadImpl:
78 void OnAssociatedInterfaceRequest(
79 const std::string& name,
80 mojo::ScopedInterfaceEndpointHandle handle) override;
81
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0682 // viz::VizMainImpl::Delegate:
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1583 void OnInitializationFailed() override;
84 void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override;
Sadrul Habib Chowdhury97c6f1f2018-03-02 01:21:1685 void PostCompositorThreadCreated(
86 base::SingleThreadTaskRunner* task_runner) override;
Wez6979109b2018-09-07 17:30:5687 void QuitMainMessageLoop() override;
fsamuela660ce02016-02-25 03:56:1688
Khushal0aac62072018-06-01 19:33:1789 void OnMemoryPressure(
90 base::MemoryPressureListener::MemoryPressureLevel level);
91
Eric Karl23af711f2018-11-02 20:47:3492 // Returns a closure which calls into the VizMainImpl to perform shutdown
93 // before quitting the main message loop. Must be called on the main thread.
94 static base::RepeatingClosure MakeQuitSafelyClosure();
95 static void QuitSafelyHelper(
96 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
97
liberato441ca702017-05-13 16:50:3898#if defined(OS_ANDROID)
99 static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay(
Chris Watkins88a40002017-09-28 01:16:42100 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
liberato441ca702017-05-13 16:50:38101 const base::UnguessableToken& routing_token,
102 media::AndroidOverlayConfig);
103#endif
104
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06105 viz::VizMainImpl viz_main_;
[email protected]ec4bda62013-06-14 15:51:03106
rockot400ea35b2016-10-15 19:15:32107 // ServiceFactory for service_manager::Service hosting.
ben507aa812016-08-10 23:26:19108 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:14109
Ken Rockot26e4e802018-07-31 15:03:33110 blink::AssociatedInterfaceRegistry associated_interfaces_;
sadrul72aae8a2017-01-24 04:52:32111
bend6234442017-04-24 22:51:13112 // Holds a closure that releases pending interface requests on the IO thread.
kylechared18a482019-02-07 14:07:21113 base::OnceClosure release_pending_requests_closure_;
bend6234442017-04-24 22:51:13114
Eric Karl23af711f2018-11-02 20:47:34115 // A closure which quits the main message loop.
116 base::RepeatingClosure quit_closure_;
117
Khushal0aac62072018-06-01 19:33:17118 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
119
Ken Rockotb2928f32019-03-12 04:43:03120 // Retains pending GPU-process service startup requests (i.e. RunService
121 // invocations from the browser) until the process is fully initialized.
122 struct PendingServiceRequest {
123 PendingServiceRequest(
124 const std::string& service_name,
125 mojo::PendingReceiver<service_manager::mojom::Service> receiver);
126 PendingServiceRequest(PendingServiceRequest&&);
127 ~PendingServiceRequest();
128
129 std::string service_name;
130 mojo::PendingReceiver<service_manager::mojom::Service> receiver;
131 };
132 std::vector<PendingServiceRequest> pending_service_requests_;
133
bend6234442017-04-24 22:51:13134 base::WeakPtrFactory<GpuChildThread> weak_factory_;
135
[email protected]7a31f7c2011-03-21 23:22:04136 DISALLOW_COPY_AND_ASSIGN(GpuChildThread);
137};
138
[email protected]eb398192012-10-22 20:16:19139} // namespace content
140
[email protected]7a31f7c2011-03-21 23:22:04141#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_