| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 18 #include "content/common/message_router.h" | 19 #include "content/common/message_router.h" |
| 19 #include "content/public/common/gpu_info.h" | 20 #include "content/public/common/gpu_info.h" |
| 20 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" | 21 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" |
| 21 #include "ipc/ipc_channel_handle.h" | 22 #include "ipc/ipc_channel_handle.h" |
| 22 #include "ipc/ipc_channel_proxy.h" | 23 #include "ipc/ipc_channel_proxy.h" |
| 23 #include "ipc/ipc_sync_channel.h" | 24 #include "ipc/ipc_sync_channel.h" |
| 24 #include "ui/gfx/gl/gpu_preference.h" | 25 #include "ui/gfx/gl/gpu_preference.h" |
| 25 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
| 26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
| 27 | 28 |
| 28 class CommandBufferProxy; | 29 class CommandBufferProxy; |
| 30 struct GPUCreateCommandBufferConfig; |
| 29 class GURL; | 31 class GURL; |
| 30 class TransportTextureService; | 32 class TransportTextureService; |
| 33 class MessageLoop; |
| 31 | 34 |
| 32 namespace base { | 35 namespace base { |
| 33 class MessageLoopProxy; | 36 class MessageLoopProxy; |
| 34 } | 37 } |
| 35 | 38 |
| 36 namespace IPC { | 39 namespace IPC { |
| 37 class SyncMessageFilter; | 40 class SyncMessageFilter; |
| 38 } | 41 } |
| 39 | 42 |
| 40 struct GpuListenerInfo { | 43 struct GpuListenerInfo { |
| 41 GpuListenerInfo(); | 44 GpuListenerInfo(); |
| 42 ~GpuListenerInfo(); | 45 ~GpuListenerInfo(); |
| 43 | 46 |
| 44 base::WeakPtr<IPC::Channel::Listener> listener; | 47 base::WeakPtr<IPC::Channel::Listener> listener; |
| 45 scoped_refptr<base::MessageLoopProxy> loop; | 48 scoped_refptr<base::MessageLoopProxy> loop; |
| 46 }; | 49 }; |
| 47 | 50 |
| 51 class GpuChannelHostFactory { |
| 52 public: |
| 53 virtual ~GpuChannelHostFactory(); |
| 54 static GpuChannelHostFactory* instance() { return instance_; } |
| 55 |
| 56 virtual bool IsMainThread() = 0; |
| 57 virtual bool IsIOThread() = 0; |
| 58 virtual MessageLoop* GetMainLoop() = 0; |
| 59 virtual base::MessageLoopProxy* GetIOLoopProxy() = 0; |
| 60 virtual base::WaitableEvent* GetShutDownEvent() = 0; |
| 61 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(uint32 size) = 0; |
| 62 virtual int32 CreateViewCommandBuffer( |
| 63 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) = 0; |
| 64 virtual GpuChannelHost* EstablishGpuChannelSync( |
| 65 content::CauseForGpuLaunch) = 0; |
| 66 |
| 67 protected: |
| 68 static void set_instance(GpuChannelHostFactory* instance) { |
| 69 instance_ = instance; |
| 70 } |
| 71 |
| 72 private: |
| 73 static GpuChannelHostFactory* instance_; |
| 74 }; |
| 75 |
| 48 // Encapsulates an IPC channel between the renderer and one plugin process. | 76 // Encapsulates an IPC channel between the renderer and one plugin process. |
| 49 // On the plugin side there's a corresponding GpuChannel. | 77 // On the plugin side there's a corresponding GpuChannel. |
| 50 class GpuChannelHost : public IPC::Message::Sender, | 78 class GpuChannelHost : public IPC::Message::Sender, |
| 51 public base::RefCountedThreadSafe<GpuChannelHost> { | 79 public base::RefCountedThreadSafe<GpuChannelHost> { |
| 52 public: | 80 public: |
| 53 enum State { | 81 enum State { |
| 54 // Not yet connected. | 82 // Not yet connected. |
| 55 kUnconnected, | 83 kUnconnected, |
| 56 // Ready to use. | 84 // Ready to use. |
| 57 kConnected, | 85 kConnected, |
| 58 // An error caused the host to become disconnected. Recreate channel to | 86 // An error caused the host to become disconnected. Recreate channel to |
| 59 // reestablish connection. | 87 // reestablish connection. |
| 60 kLost | 88 kLost |
| 61 }; | 89 }; |
| 62 | 90 |
| 63 // Called on the render thread | 91 // Called on the render thread |
| 64 GpuChannelHost(); | 92 explicit GpuChannelHost(GpuChannelHostFactory* factory); |
| 65 virtual ~GpuChannelHost(); | 93 virtual ~GpuChannelHost(); |
| 66 | 94 |
| 67 // Connect to GPU process channel. | 95 // Connect to GPU process channel. |
| 68 void Connect(const IPC::ChannelHandle& channel_handle, | 96 void Connect(const IPC::ChannelHandle& channel_handle, |
| 69 base::ProcessHandle renderer_process_for_gpu); | 97 base::ProcessHandle renderer_process_for_gpu); |
| 70 | 98 |
| 71 State state() const { return state_; } | 99 State state() const { return state_; } |
| 72 | 100 |
| 73 // Change state to kLost. | 101 // Change state to kLost. |
| 74 void SetStateLost(); | 102 void SetStateLost(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // to be dropped. | 149 // to be dropped. |
| 122 bool WillGpuSwitchOccur(bool is_creating_context, | 150 bool WillGpuSwitchOccur(bool is_creating_context, |
| 123 gfx::GpuPreference gpu_preference); | 151 gfx::GpuPreference gpu_preference); |
| 124 | 152 |
| 125 // Forcibly close the channel on the GPU process side. This will | 153 // Forcibly close the channel on the GPU process side. This will |
| 126 // cause all command buffers on this side to soon afterward start | 154 // cause all command buffers on this side to soon afterward start |
| 127 // registering lost contexts. It also has the side effect of setting | 155 // registering lost contexts. It also has the side effect of setting |
| 128 // the state on this side to lost. | 156 // the state on this side to lost. |
| 129 void ForciblyCloseChannel(); | 157 void ForciblyCloseChannel(); |
| 130 | 158 |
| 159 GpuChannelHostFactory* factory() const { return factory_; } |
| 160 |
| 131 private: | 161 private: |
| 132 // A filter used internally to route incoming messages from the IO thread | 162 // A filter used internally to route incoming messages from the IO thread |
| 133 // to the correct message loop. | 163 // to the correct message loop. |
| 134 class MessageFilter : public IPC::ChannelProxy::MessageFilter { | 164 class MessageFilter : public IPC::ChannelProxy::MessageFilter { |
| 135 public: | 165 public: |
| 136 explicit MessageFilter(GpuChannelHost* parent); | 166 explicit MessageFilter(GpuChannelHost* parent); |
| 137 virtual ~MessageFilter(); | 167 virtual ~MessageFilter(); |
| 138 | 168 |
| 139 void AddRoute(int route_id, | 169 void AddRoute(int route_id, |
| 140 base::WeakPtr<IPC::Channel::Listener> listener, | 170 base::WeakPtr<IPC::Channel::Listener> listener, |
| 141 scoped_refptr<base::MessageLoopProxy> loop); | 171 scoped_refptr<base::MessageLoopProxy> loop); |
| 142 void RemoveRoute(int route_id); | 172 void RemoveRoute(int route_id); |
| 143 | 173 |
| 144 // IPC::ChannelProxy::MessageFilter implementation: | 174 // IPC::ChannelProxy::MessageFilter implementation: |
| 145 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 175 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 146 virtual void OnChannelError() OVERRIDE; | 176 virtual void OnChannelError() OVERRIDE; |
| 147 | 177 |
| 148 private: | 178 private: |
| 149 GpuChannelHost* parent_; | 179 GpuChannelHost* parent_; |
| 150 | 180 |
| 151 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; | 181 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; |
| 152 ListenerMap listeners_; | 182 ListenerMap listeners_; |
| 153 }; | 183 }; |
| 154 | 184 |
| 185 GpuChannelHostFactory* factory_; |
| 186 |
| 155 State state_; | 187 State state_; |
| 156 | 188 |
| 157 content::GPUInfo gpu_info_; | 189 content::GPUInfo gpu_info_; |
| 158 | 190 |
| 159 scoped_ptr<IPC::SyncChannel> channel_; | 191 scoped_ptr<IPC::SyncChannel> channel_; |
| 160 scoped_refptr<MessageFilter> channel_filter_; | 192 scoped_refptr<MessageFilter> channel_filter_; |
| 161 | 193 |
| 162 // Used to look up a proxy from its routing id. | 194 // Used to look up a proxy from its routing id. |
| 163 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; | 195 typedef base::hash_map<int, CommandBufferProxy*> ProxyMap; |
| 164 ProxyMap proxies_; | 196 ProxyMap proxies_; |
| 165 | 197 |
| 166 // A lock to guard against concurrent access to members like the proxies map | 198 // A lock to guard against concurrent access to members like the proxies map |
| 167 // for calls from contexts that may live on the compositor or main thread. | 199 // for calls from contexts that may live on the compositor or main thread. |
| 168 mutable base::Lock context_lock_; | 200 mutable base::Lock context_lock_; |
| 169 | 201 |
| 170 // A filter for sending messages from thread other than the main thread. | 202 // A filter for sending messages from thread other than the main thread. |
| 171 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; | 203 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
| 172 | 204 |
| 173 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 205 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
| 174 }; | 206 }; |
| 175 | 207 |
| 176 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ | 208 #endif // CONTENT_RENDERER_GPU_GPU_CHANNEL_HOST_H_ |
| OLD | NEW |