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

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: nest class 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"
15 #include "base/memory/weak_ptr.h"
14 #include "base/process_util.h" 16 #include "base/process_util.h"
17 #include "base/synchronization/lock.h"
18 #include "base/threading/non_thread_safe.h"
15 #include "content/common/gpu/gpu_info.h" 19 #include "content/common/gpu/gpu_info.h"
16 #include "content/common/message_router.h" 20 #include "content/common/message_router.h"
17 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" 21 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h"
18 #include "ipc/ipc_channel_handle.h" 22 #include "ipc/ipc_channel_handle.h"
23 #include "ipc/ipc_channel_proxy.h"
19 #include "ipc/ipc_sync_channel.h" 24 #include "ipc/ipc_sync_channel.h"
20 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
21 #include "ui/gfx/size.h" 26 #include "ui/gfx/size.h"
22 27
23 class CommandBufferProxy; 28 class CommandBufferProxy;
24 class GpuSurfaceProxy; 29 class GpuSurfaceProxy;
25 class GURL; 30 class GURL;
26 class TransportTextureService; 31 class TransportTextureService;
27 32
33 namespace base {
34 class MessageLoopProxy;
35 }
36
37 namespace IPC {
38 class SyncMessageFilter;
39 }
40
28 // Encapsulates an IPC channel between the renderer and one plugin process. 41 // Encapsulates an IPC channel between the renderer and one plugin process.
29 // On the plugin side there's a corresponding GpuChannel. 42 // On the plugin side there's a corresponding GpuChannel.
30 class GpuChannelHost : public IPC::Channel::Listener, 43 class GpuChannelHost : public IPC::Message::Sender,
31 public IPC::Message::Sender,
32 public base::RefCountedThreadSafe<GpuChannelHost> { 44 public base::RefCountedThreadSafe<GpuChannelHost> {
33 public: 45 public:
34 enum State { 46 enum State {
35 // Not yet connected. 47 // Not yet connected.
36 kUnconnected, 48 kUnconnected,
37 // Ready to use. 49 // Ready to use.
38 kConnected, 50 kConnected,
39 // An error caused the host to become disconnected. Recreate channel to 51 // An error caused the host to become disconnected. Recreate channel to
40 // reestablish connection. 52 // reestablish connection.
41 kLost 53 kLost
42 }; 54 };
43 55
44 // Called on the render thread 56 // Called on the render thread
45 GpuChannelHost(); 57 GpuChannelHost();
46 virtual ~GpuChannelHost(); 58 virtual ~GpuChannelHost();
47 59
48 // Connect to GPU process channel. 60 // Connect to GPU process channel.
49 void Connect(const IPC::ChannelHandle& channel_handle, 61 void Connect(const IPC::ChannelHandle& channel_handle,
50 base::ProcessHandle renderer_process_for_gpu); 62 base::ProcessHandle renderer_process_for_gpu);
51 63
52 State state() const { return state_; } 64 State state() const { return state_; }
53 65
54 // Change state to kLost. 66 // Change state to kLost.
55 void SetStateLost(); 67 void SetStateLost();
56 68
57 // The GPU stats reported by the GPU process. 69 // The GPU stats reported by the GPU process.
58 void set_gpu_info(const GPUInfo& gpu_info); 70 void set_gpu_info(const GPUInfo& gpu_info);
59 const GPUInfo& gpu_info() const; 71 const GPUInfo& gpu_info() const;
60 72
61 // IPC::Channel::Listener implementation: 73 void OnChannelError();
62 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
63 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
64 virtual void OnChannelError() OVERRIDE;
65 74
66 // IPC::Message::Sender implementation: 75 // IPC::Message::Sender implementation:
67 virtual bool Send(IPC::Message* msg); 76 virtual bool Send(IPC::Message* msg);
68 77
69 // Create and connect to a command buffer in the GPU process. 78 // Create and connect to a command buffer in the GPU process.
70 CommandBufferProxy* CreateViewCommandBuffer( 79 CommandBufferProxy* CreateViewCommandBuffer(
71 int render_view_id, 80 int render_view_id,
72 CommandBufferProxy* share_group, 81 CommandBufferProxy* share_group,
73 const std::string& allowed_extensions, 82 const std::string& allowed_extensions,
74 const std::vector<int32>& attribs, 83 const std::vector<int32>& attribs,
(...skipping 20 matching lines...) Expand all
95 // Create a surface in the GPU process. Returns null on failure. 104 // Create a surface in the GPU process. Returns null on failure.
96 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); 105 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size);
97 106
98 // Destroy a surface in the GPU process. 107 // Destroy a surface in the GPU process.
99 void DestroySurface(GpuSurfaceProxy* surface); 108 void DestroySurface(GpuSurfaceProxy* surface);
100 109
101 TransportTextureService* transport_texture_service() { 110 TransportTextureService* transport_texture_service() {
102 return transport_texture_service_.get(); 111 return transport_texture_service_.get();
103 } 112 }
104 113
105 // Called to add/remove a listener for a particular message routing ID. 114 // Add a route for the current message loop.
106 void AddRoute(int32 route_id, IPC::Channel::Listener* listener); 115 void AddRoute(int route_id, base::WeakPtr<IPC::Channel::Listener> listener);
107 void RemoveRoute(int32 route_id); 116 void RemoveRoute(int route_id);
108 117
109 private: 118 private:
119 // An shim class for working with listeners between threads.
120 // It is used to post a task to the thread that owns the listener,
121 // and where it's safe to dereference the weak pointer.
122 class Listener :
123 public base::RefCountedThreadSafe<Listener> {
124 public:
125 Listener(base::WeakPtr<IPC::Channel::Listener> listener,
126 scoped_refptr<base::MessageLoopProxy> loop);
127 virtual ~Listener();
128
129 void DispatchMessage(const IPC::Message& msg);
130 void DispatchError();
131
132 scoped_refptr<base::MessageLoopProxy> loop() { return loop_; }
133
134 private:
135 base::WeakPtr<IPC::Channel::Listener> listener_;
136 scoped_refptr<base::MessageLoopProxy> loop_;
137 };
138
139 // A filter used internally to route incoming messages from the IO thread
140 // to the correct message loop.
141 class MessageFilter : public IPC::ChannelProxy::MessageFilter,
142 public base::NonThreadSafe {
143 public:
144 MessageFilter(GpuChannelHost* parent);
145 virtual ~MessageFilter();
146
147 void AddRoute(int route_id,
148 base::WeakPtr<IPC::Channel::Listener> listener,
149 scoped_refptr<base::MessageLoopProxy> loop);
150 void RemoveRoute(int route_id);
151
152 // IPC::ChannelProxy::MessageFilter implementation:
153 virtual bool OnMessageReceived(const IPC::Message& msg);
154 virtual void OnChannelError();
155
156 private:
157 GpuChannelHost* parent_;
158
159 typedef base::hash_map<int,
160 scoped_refptr<GpuChannelHost::Listener> > ListenerMap;
161 ListenerMap listeners_;
162 };
163
110 State state_; 164 State state_;
111 165
112 GPUInfo gpu_info_; 166 GPUInfo gpu_info_;
113 167
114 scoped_ptr<IPC::SyncChannel> channel_; 168 scoped_ptr<IPC::SyncChannel> channel_;
169 scoped_refptr<MessageFilter> channel_filter_;
115 170
116 // Used to implement message routing functionality to CommandBufferProxy 171 // Used to look up a proxy from its routing id.
117 // objects
118 MessageRouter router_;
119
120 // Keep track of all the registered CommandBufferProxies to
121 // inform about OnChannelError
122 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; 172 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap;
123 ProxyMap proxies_; 173 ProxyMap proxies_;
124 174
175 // A lock to guard against concurrent access to members like the proxies map
176 // for calls from contexts that may live on the compositor or main thread.
177 mutable base::Lock context_lock_;
178
125 // This is a MessageFilter to intercept IPC messages related to transport 179 // This is a MessageFilter to intercept IPC messages related to transport
126 // textures. These messages are routed to TransportTextureHost. 180 // textures. These messages are routed to TransportTextureHost.
127 scoped_refptr<TransportTextureService> transport_texture_service_; 181 scoped_refptr<TransportTextureService> transport_texture_service_;
128 182
183 // A filter for sending messages from thread other than the main thread.
184 scoped_refptr<IPC::SyncMessageFilter> sync_filter_;
185
129 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); 186 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
130 }; 187 };
131 188
132 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ 189 #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