blob: 417035ddcb0c22946d8e1a433793d245c444a2c6 [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"
[email protected]abb522162013-06-28 01:54:1619#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0420#include "build/build_config.h"
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:3821#include "components/viz/service/gl/gpu_service_impl.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0622#include "components/viz/service/main/viz_main_impl.h"
jam8a021512a2015-02-03 18:16:0823#include "content/child/child_thread_impl.h"
sadrul72aae8a2017-01-24 04:52:3224#include "content/common/associated_interface_registry_impl.h"
penghuang7404df9882016-02-29 23:07:2925#include "gpu/command_buffer/service/gpu_preferences.h"
ericrk41a1579e2017-02-10 20:56:2826#include "gpu/config/gpu_feature_info.h"
[email protected]d7b5cc72013-05-23 20:05:0027#include "gpu/config/gpu_info.h"
markdittmerd88b8352016-04-08 15:28:4528#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"
liberato441ca702017-05-13 16:50:3833#include "media/base/android_overlay_mojo_factory.h"
sadrul72aae8a2017-01-24 04:52:3234#include "mojo/public/cpp/bindings/associated_binding_set.h"
rockot4a93a862016-07-07 20:50:1435#include "mojo/public/cpp/bindings/binding_set.h"
Chris Watkins88a40002017-09-28 01:16:4236#include "services/service_manager/public/cpp/service_context_ref.h"
Ken Rockot543f5e32018-02-04 02:13:5037#include "services/service_manager/public/mojom/service_factory.mojom.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0638#include "services/viz/privileged/interfaces/viz_main.mojom.h"
[email protected]7a31f7c2011-03-21 23:22:0439#include "ui/gfx/native_widget_types.h"
40
[email protected]eb398192012-10-22 20:16:1941namespace content {
ben507aa812016-08-10 23:26:1942class GpuServiceFactory;
[email protected]7a31f7c2011-03-21 23:22:0443
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
markdittmerd88b8352016-04-08 15:28:4546// IPC messages to gpu::GpuChannelManager, which is responsible for issuing
47// rendering commands to the GPU.
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0648class GpuChildThread : public ChildThreadImpl,
49 public viz::VizMainImpl::Delegate {
[email protected]7a31f7c2011-03-21 23:22:0450 public:
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5751 GpuChildThread(std::unique_ptr<gpu::GpuInit> gpu_init,
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0652 viz::VizMainImpl::LogMessages deferred_messages);
[email protected]7a31f7c2011-03-21 23:22:0453
sadrul3f8d0fa2016-09-08 17:47:4154 GpuChildThread(const InProcessChildThreadParams& params,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5755 std::unique_ptr<gpu::GpuInit> gpu_init);
[email protected]7a31f7c2011-03-21 23:22:0456
dchenge933b3e2014-10-21 11:44:0957 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0458
59 void Init(const base::Time& process_start_time);
[email protected]7a31f7c2011-03-21 23:22:0460
penghuang7404df9882016-02-29 23:07:2961 private:
sadrul041ca722017-03-24 22:35:3562 GpuChildThread(const ChildThreadImpl::Options& options,
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5763 std::unique_ptr<gpu::GpuInit> gpu_init);
sadrul041ca722017-03-24 22:35:3564
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0665 void CreateVizMainService(viz::mojom::VizMainAssociatedRequest request);
sadrul6c5aed8c2017-01-11 23:11:4466
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1567 bool in_process_gpu() const;
68
asvitkine5dc812a2016-06-07 18:20:3069 // ChildThreadImpl:.
dchenge933b3e2014-10-21 11:44:0970 bool Send(IPC::Message* msg) override;
[email protected]7a31f7c2011-03-21 23:22:0471
sadrul72aae8a2017-01-24 04:52:3272 // IPC::Listener implementation via ChildThreadImpl:
73 void OnAssociatedInterfaceRequest(
74 const std::string& name,
75 mojo::ScopedInterfaceEndpointHandle handle) override;
76
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0677 // viz::VizMainImpl::Delegate:
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1578 void OnInitializationFailed() override;
79 void OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) override;
Sadrul Habib Chowdhury97c6f1f2018-03-02 01:21:1680 void PostCompositorThreadCreated(
81 base::SingleThreadTaskRunner* task_runner) override;
fsamuela660ce02016-02-25 03:56:1682
rockot400ea35b2016-10-15 19:15:3283 void BindServiceFactoryRequest(
84 service_manager::mojom::ServiceFactoryRequest request);
rockot4a93a862016-07-07 20:50:1485
liberato441ca702017-05-13 16:50:3886#if defined(OS_ANDROID)
87 static std::unique_ptr<media::AndroidOverlay> CreateAndroidOverlay(
Chris Watkins88a40002017-09-28 01:16:4288 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
liberato441ca702017-05-13 16:50:3889 const base::UnguessableToken& routing_token,
90 media::AndroidOverlayConfig);
91#endif
92
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0693 viz::VizMainImpl viz_main_;
[email protected]ec4bda62013-06-14 15:51:0394
rockot400ea35b2016-10-15 19:15:3295 // ServiceFactory for service_manager::Service hosting.
ben507aa812016-08-10 23:26:1996 std::unique_ptr<GpuServiceFactory> service_factory_;
rockot4a93a862016-07-07 20:50:1497
rockot400ea35b2016-10-15 19:15:3298 // Bindings to the service_manager::mojom::ServiceFactory impl.
99 mojo::BindingSet<service_manager::mojom::ServiceFactory>
100 service_factory_bindings_;
rockot4a93a862016-07-07 20:50:14101
sadrul72aae8a2017-01-24 04:52:32102 AssociatedInterfaceRegistryImpl associated_interfaces_;
sadrul72aae8a2017-01-24 04:52:32103
bend6234442017-04-24 22:51:13104 // 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]7a31f7c2011-03-21 23:22:04109 DISALLOW_COPY_AND_ASSIGN(GpuChildThread);
110};
111
[email protected]eb398192012-10-22 20:16:19112} // namespace content
113
[email protected]7a31f7c2011-03-21 23:22:04114#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_