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

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: 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 unified diff | Download patch | Annotate | Revision Log
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
40 // An interface for working with cmdbuffer and surface proxies between
41 // threads.
42 class GpuChannelListener :
43 public base::RefCountedThreadSafe<GpuChannelListener> {
44 public:
45 GpuChannelListener();
46 virtual ~GpuChannelListener();
47
48 virtual bool OnMessageReceived(const IPC::Message& msg) = 0;
49 virtual void OnChannelError() = 0;
50
51 scoped_refptr<base::MessageLoopProxy> loop() { return loop_; }
52
53 // An orphaned listener is one whose parent context (might have) got
54 // deleted and which should ignore incoming messages. This flag is used
55 // to handle race conditions in between a context being deleted and
56 // the io thread referencing the proxy for message routing purposes.
57 void Orphan() { orphaned_ = true; }
58 bool IsOrphaned() { return orphaned_; }
59
60 private:
61 bool orphaned_;
62 scoped_refptr<base::MessageLoopProxy> loop_;
63 };
64
28 // Encapsulates an IPC channel between the renderer and one plugin process. 65 // Encapsulates an IPC channel between the renderer and one plugin process.
29 // On the plugin side there's a corresponding GpuChannel. 66 // On the plugin side there's a corresponding GpuChannel.
30 class GpuChannelHost : public IPC::Channel::Listener, 67 class GpuChannelHost : public IPC::Message::Sender,
31 public IPC::Message::Sender,
32 public base::RefCountedThreadSafe<GpuChannelHost> { 68 public base::RefCountedThreadSafe<GpuChannelHost> {
33 public: 69 public:
34 enum State { 70 enum State {
35 // Not yet connected. 71 // Not yet connected.
36 kUnconnected, 72 kUnconnected,
37 // Ready to use. 73 // Ready to use.
38 kConnected, 74 kConnected,
39 // An error caused the host to become disconnected. Recreate channel to 75 // An error caused the host to become disconnected. Recreate channel to
40 // reestablish connection. 76 // reestablish connection.
41 kLost 77 kLost
42 }; 78 };
43 79
44 // Called on the render thread 80 // Called on the render thread
45 GpuChannelHost(); 81 GpuChannelHost();
46 virtual ~GpuChannelHost(); 82 virtual ~GpuChannelHost();
47 83
48 // Connect to GPU process channel. 84 // Connect to GPU process channel.
49 void Connect(const IPC::ChannelHandle& channel_handle, 85 void Connect(const IPC::ChannelHandle& channel_handle,
50 base::ProcessHandle renderer_process_for_gpu); 86 base::ProcessHandle renderer_process_for_gpu);
51 87
52 State state() const { return state_; } 88 State state() const { return state_; }
53 89
54 // Change state to kLost. 90 // Change state to kLost.
55 void SetStateLost(); 91 void SetStateLost();
56 92
57 // The GPU stats reported by the GPU process. 93 // The GPU stats reported by the GPU process.
58 void set_gpu_info(const GPUInfo& gpu_info); 94 void set_gpu_info(const GPUInfo& gpu_info);
59 const GPUInfo& gpu_info() const; 95 const GPUInfo& gpu_info() const;
60 96
61 // IPC::Channel::Listener implementation: 97 void OnChannelError();
62 virtual bool OnMessageReceived(const IPC::Message& msg);
63 virtual void OnChannelConnected(int32 peer_pid);
64 virtual void OnChannelError();
65 98
66 // IPC::Message::Sender implementation: 99 // IPC::Message::Sender implementation:
67 virtual bool Send(IPC::Message* msg); 100 virtual bool Send(IPC::Message* msg);
68 101
69 // Create and connect to a command buffer in the GPU process. 102 // Create and connect to a command buffer in the GPU process.
70 CommandBufferProxy* CreateViewCommandBuffer( 103 scoped_refptr<CommandBufferProxy> CreateViewCommandBuffer(
71 int render_view_id, 104 int render_view_id,
72 CommandBufferProxy* share_group, 105 CommandBufferProxy* share_group,
73 const std::string& allowed_extensions, 106 const std::string& allowed_extensions,
74 const std::vector<int32>& attribs, 107 const std::vector<int32>& attribs,
75 const GURL& active_url); 108 const GURL& active_url);
76 109
77 // Create and connect to a command buffer in the GPU process. 110 // Create and connect to a command buffer in the GPU process.
78 CommandBufferProxy* CreateOffscreenCommandBuffer( 111 scoped_refptr<CommandBufferProxy> CreateOffscreenCommandBuffer(
79 const gfx::Size& size, 112 const gfx::Size& size,
80 CommandBufferProxy* share_group, 113 CommandBufferProxy* share_group,
81 const std::string& allowed_extensions, 114 const std::string& allowed_extensions,
82 const std::vector<int32>& attribs, 115 const std::vector<int32>& attribs,
83 const GURL& active_url); 116 const GURL& active_url);
84 117
85 // Creates a video decoder in the GPU process. 118 // Creates a video decoder in the GPU process.
86 // Returned pointer is owned by the CommandBufferProxy for |route_id|. 119 // Returned pointer is owned by the CommandBufferProxy for |route_id|.
87 GpuVideoDecodeAcceleratorHost* CreateVideoDecoder( 120 GpuVideoDecodeAcceleratorHost* CreateVideoDecoder(
88 int command_buffer_route_id, 121 int command_buffer_route_id,
89 const std::vector<int32>& configs, 122 const std::vector<int32>& configs,
90 media::VideoDecodeAccelerator::Client* client); 123 media::VideoDecodeAccelerator::Client* client);
91 124
92 // Destroy a command buffer created by this channel. 125 // Destroy a command buffer created by this channel.
93 void DestroyCommandBuffer(CommandBufferProxy* command_buffer); 126 void DestroyCommandBuffer(CommandBufferProxy* command_buffer);
94 127
95 // Create a surface in the GPU process. Returns null on failure. 128 // Create a surface in the GPU process. Returns null on failure.
96 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); 129 scoped_refptr<GpuSurfaceProxy> CreateOffscreenSurface(const gfx::Size& size);
97 130
98 // Destroy a surface in the GPU process. 131 // Destroy a surface in the GPU process.
99 void DestroySurface(GpuSurfaceProxy* surface); 132 void DestroySurface(GpuSurfaceProxy* surface);
100 133
101 TransportTextureService* transport_texture_service() { 134 TransportTextureService* transport_texture_service() {
102 return transport_texture_service_.get(); 135 return transport_texture_service_.get();
103 } 136 }
104 137
138 class MessageFilter : public IPC::ChannelProxy::MessageFilter,
139 public base::NonThreadSafe {
140 public:
141 MessageFilter(GpuChannelHost* parent);
142 virtual ~MessageFilter();
143
144 void AddRoute(int route_id, scoped_refptr<GpuChannelListener> listener);
145 void RemoveRoute(int route_id);
146
147 // IPC::ChannelProxy::MessageFilter implementation:
148 virtual bool OnMessageReceived(const IPC::Message& msg);
149 virtual void OnChannelError();
150
151 private:
152 GpuChannelHost* parent_;
153
154 typedef base::hash_map<int, scoped_refptr<GpuChannelListener> > ListenerMap;
155 ListenerMap listeners_;
156 };
157
105 private: 158 private:
159 // Add a route for the current message loop.
160 void AddRoute(int route_id, scoped_refptr<GpuChannelListener> listener);
161 void RemoveRoute(int route_id);
162
106 State state_; 163 State state_;
107 164
108 GPUInfo gpu_info_; 165 GPUInfo gpu_info_;
109 166
110 scoped_ptr<IPC::SyncChannel> channel_; 167 scoped_ptr<IPC::SyncChannel> channel_;
168 scoped_refptr<MessageFilter> channel_filter_;
111 169
112 // Used to implement message routing functionality to CommandBufferProxy 170 // Used to look up a proxy from its routing id.
113 // objects 171 typedef base::hash_map<int, scoped_refptr<CommandBufferProxy> > ProxyMap;
114 MessageRouter router_; 172 ProxyMap proxies_;
115 173
116 // Keep track of all the registered CommandBufferProxies to 174 // A lock to guard against concurrent access to members like the proxies map
117 // inform about OnChannelError 175 // for calls from contexts that may live on the compositor or main thread.
118 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; 176 mutable base::Lock context_lock_;
119 ProxyMap proxies_;
120 177
121 // This is a MessageFilter to intercept IPC messages related to transport 178 // This is a MessageFilter to intercept IPC messages related to transport
122 // textures. These messages are routed to TransportTextureHost. 179 // textures. These messages are routed to TransportTextureHost.
123 scoped_refptr<TransportTextureService> transport_texture_service_; 180 scoped_refptr<TransportTextureService> transport_texture_service_;
124 181
182 // A filter for sending messages from thread other than the main thread.
183 scoped_ptr<IPC::SyncMessageFilter> sync_filter_;
184
125 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); 185 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
126 }; 186 };
127 187
128 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ 188 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698