Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / gpu / gpu_child_thread.h
blob242ff8115865623e413c2f7578d98e0302c41980
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_GPU_GPU_CHILD_THREAD_H_
6 #define CONTENT_GPU_GPU_CHILD_THREAD_H_
8 #include <queue>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/command_line.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h"
16 #include "build/build_config.h"
17 #include "content/child/child_thread_impl.h"
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"
21 #include "content/common/gpu/x_util.h"
22 #include "gpu/config/gpu_info.h"
23 #include "ui/gfx/native_widget_types.h"
25 namespace gpu {
26 class SyncPointManager;
29 namespace sandbox {
30 class TargetServices;
33 namespace content {
34 class GpuMemoryBufferFactory;
35 class GpuWatchdogThread;
37 // The main thread of the GPU child process. There will only ever be one of
38 // these per process. It does process initialization and shutdown. It forwards
39 // IPC messages to GpuChannelManager, which is responsible for issuing rendering
40 // commands to the GPU.
41 class GpuChildThread : public ChildThreadImpl {
42 public:
43 typedef std::queue<IPC::Message*> DeferredMessages;
45 GpuChildThread(GpuWatchdogThread* gpu_watchdog_thread,
46 bool dead_on_arrival,
47 const gpu::GPUInfo& gpu_info,
48 const DeferredMessages& deferred_messages,
49 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
50 gpu::SyncPointManager* sync_point_manager);
52 GpuChildThread(const InProcessChildThreadParams& params,
53 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
54 gpu::SyncPointManager* sync_point_manager);
56 ~GpuChildThread() override;
58 static gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType();
60 void Shutdown() override;
62 void Init(const base::Time& process_start_time);
63 void StopWatchdog();
65 // ChildThread overrides.
66 bool Send(IPC::Message* msg) override;
67 bool OnControlMessageReceived(const IPC::Message& msg) override;
69 private:
70 // Message handlers.
71 void OnInitialize();
72 void OnCollectGraphicsInfo();
73 void OnGetVideoMemoryUsageStats();
74 void OnSetVideoMemoryWindowCount(uint32 window_count);
76 void OnClean();
77 void OnCrash();
78 void OnHang();
79 void OnDisableWatchdog();
80 void OnGpuSwitched();
82 #if defined(USE_TCMALLOC)
83 void OnGetGpuTcmalloc();
84 #endif
86 // Set this flag to true if a fatal error occurred before we receive the
87 // OnInitialize message, in which case we just declare ourselves DOA.
88 bool dead_on_arrival_;
89 base::Time process_start_time_;
90 scoped_refptr<GpuWatchdogThread> watchdog_thread_;
92 #if defined(OS_WIN)
93 // Windows specific client sandbox interface.
94 sandbox::TargetServices* target_services_;
95 #endif
97 // Non-owning.
98 gpu::SyncPointManager* sync_point_manager_;
100 scoped_ptr<GpuChannelManager> gpu_channel_manager_;
102 // Information about the GPU, such as device and vendor ID.
103 gpu::GPUInfo gpu_info_;
105 // Error messages collected in gpu_main() before the thread is created.
106 DeferredMessages deferred_messages_;
108 // Whether the GPU thread is running in the browser process.
109 bool in_browser_process_;
111 // The GpuMemoryBufferFactory instance used to allocate GpuMemoryBuffers.
112 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
114 DISALLOW_COPY_AND_ASSIGN(GpuChildThread);
117 } // namespace content
119 #endif // CONTENT_GPU_GPU_CHILD_THREAD_H_