[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> |
13 | |||||
rockot | caccf78 | 2016-06-29 23:39:16 | [diff] [blame] | 14 | #include "base/callback.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 15 | #include "base/command_line.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 17 | #include "base/memory/ref_counted.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 18 | #include "base/memory/weak_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 19 | #include "base/time/time.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 20 | #include "build/build_config.h" |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 21 | #include "components/viz/service/gl/gpu_service_impl.h" |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 22 | #include "components/viz/service/main/viz_main_impl.h" |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 23 | #include "content/child/child_thread_impl.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 24 | #include "content/common/associated_interface_registry_impl.h" |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 25 | #include "gpu/command_buffer/service/gpu_preferences.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" |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 28 | #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" | ||||
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 33 | #include "media/base/android_overlay_mojo_factory.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 34 | #include "mojo/public/cpp/bindings/associated_binding_set.h" |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 35 | #include "mojo/public/cpp/bindings/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" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 37 | #include "services/service_manager/public/mojom/service_factory.mojom.h" |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 38 | #include "services/viz/privileged/interfaces/viz_main.mojom.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, |
49 | public viz::VizMainImpl::Delegate { | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 50 | public: |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 51 | GpuChildThread(std::unique_ptr<gpu::GpuInit> gpu_init, |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 52 | viz::VizMainImpl::LogMessages deferred_messages); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 53 | |
sadrul | 3f8d0fa | 2016-09-08 17:47:41 | [diff] [blame] | 54 | GpuChildThread(const InProcessChildThreadParams& params, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 55 | std::unique_ptr<gpu::GpuInit> gpu_init); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 56 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 57 | ~GpuChildThread() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 58 | |
59 | void Init(const base::Time& process_start_time); | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 60 | |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 61 | private: |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 62 | GpuChildThread(const ChildThreadImpl::Options& options, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 63 | std::unique_ptr<gpu::GpuInit> gpu_init); |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 64 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 65 | void CreateVizMainService(viz::mojom::VizMainAssociatedRequest request); |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 66 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 67 | bool in_process_gpu() const; |
68 | |||||
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 69 | // ChildThreadImpl:. |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 70 | bool Send(IPC::Message* msg) override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 71 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 72 | // IPC::Listener implementation via ChildThreadImpl: |
73 | void OnAssociatedInterfaceRequest( | ||||
74 | const std::string& name, | ||||
75 | mojo::ScopedInterfaceEndpointHandle handle) override; | ||||
76 | |||||
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 77 | // viz::VizMainImpl::Delegate: |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 78 | void OnInitializationFailed() override; |
79 | void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override; | ||||
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 80 | void PostCompositorThreadCreated( |
81 | base::SingleThreadTaskRunner* task_runner) override; | ||||
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 82 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 83 | void BindServiceFactoryRequest( |
84 | service_manager::mojom::ServiceFactoryRequest request); | ||||
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 85 | |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 86 | #if defined(OS_ANDROID) |
87 | static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay( | ||||
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 88 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 89 | const base::UnguessableToken& routing_token, |
90 | media::AndroidOverlayConfig); | ||||
91 | #endif | ||||
92 | |||||
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 93 | viz::VizMainImpl viz_main_; |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 94 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 95 | // ServiceFactory for service_manager::Service hosting. |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 96 | std::unique_ptr<GpuServiceFactory> service_factory_; |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 97 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 98 | // Bindings to the service_manager::mojom::ServiceFactory impl. |
99 | mojo::BindingSet<service_manager::mojom::ServiceFactory> | ||||
100 | service_factory_bindings_; | ||||
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 101 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 102 | AssociatedInterfaceRegistryImpl associated_interfaces_; |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 103 | |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 104 | // Holds a closure that releases pending interface requests on the IO thread. |
105 | base::Closure release_pending_requests_closure_; | ||||
106 | |||||
107 | base::WeakPtrFactory<GpuChildThread> weak_factory_; | ||||
108 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 109 | DISALLOW_COPY_AND_ASSIGN(GpuChildThread); |
110 | }; | ||||
111 | |||||
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 112 | } // namespace content |
113 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 114 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |