blob: b3ab0546f11575ccc081a7612c731209148b1282 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[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>
Ken Rockotb2928f32019-03-12 04:43:0311#include <vector>
[email protected]7a31f7c2011-03-21 23:22:0412
[email protected]7a31f7c2011-03-21 23:22:0413#include "base/command_line.h"
Avi Drissmanadac21992023-01-11 23:46:3914#include "base/functional/callback.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/ref_counted.h"
bend6234442017-04-24 22:51:1316#include "base/memory/weak_ptr.h"
Sean Mahere672a662023-01-09 21:42:2817#include "base/task/single_thread_task_runner.h"
Jiahe Zhang26d66762025-09-15 06:35:3918#include "base/task/task_observer.h"
[email protected]abb522162013-06-28 01:54:1619#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0420#include "build/build_config.h"
Jiahe Zhang26d66762025-09-15 06:35:3921#include "components/performance_manager/scenario_api/performance_scenarios.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"
ericrk41a1579e2017-02-10 20:56:2825#include "gpu/config/gpu_feature_info.h"
[email protected]d7b5cc72013-05-23 20:05:0026#include "gpu/config/gpu_info.h"
Jonathan Backer0af509962018-05-30 16:05:0727#include "gpu/config/gpu_preferences.h"
markdittmerd88b8352016-04-08 15:28:4528#include "gpu/ipc/service/gpu_channel.h"
29#include "gpu/ipc/service/gpu_channel_manager.h"
30#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
31#include "gpu/ipc/service/gpu_config.h"
32#include "gpu/ipc/service/x_util.h"
liberato441ca702017-05-13 16:50:3833#include "media/base/android_overlay_mojo_factory.h"
[email protected]7a31f7c2011-03-21 23:22:0434
Jiahe Zhang26d66762025-09-15 06:35:3935namespace base::sequence_manager {
36class SequenceManager;
37} // namespace base::sequence_manager
38
[email protected]eb398192012-10-22 20:16:1939namespace content {
ben507aa812016-08-10 23:26:1940class GpuServiceFactory;
[email protected]7a31f7c2011-03-21 23:22:0441
42// The main thread of the GPU child process. There will only ever be one of
43// these per process. It does process initialization and shutdown. It forwards
markdittmerd88b8352016-04-08 15:28:4544// IPC messages to gpu::GpuChannelManager, which is responsible for issuing
45// rendering commands to the GPU.
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0646class GpuChildThread : public ChildThreadImpl,
Jiahe Zhang26d66762025-09-15 06:35:3947 public viz::VizMainImpl::Delegate,
Patrick Monette9cfd10c2025-10-10 14:01:0248 public base::TaskObserver,
49 public base::MemoryPressureListener {
[email protected]7a31f7c2011-03-21 23:22:0450 public:
Wez6979109b2018-09-07 17:30:5651 GpuChildThread(base::RepeatingClosure quit_closure,
Dale Curtis1b6becebb2020-03-30 20:13:3552 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0453
sadrul3f8d0fa2016-09-08 17:47:4154 GpuChildThread(const InProcessChildThreadParams& params,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5755 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0456
Peter Boström828b9022021-09-21 02:28:4357 GpuChildThread(const GpuChildThread&) = delete;
58 GpuChildThread& operator=(const GpuChildThread&) = delete;
59
dchenge933b3eb2014-10-21 11:44:0960 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0461
Jiahe Zhang26d66762025-09-15 06:35:3962 void Init(
63 const base::TimeTicks& process_start_time,
64 base::sequence_manager::SequenceManager* sequence_manager = nullptr);
[email protected]7a31f7c2011-03-21 23:22:0465
penghuang7404df9882016-02-29 23:07:2966 private:
Wez6979109b2018-09-07 17:30:5667 GpuChildThread(base::RepeatingClosure quit_closure,
Ken Rockot6d9ed95032019-11-13 17:20:4768 ChildThreadImpl::Options options,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5769 std::unique_ptr<gpu::GpuInit> gpu_init);
sadrul041ca722017-03-24 22:35:3570
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1571 bool in_process_gpu() const;
72
Ken Rockotb2928f32019-03-12 04:43:0373 // ChildThreadImpl:
Ken Rockot8322a042019-08-20 18:02:0074 void BindServiceInterface(mojo::GenericPendingReceiver receiver) override;
[email protected]7a31f7c2011-03-21 23:22:0475
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0676 // viz::VizMainImpl::Delegate:
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1577 void OnInitializationFailed() override;
78 void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override;
Sadrul Habib Chowdhury97c6f1f2018-03-02 01:21:1679 void PostCompositorThreadCreated(
80 base::SingleThreadTaskRunner* task_runner) override;
Wez6979109b2018-09-07 17:30:5681 void QuitMainMessageLoop() override;
fsamuela660ce02016-02-25 03:56:1682
Jiahe Zhang26d66762025-09-15 06:35:3983 // base::TaskObserver:
84 void WillProcessTask(const base::PendingTask& pending_task,
85 bool was_blocked_or_low_priority) override;
86 void DidProcessTask(const base::PendingTask& pending_task) override {}
87
Patrick Monette9cfd10c2025-10-10 14:01:0288 void OnMemoryPressure(base::MemoryPressureLevel level) override;
Khushal0aac62072018-06-01 19:33:1789
Eric Karl23af711f2018-11-02 20:47:3490 // Returns a closure which calls into the VizMainImpl to perform shutdown
91 // before quitting the main message loop. Must be called on the main thread.
92 static base::RepeatingClosure MakeQuitSafelyClosure();
93 static void QuitSafelyHelper(
94 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
95
Xiaohan Wang62737b52022-01-15 18:09:0296#if BUILDFLAG(IS_ANDROID)
liberato441ca702017-05-13 16:50:3897 static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay(
Chris Watkins88a40002017-09-28 01:16:4298 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
liberato441ca702017-05-13 16:50:3899 const base::UnguessableToken& routing_token,
100 media::AndroidOverlayConfig);
101#endif
102
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06103 viz::VizMainImpl viz_main_;
[email protected]ec4bda62013-06-14 15:51:03104
Ken Rockota2924172019-12-18 03:27:05105 // ServiceFactory for Mojo service hosting.
ben507aa812016-08-10 23:26:19106 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:14107
Ken Rockota2924172019-12-18 03:27:05108 // A queue of incoming service interface requests received prior to
109 // |service_factory_| initialization.
110 std::vector<mojo::GenericPendingReceiver> pending_service_receivers_;
111
Eric Karl23af711f2018-11-02 20:47:34112 // A closure which quits the main message loop.
113 base::RepeatingClosure quit_closure_;
114
Patrick Monettecc99f492025-10-08 20:22:00115 std::unique_ptr<base::AsyncMemoryPressureListenerRegistration>
116 memory_pressure_listener_registration_;
Khushal0aac62072018-06-01 19:33:17117
Jiahe Zhang26d66762025-09-15 06:35:39118 performance_scenarios::InputScenario last_input_scenario_;
119
Jeremy Roman3bca4bf2019-07-11 03:41:25120 base::WeakPtrFactory<GpuChildThread> weak_factory_{this};
[email protected]7a31f7c2011-03-21 23:22:04121};
122
[email protected]eb398192012-10-22 20:16:19123} // namespace content
124
[email protected]7a31f7c2011-03-21 23:22:04125#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_