Add P2PDatagramSocket and P2PStreamSocket interfaces.
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager.h
blob733081b4b45e4d555bd60e8fa5665d09b8372211
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 GpuMemoryBufferFactory* gpu_memory_buffer_factory);
72 ~GpuChannelManager() override;
74 // Remove the channel for a particular renderer.
75 void RemoveChannel(int client_id);
77 // Listener overrides.
78 bool OnMessageReceived(const IPC::Message& msg) override;
80 // Sender overrides.
81 bool Send(IPC::Message* msg) override;
83 bool HandleMessagesScheduled();
84 uint64 MessagesProcessed();
86 void LoseAllContexts();
88 int GenerateRouteID();
89 void AddRoute(int32 routing_id, IPC::Listener* listener);
90 void RemoveRoute(int32 routing_id);
92 gpu::gles2::ProgramCache* program_cache();
93 gpu::gles2::ShaderTranslatorCache* shader_translator_cache();
95 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; }
97 GpuChannel* LookupChannel(int32 client_id);
99 gpu::SyncPointManager* sync_point_manager() {
100 return sync_point_manager_.get();
103 gfx::GLSurface* GetDefaultOffscreenSurface();
105 GpuMemoryBufferFactory* gpu_memory_buffer_factory() {
106 return gpu_memory_buffer_factory_;
109 private:
110 typedef base::ScopedPtrHashMap<int, scoped_ptr<GpuChannel>> GpuChannelMap;
112 // Message handlers.
113 void OnEstablishChannel(int client_id,
114 bool share_context,
115 bool allow_future_sync_points);
116 void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
117 void OnVisibilityChanged(
118 int32 render_view_id, int32 client_id, bool visible);
119 void OnCreateViewCommandBuffer(
120 const gfx::GLSurfaceHandle& window,
121 int32 render_view_id,
122 int32 client_id,
123 const GPUCreateCommandBufferConfig& init_params,
124 int32 route_id);
125 void OnLoadedShader(std::string shader);
126 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id);
127 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id);
128 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
129 int client_id,
130 int32 sync_point);
132 void OnRelinquishResources();
133 void OnResourcesRelinquished();
135 void OnUpdateValueState(int client_id,
136 unsigned int target,
137 const gpu::ValueState& state);
139 void OnLoseAllContexts();
140 void CheckRelinquishGpuResources();
142 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
143 base::WaitableEvent* shutdown_event_;
145 // Used to send and receive IPC messages from the browser process.
146 MessageRouter* const router_;
148 // These objects manage channels to individual renderer processes there is
149 // one channel for each renderer process that has connected to this GPU
150 // process.
151 GpuChannelMap gpu_channels_;
152 scoped_refptr<gfx::GLShareGroup> share_group_;
153 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
154 GpuMemoryManager gpu_memory_manager_;
155 GpuWatchdog* watchdog_;
156 scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
157 scoped_ptr<gpu::gles2::ProgramCache> program_cache_;
158 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
159 scoped_refptr<gfx::GLSurface> default_offscreen_surface_;
160 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
161 IPC::SyncChannel* channel_;
162 bool relinquish_resources_pending_;
163 // Must outlive this instance of GpuChannelManager.
164 IPC::AttachmentBroker* attachment_broker_;
166 // Member variables should appear before the WeakPtrFactory, to ensure
167 // that any WeakPtrs to Controller are invalidated before its members
168 // variable's destructors are executed, rendering them invalid.
169 base::WeakPtrFactory<GpuChannelManager> weak_factory_;
171 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
174 } // namespace content
176 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_