OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_GPU_CHANNEL_HOST_H_ | |
6 #define CONTENT_RENDERER_GPU_CHANNEL_HOST_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/hash_tables.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/process_util.h" | |
15 #include "content/common/gpu/gpu_info.h" | |
16 #include "content/common/message_router.h" | |
17 #include "ipc/ipc_channel_handle.h" | |
18 #include "ipc/ipc_sync_channel.h" | |
19 #include "ui/gfx/native_widget_types.h" | |
20 #include "ui/gfx/size.h" | |
21 | |
22 class CommandBufferProxy; | |
23 class GpuSurfaceProxy; | |
24 class GURL; | |
25 class GpuVideoServiceHost; | |
26 class TransportTextureService; | |
27 | |
28 // Encapsulates an IPC channel between the renderer and one plugin process. | |
29 // On the plugin side there's a corresponding GpuChannel. | |
30 class GpuChannelHost : public IPC::Channel::Listener, | |
31 public IPC::Message::Sender, | |
32 public base::RefCountedThreadSafe<GpuChannelHost> { | |
33 public: | |
34 enum State { | |
35 // Not yet connected. | |
36 kUnconnected, | |
37 // Ready to use. | |
38 kConnected, | |
39 // An error caused the host to become disconnected. Recreate channel to | |
40 // reestablish connection. | |
41 kLost | |
42 }; | |
43 | |
44 // Called on the render thread | |
45 GpuChannelHost(); | |
46 ~GpuChannelHost(); | |
47 | |
48 // Connect to GPU process channel. | |
49 void Connect(const IPC::ChannelHandle& channel_handle, | |
50 base::ProcessHandle renderer_process_for_gpu); | |
51 | |
52 State state() const { return state_; } | |
53 | |
54 // Change state to kLost. | |
55 void SetStateLost(); | |
56 | |
57 // The GPU stats reported by the GPU process. | |
58 void set_gpu_info(const GPUInfo& gpu_info); | |
59 const GPUInfo& gpu_info() const; | |
60 | |
61 // IPC::Channel::Listener implementation: | |
62 virtual bool OnMessageReceived(const IPC::Message& msg); | |
63 virtual void OnChannelConnected(int32 peer_pid); | |
64 virtual void OnChannelError(); | |
65 | |
66 // IPC::Message::Sender implementation: | |
67 virtual bool Send(IPC::Message* msg); | |
68 | |
69 // Create and connect to a command buffer in the GPU process. | |
70 CommandBufferProxy* CreateViewCommandBuffer( | |
71 gfx::PluginWindowHandle compositing_surface, | |
72 int render_view_id, | |
73 const std::string& allowed_extensions, | |
74 const std::vector<int32>& attribs, | |
75 const GURL& active_url); | |
76 | |
77 // Create and connect to a command buffer in the GPU process. | |
78 CommandBufferProxy* CreateOffscreenCommandBuffer( | |
79 CommandBufferProxy* parent, | |
80 const gfx::Size& size, | |
81 const std::string& allowed_extensions, | |
82 const std::vector<int32>& attribs, | |
83 uint32 parent_texture_id, | |
84 const GURL& active_url); | |
85 | |
86 // Destroy a command buffer created by this channel. | |
87 void DestroyCommandBuffer(CommandBufferProxy* command_buffer); | |
88 | |
89 // Create a surface in the GPU process. Returns null on failure. | |
90 GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); | |
91 | |
92 // Destroy a surface in the GPU process. | |
93 void DestroySurface(GpuSurfaceProxy* surface); | |
94 | |
95 GpuVideoServiceHost* gpu_video_service_host() { | |
96 return gpu_video_service_host_.get(); | |
97 } | |
98 | |
99 TransportTextureService* transport_texture_service() { | |
100 return transport_texture_service_.get(); | |
101 } | |
102 | |
103 private: | |
104 State state_; | |
105 | |
106 GPUInfo gpu_info_; | |
107 | |
108 scoped_ptr<IPC::SyncChannel> channel_; | |
109 | |
110 // Used to implement message routing functionality to CommandBufferProxy | |
111 // objects | |
112 MessageRouter router_; | |
113 | |
114 // Keep track of all the registered CommandBufferProxies to | |
115 // inform about OnChannelError | |
116 typedef base::hash_map<int, IPC::Channel::Listener*> ProxyMap; | |
117 ProxyMap proxies_; | |
118 | |
119 // This is a MessageFilter to intercept IPC messages and distribute them | |
120 // to the corresponding GpuVideoDecoderHost. | |
121 scoped_refptr<GpuVideoServiceHost> gpu_video_service_host_; | |
122 | |
123 // This is a MessageFilter to intercept IPC messages related to transport | |
124 // textures. These messages are routed to TransportTextureHost. | |
125 scoped_refptr<TransportTextureService> transport_texture_service_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | |
128 }; | |
129 | |
130 #endif // CONTENT_RENDERER_GPU_CHANNEL_HOST_H_ | |
OLD | NEW |