blob: c279c5f2a7caf07b97d5c45f40ae3749cc0c5325 [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
[email protected]ec4bda62013-06-14 15:51:0310#include <queue>
[email protected]7a31f7c2011-03-21 23:22:0411#include <string>
12
[email protected]7a31f7c2011-03-21 23:22:0413#include "base/command_line.h"
avi66a07722015-12-25 23:38:1214#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/ref_counted.h"
16#include "base/memory/scoped_ptr.h"
[email protected]abb522162013-06-28 01:54:1617#include "base/time/time.h"
[email protected]7a31f7c2011-03-21 23:22:0418#include "build/build_config.h"
jam8a021512a2015-02-03 18:16:0819#include "content/child/child_thread_impl.h"
[email protected]f24a1e2b2011-04-08 01:48:4820#include "content/common/gpu/gpu_channel.h"
21#include "content/common/gpu/gpu_channel_manager.h"
fsamuela660ce02016-02-25 03:56:1622#include "content/common/gpu/gpu_channel_manager_delegate.h"
[email protected]f24a1e2b2011-04-08 01:48:4823#include "content/common/gpu/gpu_config.h"
[email protected]f24a1e2b2011-04-08 01:48:4824#include "content/common/gpu/x_util.h"
rockot54b52492015-12-17 03:21:5825#include "content/common/process_control.mojom.h"
[email protected]d7b5cc72013-05-23 20:05:0026#include "gpu/config/gpu_info.h"
rockot85dce0862015-11-13 01:33:5927#include "mojo/public/cpp/bindings/interface_request.h"
yzshenf1490012016-02-24 21:50:5728#include "mojo/public/cpp/bindings/weak_binding_set.h"
[email protected]7a31f7c2011-03-21 23:22:0429#include "ui/gfx/native_widget_types.h"
30
boliuc5befe72015-07-21 19:08:5631namespace gpu {
32class SyncPointManager;
33}
34
[email protected]7a31f7c2011-03-21 23:22:0435namespace sandbox {
36class TargetServices;
37}
38
[email protected]eb398192012-10-22 20:16:1939namespace content {
reveman611d024f2015-06-25 22:42:4040class GpuMemoryBufferFactory;
xhwang9c8e1282015-10-10 01:54:0741class GpuProcessControlImpl;
[email protected]7a31f7c2011-03-21 23:22:0442class GpuWatchdogThread;
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
[email protected]f24a1e2b2011-04-08 01:48:4846// IPC messages to GpuChannelManager, which is responsible for issuing rendering
[email protected]7a31f7c2011-03-21 23:22:0447// commands to the GPU.
fsamuela660ce02016-02-25 03:56:1648class GpuChildThread : public ChildThreadImpl,
49 public GpuChannelManagerDelegate {
[email protected]7a31f7c2011-03-21 23:22:0450 public:
[email protected]ec4bda62013-06-14 15:51:0351 typedef std::queue<IPC::Message*> DeferredMessages;
52
reveman611d024f2015-06-25 22:42:4053 GpuChildThread(GpuWatchdogThread* gpu_watchdog_thread,
54 bool dead_on_arrival,
55 const gpu::GPUInfo& gpu_info,
56 const DeferredMessages& deferred_messages,
boliuc5befe72015-07-21 19:08:5657 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
58 gpu::SyncPointManager* sync_point_manager);
[email protected]7a31f7c2011-03-21 23:22:0459
grt8c648422015-06-29 18:17:1760 GpuChildThread(const InProcessChildThreadParams& params,
boliuc5befe72015-07-21 19:08:5661 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
62 gpu::SyncPointManager* sync_point_manager);
[email protected]7a31f7c2011-03-21 23:22:0463
dchenge933b3e2014-10-21 11:44:0964 ~GpuChildThread() override;
[email protected]7a31f7c2011-03-21 23:22:0465
dchenge933b3e2014-10-21 11:44:0966 void Shutdown() override;
[email protected]ce79d8512013-04-22 22:44:4167
[email protected]7a31f7c2011-03-21 23:22:0468 void Init(const base::Time& process_start_time);
69 void StopWatchdog();
70
71 // ChildThread overrides.
dchenge933b3e2014-10-21 11:44:0972 bool Send(IPC::Message* msg) override;
73 bool OnControlMessageReceived(const IPC::Message& msg) override;
sunnyps498edc202015-08-22 02:00:3974 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]7a31f7c2011-03-21 23:22:0475
76 private:
fsamuela660ce02016-02-25 03:56:1677 // GpuChannelManagerDelegate implementation.
78 void AddSubscription(int32_t client_id, unsigned int target) override;
79 void ChannelEstablished(const IPC::ChannelHandle& channel_handle) override;
80 void DidCreateOffscreenContext(const GURL& active_url) override;
81 void DidDestroyChannel(int client_id) override;
82 void DidDestroyOffscreenContext(const GURL& active_url) override;
83 void DidLoseContext(bool offscreen,
84 gpu::error::ContextLostReason reason,
85 const GURL& active_url) override;
86 void GpuMemoryUmaStats(const GPUMemoryUmaStats& params) override;
87 void RemoveSubscription(int32_t client_id, unsigned int target) override;
88#if defined(OS_MACOSX)
89 void SendAcceleratedSurfaceBuffersSwapped(
90 const AcceleratedSurfaceBuffersSwappedParams& params) override;
91#endif
92#if defined(OS_WIN)
93 void SendAcceleratedSurfaceCreatedChildWindow(
94 const gfx::PluginWindowHandle& parent_window,
95 const gfx::PluginWindowHandle& child_window) override;
96#endif
97 void StoreShaderToDisk(int32_t client_id,
98 const std::string& key,
99 const std::string& shader) override;
100
[email protected]7a31f7c2011-03-21 23:22:04101 // Message handlers.
102 void OnInitialize();
sunnyps498edc202015-08-22 02:00:39103 void OnFinalize();
[email protected]7a31f7c2011-03-21 23:22:04104 void OnCollectGraphicsInfo();
[email protected]fb246af2012-08-18 03:11:41105 void OnGetVideoMemoryUsageStats();
avi66a07722015-12-25 23:38:12106 void OnSetVideoMemoryWindowCount(uint32_t window_count);
[email protected]07cb03a2012-10-01 23:52:11107
[email protected]184e3f3802011-05-04 20:48:52108 void OnClean();
[email protected]7a31f7c2011-03-21 23:22:04109 void OnCrash();
110 void OnHang();
[email protected]31583a9d2012-11-30 00:37:17111 void OnDisableWatchdog();
ccameron17d51092014-10-24 22:17:07112 void OnGpuSwitched();
[email protected]7a31f7c2011-03-21 23:22:04113
fsamuela660ce02016-02-25 03:56:16114#if defined(OS_MACOSX)
115 void OnBufferPresented(const BufferPresentedParams& params);
116#endif
117 void OnEstablishChannel(const EstablishChannelParams& params);
118 void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
119 void OnLoadedShader(const std::string& shader);
120 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
121 int client_id,
122 const gpu::SyncToken& sync_token);
123 void OnUpdateValueState(int client_id,
124 unsigned int target,
125 const gpu::ValueState& state);
126#if defined(OS_ANDROID)
127 void OnWakeUpGpu();
128#endif
129 void OnLoseAllContexts();
130
xhwang9c8e1282015-10-10 01:54:07131 void BindProcessControlRequest(
132 mojo::InterfaceRequest<ProcessControl> request);
133
[email protected]0b2cec62011-07-22 18:13:28134 // Set this flag to true if a fatal error occurred before we receive the
135 // OnInitialize message, in which case we just declare ourselves DOA.
136 bool dead_on_arrival_;
[email protected]7a31f7c2011-03-21 23:22:04137 base::Time process_start_time_;
138 scoped_refptr<GpuWatchdogThread> watchdog_thread_;
139
140#if defined(OS_WIN)
141 // Windows specific client sandbox interface.
142 sandbox::TargetServices* target_services_;
[email protected]7a31f7c2011-03-21 23:22:04143#endif
144
boliuc5befe72015-07-21 19:08:56145 // Non-owning.
146 gpu::SyncPointManager* sync_point_manager_;
147
[email protected]f24a1e2b2011-04-08 01:48:48148 scoped_ptr<GpuChannelManager> gpu_channel_manager_;
[email protected]7a31f7c2011-03-21 23:22:04149
150 // Information about the GPU, such as device and vendor ID.
[email protected]d7b5cc72013-05-23 20:05:00151 gpu::GPUInfo gpu_info_;
[email protected]7a31f7c2011-03-21 23:22:04152
[email protected]ec4bda62013-06-14 15:51:03153 // Error messages collected in gpu_main() before the thread is created.
154 DeferredMessages deferred_messages_;
155
[email protected]2d3de5452013-01-18 10:03:40156 // Whether the GPU thread is running in the browser process.
157 bool in_browser_process_;
158
reveman611d024f2015-06-25 22:42:40159 // The GpuMemoryBufferFactory instance used to allocate GpuMemoryBuffers.
160 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
161
xhwang9c8e1282015-10-10 01:54:07162 // Process control for Mojo application hosting.
163 scoped_ptr<GpuProcessControlImpl> process_control_;
164
165 // Bindings to the ProcessControl impl.
yzshenf1490012016-02-24 21:50:57166 mojo::WeakBindingSet<ProcessControl> process_control_bindings_;
xhwang9c8e1282015-10-10 01:54:07167
[email protected]7a31f7c2011-03-21 23:22:04168 DISALLOW_COPY_AND_ASSIGN(GpuChildThread);
169};
170
[email protected]eb398192012-10-22 20:16:19171} // namespace content
172
[email protected]7a31f7c2011-03-21 23:22:04173#endif // CONTENT_GPU_GPU_CHILD_THREAD_H_