OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_GPU_GPU_CHANNEL_H_ | 5 #ifndef CHROME_GPU_GPU_CHANNEL_H_ |
6 #define CHROME_GPU_GPU_CHANNEL_H_ | 6 #define CHROME_GPU_GPU_CHANNEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/scoped_open_process.h" | 14 #include "base/process.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/gpu_create_command_buffer_config.h" | 17 #include "chrome/common/gpu_create_command_buffer_config.h" |
18 #include "chrome/common/gpu_video_common.h" | 18 #include "chrome/common/gpu_video_common.h" |
19 #include "chrome/common/message_router.h" | 19 #include "chrome/common/message_router.h" |
20 #include "chrome/gpu/gpu_command_buffer_stub.h" | 20 #include "chrome/gpu/gpu_command_buffer_stub.h" |
21 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
22 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
23 #include "ipc/ipc_sync_channel.h" | 23 #include "ipc/ipc_sync_channel.h" |
24 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
25 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
26 | 26 |
27 class GpuThread; | 27 class GpuThread; |
28 | 28 |
29 // Encapsulates an IPC channel between the GPU process and one renderer | 29 // Encapsulates an IPC channel between the GPU process and one renderer |
30 // process. On the renderer side there's a corresponding GpuChannelHost. | 30 // process. On the renderer side there's a corresponding GpuChannelHost. |
31 class GpuChannel : public IPC::Channel::Listener, | 31 class GpuChannel : public IPC::Channel::Listener, |
32 public IPC::Message::Sender, | 32 public IPC::Message::Sender, |
33 public base::RefCountedThreadSafe<GpuChannel> { | 33 public base::RefCountedThreadSafe<GpuChannel> { |
34 public: | 34 public: |
35 GpuChannel(GpuThread* gpu_thread, int renderer_id); | 35 // Takes ownership of the renderer process handle. |
| 36 GpuChannel(GpuThread* gpu_thread, |
| 37 int renderer_id); |
36 virtual ~GpuChannel(); | 38 virtual ~GpuChannel(); |
37 | 39 |
38 bool Init(); | 40 bool Init(); |
39 | 41 |
40 // Get the GpuThread that owns this channel. | 42 // Get the GpuThread that owns this channel. |
41 GpuThread* gpu_thread() const { return gpu_thread_; } | 43 GpuThread* gpu_thread() const { return gpu_thread_; } |
42 | 44 |
43 // Returns the name of the associated IPC channel. | 45 // Returns the name of the associated IPC channel. |
44 std::string GetChannelName(); | 46 std::string GetChannelName(); |
45 | 47 |
46 #if defined(OS_POSIX) | 48 #if defined(OS_POSIX) |
47 int GetRendererFileDescriptor(); | 49 int GetRendererFileDescriptor(); |
48 #endif // defined(OS_POSIX) | 50 #endif // defined(OS_POSIX) |
49 | 51 |
50 base::ProcessHandle renderer_handle() const { | 52 base::ProcessHandle renderer_process() const { |
51 return renderer_process_.handle(); | 53 return renderer_process_; |
52 } | 54 } |
53 | 55 |
54 // IPC::Channel::Listener implementation: | 56 // IPC::Channel::Listener implementation: |
55 virtual bool OnMessageReceived(const IPC::Message& msg); | 57 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 58 virtual void OnChannelError(); |
56 virtual void OnChannelConnected(int32 peer_pid); | 59 virtual void OnChannelConnected(int32 peer_pid); |
57 virtual void OnChannelError(); | |
58 | 60 |
59 // IPC::Message::Sender implementation: | 61 // IPC::Message::Sender implementation: |
60 virtual bool Send(IPC::Message* msg); | 62 virtual bool Send(IPC::Message* msg); |
61 | 63 |
62 void CreateViewCommandBuffer( | 64 void CreateViewCommandBuffer( |
63 gfx::PluginWindowHandle window, | 65 gfx::PluginWindowHandle window, |
64 int32 render_view_id, | 66 int32 render_view_id, |
65 const GPUCreateCommandBufferConfig& init_params, | 67 const GPUCreateCommandBufferConfig& init_params, |
66 int32* route_id); | 68 int32* route_id); |
67 | 69 |
68 #if defined(OS_MACOSX) | 70 #if defined(OS_MACOSX) |
69 virtual void AcceleratedSurfaceBuffersSwapped( | 71 virtual void AcceleratedSurfaceBuffersSwapped( |
70 int32 route_id, uint64 swap_buffers_count); | 72 int32 route_id, uint64 swap_buffers_count); |
71 void DidDestroySurface(int32 renderer_route_id); | 73 void DidDestroySurface(int32 renderer_route_id); |
72 | 74 |
73 bool IsRenderViewGone(int32 renderer_route_id); | 75 bool IsRenderViewGone(int32 renderer_route_id); |
74 #endif | 76 #endif |
75 | 77 |
76 private: | 78 private: |
77 bool OnControlMessageReceived(const IPC::Message& msg); | 79 bool OnControlMessageReceived(const IPC::Message& msg); |
78 | 80 |
79 int GenerateRouteID(); | 81 int GenerateRouteID(); |
80 | 82 |
81 // Message handlers. | 83 // Message handlers. |
| 84 void OnInitialize(base::ProcessHandle renderer_process); |
82 void OnCreateOffscreenCommandBuffer( | 85 void OnCreateOffscreenCommandBuffer( |
83 int32 parent_route_id, | 86 int32 parent_route_id, |
84 const gfx::Size& size, | 87 const gfx::Size& size, |
85 const GPUCreateCommandBufferConfig& init_params, | 88 const GPUCreateCommandBufferConfig& init_params, |
86 uint32 parent_texture_id, | 89 uint32 parent_texture_id, |
87 int32* route_id); | 90 int32* route_id); |
88 void OnDestroyCommandBuffer(int32 route_id); | 91 void OnDestroyCommandBuffer(int32 route_id); |
89 | 92 |
90 void OnCreateVideoDecoder(int32 context_route_id, | 93 void OnCreateVideoDecoder(int32 context_route_id, |
91 int32 decoder_host_id); | 94 int32 decoder_host_id); |
92 void OnDestroyVideoDecoder(int32 decoder_id); | 95 void OnDestroyVideoDecoder(int32 decoder_id); |
93 | 96 |
94 // The lifetime of objects of this class is managed by a GpuThread. The | 97 // The lifetime of objects of this class is managed by a GpuThread. The |
95 // GpuThreadss destroy all the GpuChannels that they own when they | 98 // GpuThreadss destroy all the GpuChannels that they own when they |
96 // are destroyed. So a raw pointer is safe. | 99 // are destroyed. So a raw pointer is safe. |
97 GpuThread* gpu_thread_; | 100 GpuThread* gpu_thread_; |
98 | 101 |
99 scoped_ptr<IPC::SyncChannel> channel_; | 102 scoped_ptr<IPC::SyncChannel> channel_; |
100 | 103 |
101 // Handle to the renderer process who is on the other side of the channel. | |
102 base::ScopedOpenProcess renderer_process_; | |
103 | |
104 // The id of the renderer who is on the other side of the channel. | 104 // The id of the renderer who is on the other side of the channel. |
105 int renderer_id_; | 105 int renderer_id_; |
106 | 106 |
| 107 // Handle to the renderer process that is on the other side of the channel. |
| 108 base::ProcessHandle renderer_process_; |
| 109 |
| 110 // The process id of the renderer process. |
| 111 base::ProcessId renderer_pid_; |
| 112 |
107 // Used to implement message routing functionality to CommandBuffer objects | 113 // Used to implement message routing functionality to CommandBuffer objects |
108 MessageRouter router_; | 114 MessageRouter router_; |
109 | 115 |
110 #if defined(ENABLE_GPU) | 116 #if defined(ENABLE_GPU) |
111 typedef IDMap<GpuCommandBufferStub, IDMapOwnPointer> StubMap; | 117 typedef IDMap<GpuCommandBufferStub, IDMapOwnPointer> StubMap; |
112 StubMap stubs_; | 118 StubMap stubs_; |
113 | 119 |
114 #if defined(OS_MACOSX) | 120 #if defined(OS_MACOSX) |
115 std::set<int32> destroyed_renderer_routes_; | 121 std::set<int32> destroyed_renderer_routes_; |
116 #endif // defined (OS_MACOSX) | 122 #endif // defined (OS_MACOSX) |
117 #endif // defined (ENABLE_GPU) | 123 #endif // defined (ENABLE_GPU) |
118 | 124 |
119 bool log_messages_; // True if we should log sent and received messages. | 125 bool log_messages_; // True if we should log sent and received messages. |
120 | 126 |
121 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 127 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
122 }; | 128 }; |
123 | 129 |
124 #endif // CHROME_GPU_GPU_CHANNEL_H_ | 130 #endif // CHROME_GPU_GPU_CHANNEL_H_ |
OLD | NEW |