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_
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/native_widget_types.h"
23 #include "ui/gl/gl_surface.h"
31 struct GpuMemoryBufferHandle
;
38 class ShaderTranslatorCache
;
46 struct GPUCreateCommandBufferConfig
;
52 class SyncPointManager
;
54 // A GpuChannelManager is a thread responsible for issuing rendering commands
55 // managing the lifetimes of GPU channels and forwarding IPC requests from the
56 // browser process to them based on the corresponding renderer ID.
57 class GpuChannelManager
: public IPC::Listener
,
60 GpuChannelManager(MessageRouter
* router
,
61 GpuWatchdog
* watchdog
,
62 base::MessageLoopProxy
* io_message_loop
,
63 base::WaitableEvent
* shutdown_event
);
64 virtual ~GpuChannelManager();
66 // Remove the channel for a particular renderer.
67 void RemoveChannel(int client_id
);
69 // Listener overrides.
70 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
73 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
75 bool HandleMessagesScheduled();
76 uint64
MessagesProcessed();
78 void LoseAllContexts();
80 base::WeakPtrFactory
<GpuChannelManager
> weak_factory_
;
82 int GenerateRouteID();
83 void AddRoute(int32 routing_id
, IPC::Listener
* listener
);
84 void RemoveRoute(int32 routing_id
);
86 gpu::gles2::ProgramCache
* program_cache();
87 gpu::gles2::ShaderTranslatorCache
* shader_translator_cache();
89 GpuMemoryManager
* gpu_memory_manager() { return &gpu_memory_manager_
; }
91 GpuEventsDispatcher
* gpu_devtools_events_dispatcher() {
92 return &gpu_devtools_events_dispatcher_
;
95 GpuChannel
* LookupChannel(int32 client_id
);
97 SyncPointManager
* sync_point_manager() { return sync_point_manager_
.get(); }
99 gfx::GLSurface
* GetDefaultOffscreenSurface();
102 struct ImageOperation
{
103 ImageOperation(int32 sync_point
, base::Closure callback
);
107 base::Closure callback
;
109 typedef base::ScopedPtrHashMap
<int, GpuChannel
> GpuChannelMap
;
110 typedef std::deque
<ImageOperation
*> ImageOperationQueue
;
113 void OnEstablishChannel(int client_id
,
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
,
123 const GPUCreateCommandBufferConfig
& init_params
,
126 gfx::PluginWindowHandle window
, int32 client_id
, int32 image_id
);
128 gfx::PluginWindowHandle window
, int32 client_id
, int32 image_id
);
129 void DeleteImage(int32 client_id
, int32 image_id
);
130 void OnDeleteImage(int32 client_id
, int32 image_id
, int32 sync_point
);
131 void OnDeleteImageSyncPointRetired(ImageOperation
*);
132 void OnLoadedShader(std::string shader
);
133 void OnCreateGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle
& handle
,
134 const gfx::Size
& size
,
135 unsigned internalformat
,
137 void OnDestroyGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle
& handle
,
140 void OnLoseAllContexts();
142 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_
;
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
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 GpuEventsDispatcher gpu_devtools_events_dispatcher_
;
156 GpuWatchdog
* watchdog_
;
157 scoped_refptr
<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 ImageOperationQueue image_operations_
;
163 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager
);
166 } // namespace content
168 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_