blob: 1dba2ee34a00a0e653d5cac5a3289beb315a1e10 [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"
[email protected]abb522162013-06-28 01:54:1618#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0419#include "build/build_config.h"
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:3820#include "components/viz/service/gl/gpu_service_impl.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0621#include "components/viz/service/main/viz_main_impl.h"
jam8a021512a2015-02-03 18:16:0822#include "content/child/child_thread_impl.h"
ericrk41a1579e2017-02-10 20:56:2823#include "gpu/config/gpu_feature_info.h"
[email protected]d7b5cc72013-05-23 20:05:0024#include "gpu/config/gpu_info.h"
Jonathan Backer0af509962018-05-30 16:05:0725#include "gpu/config/gpu_preferences.h"
markdittmerd88b8352016-04-08 15:28:4526#include "gpu/ipc/service/gpu_channel.h"
27#include "gpu/ipc/service/gpu_channel_manager.h"
28#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
29#include "gpu/ipc/service/gpu_config.h"
30#include "gpu/ipc/service/x_util.h"
liberato441ca702017-05-13 16:50:3831#include "media/base/android_overlay_mojo_factory.h"
[email protected]7a31f7c2011-03-21 23:22:0432
[email protected]eb398192012-10-22 20:16:1933namespace content {
ben507aa812016-08-10 23:26:1934class GpuServiceFactory;
[email protected]7a31f7c2011-03-21 23:22:0435
36// The main thread of the GPU child process. There will only ever be one of
37// these per process. It does process initialization and shutdown. It forwards
markdittmerd88b8352016-04-08 15:28:4538// IPC messages to gpu::GpuChannelManager, which is responsible for issuing
39// rendering commands to the GPU.
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0640class GpuChildThread : public ChildThreadImpl,
Takashi Sakamotobb074802018-10-15 07:35:2741 public viz::VizMainImpl::Delegate {
[email protected]7a31f7c2011-03-21 23:22:0442 public:
Wez6979109b2018-09-07 17:30:5643 GpuChildThread(base::RepeatingClosure quit_closure,
Dale Curtis1b6becebb2020-03-30 20:13:3544 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0445
sadrul3f8d0fa2016-09-08 17:47:4146 GpuChildThread(const InProcessChildThreadParams& params,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5747 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0448
Peter Boström828b9022021-09-21 02:28:4349 GpuChildThread(const GpuChildThread&) = delete;
50 GpuChildThread& operator=(const GpuChildThread&) = delete;
51
dchenge933b3eb2014-10-21 11:44:0952 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0453
Sean Maherf36d8122022-08-05 02:33:3554 void Init(const base::TimeTicks& process_start_time);
[email protected]7a31f7c2011-03-21 23:22:0455
penghuang7404df9882016-02-29 23:07:2956 private:
Wez6979109b2018-09-07 17:30:5657 GpuChildThread(base::RepeatingClosure quit_closure,
Ken Rockot6d9ed95032019-11-13 17:20:4758 ChildThreadImpl::Options options,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5759 std::unique_ptr<gpu::GpuInit> gpu_init);
sadrul041ca722017-03-24 22:35:3560
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1561 bool in_process_gpu() const;
62
Ken Rockotb2928f32019-03-12 04:43:0363 // ChildThreadImpl:
Ken Rockot8322a042019-08-20 18:02:0064 void BindServiceInterface(mojo::GenericPendingReceiver receiver) override;
[email protected]7a31f7c2011-03-21 23:22:0465
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0666 // viz::VizMainImpl::Delegate:
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1567 void OnInitializationFailed() override;
68 void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override;
Sadrul Habib Chowdhury97c6f1f2018-03-02 01:21:1669 void PostCompositorThreadCreated(
70 base::SingleThreadTaskRunner* task_runner) override;
Wez6979109b2018-09-07 17:30:5671 void QuitMainMessageLoop() override;
fsamuela660ce02016-02-25 03:56:1672
Khushal0aac62072018-06-01 19:33:1773 void OnMemoryPressure(
74 base::MemoryPressureListener::MemoryPressureLevel level);
75
Eric Karl23af711f2018-11-02 20:47:3476 // Returns a closure which calls into the VizMainImpl to perform shutdown
77 // before quitting the main message loop. Must be called on the main thread.
78 static base::RepeatingClosure MakeQuitSafelyClosure();
79 static void QuitSafelyHelper(
80 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
81
Xiaohan Wang62737b52022-01-15 18:09:0282#if BUILDFLAG(IS_ANDROID)
liberato441ca702017-05-13 16:50:3883 static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay(
Chris Watkins88a40002017-09-28 01:16:4284 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
liberato441ca702017-05-13 16:50:3885 const base::UnguessableToken& routing_token,
86 media::AndroidOverlayConfig);
87#endif
88
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0689 viz::VizMainImpl viz_main_;
[email protected]ec4bda62013-06-14 15:51:0390
Ken Rockota2924172019-12-18 03:27:0591 // ServiceFactory for Mojo service hosting.
ben507aa812016-08-10 23:26:1992 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:1493
Ken Rockota2924172019-12-18 03:27:0594 // A queue of incoming service interface requests received prior to
95 // |service_factory_| initialization.
96 std::vector<mojo::GenericPendingReceiver> pending_service_receivers_;
97
Eric Karl23af711f2018-11-02 20:47:3498 // A closure which quits the main message loop.
99 base::RepeatingClosure quit_closure_;
100
Khushal0aac62072018-06-01 19:33:17101 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
102
Jeremy Roman3bca4bf2019-07-11 03:41:25103 base::WeakPtrFactory<GpuChildThread> weak_factory_{this};
[email protected]7a31f7c2011-03-21 23:22:04104};
105
[email protected]eb398192012-10-22 20:16:19106} // namespace content
107
[email protected]7a31f7c2011-03-21 23:22:04108#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_