Mac Remote CoreAnimation: Fix flashing at tab-switch
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager.h
blob1b5f6687e38e34fb183ef20751c2910e8801107c
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/gpu/devtools_gpu_instrumentation.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;
32 struct GpuMemoryBufferHandle;
35 namespace gpu {
36 class SyncPointManager;
37 namespace gles2 {
38 class MailboxManager;
39 class ProgramCache;
40 class ShaderTranslatorCache;
44 namespace IPC {
45 struct ChannelHandle;
46 class SyncChannel;
47 class MessageFilter;
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 GpuChannelManager : public IPC::Listener,
62 public IPC::Sender {
63 public:
64 GpuChannelManager(MessageRouter* router,
65 GpuWatchdog* watchdog,
66 base::MessageLoopProxy* io_message_loop,
67 base::WaitableEvent* shutdown_event,
68 IPC::SyncChannel* channel);
69 ~GpuChannelManager() override;
71 // Remove the channel for a particular renderer.
72 void RemoveChannel(int client_id);
74 // Listener overrides.
75 bool OnMessageReceived(const IPC::Message& msg) override;
77 // Sender overrides.
78 bool Send(IPC::Message* msg) override;
80 bool HandleMessagesScheduled();
81 uint64 MessagesProcessed();
83 void LoseAllContexts();
85 int GenerateRouteID();
86 void AddRoute(int32 routing_id, IPC::Listener* listener);
87 void RemoveRoute(int32 routing_id);
89 gpu::gles2::ProgramCache* program_cache();
90 gpu::gles2::ShaderTranslatorCache* shader_translator_cache();
92 GpuMemoryManager* gpu_memory_manager() { return &gpu_memory_manager_; }
94 GpuEventsDispatcher* gpu_devtools_events_dispatcher() {
95 return &gpu_devtools_events_dispatcher_;
98 GpuChannel* LookupChannel(int32 client_id);
100 gpu::SyncPointManager* sync_point_manager() {
101 return sync_point_manager_.get();
104 gfx::GLSurface* GetDefaultOffscreenSurface();
106 GpuMemoryBufferFactory* gpu_memory_buffer_factory() {
107 return gpu_memory_buffer_factory_.get();
110 private:
111 typedef base::ScopedPtrHashMap<int, 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::GpuMemoryBufferType type,
128 gfx::GpuMemoryBufferId id,
129 int client_id);
130 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferType type,
131 gfx::GpuMemoryBufferId id,
132 int client_id);
133 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
134 gfx::GpuMemoryBufferId id,
135 int client_id,
136 int32 sync_point);
138 void OnLoseAllContexts();
140 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
141 base::WaitableEvent* shutdown_event_;
143 // Used to send and receive IPC messages from the browser process.
144 MessageRouter* const router_;
146 // These objects manage channels to individual renderer processes there is
147 // one channel for each renderer process that has connected to this GPU
148 // process.
149 GpuChannelMap gpu_channels_;
150 scoped_refptr<gfx::GLShareGroup> share_group_;
151 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
152 GpuMemoryManager gpu_memory_manager_;
153 GpuEventsDispatcher gpu_devtools_events_dispatcher_;
154 GpuWatchdog* watchdog_;
155 scoped_refptr<gpu::SyncPointManager> sync_point_manager_;
156 scoped_ptr<gpu::gles2::ProgramCache> program_cache_;
157 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
158 scoped_refptr<gfx::GLSurface> default_offscreen_surface_;
159 scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
160 IPC::SyncChannel* channel_;
161 scoped_refptr<IPC::MessageFilter> filter_;
163 // Member variables should appear before the WeakPtrFactory, to ensure
164 // that any WeakPtrs to Controller are invalidated before its members
165 // variable's destructors are executed, rendering them invalid.
166 base::WeakPtrFactory<GpuChannelManager> weak_factory_;
168 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
171 } // namespace content
173 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_