Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager.h
blob2bbca8b9d88425921727d68cacc60e1f1856770e
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_COMMON_GPU_GPU_CHANNEL_MANAGER_H_
6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_
8 #include <deque>
9 #include <string>
10 #include <vector>
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "build/build_config.h"
17 #include "content/common/content_export.h"
18 #include "content/common/content_param_traits.h"
19 #include "content/common/gpu/gpu_memory_manager.h"
20 #include "ipc/ipc_listener.h"
21 #include "ipc/ipc_sender.h"
22 #include "ui/gfx/gpu_memory_buffer.h"
23 #include "ui/gfx/native_widget_types.h"
24 #include "ui/gl/gl_surface.h"
26 namespace base {
27 class WaitableEvent;
30 namespace gfx {
31 class GLShareGroup;
34 namespace gpu {
35 class SyncPointManager;
36 union ValueState;
37 namespace gles2 {
38 class MailboxManager;
39 class ProgramCache;
40 class ShaderTranslatorCache;
44 namespace IPC {
45 class AttachmentBroker;
46 struct ChannelHandle;
47 class SyncChannel;
50 struct GPUCreateCommandBufferConfig;
52 namespace content {
53 class GpuChannel;
54 class GpuMemoryBufferFactory;
55 class GpuWatchdog;
56 class MessageRouter;
58 // A GpuChannelManager is a thread responsible for issuing rendering commands
59 // managing the lifetimes of GPU channels and forwarding IPC requests from the
60 // browser process to them based on the corresponding renderer ID.
61 class CONTENT_EXPORT GpuChannelManager : public IPC::Listener,
62 public IPC::Sender {
63 public:
64 // |broker| must outlive GpuChannelManager and any channels it creates.
65 GpuChannelManager(MessageRouter* router,
66 GpuWatchdog* watchdog,
67 base::SingleThreadTaskRunner* io_task_runner,
68 base::WaitableEvent* shutdown_event,
69 IPC::SyncChannel* channel,
70 IPC::AttachmentBroker* broker,
71 gpu::SyncPointManager* sync_point_manager,
72 GpuMemoryBufferFactory* gpu_memory_buffer_factory);
73 ~GpuChannelManager() override;
75 // Remove the channel for a particular renderer.
76 void RemoveChannel(int client_id);
78 // Listener overrides.
79 bool OnMessageReceived(const IPC::Message& msg) override;
81 // Sender overrides.
82 bool Send(IPC::Message* msg) override;
84 bool HandleMessagesScheduled();
85 uint64 MessagesProcessed();
87 void LoseAllContexts();
89 int GenerateRouteID();
90 void AddRoute(int32 routing_id, IPC::Listener* listener);
91 void RemoveRoute(int32 routing_id);
93 gpu::gles2::ProgramCache* program_cache();
94 gpu::gles2::ShaderTranslatorCache* shader_translator_cache();
96 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; }
98 GpuChannel* LookupChannel(int32 client_id);
100 gpu::SyncPointManager* sync_point_manager() {
101 return sync_point_manager_;
104 gfx::GLSurface* GetDefaultOffscreenSurface();
106 GpuMemoryBufferFactory* gpu_memory_buffer_factory() {
107 return gpu_memory_buffer_factory_;
110 private:
111 typedef base::ScopedPtrHashMap<int, scoped_ptr<GpuChannel>> GpuChannelMap;
113 // Message handlers.
114 void OnEstablishChannel(int client_id,
115 bool share_context,
116 bool allow_future_sync_points);
117 void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
118 void OnVisibilityChanged(
119 int32 render_view_id, int32 client_id, bool visible);
120 void OnCreateViewCommandBuffer(
121 const gfx::GLSurfaceHandle& window,
122 int32 render_view_id,
123 int32 client_id,
124 const GPUCreateCommandBufferConfig& init_params,
125 int32 route_id);
126 void OnLoadedShader(std::string shader);
127 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id);
128 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id);
129 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
130 int client_id,
131 int32 sync_point);
133 void OnRelinquishResources();
134 void OnResourcesRelinquished();
136 void OnUpdateValueState(int client_id,
137 unsigned int target,
138 const gpu::ValueState& state);
140 void OnLoseAllContexts();
141 void CheckRelinquishGpuResources();
143 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
144 base::WaitableEvent* shutdown_event_;
146 // Used to send and receive IPC messages from the browser process.
147 MessageRouter* const router_;
149 // These objects manage channels to individual renderer processes there is
150 // one channel for each renderer process that has connected to this GPU
151 // process.
152 GpuChannelMap gpu_channels_;
153 scoped_refptr<gfx::GLShareGroup> share_group_;
154 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
155 GpuMemoryManager gpu_memory_manager_;
156 GpuWatchdog* watchdog_;
157 // SyncPointManager guaranteed to outlive running MessageLoop.
158 gpu::SyncPointManager* sync_point_manager_;
159 scoped_ptr<gpu::gles2::ProgramCache> program_cache_;
160 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
161 scoped_refptr<gfx::GLSurface> default_offscreen_surface_;
162 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
163 IPC::SyncChannel* channel_;
164 bool relinquish_resources_pending_;
165 // Must outlive this instance of GpuChannelManager.
166 IPC::AttachmentBroker* attachment_broker_;
168 // Member variables should appear before the WeakPtrFactory, to ensure
169 // that any WeakPtrs to Controller are invalidated before its members
170 // variable's destructors are executed, rendering them invalid.
171 base::WeakPtrFactory<GpuChannelManager> weak_factory_;
173 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
176 } // namespace content
178 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_