| OLD | NEW |
| 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 |
| 41 class GpuChannelListener; |
| 42 |
| 28 // Encapsulates an IPC channel between the renderer and one plugin process. | 43 // Encapsulates an IPC channel between the renderer and one plugin process. |
| 29 // On the plugin side there's a corresponding GpuChannel. | 44 // On the plugin side there's a corresponding GpuChannel. |
| 30 class GpuChannelHost : public IPC::Channel::Listener, | 45 class GpuChannelHost : public IPC::Message::Sender, |
| 31 public IPC::Message::Sender, | |
| 32 public base::RefCountedThreadSafe<GpuChannelHost> { | 46 public base::RefCountedThreadSafe<GpuChannelHost> { |
| 33 public: | 47 public: |
| 34 enum State { | 48 enum State { |
| 35 // Not yet connected. | 49 // Not yet connected. |
| 36 kUnconnected, | 50 kUnconnected, |
| 37 // Ready to use. | 51 // Ready to use. |
| 38 kConnected, | 52 kConnected, |
| 39 // An error caused the host to become disconnected. Recreate channel to | 53 // An error caused the host to become disconnected. Recreate channel to |
| 40 // reestablish connection. | 54 // reestablish connection. |
| 41 kLost | 55 kLost |
| 42 }; | 56 }; |
| 43 | 57 |
| 44 // Called on the render thread | 58 // Called on the render thread |
| 45 GpuChannelHost(); | 59 GpuChannelHost(); |
| 46 virtual ~GpuChannelHost(); | 60 virtual ~GpuChannelHost(); |
| 47 | 61 |
| 48 // Connect to GPU process channel. | 62 // Connect to GPU process channel. |
| 49 void Connect(const IPC::ChannelHandle& channel_handle, | 63 void Connect(const IPC::ChannelHandle& channel_handle, |
| 50 base::ProcessHandle renderer_process_for_gpu); | 64 base::ProcessHandle renderer_process_for_gpu); |
| 51 | 65 |
| 52 State state() const { return state_; } | 66 State state() const { return state_; } |
| 53 | 67 |
| 54 // Change state to kLost. | 68 // Change state to kLost. |
| 55 void SetStateLost(); | 69 void SetStateLost(); |
| 56 | 70 |
| 57 // The GPU stats reported by the GPU process. | 71 // The GPU stats reported by the GPU process. |
| 58 void set_gpu_info(const GPUInfo& gpu_info); | 72 void set_gpu_info(const GPUInfo& gpu_info); |
| 59 const GPUInfo& gpu_info() const; | 73 const GPUInfo& gpu_info() const; |
| 60 | 74 |
| 61 // IPC::Channel::Listener implementation: | 75 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 | 76 |
| 66 // IPC::Message::Sender implementation: | 77 // IPC::Message::Sender implementation: |
| 67 virtual bool Send(IPC::Message* msg); | 78 virtual bool Send(IPC::Message* msg); |
| 68 | 79 |
| 69 // Create and connect to a command buffer in the GPU process. | 80 // Create and connect to a command buffer in the GPU process. |
| 70 CommandBufferProxy* CreateViewCommandBuffer( | 81 CommandBufferProxy* CreateViewCommandBuffer( |
| 71 int render_view_id, | 82 int render_view_id, |
| 72 CommandBufferProxy* share_group, | 83 CommandBufferProxy* share_group, |
| 73 const std::string& allowed_extensions, | 84 const std::string& allowed_extensions, |
| 74 const std::vector<int32>& attribs, | 85 const std::vector<int32>& attribs, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 95 // Create a surface in the GPU process. Returns null on failure. | 106 // Create a surface in the GPU process. Returns null on failure. |
| 96 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); | 107 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); |
| 97 | 108 |
| 98 // Destroy a surface in the GPU process. | 109 // Destroy a surface in the GPU process. |
| 99 void DestroySurface(GpuSurfaceProxy* surface); | 110 void DestroySurface(GpuSurfaceProxy* surface); |
| 100 | 111 |
| 101 TransportTextureService* transport_texture_service() { | 112 TransportTextureService* transport_texture_service() { |
| 102 return transport_texture_service_.get(); | 113 return transport_texture_service_.get(); |
| 103 } | 114 } |
| 104 | 115 |
| 105 // Called to add/remove a listener for a particular message routing ID. | 116 class MessageFilter : public IPC::ChannelProxy::MessageFilter, |
| 106 void AddRoute(int32 route_id, IPC::Channel::Listener* listener); | 117 public base::NonThreadSafe { |
| 107 void RemoveRoute(int32 route_id); | 118 public: |
| 119 MessageFilter(GpuChannelHost* parent); |
| 120 virtual ~MessageFilter(); |
| 121 |
| 122 void AddRoute(int route_id, |
| 123 base::WeakPtr<IPC::Channel::Listener> listener, |
| 124 scoped_refptr<base::MessageLoopProxy> loop); |
| 125 void RemoveRoute(int route_id); |
| 126 |
| 127 // IPC::ChannelProxy::MessageFilter implementation: |
| 128 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 129 virtual void OnChannelError(); |
| 130 |
| 131 private: |
| 132 GpuChannelHost* parent_; |
| 133 |
| 134 typedef base::hash_map<int, scoped_refptr<GpuChannelListener> > ListenerMap; |
| 135 ListenerMap listeners_; |
| 136 }; |
| 137 |
| 138 // Add a route for the current message loop. |
| 139 void AddRoute(int route_id, base::WeakPtr<IPC::Channel::Listener> listener); |
| 140 void RemoveRoute(int route_id); |
| 108 | 141 |
| 109 private: | 142 private: |
| 110 State state_; | 143 State state_; |
| 111 | 144 |
| 112 GPUInfo gpu_info_; | 145 GPUInfo gpu_info_; |
| 113 | 146 |
| 114 scoped_ptr<IPC::SyncChannel> channel_; | 147 scoped_ptr<IPC::SyncChannel> channel_; |
| 148 scoped_refptr<MessageFilter> channel_filter_; |
| 115 | 149 |
| 116 // Used to implement message routing functionality to CommandBufferProxy | 150 // 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; | 151 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; |
| 123 ProxyMap proxies_; | 152 ProxyMap proxies_; |
| 124 | 153 |
| 154 // A lock to guard against concurrent access to members like the proxies map |
| 155 // for calls from contexts that may live on the compositor or main thread. |
| 156 mutable base::Lock context_lock_; |
| 157 |
| 125 // This is a MessageFilter to intercept IPC messages related to transport | 158 // This is a MessageFilter to intercept IPC messages related to transport |
| 126 // textures. These messages are routed to TransportTextureHost. | 159 // textures. These messages are routed to TransportTextureHost. |
| 127 scoped_refptr<TransportTextureService> transport_texture_service_; | 160 scoped_refptr<TransportTextureService> transport_texture_service_; |
| 128 | 161 |
| 162 // A filter for sending messages from thread other than the main thread. |
| 163 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
| 164 |
| 129 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 165 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
| 130 }; | 166 }; |
| 131 | 167 |
| 132 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ | 168 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ |
| OLD | NEW |