[memory-inspector] UI fixes + bump version number for release.
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager.h
blobbe994134ec09605e3e763ea2e54624be7c06534f
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 "base/message_loop/message_loop_proxy.h"
17 #include "build/build_config.h"
18 #include "content/common/content_export.h"
19 #include "content/common/content_param_traits.h"
20 #include "content/common/gpu/devtools_gpu_instrumentation.h"
21 #include "content/common/gpu/gpu_memory_manager.h"
22 #include "ipc/ipc_listener.h"
23 #include "ipc/ipc_sender.h"
24 #include "ui/gfx/gpu_memory_buffer.h"
25 #include "ui/gfx/native_widget_types.h"
26 #include "ui/gl/gl_surface.h"
28 namespace base {
29 class WaitableEvent;
32 namespace gfx {
33 class GLShareGroup;
34 struct GpuMemoryBufferHandle;
37 namespace gpu {
38 class SyncPointManager;
39 union ValueState;
40 namespace gles2 {
41 class MailboxManager;
42 class ProgramCache;
43 class ShaderTranslatorCache;
47 namespace IPC {
48 struct ChannelHandle;
49 class SyncChannel;
50 class MessageFilter;
53 struct GPUCreateCommandBufferConfig;
55 namespace content {
56 class GpuChannel;
57 class GpuMemoryBufferFactory;
58 class GpuWatchdog;
59 class MessageRouter;
61 // A GpuChannelManager is a thread responsible for issuing rendering commands
62 // managing the lifetimes of GPU channels and forwarding IPC requests from the
63 // browser process to them based on the corresponding renderer ID.
64 class CONTENT_EXPORT GpuChannelManager : public IPC::Listener,
65 public IPC::Sender {
66 public:
67 GpuChannelManager(MessageRouter* router,
68 GpuWatchdog* watchdog,
69 base::MessageLoopProxy* io_message_loop,
70 base::WaitableEvent* shutdown_event,
71 IPC::SyncChannel* channel);
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 GpuEventsDispatcher* gpu_devtools_events_dispatcher() {
98 return &gpu_devtools_events_dispatcher_;
101 GpuChannel* LookupChannel(int32 client_id);
103 gpu::SyncPointManager* sync_point_manager() {
104 return sync_point_manager_.get();
107 gfx::GLSurface* GetDefaultOffscreenSurface();
109 GpuMemoryBufferFactory* gpu_memory_buffer_factory() {
110 return gpu_memory_buffer_factory_.get();
113 private:
114 typedef base::ScopedPtrHashMap<int, GpuChannel> GpuChannelMap;
116 // Message handlers.
117 void OnEstablishChannel(int client_id,
118 bool share_context,
119 bool allow_future_sync_points);
120 void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
121 void OnVisibilityChanged(
122 int32 render_view_id, int32 client_id, bool visible);
123 void OnCreateViewCommandBuffer(
124 const gfx::GLSurfaceHandle& window,
125 int32 render_view_id,
126 int32 client_id,
127 const GPUCreateCommandBufferConfig& init_params,
128 int32 route_id);
129 void OnLoadedShader(std::string shader);
130 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id);
131 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id);
132 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
133 int client_id,
134 int32 sync_point);
136 void OnRelinquishResources();
137 void OnResourcesRelinquished();
139 void OnUpdateValueState(int client_id,
140 unsigned int target,
141 const gpu::ValueState& state);
143 void OnLoseAllContexts();
144 void CheckRelinquishGpuResources();
146 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
147 base::WaitableEvent* shutdown_event_;
149 // Used to send and receive IPC messages from the browser process.
150 MessageRouter* const router_;
152 // These objects manage channels to individual renderer processes there is
153 // one channel for each renderer process that has connected to this GPU
154 // process.
155 GpuChannelMap gpu_channels_;
156 scoped_refptr<gfx::GLShareGroup> share_group_;
157 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
158 GpuMemoryManager gpu_memory_manager_;
159 GpuEventsDispatcher gpu_devtools_events_dispatcher_;
160 GpuWatchdog* watchdog_;
161 scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
162 scoped_ptr<gpu::gles2::ProgramCache> program_cache_;
163 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
164 scoped_refptr<gfx::GLSurface> default_offscreen_surface_;
165 scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
166 IPC::SyncChannel* channel_;
167 scoped_refptr<IPC::MessageFilter> filter_;
168 bool relinquish_resources_pending_;
170 // Member variables should appear before the WeakPtrFactory, to ensure
171 // that any WeakPtrs to Controller are invalidated before its members
172 // variable's destructors are executed, rendering them invalid.
173 base::WeakPtrFactory<GpuChannelManager> weak_factory_;
175 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
178 } // namespace content
180 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_