blob: a84795aa9dfd85f27d3e5272736d28f680beec98 [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,
48 public base::TaskObserver {
[email protected]7a31f7c2011-03-21 23:22:0449 public:
Wez6979109b2018-09-07 17:30:5650 GpuChildThread(base::RepeatingClosure quit_closure,
Dale Curtis1b6becebb2020-03-30 20:13:3551 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0452
sadrul3f8d0fa2016-09-08 17:47:4153 GpuChildThread(const InProcessChildThreadParams& params,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5754 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0455
Peter Boström828b9022021-09-21 02:28:4356 GpuChildThread(const GpuChildThread&) = delete;
57 GpuChildThread& operator=(const GpuChildThread&) = delete;
58
dchenge933b3eb2014-10-21 11:44:0959 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0460
Jiahe Zhang26d66762025-09-15 06:35:3961 void Init(
62 const base::TimeTicks& process_start_time,
63 base::sequence_manager::SequenceManager* sequence_manager = nullptr);
[email protected]7a31f7c2011-03-21 23:22:0464
penghuang7404df9882016-02-29 23:07:2965 private:
Wez6979109b2018-09-07 17:30:5666 GpuChildThread(base::RepeatingClosure quit_closure,
Ken Rockot6d9ed95032019-11-13 17:20:4767 ChildThreadImpl::Options options,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5768 std::unique_ptr<gpu::GpuInit> gpu_init);
sadrul041ca722017-03-24 22:35:3569
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1570 bool in_process_gpu() const;
71
Ken Rockotb2928f32019-03-12 04:43:0372 // ChildThreadImpl:
Ken Rockot8322a042019-08-20 18:02:0073 void BindServiceInterface(mojo::GenericPendingReceiver receiver) override;
[email protected]7a31f7c2011-03-21 23:22:0474
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0675 // viz::VizMainImpl::Delegate:
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1576 void OnInitializationFailed() override;
77 void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override;
Sadrul Habib Chowdhury97c6f1f2018-03-02 01:21:1678 void PostCompositorThreadCreated(
79 base::SingleThreadTaskRunner* task_runner) override;
Wez6979109b2018-09-07 17:30:5680 void QuitMainMessageLoop() override;
fsamuela660ce02016-02-25 03:56:1681
Jiahe Zhang26d66762025-09-15 06:35:3982 // base::TaskObserver:
83 void WillProcessTask(const base::PendingTask& pending_task,
84 bool was_blocked_or_low_priority) override;
85 void DidProcessTask(const base::PendingTask& pending_task) override {}
86
Patrick Monette845ec832025-10-07 18:23:2387 void OnMemoryPressure(base::MemoryPressureLevel level);
Khushal0aac62072018-06-01 19:33:1788
Eric Karl23af711f2018-11-02 20:47:3489 // Returns a closure which calls into the VizMainImpl to perform shutdown
90 // before quitting the main message loop. Must be called on the main thread.
91 static base::RepeatingClosure MakeQuitSafelyClosure();
92 static void QuitSafelyHelper(
93 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
94
Xiaohan Wang62737b52022-01-15 18:09:0295#if BUILDFLAG(IS_ANDROID)
liberato441ca702017-05-13 16:50:3896 static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay(
Chris Watkins88a40002017-09-28 01:16:4297 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
liberato441ca702017-05-13 16:50:3898 const base::UnguessableToken& routing_token,
99 media::AndroidOverlayConfig);
100#endif
101
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06102 viz::VizMainImpl viz_main_;
[email protected]ec4bda62013-06-14 15:51:03103
Ken Rockota2924172019-12-18 03:27:05104 // ServiceFactory for Mojo service hosting.
ben507aa812016-08-10 23:26:19105 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:14106
Ken Rockota2924172019-12-18 03:27:05107 // A queue of incoming service interface requests received prior to
108 // |service_factory_| initialization.
109 std::vector<mojo::GenericPendingReceiver> pending_service_receivers_;
110
Eric Karl23af711f2018-11-02 20:47:34111 // A closure which quits the main message loop.
112 base::RepeatingClosure quit_closure_;
113
Patrick Monettecc99f492025-10-08 20:22:00114 std::unique_ptr<base::AsyncMemoryPressureListenerRegistration>
115 memory_pressure_listener_registration_;
Khushal0aac62072018-06-01 19:33:17116
Jiahe Zhang26d66762025-09-15 06:35:39117 performance_scenarios::InputScenario last_input_scenario_;
118
Jeremy Roman3bca4bf2019-07-11 03:41:25119 base::WeakPtrFactory<GpuChildThread> weak_factory_{this};
[email protected]7a31f7c2011-03-21 23:22:04120};
121
[email protected]eb398192012-10-22 20:16:19122} // namespace content
123
[email protected]7a31f7c2011-03-21 23:22:04124#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_