[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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> |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 11 | #include <queue> |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 12 | #include <string> |
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 13 | #include <vector> |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 14 | |
rockot | caccf78 | 2016-06-29 23:39:16 | [diff] [blame] | 15 | #include "base/callback.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 16 | #include "base/command_line.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 17 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 20 | #include "base/time/time.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 21 | #include "build/build_config.h" |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 22 | #include "components/viz/service/gl/gpu_service_impl.h" |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 23 | #include "components/viz/service/main/viz_main_impl.h" |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 24 | #include "content/child/child_thread_impl.h" |
Jonah Ryan-Davis | a70577c | 2019-06-26 18:54:31 | [diff] [blame] | 25 | #include "gpu/config/gpu_extra_info.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 26 | #include "gpu/config/gpu_feature_info.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 27 | #include "gpu/config/gpu_info.h" |
Jonathan Backer | 0af50996 | 2018-05-30 16:05:07 | [diff] [blame] | 28 | #include "gpu/config/gpu_preferences.h" |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 29 | #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" |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 34 | #include "media/base/android_overlay_mojo_factory.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 35 | #include "mojo/public/cpp/bindings/associated_binding_set.h" |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 36 | #include "services/service_manager/public/cpp/service_context_ref.h" |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 37 | #include "services/viz/privileged/interfaces/viz_main.mojom.h" |
Ken Rockot | 26e4e80 | 2018-07-31 15:03:33 | [diff] [blame] | 38 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 39 | #include "ui/gfx/native_widget_types.h" |
| 40 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 41 | namespace content { |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 42 | class GpuServiceFactory; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 43 | |
| 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 |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 46 | // IPC messages to gpu::GpuChannelManager, which is responsible for issuing |
| 47 | // rendering commands to the GPU. |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 48 | class GpuChildThread : public ChildThreadImpl, |
Takashi Sakamoto | bb07480 | 2018-10-15 07:35:27 | [diff] [blame] | 49 | public viz::VizMainImpl::Delegate { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 50 | public: |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 51 | GpuChildThread(base::RepeatingClosure quit_closure, |
| 52 | std::unique_ptr<gpu::GpuInit> gpu_init, |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 53 | viz::VizMainImpl::LogMessages deferred_messages); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 54 | |
sadrul | 3f8d0fa | 2016-09-08 17:47:41 | [diff] [blame] | 55 | GpuChildThread(const InProcessChildThreadParams& params, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 56 | std::unique_ptr<gpu::GpuInit> gpu_init); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 57 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 58 | ~GpuChildThread() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 59 | |
| 60 | void Init(const base::Time& process_start_time); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 61 | |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 62 | private: |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 63 | GpuChildThread(base::RepeatingClosure quit_closure, |
| 64 | const ChildThreadImpl::Options& options, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 65 | std::unique_ptr<gpu::GpuInit> gpu_init); |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 66 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 67 | void CreateVizMainService(viz::mojom::VizMainAssociatedRequest request); |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 68 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 69 | bool in_process_gpu() const; |
| 70 | |
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 71 | // ChildThreadImpl: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 72 | bool Send(IPC::Message* msg) override; |
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 73 | void RunService( |
| 74 | const std::string& service_name, |
| 75 | mojo::PendingReceiver<service_manager::mojom::Service> receiver) override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 76 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 77 | // IPC::Listener implementation via ChildThreadImpl: |
| 78 | void OnAssociatedInterfaceRequest( |
| 79 | const std::string& name, |
| 80 | mojo::ScopedInterfaceEndpointHandle handle) override; |
| 81 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 82 | // viz::VizMainImpl::Delegate: |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 83 | void OnInitializationFailed() override; |
| 84 | void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override; |
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 85 | void PostCompositorThreadCreated( |
| 86 | base::SingleThreadTaskRunner* task_runner) override; |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 87 | void QuitMainMessageLoop() override; |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 88 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 89 | void OnMemoryPressure( |
| 90 | base::MemoryPressureListener::MemoryPressureLevel level); |
| 91 | |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 92 | // 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 | |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 98 | #if defined(OS_ANDROID) |
| 99 | static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 100 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 101 | const base::UnguessableToken& routing_token, |
| 102 | media::AndroidOverlayConfig); |
| 103 | #endif |
| 104 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 105 | viz::VizMainImpl viz_main_; |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 106 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 107 | // ServiceFactory for service_manager::Service hosting. |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 108 | std::unique_ptr<GpuServiceFactory> service_factory_; |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 109 | |
Ken Rockot | 26e4e80 | 2018-07-31 15:03:33 | [diff] [blame] | 110 | blink::AssociatedInterfaceRegistry associated_interfaces_; |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 111 | |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 112 | // Holds a closure that releases pending interface requests on the IO thread. |
kylechar | ed18a48 | 2019-02-07 14:07:21 | [diff] [blame] | 113 | base::OnceClosure release_pending_requests_closure_; |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 114 | |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 115 | // A closure which quits the main message loop. |
| 116 | base::RepeatingClosure quit_closure_; |
| 117 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 118 | std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 119 | |
Ken Rockot | b2928f3 | 2019-03-12 04:43:03 | [diff] [blame] | 120 | // 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 | |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 134 | base::WeakPtrFactory<GpuChildThread> weak_factory_; |
| 135 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 136 | DISALLOW_COPY_AND_ASSIGN(GpuChildThread); |
| 137 | }; |
| 138 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 139 | } // namespace content |
| 140 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 141 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |