[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 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 10 | #include <queue> |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 11 | #include <string> |
| 12 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 13 | #include "base/command_line.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
| 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 17 | #include "base/time/time.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 18 | #include "build/build_config.h" |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 19 | #include "content/child/child_thread_impl.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 20 | #include "content/common/gpu/gpu_channel.h" |
| 21 | #include "content/common/gpu/gpu_channel_manager.h" |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame^] | 22 | #include "content/common/gpu/gpu_channel_manager_delegate.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 23 | #include "content/common/gpu/gpu_config.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 24 | #include "content/common/gpu/x_util.h" |
rockot | 54b5249 | 2015-12-17 03:21:58 | [diff] [blame] | 25 | #include "content/common/process_control.mojom.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 26 | #include "gpu/config/gpu_info.h" |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 27 | #include "mojo/public/cpp/bindings/interface_request.h" |
yzshen | f149001 | 2016-02-24 21:50:57 | [diff] [blame] | 28 | #include "mojo/public/cpp/bindings/weak_binding_set.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 29 | #include "ui/gfx/native_widget_types.h" |
| 30 | |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 31 | namespace gpu { |
| 32 | class SyncPointManager; |
| 33 | } |
| 34 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 35 | namespace sandbox { |
| 36 | class TargetServices; |
| 37 | } |
| 38 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 39 | namespace content { |
reveman | 611d024f | 2015-06-25 22:42:40 | [diff] [blame] | 40 | class GpuMemoryBufferFactory; |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 41 | class GpuProcessControlImpl; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 42 | class 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] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 46 | // IPC messages to GpuChannelManager, which is responsible for issuing rendering |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 47 | // commands to the GPU. |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame^] | 48 | class GpuChildThread : public ChildThreadImpl, |
| 49 | public GpuChannelManagerDelegate { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 50 | public: |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 51 | typedef std::queue<IPC::Message*> DeferredMessages; |
| 52 | |
reveman | 611d024f | 2015-06-25 22:42:40 | [diff] [blame] | 53 | GpuChildThread(GpuWatchdogThread* gpu_watchdog_thread, |
| 54 | bool dead_on_arrival, |
| 55 | const gpu::GPUInfo& gpu_info, |
| 56 | const DeferredMessages& deferred_messages, |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 57 | GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 58 | gpu::SyncPointManager* sync_point_manager); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 59 | |
grt | 8c64842 | 2015-06-29 18:17:17 | [diff] [blame] | 60 | GpuChildThread(const InProcessChildThreadParams& params, |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 61 | GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 62 | gpu::SyncPointManager* sync_point_manager); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 63 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 64 | ~GpuChildThread() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 65 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 66 | void Shutdown() override; |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 67 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 68 | void Init(const base::Time& process_start_time); |
| 69 | void StopWatchdog(); |
| 70 | |
| 71 | // ChildThread overrides. |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 72 | bool Send(IPC::Message* msg) override; |
| 73 | bool OnControlMessageReceived(const IPC::Message& msg) override; |
sunnyps | 498edc20 | 2015-08-22 02:00:39 | [diff] [blame] | 74 | bool OnMessageReceived(const IPC::Message& msg) override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 75 | |
| 76 | private: |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame^] | 77 | // 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] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 101 | // Message handlers. |
| 102 | void OnInitialize(); |
sunnyps | 498edc20 | 2015-08-22 02:00:39 | [diff] [blame] | 103 | void OnFinalize(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 104 | void OnCollectGraphicsInfo(); |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 105 | void OnGetVideoMemoryUsageStats(); |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 106 | void OnSetVideoMemoryWindowCount(uint32_t window_count); |
[email protected] | 07cb03a | 2012-10-01 23:52:11 | [diff] [blame] | 107 | |
[email protected] | 184e3f380 | 2011-05-04 20:48:52 | [diff] [blame] | 108 | void OnClean(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 109 | void OnCrash(); |
| 110 | void OnHang(); |
[email protected] | 31583a9d | 2012-11-30 00:37:17 | [diff] [blame] | 111 | void OnDisableWatchdog(); |
ccameron | 17d5109 | 2014-10-24 22:17:07 | [diff] [blame] | 112 | void OnGpuSwitched(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 113 | |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame^] | 114 | #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 | |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 131 | void BindProcessControlRequest( |
| 132 | mojo::InterfaceRequest<ProcessControl> request); |
| 133 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 134 | // 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] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 137 | 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] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 143 | #endif |
| 144 | |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 145 | // Non-owning. |
| 146 | gpu::SyncPointManager* sync_point_manager_; |
| 147 | |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 148 | scoped_ptr<GpuChannelManager> gpu_channel_manager_; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 149 | |
| 150 | // Information about the GPU, such as device and vendor ID. |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 151 | gpu::GPUInfo gpu_info_; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 152 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 153 | // Error messages collected in gpu_main() before the thread is created. |
| 154 | DeferredMessages deferred_messages_; |
| 155 | |
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 156 | // Whether the GPU thread is running in the browser process. |
| 157 | bool in_browser_process_; |
| 158 | |
reveman | 611d024f | 2015-06-25 22:42:40 | [diff] [blame] | 159 | // The GpuMemoryBufferFactory instance used to allocate GpuMemoryBuffers. |
| 160 | GpuMemoryBufferFactory* const gpu_memory_buffer_factory_; |
| 161 | |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 162 | // Process control for Mojo application hosting. |
| 163 | scoped_ptr<GpuProcessControlImpl> process_control_; |
| 164 | |
| 165 | // Bindings to the ProcessControl impl. |
yzshen | f149001 | 2016-02-24 21:50:57 | [diff] [blame] | 166 | mojo::WeakBindingSet<ProcessControl> process_control_bindings_; |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 167 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 168 | DISALLOW_COPY_AND_ASSIGN(GpuChildThread); |
| 169 | }; |
| 170 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 171 | } // namespace content |
| 172 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 173 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |