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

Side by Side 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: MessageLoop::current() -> MessageLoopProxy::current() 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/gpu/command_buffer_proxy.cc ('k') | content/renderer/gpu/gpu_channel_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ 5 #ifndef CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_
6 #define CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ 6 #define CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/process_util.h" 15 #include "base/process_util.h"
16 #include "base/synchronization/lock.h"
17 #include "base/threading/non_thread_safe.h"
15 #include "content/common/gpu/gpu_info.h" 18 #include "content/common/gpu/gpu_info.h"
16 #include "content/common/message_router.h" 19 #include "content/common/message_router.h"
17 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" 20 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h"
18 #include "ipc/ipc_channel_handle.h" 21 #include "ipc/ipc_channel_handle.h"
22 #include "ipc/ipc_channel_proxy.h"
19 #include "ipc/ipc_sync_channel.h" 23 #include "ipc/ipc_sync_channel.h"
20 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
21 #include "ui/gfx/size.h" 25 #include "ui/gfx/size.h"
22 26
23 class CommandBufferProxy; 27 class CommandBufferProxy;
24 class GpuSurfaceProxy; 28 class GpuSurfaceProxy;
25 class GURL; 29 class GURL;
26 class TransportTextureService; 30 class TransportTextureService;
27 31
32 namespace base {
33 class MessageLoopProxy;
34 }
35
36 namespace IPC {
37 class SyncMessageFilter;
38 }
39
28 // Encapsulates an IPC channel between the renderer and one plugin process. 40 // Encapsulates an IPC channel between the renderer and one plugin process.
29 // On the plugin side there's a corresponding GpuChannel. 41 // On the plugin side there's a corresponding GpuChannel.
30 class GpuChannelHost : public IPC::Channel::Listener, 42 class GpuChannelHost : public IPC::Message::Sender,
31 public IPC::Message::Sender,
32 public base::RefCountedThreadSafe<GpuChannelHost> { 43 public base::RefCountedThreadSafe<GpuChannelHost> {
33 public: 44 public:
34 enum State { 45 enum State {
35 // Not yet connected. 46 // Not yet connected.
36 kUnconnected, 47 kUnconnected,
37 // Ready to use. 48 // Ready to use.
38 kConnected, 49 kConnected,
39 // An error caused the host to become disconnected. Recreate channel to 50 // An error caused the host to become disconnected. Recreate channel to
40 // reestablish connection. 51 // reestablish connection.
41 kLost 52 kLost
42 }; 53 };
43 54
44 // Called on the render thread 55 // Called on the render thread
45 GpuChannelHost(); 56 GpuChannelHost();
46 virtual ~GpuChannelHost(); 57 virtual ~GpuChannelHost();
47 58
48 // Connect to GPU process channel. 59 // Connect to GPU process channel.
49 void Connect(const IPC::ChannelHandle& channel_handle, 60 void Connect(const IPC::ChannelHandle& channel_handle,
50 base::ProcessHandle renderer_process_for_gpu); 61 base::ProcessHandle renderer_process_for_gpu);
51 62
52 State state() const { return state_; } 63 State state() const { return state_; }
53 64
54 // Change state to kLost. 65 // Change state to kLost.
55 void SetStateLost(); 66 void SetStateLost();
56 67
57 // The GPU stats reported by the GPU process. 68 // The GPU stats reported by the GPU process.
58 void set_gpu_info(const GPUInfo& gpu_info); 69 void set_gpu_info(const GPUInfo& gpu_info);
59 const GPUInfo& gpu_info() const; 70 const GPUInfo& gpu_info() const;
60 71
61 // IPC::Channel::Listener implementation: 72 void OnChannelError();
62 virtual bool OnMessageReceived(const IPC::Message& msg);
63 virtual void OnChannelConnected(int32 peer_pid);
64 virtual void OnChannelError();
65 73
66 // IPC::Message::Sender implementation: 74 // IPC::Message::Sender implementation:
67 virtual bool Send(IPC::Message* msg); 75 virtual bool Send(IPC::Message* msg);
68 76
69 // Create and connect to a command buffer in the GPU process. 77 // Create and connect to a command buffer in the GPU process.
70 CommandBufferProxy* CreateViewCommandBuffer( 78 scoped_refptr<CommandBufferProxy> CreateViewCommandBuffer(
71 int render_view_id, 79 int render_view_id,
72 CommandBufferProxy* share_group, 80 CommandBufferProxy* share_group,
73 const std::string& allowed_extensions, 81 const std::string& allowed_extensions,
74 const std::vector<int32>& attribs, 82 const std::vector<int32>& attribs,
75 const GURL& active_url); 83 const GURL& active_url);
76 84
77 // Create and connect to a command buffer in the GPU process. 85 // Create and connect to a command buffer in the GPU process.
78 CommandBufferProxy* CreateOffscreenCommandBuffer( 86 scoped_refptr<CommandBufferProxy> CreateOffscreenCommandBuffer(
79 const gfx::Size& size, 87 const gfx::Size& size,
80 CommandBufferProxy* share_group, 88 CommandBufferProxy* share_group,
81 const std::string& allowed_extensions, 89 const std::string& allowed_extensions,
82 const std::vector<int32>& attribs, 90 const std::vector<int32>& attribs,
83 const GURL& active_url); 91 const GURL& active_url);
84 92
85 // Creates a video decoder in the GPU process. 93 // Creates a video decoder in the GPU process.
86 // Returned pointer is owned by the CommandBufferProxy for |route_id|. 94 // Returned pointer is owned by the CommandBufferProxy for |route_id|.
87 GpuVideoDecodeAcceleratorHost* CreateVideoDecoder( 95 GpuVideoDecodeAcceleratorHost* CreateVideoDecoder(
88 int command_buffer_route_id, 96 int command_buffer_route_id,
89 const std::vector<int32>& configs, 97 const std::vector<int32>& configs,
90 media::VideoDecodeAccelerator::Client* client); 98 media::VideoDecodeAccelerator::Client* client);
91 99
92 // Destroy a command buffer created by this channel. 100 // Destroy a command buffer created by this channel.
93 void DestroyCommandBuffer(CommandBufferProxy* command_buffer); 101 void DestroyCommandBuffer(CommandBufferProxy* command_buffer);
94 102
95 // Create a surface in the GPU process. Returns null on failure. 103 // Create a surface in the GPU process. Returns null on failure.
96 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); 104 scoped_refptr<GpuSurfaceProxy> CreateOffscreenSurface(const gfx::Size& size);
97 105
98 // Destroy a surface in the GPU process. 106 // Destroy a surface in the GPU process.
99 void DestroySurface(GpuSurfaceProxy* surface); 107 void DestroySurface(GpuSurfaceProxy* surface);
100 108
101 TransportTextureService* transport_texture_service() { 109 TransportTextureService* transport_texture_service() {
102 return transport_texture_service_.get(); 110 return transport_texture_service_.get();
103 } 111 }
104 112
113 class MessageFilter : public IPC::ChannelProxy::MessageFilter,
114 public base::NonThreadSafe {
115 public:
116 MessageFilter(GpuChannelHost* parent);
117
118 class Listener;
119 void AddRoute(int route_id,
120 scoped_refptr<Listener> listener,
121 base::MessageLoopProxy* loop);
122 void RemoveRoute(int route_id);
123
124 // IPC::ChannelProxy::MessageFilter implementation:
125 virtual bool OnMessageReceived(const IPC::Message& msg);
126 virtual void OnChannelError();
127
128 // An interface for working with cmdbuffer and surface proxies between
129 // threads.
130 class Listener : public base::RefCountedThreadSafe<Listener> {
nduca 2011/08/15 21:37:52 Promote this class out of MessageFilter and as eit
131 public:
132 Listener();
133 virtual ~Listener();
134
135 virtual bool OnMessageReceived(const IPC::Message& msg) = 0;
136 virtual void OnChannelError() = 0;
137
138 // An orphaned listener is one whose parent context (might have) got
139 // deleted and which should ignore incoming messages. This flag is used
140 // to handle race conditions in between a context being deleted and
141 // the io thread referencing the proxy for message routing purposes.
142 void Orphan() { orphaned_ = true; }
143 bool IsOrphaned() { return orphaned_; }
144 private:
145 bool orphaned_;
146 };
147
148 private:
149 GpuChannelHost* parent_;
150
151 class ListenerInfo {
nduca 2011/08/15 21:37:52 scoped_refptr<MessageLoopProxy> not MessageLoopPro
152 public:
153 ListenerInfo();
154 ListenerInfo(base::MessageLoopProxy* loop,
155 scoped_refptr<Listener> listener);
156 virtual ~ListenerInfo();
157
158 base::MessageLoopProxy* loop_;
159 scoped_refptr<Listener> listener_;
160 };
161 typedef base::hash_map<int, ListenerInfo> ListenerMap;
162 ListenerMap listeners_;
163 };
164
105 private: 165 private:
166 // Add a route for the current message loop.
167 void AddRoute(int route_id, scoped_refptr<MessageFilter::Listener> listener);
168 void RemoveRoute(int route_id);
169
106 State state_; 170 State state_;
107 171
108 GPUInfo gpu_info_; 172 GPUInfo gpu_info_;
109 173
110 scoped_ptr<IPC::SyncChannel> channel_; 174 scoped_ptr<IPC::SyncChannel> channel_;
175 scoped_refptr<MessageFilter> channel_filter_;
111 176
112 // Used to implement message routing functionality to CommandBufferProxy 177 // Used to look up a proxy from its routing id.
113 // objects 178 typedef base::hash_map<int, scoped_refptr<CommandBufferProxy> > ProxyMap;
114 MessageRouter router_; 179 ProxyMap proxies_;
115 180
116 // Keep track of all the registered CommandBufferProxies to 181 // A lock to guard against concurrent access to members like the proxies map
117 // inform about OnChannelError 182 // for calls from contexts that may live on the compositor or main thread.
118 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; 183 mutable base::Lock context_lock_;
119 ProxyMap proxies_;
120 184
121 // This is a MessageFilter to intercept IPC messages related to transport 185 // This is a MessageFilter to intercept IPC messages related to transport
122 // textures. These messages are routed to TransportTextureHost. 186 // textures. These messages are routed to TransportTextureHost.
123 scoped_refptr<TransportTextureService> transport_texture_service_; 187 scoped_refptr<TransportTextureService> transport_texture_service_;
124 188
189 // A filter for sending messages from thread other than the main thread.
190 scoped_ptr<IPC::SyncMessageFilter> sync_filter_;
191
125 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); 192 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
126 }; 193 };
127 194
128 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ 195 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_
OLDNEW
« no previous file with comments | « content/renderer/gpu/command_buffer_proxy.cc ('k') | content/renderer/gpu/gpu_channel_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698