blob: 55c5f0ece5397ef4dc809496ec7c076dd8d152e2 [file] [log] [blame]
[email protected]f0918242012-02-18 00:30:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[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>
[email protected]ec4bda62013-06-14 15:51:0311#include <queue>
[email protected]7a31f7c2011-03-21 23:22:0412#include <string>
13
rockotcaccf782016-06-29 23:39:1614#include "base/callback.h"
[email protected]7a31f7c2011-03-21 23:22:0415#include "base/command_line.h"
avi66a07722015-12-25 23:38:1216#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/ref_counted.h"
bend6234442017-04-24 22:51:1318#include "base/memory/weak_ptr.h"
asvitkine5dc812a2016-06-07 18:20:3019#include "base/metrics/field_trial.h"
[email protected]abb522162013-06-28 01:54:1620#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0421#include "build/build_config.h"
jam8a021512a2015-02-03 18:16:0822#include "content/child/child_thread_impl.h"
sadrul72aae8a2017-01-24 04:52:3223#include "content/common/associated_interface_registry_impl.h"
penghuang7404df9882016-02-29 23:07:2924#include "gpu/command_buffer/service/gpu_preferences.h"
ericrk41a1579e2017-02-10 20:56:2825#include "gpu/config/gpu_feature_info.h"
[email protected]d7b5cc72013-05-23 20:05:0026#include "gpu/config/gpu_info.h"
markdittmerd88b8352016-04-08 15:28:4527#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"
sadrul72aae8a2017-01-24 04:52:3232#include "mojo/public/cpp/bindings/associated_binding_set.h"
rockot4a93a862016-07-07 20:50:1433#include "mojo/public/cpp/bindings/binding_set.h"
rockot734fb662016-10-15 16:41:3034#include "services/service_manager/public/interfaces/service_factory.mojom.h"
sadrul72aae8a2017-01-24 04:52:3235#include "services/ui/gpu/gpu_service.h"
sadrul6c5aed8c2017-01-11 23:11:4436#include "services/ui/gpu/interfaces/gpu_main.mojom.h"
[email protected]7a31f7c2011-03-21 23:22:0437#include "ui/gfx/native_widget_types.h"
38
boliuc5befe72015-07-21 19:08:5639namespace gpu {
sadrul2fb7e152016-08-30 05:21:4540class GpuWatchdogThread;
markdittmer6e70beb82016-05-02 05:40:4741}
42
[email protected]eb398192012-10-22 20:16:1943namespace content {
ben507aa812016-08-10 23:26:1944class GpuServiceFactory;
[email protected]7a31f7c2011-03-21 23:22:0445
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
markdittmerd88b8352016-04-08 15:28:4548// IPC messages to gpu::GpuChannelManager, which is responsible for issuing
49// rendering commands to the GPU.
fsamuela660ce02016-02-25 03:56:1650class GpuChildThread : public ChildThreadImpl,
sadrul72aae8a2017-01-24 04:52:3251 public ui::mojom::GpuMain,
asvitkine5dc812a2016-06-07 18:20:3052 public base::FieldTrialList::Observer {
[email protected]7a31f7c2011-03-21 23:22:0453 public:
sadruldb04bc32017-01-04 04:50:3054 struct LogMessage {
55 int severity;
56 std::string header;
57 std::string message;
58 };
sadrul041ca722017-03-24 22:35:3559 typedef std::vector<LogMessage> DeferredMessages;
[email protected]ec4bda62013-06-14 15:51:0360
ericrk32c08ce2016-10-14 15:44:1261 GpuChildThread(std::unique_ptr<gpu::GpuWatchdogThread> gpu_watchdog_thread,
reveman611d024f2015-06-25 22:42:4062 bool dead_on_arrival,
63 const gpu::GPUInfo& gpu_info,
ericrk41a1579e2017-02-10 20:56:2864 const gpu::GpuFeatureInfo& gpu_feature_info,
sadrul6d41b822017-04-02 03:38:5065 DeferredMessages deferred_messages);
[email protected]7a31f7c2011-03-21 23:22:0466
sadrul3f8d0fa2016-09-08 17:47:4167 GpuChildThread(const InProcessChildThreadParams& params,
thomasanderson62ba78ff2016-10-01 02:03:4268 const gpu::GPUInfo& gpu_info,
sadrul6d41b822017-04-02 03:38:5069 const gpu::GpuFeatureInfo& gpu_feature_info);
[email protected]7a31f7c2011-03-21 23:22:0470
dchenge933b3e2014-10-21 11:44:0971 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0472
73 void Init(const base::Time& process_start_time);
[email protected]7a31f7c2011-03-21 23:22:0474
penghuang7404df9882016-02-29 23:07:2975 private:
sadrul041ca722017-03-24 22:35:3576 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,
sadrul6d41b822017-04-02 03:38:5081 const gpu::GpuFeatureInfo& gpu_feature_info);
sadrul041ca722017-03-24 22:35:3582
sadrul6c5aed8c2017-01-11 23:11:4483 void CreateGpuMainService(ui::mojom::GpuMainAssociatedRequest request);
84
asvitkine5dc812a2016-06-07 18:20:3085 // ChildThreadImpl:.
dchenge933b3e2014-10-21 11:44:0986 bool Send(IPC::Message* msg) override;
[email protected]7a31f7c2011-03-21 23:22:0487
sadrul72aae8a2017-01-24 04:52:3288 // 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,
ericrk8c0b7bf62017-03-17 20:07:2396 const gpu::GpuPreferences& preferences,
97 mojo::ScopedSharedBufferHandle activity_flags) override;
kylechar486c4552017-04-04 15:31:4498 void CreateFrameSinkManager(
99 cc::mojom::FrameSinkManagerRequest request,
100 cc::mojom::FrameSinkManagerClientPtr client) override;
fsamuela660ce02016-02-25 03:56:16101
asvitkine5dc812a2016-06-07 18:20:30102 // base::FieldTrialList::Observer:
103 void OnFieldTrialGroupFinalized(const std::string& trial_name,
104 const std::string& group_name) override;
105
rockot400ea35b2016-10-15 19:15:32106 void BindServiceFactoryRequest(
107 service_manager::mojom::ServiceFactoryRequest request);
rockot4a93a862016-07-07 20:50:14108
sadrul72aae8a2017-01-24 04:52:32109 gpu::GpuChannelManager* gpu_channel_manager() {
110 return gpu_service_->gpu_channel_manager();
111 }
112
[email protected]0b2cec62011-07-22 18:13:28113 // 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.
sadrul454af332016-09-09 18:14:32115 const bool dead_on_arrival_;
[email protected]7a31f7c2011-03-21 23:22:04116
[email protected]ec4bda62013-06-14 15:51:03117 // Error messages collected in gpu_main() before the thread is created.
118 DeferredMessages deferred_messages_;
119
[email protected]2d3de5452013-01-18 10:03:40120 // Whether the GPU thread is running in the browser process.
sadrul041ca722017-03-24 22:35:35121 const bool in_browser_process_;
[email protected]2d3de5452013-01-18 10:03:40122
rockot400ea35b2016-10-15 19:15:32123 // ServiceFactory for service_manager::Service hosting.
ben507aa812016-08-10 23:26:19124 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:14125
rockot400ea35b2016-10-15 19:15:32126 // Bindings to the service_manager::mojom::ServiceFactory impl.
127 mojo::BindingSet<service_manager::mojom::ServiceFactory>
128 service_factory_bindings_;
rockot4a93a862016-07-07 20:50:14129
sadrul72aae8a2017-01-24 04:52:32130 AssociatedInterfaceRegistryImpl associated_interfaces_;
131 std::unique_ptr<ui::GpuService> gpu_service_;
132 mojo::AssociatedBinding<ui::mojom::GpuMain> gpu_main_binding_;
133
bend6234442017-04-24 22:51:13134 // 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]7a31f7c2011-03-21 23:22:04139 DISALLOW_COPY_AND_ASSIGN(GpuChildThread);
140};
141
[email protected]eb398192012-10-22 20:16:19142} // namespace content
143
[email protected]7a31f7c2011-03-21 23:22:04144#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_