Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1036)

Unified Diff: content/renderer/gpu/gpu_channel_host.h

Issue 7634019: Allow cmdbuffer creation from compositor thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b8b571f83ffcf9cc216c0d21aaf2a855702e1cc1 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,42 @@ class GpuSurfaceProxy;
class GURL;
class TransportTextureService;
+namespace base {
+class MessageLoopProxy;
+}
+
+namespace IPC {
+class SyncMessageFilter;
+}
+
+// An interface for working with cmdbuffer and surface proxies between
+// threads.
+class GpuChannelListener :
+ public base::RefCountedThreadSafe<GpuChannelListener> {
+ public:
+ GpuChannelListener();
+ virtual ~GpuChannelListener();
+
+ virtual bool OnMessageReceived(const IPC::Message& msg) = 0;
+ virtual void OnChannelError() = 0;
+
+ scoped_refptr<base::MessageLoopProxy> loop() { return loop_; }
+
+ // 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_;
+ scoped_refptr<base::MessageLoopProxy> loop_;
+};
+
// 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 +94,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 +108,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 +126,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 +135,53 @@ class GpuChannelHost : public IPC::Channel::Listener,
return transport_texture_service_.get();
}
+ class MessageFilter : public IPC::ChannelProxy::MessageFilter,
+ public base::NonThreadSafe {
+ public:
+ MessageFilter(GpuChannelHost* parent);
+ virtual ~MessageFilter();
+
+ void AddRoute(int route_id, scoped_refptr<GpuChannelListener> listener);
+ void RemoveRoute(int route_id);
+
+ // IPC::ChannelProxy::MessageFilter implementation:
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelError();
+
+ private:
+ GpuChannelHost* parent_;
+
+ typedef base::hash_map<int, scoped_refptr<GpuChannelListener> > ListenerMap;
+ ListenerMap listeners_;
+ };
+
private:
+ // Add a route for the current message loop.
+ void AddRoute(int route_id, scoped_refptr<GpuChannelListener> 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);
};

Powered by Google App Engine
This is Rietveld 408576698