[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" |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 19 | #include "base/metrics/field_trial.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" |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 22 | #include "content/child/child_thread_impl.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 23 | #include "content/common/associated_interface_registry_impl.h" |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 24 | #include "gpu/command_buffer/service/gpu_preferences.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 25 | #include "gpu/config/gpu_feature_info.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 26 | #include "gpu/config/gpu_info.h" |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 27 | #include "gpu/ipc/service/gpu_channel.h" |
| 28 | #include "gpu/ipc/service/gpu_channel_manager.h" |
| 29 | #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
| 30 | #include "gpu/ipc/service/gpu_config.h" |
| 31 | #include "gpu/ipc/service/x_util.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 32 | #include "mojo/public/cpp/bindings/associated_binding_set.h" |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 33 | #include "mojo/public/cpp/bindings/binding_set.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 34 | #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 35 | #include "services/ui/gpu/gpu_service.h" |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 36 | #include "services/ui/gpu/interfaces/gpu_main.mojom.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 37 | #include "ui/gfx/native_widget_types.h" |
| 38 | |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 39 | namespace gpu { |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame] | 40 | class GpuWatchdogThread; |
markdittmer | 6e70beb8 | 2016-05-02 05:40:47 | [diff] [blame] | 41 | } |
| 42 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 43 | namespace content { |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 44 | class GpuServiceFactory; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 45 | |
| 46 | // The main thread of the GPU child process. There will only ever be one of |
| 47 | // these per process. It does process initialization and shutdown. It forwards |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 48 | // IPC messages to gpu::GpuChannelManager, which is responsible for issuing |
| 49 | // rendering commands to the GPU. |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 50 | class GpuChildThread : public ChildThreadImpl, |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 51 | public ui::mojom::GpuMain, |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 52 | public base::FieldTrialList::Observer { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 53 | public: |
sadrul | db04bc3 | 2017-01-04 04:50:30 | [diff] [blame] | 54 | struct LogMessage { |
| 55 | int severity; |
| 56 | std::string header; |
| 57 | std::string message; |
| 58 | }; |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 59 | typedef std::vector<LogMessage> DeferredMessages; |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 60 | |
ericrk | 32c08ce | 2016-10-14 15:44:12 | [diff] [blame] | 61 | GpuChildThread(std::unique_ptr<gpu::GpuWatchdogThread> gpu_watchdog_thread, |
reveman | 611d024f | 2015-06-25 22:42:40 | [diff] [blame] | 62 | bool dead_on_arrival, |
| 63 | const gpu::GPUInfo& gpu_info, |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 64 | const gpu::GpuFeatureInfo& gpu_feature_info, |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 65 | DeferredMessages deferred_messages); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 66 | |
sadrul | 3f8d0fa | 2016-09-08 17:47:41 | [diff] [blame] | 67 | GpuChildThread(const InProcessChildThreadParams& params, |
thomasanderson | 62ba78ff | 2016-10-01 02:03:42 | [diff] [blame] | 68 | const gpu::GPUInfo& gpu_info, |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 69 | const gpu::GpuFeatureInfo& gpu_feature_info); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 70 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 71 | ~GpuChildThread() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 72 | |
| 73 | void Init(const base::Time& process_start_time); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 74 | |
penghuang | 7404df988 | 2016-02-29 23:07:29 | [diff] [blame] | 75 | private: |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 76 | GpuChildThread(const ChildThreadImpl::Options& options, |
| 77 | std::unique_ptr<gpu::GpuWatchdogThread> gpu_watchdog_thread, |
| 78 | bool dead_on_arrival, |
| 79 | bool in_browser_process, |
| 80 | const gpu::GPUInfo& gpu_info, |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 81 | const gpu::GpuFeatureInfo& gpu_feature_info); |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 82 | |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 83 | void CreateGpuMainService(ui::mojom::GpuMainAssociatedRequest request); |
| 84 | |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 85 | // ChildThreadImpl:. |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 86 | bool Send(IPC::Message* msg) override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 87 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 88 | // IPC::Listener implementation via ChildThreadImpl: |
| 89 | void OnAssociatedInterfaceRequest( |
| 90 | const std::string& name, |
| 91 | mojo::ScopedInterfaceEndpointHandle handle) override; |
| 92 | |
| 93 | // ui::mojom::GpuMain: |
| 94 | void CreateGpuService(ui::mojom::GpuServiceRequest request, |
| 95 | ui::mojom::GpuHostPtr gpu_host, |
ericrk | 8c0b7bf6 | 2017-03-17 20:07:23 | [diff] [blame] | 96 | const gpu::GpuPreferences& preferences, |
| 97 | mojo::ScopedSharedBufferHandle activity_flags) override; |
kylechar | 486c455 | 2017-04-04 15:31:44 | [diff] [blame] | 98 | void CreateFrameSinkManager( |
| 99 | cc::mojom::FrameSinkManagerRequest request, |
| 100 | cc::mojom::FrameSinkManagerClientPtr client) override; |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 101 | |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 102 | // base::FieldTrialList::Observer: |
| 103 | void OnFieldTrialGroupFinalized(const std::string& trial_name, |
| 104 | const std::string& group_name) override; |
| 105 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 106 | void BindServiceFactoryRequest( |
| 107 | service_manager::mojom::ServiceFactoryRequest request); |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 108 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 109 | gpu::GpuChannelManager* gpu_channel_manager() { |
| 110 | return gpu_service_->gpu_channel_manager(); |
| 111 | } |
| 112 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 113 | // Set this flag to true if a fatal error occurred before we receive the |
| 114 | // OnInitialize message, in which case we just declare ourselves DOA. |
sadrul | 454af33 | 2016-09-09 18:14:32 | [diff] [blame] | 115 | const bool dead_on_arrival_; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 116 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 117 | // Error messages collected in gpu_main() before the thread is created. |
| 118 | DeferredMessages deferred_messages_; |
| 119 | |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 120 | // Whether the GPU thread is running in the browser process. |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 121 | const bool in_browser_process_; |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 122 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 123 | // ServiceFactory for service_manager::Service hosting. |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 124 | std::unique_ptr<GpuServiceFactory> service_factory_; |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 125 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 126 | // Bindings to the service_manager::mojom::ServiceFactory impl. |
| 127 | mojo::BindingSet<service_manager::mojom::ServiceFactory> |
| 128 | service_factory_bindings_; |
rockot | 4a93a86 | 2016-07-07 20:50:14 | [diff] [blame] | 129 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 130 | AssociatedInterfaceRegistryImpl associated_interfaces_; |
| 131 | std::unique_ptr<ui::GpuService> gpu_service_; |
| 132 | mojo::AssociatedBinding<ui::mojom::GpuMain> gpu_main_binding_; |
| 133 | |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame^] | 134 | // Holds a closure that releases pending interface requests on the IO thread. |
| 135 | base::Closure release_pending_requests_closure_; |
| 136 | |
| 137 | base::WeakPtrFactory<GpuChildThread> weak_factory_; |
| 138 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 139 | DISALLOW_COPY_AND_ASSIGN(GpuChildThread); |
| 140 | }; |
| 141 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 142 | } // namespace content |
| 143 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 144 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |