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/hash_tables.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/gpu_memory_manager.h"
19 #include "ipc/ipc_listener.h"
20 #include "ipc/ipc_sender.h"
21 #include "ui/gfx/native_widget_types.h"
22 #include "ui/gl/gl_surface.h"
43 struct GPUCreateCommandBufferConfig
;
49 class SyncPointManager
;
51 // A GpuChannelManager is a thread responsible for issuing rendering commands
52 // managing the lifetimes of GPU channels and forwarding IPC requests from the
53 // browser process to them based on the corresponding renderer ID.
55 // A GpuChannelManager can also be hosted in the browser process in single
56 // process or in-process GPU modes. In this case there is no corresponding
57 // GpuChildThread and this is the reason the GpuChildThread is referenced via
58 // a pointer to IPC::Sender, which can be implemented by other hosts to send
59 // IPC messages to the browser process IO thread on the GpuChannelManager's
61 class GpuChannelManager
: public IPC::Listener
,
64 GpuChannelManager(ChildThread
* gpu_child_thread
,
65 GpuWatchdog
* watchdog
,
66 base::MessageLoopProxy
* io_message_loop
,
67 base::WaitableEvent
* shutdown_event
);
68 virtual ~GpuChannelManager();
70 // Remove the channel for a particular renderer.
71 void RemoveChannel(int client_id
);
73 // Listener overrides.
74 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
77 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
79 bool HandleMessagesScheduled();
80 uint64
MessagesProcessed();
82 void LoseAllContexts();
84 base::WeakPtrFactory
<GpuChannelManager
> weak_factory_
;
86 int GenerateRouteID();
87 void AddRoute(int32 routing_id
, IPC::Listener
* listener
);
88 void RemoveRoute(int32 routing_id
);
90 gpu::gles2::ProgramCache
* program_cache();
92 GpuMemoryManager
* gpu_memory_manager() { return &gpu_memory_manager_
; }
94 GpuChannel
* LookupChannel(int32 client_id
);
96 SyncPointManager
* sync_point_manager() { return sync_point_manager_
.get(); }
98 gfx::GLSurface
* GetDefaultOffscreenSurface();
101 struct ImageOperation
{
102 ImageOperation(int32 sync_point
, base::Closure callback
);
106 base::Closure callback
;
108 typedef base::hash_map
<int, scoped_refptr
<GpuChannel
> > GpuChannelMap
;
109 typedef std::deque
<ImageOperation
*> ImageOperationQueue
;
112 void OnEstablishChannel(int client_id
, bool share_context
);
113 void OnCloseChannel(const IPC::ChannelHandle
& channel_handle
);
114 void OnVisibilityChanged(
115 int32 render_view_id
, int32 client_id
, bool visible
);
116 void OnCreateViewCommandBuffer(
117 const gfx::GLSurfaceHandle
& window
,
118 int32 render_view_id
,
120 const GPUCreateCommandBufferConfig
& init_params
);
122 gfx::PluginWindowHandle window
, int32 client_id
, int32 image_id
);
124 gfx::PluginWindowHandle window
, int32 client_id
, int32 image_id
);
125 void DeleteImage(int32 client_id
, int32 image_id
);
126 void OnDeleteImage(int32 client_id
, int32 image_id
, int32 sync_point
);
127 void OnDeleteImageSyncPointRetired(ImageOperation
*);
128 void OnLoadedShader(std::string shader
);
130 void OnLoseAllContexts();
132 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_
;
133 base::WaitableEvent
* shutdown_event_
;
135 // Used to send and receive IPC messages from the browser process.
136 ChildThread
* gpu_child_thread_
;
138 // These objects manage channels to individual renderer processes there is
139 // one channel for each renderer process that has connected to this GPU
141 GpuChannelMap gpu_channels_
;
142 scoped_refptr
<gfx::GLShareGroup
> share_group_
;
143 scoped_refptr
<gpu::gles2::MailboxManager
> mailbox_manager_
;
144 GpuMemoryManager gpu_memory_manager_
;
145 GpuWatchdog
* watchdog_
;
146 scoped_refptr
<SyncPointManager
> sync_point_manager_
;
147 scoped_ptr
<gpu::gles2::ProgramCache
> program_cache_
;
148 scoped_refptr
<gfx::GLSurface
> default_offscreen_surface_
;
149 ImageOperationQueue image_operations_
;
151 DISALLOW_COPY_AND_ASSIGN(GpuChannelManager
);
154 } // namespace content
156 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_