cc: Use worker context for one-copy tile initialization.
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager.h
blobf90a76dd530857cbe2950d9f47439009c0ca089c
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 uint64_t client_tracing_id,
116 bool share_context,
117 bool allow_future_sync_points);
118 void OnCloseChannel(const IPC::ChannelHandle& channel_handle);
119 void OnVisibilityChanged(
120 int32 render_view_id, int32 client_id, bool visible);
121 void OnCreateViewCommandBuffer(
122 const gfx::GLSurfaceHandle& window,
123 int32 render_view_id,
124 int32 client_id,
125 const GPUCreateCommandBufferConfig& init_params,
126 int32 route_id);
127 void OnLoadedShader(std::string shader);
128 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id);
129 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id);
130 void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
131 int client_id,
132 int32 sync_point);
134 void OnFinalize();
136 void OnUpdateValueState(int client_id,
137 unsigned int target,
138 const gpu::ValueState& state);
140 void OnLoseAllContexts();
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 // SyncPointManager guaranteed to outlive running MessageLoop.
157 gpu::SyncPointManager* sync_point_manager_;
158 scoped_ptr<gpu::gles2::ProgramCache> program_cache_;
159 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
160 scoped_refptr<gfx::GLSurface> default_offscreen_surface_;
161 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
162 IPC::SyncChannel* channel_;
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_