Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 2 | // 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] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 7 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 10 | #include <memory> |
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 12 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 13 | #include "base/command_line.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 14 | #include "base/functional/callback.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
Sean Maher | e672a66 | 2023-01-09 21:42:28 | [diff] [blame] | 17 | #include "base/task/single_thread_task_runner.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 18 | #include "base/time/time.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 19 | #include "build/build_config.h" |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 20 | #include "components/viz/service/gl/gpu_service_impl.h" |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 21 | #include "components/viz/service/main/viz_main_impl.h" |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 22 | #include "content/child/child_thread_impl.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 23 | #include "gpu/config/gpu_feature_info.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 24 | #include "gpu/config/gpu_info.h" |
Jonathan Backer | 0af50996 | 2018-05-30 16:05:07 | [diff] [blame] | 25 | #include "gpu/config/gpu_preferences.h" |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 26 | #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" | ||||
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 31 | #include "media/base/android_overlay_mojo_factory.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 32 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 33 | namespace content { |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 34 | class GpuServiceFactory; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 35 | |
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 | ||||
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 38 | // IPC messages to gpu::GpuChannelManager, which is responsible for issuing |
39 | // rendering commands to the GPU. | ||||
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 40 | class GpuChildThread : public ChildThreadImpl, |
Takashi Sakamoto | bb07480 | 2018-10-15 07:35:27 | [diff] [blame] | 41 | public viz::VizMainImpl::Delegate { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 42 | public: |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 43 | GpuChildThread(base::RepeatingClosure quit_closure, |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 44 | std::unique_ptr<gpu::GpuInit> gpu_init); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 45 | |
sadrul | 3f8d0fa | 2016-09-08 17:47:41 | [diff] [blame] | 46 | GpuChildThread(const InProcessChildThreadParams& params, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 47 | std::unique_ptr<gpu::GpuInit> gpu_init); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 48 | |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 49 | GpuChildThread(const GpuChildThread&) = delete; |
50 | GpuChildThread& operator=(const GpuChildThread&) = delete; | ||||
51 | |||||
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 52 | ~GpuChildThread() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 53 | |
Sean Maher | f36d812 | 2022-08-05 02:33:35 | [diff] [blame] | 54 | void Init(const base::TimeTicks& process_start_time); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 55 | |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 56 | private: |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 57 | GpuChildThread(base::RepeatingClosure quit_closure, |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 58 | ChildThreadImpl::Options options, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 59 | std::unique_ptr<gpu::GpuInit> gpu_init); |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 60 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 61 | bool in_process_gpu() const; |
62 | |||||
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 63 | // ChildThreadImpl: |
Ken Rockot | 8322a04 | 2019-08-20 18:02:00 | [diff] [blame] | 64 | void BindServiceInterface(mojo::GenericPendingReceiver receiver) override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 65 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 66 | // viz::VizMainImpl::Delegate: |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 67 | void OnInitializationFailed() override; |
68 | void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override; | ||||
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 69 | void PostCompositorThreadCreated( |
70 | base::SingleThreadTaskRunner* task_runner) override; | ||||
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 71 | void QuitMainMessageLoop() override; |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 72 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 73 | void OnMemoryPressure( |
74 | base::MemoryPressureListener::MemoryPressureLevel level); | ||||
75 | |||||
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 76 | // 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 Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 82 | #if BUILDFLAG(IS_ANDROID) |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 83 | static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 84 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 85 | const base::UnguessableToken& routing_token, |
86 | media::AndroidOverlayConfig); | ||||
87 | #endif | ||||
88 | |||||
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 89 | viz::VizMainImpl viz_main_; |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 90 | |
Ken Rockot | a292417 | 2019-12-18 03:27:05 | [diff] [blame] | 91 | // ServiceFactory for Mojo service hosting. |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 92 | std::unique_ptr<GpuServiceFactory> service_factory_; |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 93 | |
Ken Rockot | a292417 | 2019-12-18 03:27:05 | [diff] [blame] | 94 | // A queue of incoming service interface requests received prior to |
95 | // |service_factory_| initialization. | ||||
96 | std::vector<mojo::GenericPendingReceiver> pending_service_receivers_; | ||||
97 | |||||
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 98 | // A closure which quits the main message loop. |
99 | base::RepeatingClosure quit_closure_; | ||||
100 | |||||
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 101 | std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
102 | |||||
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 103 | base::WeakPtrFactory<GpuChildThread> weak_factory_{this}; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 104 | }; |
105 | |||||
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 106 | } // namespace content |
107 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 108 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |