Chromium Code Reviews| Index: content/renderer/gpu/gpu_channel_host.h |
| diff --git a/content/renderer/gpu/gpu_channel_host.h b/content/renderer/gpu/gpu_channel_host.h |
| index ec5cd20bf25d29db8892e71bcd03e2f5b199363c..04db4047d02fa3df6b22374b669d3b13ab9c143c 100644 |
| --- a/content/renderer/gpu/gpu_channel_host.h |
| +++ b/content/renderer/gpu/gpu_channel_host.h |
| @@ -10,12 +10,16 @@ |
| #include <vector> |
| #include "base/hash_tables.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/process_util.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/non_thread_safe.h" |
| #include "content/common/gpu/gpu_info.h" |
| #include "content/common/message_router.h" |
| #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" |
| #include "ipc/ipc_channel_handle.h" |
| +#include "ipc/ipc_channel_proxy.h" |
| #include "ipc/ipc_sync_channel.h" |
| #include "ui/gfx/native_widget_types.h" |
| #include "ui/gfx/size.h" |
| @@ -25,10 +29,17 @@ class GpuSurfaceProxy; |
| class GURL; |
| class TransportTextureService; |
| +namespace base { |
| +class MessageLoopProxy; |
| +} |
| + |
| +namespace IPC { |
| +class SyncMessageFilter; |
| +} |
| + |
| // Encapsulates an IPC channel between the renderer and one plugin process. |
| // On the plugin side there's a corresponding GpuChannel. |
| -class GpuChannelHost : public IPC::Channel::Listener, |
| - public IPC::Message::Sender, |
| +class GpuChannelHost : public IPC::Message::Sender, |
| public base::RefCountedThreadSafe<GpuChannelHost> { |
| public: |
| enum State { |
| @@ -58,16 +69,13 @@ class GpuChannelHost : public IPC::Channel::Listener, |
| void set_gpu_info(const GPUInfo& gpu_info); |
| const GPUInfo& gpu_info() const; |
| - // IPC::Channel::Listener implementation: |
| - virtual bool OnMessageReceived(const IPC::Message& msg); |
| - virtual void OnChannelConnected(int32 peer_pid); |
| - virtual void OnChannelError(); |
| + void OnChannelError(); |
| // IPC::Message::Sender implementation: |
| virtual bool Send(IPC::Message* msg); |
| // Create and connect to a command buffer in the GPU process. |
| - CommandBufferProxy* CreateViewCommandBuffer( |
| + scoped_refptr<CommandBufferProxy> CreateViewCommandBuffer( |
| int render_view_id, |
| CommandBufferProxy* share_group, |
| const std::string& allowed_extensions, |
| @@ -75,7 +83,7 @@ class GpuChannelHost : public IPC::Channel::Listener, |
| const GURL& active_url); |
| // Create and connect to a command buffer in the GPU process. |
| - CommandBufferProxy* CreateOffscreenCommandBuffer( |
| + scoped_refptr<CommandBufferProxy> CreateOffscreenCommandBuffer( |
| const gfx::Size& size, |
| CommandBufferProxy* share_group, |
| const std::string& allowed_extensions, |
| @@ -93,7 +101,7 @@ class GpuChannelHost : public IPC::Channel::Listener, |
| void DestroyCommandBuffer(CommandBufferProxy* command_buffer); |
| // Create a surface in the GPU process. Returns null on failure. |
| - GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); |
| + scoped_refptr<GpuSurfaceProxy> CreateOffscreenSurface(const gfx::Size& size); |
| // Destroy a surface in the GPU process. |
| void DestroySurface(GpuSurfaceProxy* surface); |
| @@ -102,26 +110,85 @@ class GpuChannelHost : public IPC::Channel::Listener, |
| return transport_texture_service_.get(); |
| } |
| + class MessageFilter : public IPC::ChannelProxy::MessageFilter, |
| + public base::NonThreadSafe { |
| + public: |
| + MessageFilter(GpuChannelHost* parent); |
| + |
| + class Listener; |
| + void AddRoute(int route_id, |
| + scoped_refptr<Listener> listener, |
| + base::MessageLoopProxy* loop); |
| + void RemoveRoute(int route_id); |
| + |
| + // IPC::ChannelProxy::MessageFilter implementation: |
| + virtual bool OnMessageReceived(const IPC::Message& msg); |
| + virtual void OnChannelError(); |
| + |
| + // An interface for working with cmdbuffer and surface proxies between |
| + // threads. |
| + class Listener : public base::RefCountedThreadSafe<Listener> { |
|
nduca
2011/08/15 21:37:52
Promote this class out of MessageFilter and as eit
|
| + public: |
| + Listener(); |
| + virtual ~Listener(); |
| + |
| + virtual bool OnMessageReceived(const IPC::Message& msg) = 0; |
| + virtual void OnChannelError() = 0; |
| + |
| + // An orphaned listener is one whose parent context (might have) got |
| + // deleted and which should ignore incoming messages. This flag is used |
| + // to handle race conditions in between a context being deleted and |
| + // the io thread referencing the proxy for message routing purposes. |
| + void Orphan() { orphaned_ = true; } |
| + bool IsOrphaned() { return orphaned_; } |
| + private: |
| + bool orphaned_; |
| + }; |
| + |
| + private: |
| + GpuChannelHost* parent_; |
| + |
| + class ListenerInfo { |
|
nduca
2011/08/15 21:37:52
scoped_refptr<MessageLoopProxy> not MessageLoopPro
|
| + public: |
| + ListenerInfo(); |
| + ListenerInfo(base::MessageLoopProxy* loop, |
| + scoped_refptr<Listener> listener); |
| + virtual ~ListenerInfo(); |
| + |
| + base::MessageLoopProxy* loop_; |
| + scoped_refptr<Listener> listener_; |
| + }; |
| + typedef base::hash_map<int, ListenerInfo> ListenerMap; |
| + ListenerMap listeners_; |
| + }; |
| + |
| private: |
| + // Add a route for the current message loop. |
| + void AddRoute(int route_id, scoped_refptr<MessageFilter::Listener> listener); |
| + void RemoveRoute(int route_id); |
| + |
| State state_; |
| GPUInfo gpu_info_; |
| scoped_ptr<IPC::SyncChannel> channel_; |
| + scoped_refptr<MessageFilter> channel_filter_; |
| - // Used to implement message routing functionality to CommandBufferProxy |
| - // objects |
| - MessageRouter router_; |
| - |
| - // Keep track of all the registered CommandBufferProxies to |
| - // inform about OnChannelError |
| - typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; |
| + // Used to look up a proxy from its routing id. |
| + typedef base::hash_map<int, scoped_refptr<CommandBufferProxy> > ProxyMap; |
| ProxyMap proxies_; |
| + // A lock to guard against concurrent access to members like the proxies map |
| + // for calls from contexts that may live on the compositor or main thread. |
| + mutable base::Lock context_lock_; |
| + |
| // This is a MessageFilter to intercept IPC messages related to transport |
| // textures. These messages are routed to TransportTextureHost. |
| scoped_refptr<TransportTextureService> transport_texture_service_; |
| + // A filter for sending messages from thread other than the main thread. |
| + scoped_ptr<IPC::SyncMessageFilter> sync_filter_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
| }; |