[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 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 8 | #include <queue> |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 9 | #include <string> |
10 | |||||
11 | #include "base/basictypes.h" | ||||
12 | #include "base/command_line.h" | ||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
14 | #include "base/memory/scoped_ptr.h" | ||||
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 15 | #include "base/time/time.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 17 | #include "content/child/child_thread.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 18 | #include "content/common/gpu/gpu_channel.h" |
19 | #include "content/common/gpu/gpu_channel_manager.h" | ||||
20 | #include "content/common/gpu/gpu_config.h" | ||||
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 21 | #include "content/common/gpu/x_util.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 22 | #include "gpu/config/gpu_info.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 23 | #include "ui/gfx/native_widget_types.h" |
24 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 25 | namespace sandbox { |
26 | class TargetServices; | ||||
27 | } | ||||
28 | |||||
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 29 | namespace content { |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 30 | class GpuWatchdogThread; |
31 | |||||
32 | // The main thread of the GPU child process. There will only ever be one of | ||||
33 | // these per process. It does process initialization and shutdown. It forwards | ||||
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 34 | // IPC messages to GpuChannelManager, which is responsible for issuing rendering |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 35 | // commands to the GPU. |
36 | class GpuChildThread : public ChildThread { | ||||
37 | public: | ||||
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 38 | typedef std::queue<IPC::Message*> DeferredMessages; |
39 | |||||
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 40 | explicit GpuChildThread(GpuWatchdogThread* gpu_watchdog_thread, |
41 | bool dead_on_arrival, | ||||
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 42 | const gpu::GPUInfo& gpu_info, |
43 | const DeferredMessages& deferred_messages); | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 44 | |
45 | // For single-process mode. | ||||
46 | explicit GpuChildThread(const std::string& channel_id); | ||||
47 | |||||
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 48 | virtual ~GpuChildThread(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 49 | |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 50 | virtual void Shutdown() OVERRIDE; |
51 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 52 | void Init(const base::Time& process_start_time); |
53 | void StopWatchdog(); | ||||
54 | |||||
55 | // ChildThread overrides. | ||||
[email protected] | edc64de | 2011-11-17 20:07:38 | [diff] [blame] | 56 | virtual bool Send(IPC::Message* msg) OVERRIDE; |
57 | virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE; | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 58 | |
59 | private: | ||||
60 | // Message handlers. | ||||
61 | void OnInitialize(); | ||||
62 | void OnCollectGraphicsInfo(); | ||||
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 63 | void OnGetVideoMemoryUsageStats(); |
[email protected] | 07cb03a | 2012-10-01 23:52:11 | [diff] [blame] | 64 | void OnSetVideoMemoryWindowCount(uint32 window_count); |
65 | |||||
[email protected] | 184e3f380 | 2011-05-04 20:48:52 | [diff] [blame] | 66 | void OnClean(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 67 | void OnCrash(); |
68 | void OnHang(); | ||||
[email protected] | 31583a9d | 2012-11-30 00:37:17 | [diff] [blame] | 69 | void OnDisableWatchdog(); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 70 | |
[email protected] | 3d662c3 | 2012-04-25 00:05:17 | [diff] [blame] | 71 | #if defined(USE_TCMALLOC) |
72 | void OnGetGpuTcmalloc(); | ||||
73 | #endif | ||||
74 | |||||
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 75 | // Set this flag to true if a fatal error occurred before we receive the |
76 | // OnInitialize message, in which case we just declare ourselves DOA. | ||||
77 | bool dead_on_arrival_; | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 78 | base::Time process_start_time_; |
79 | scoped_refptr<GpuWatchdogThread> watchdog_thread_; | ||||
80 | |||||
81 | #if defined(OS_WIN) | ||||
82 | // Windows specific client sandbox interface. | ||||
83 | sandbox::TargetServices* target_services_; | ||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 84 | #endif |
85 | |||||
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 86 | scoped_ptr<GpuChannelManager> gpu_channel_manager_; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 87 | |
88 | // Information about the GPU, such as device and vendor ID. | ||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 89 | gpu::GPUInfo gpu_info_; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 90 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 91 | // Error messages collected in gpu_main() before the thread is created. |
92 | DeferredMessages deferred_messages_; | ||||
93 | |||||
[email protected] | 2d3de545 | 2013-01-18 10:03:40 | [diff] [blame] | 94 | // Whether the GPU thread is running in the browser process. |
95 | bool in_browser_process_; | ||||
96 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(GpuChildThread); |
98 | }; | ||||
99 | |||||
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 100 | } // namespace content |
101 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 102 | #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_ |