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 #include "chrome/gpu/gpu_channel.h" | |
6 | |
7 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
8 #include <windows.h> | 6 #include <windows.h> |
9 #endif | 7 #endif |
10 | 8 |
| 9 #include "chrome/gpu/gpu_channel.h" |
| 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/common/child_process.h" | 14 #include "chrome/common/child_process.h" |
15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/gpu_messages.h" | 17 #include "chrome/common/gpu_messages.h" |
18 #include "chrome/gpu/gpu_thread.h" | 18 #include "chrome/gpu/gpu_thread.h" |
19 #include "chrome/gpu/gpu_video_service.h" | 19 #include "chrome/gpu/gpu_video_service.h" |
20 | 20 |
21 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
22 #include "ipc/ipc_channel_posix.h" | 22 #include "ipc/ipc_channel_posix.h" |
23 #endif | 23 #endif |
24 | 24 |
25 GpuChannel::GpuChannel(GpuThread* gpu_thread, int renderer_id) | 25 GpuChannel::GpuChannel(GpuThread* gpu_thread, |
| 26 int renderer_id) |
26 : gpu_thread_(gpu_thread), | 27 : gpu_thread_(gpu_thread), |
27 renderer_id_(renderer_id) { | 28 renderer_id_(renderer_id), |
| 29 renderer_process_(NULL), |
| 30 renderer_pid_(NULL) { |
28 DCHECK(gpu_thread); | 31 DCHECK(gpu_thread); |
| 32 DCHECK(renderer_id); |
29 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 33 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
30 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 34 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
31 } | 35 } |
32 | 36 |
33 GpuChannel::~GpuChannel() { | 37 GpuChannel::~GpuChannel() { |
34 } | 38 #if defined(OS_WIN) |
35 | 39 if (renderer_process_) |
36 void GpuChannel::OnChannelConnected(int32 peer_pid) { | 40 CloseHandle(renderer_process_); |
37 if (!renderer_process_.Open(peer_pid)) { | 41 #endif |
38 NOTREACHED(); | |
39 } | |
40 } | 42 } |
41 | 43 |
42 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { | 44 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { |
43 if (log_messages_) { | 45 if (log_messages_) { |
44 VLOG(1) << "received message @" << &message << " on channel @" << this | 46 VLOG(1) << "received message @" << &message << " on channel @" << this |
45 << " with type " << message.type(); | 47 << " with type " << message.type(); |
46 } | 48 } |
47 | 49 |
48 if (message.routing_id() == MSG_ROUTING_CONTROL) | 50 if (message.routing_id() == MSG_ROUTING_CONTROL) |
49 return OnControlMessageReceived(message); | 51 return OnControlMessageReceived(message); |
50 | 52 |
51 // Fail silently if the GPU process has destroyed while the IPC message was | 53 // Fail silently if the GPU process has destroyed while the IPC message was |
52 // en-route. | 54 // en-route. |
53 return router_.RouteMessage(message); | 55 return router_.RouteMessage(message); |
54 } | 56 } |
55 | 57 |
56 void GpuChannel::OnChannelError() { | 58 void GpuChannel::OnChannelError() { |
57 gpu_thread_->RemoveChannel(renderer_id_); | 59 gpu_thread_->RemoveChannel(renderer_id_); |
58 } | 60 } |
59 | 61 |
| 62 void GpuChannel::OnChannelConnected(int32 peer_pid) { |
| 63 renderer_pid_ = peer_pid; |
| 64 } |
| 65 |
60 bool GpuChannel::Send(IPC::Message* message) { | 66 bool GpuChannel::Send(IPC::Message* message) { |
61 if (log_messages_) { | 67 if (log_messages_) { |
62 VLOG(1) << "sending message @" << message << " on channel @" << this | 68 VLOG(1) << "sending message @" << message << " on channel @" << this |
63 << " with type " << message->type(); | 69 << " with type " << message->type(); |
64 } | 70 } |
65 | 71 |
66 if (!channel_.get()) { | 72 if (!channel_.get()) { |
67 delete message; | 73 delete message; |
68 return false; | 74 return false; |
69 } | 75 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 113 } |
108 | 114 |
109 bool GpuChannel::IsRenderViewGone(int32 renderer_route_id) { | 115 bool GpuChannel::IsRenderViewGone(int32 renderer_route_id) { |
110 return destroyed_renderer_routes_.count(renderer_route_id) > 0; | 116 return destroyed_renderer_routes_.count(renderer_route_id) > 0; |
111 } | 117 } |
112 #endif | 118 #endif |
113 | 119 |
114 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 120 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
115 bool handled = true; | 121 bool handled = true; |
116 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 122 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
| 123 IPC_MESSAGE_HANDLER(GpuChannelMsg_Initialize, OnInitialize) |
117 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, | 124 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, |
118 OnCreateOffscreenCommandBuffer) | 125 OnCreateOffscreenCommandBuffer) |
119 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 126 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
120 OnDestroyCommandBuffer) | 127 OnDestroyCommandBuffer) |
121 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, | 128 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, |
122 OnCreateVideoDecoder) | 129 OnCreateVideoDecoder) |
123 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, | 130 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, |
124 OnDestroyVideoDecoder) | 131 OnDestroyVideoDecoder) |
125 IPC_MESSAGE_UNHANDLED(handled = false) | 132 IPC_MESSAGE_UNHANDLED(handled = false) |
126 IPC_END_MESSAGE_MAP() | 133 IPC_END_MESSAGE_MAP() |
127 DCHECK(handled); | 134 DCHECK(handled); |
128 return handled; | 135 return handled; |
129 } | 136 } |
130 | 137 |
131 int GpuChannel::GenerateRouteID() { | 138 int GpuChannel::GenerateRouteID() { |
132 static int last_id = 0; | 139 static int last_id = 0; |
133 return ++last_id; | 140 return ++last_id; |
134 } | 141 } |
135 | 142 |
| 143 void GpuChannel::OnInitialize(base::ProcessHandle renderer_process) { |
| 144 // Initialize should only happen once. |
| 145 DCHECK(!renderer_process_); |
| 146 |
| 147 // Verify that the renderer has passed its own process handle. |
| 148 if (base::GetProcId(renderer_process) == renderer_pid_) |
| 149 renderer_process_ = renderer_process; |
| 150 } |
| 151 |
136 void GpuChannel::OnCreateOffscreenCommandBuffer( | 152 void GpuChannel::OnCreateOffscreenCommandBuffer( |
137 int32 parent_route_id, | 153 int32 parent_route_id, |
138 const gfx::Size& size, | 154 const gfx::Size& size, |
139 const GPUCreateCommandBufferConfig& init_params, | 155 const GPUCreateCommandBufferConfig& init_params, |
140 uint32 parent_texture_id, | 156 uint32 parent_texture_id, |
141 int32* route_id) { | 157 int32* route_id) { |
142 #if defined(ENABLE_GPU) | 158 #if defined(ENABLE_GPU) |
143 *route_id = GenerateRouteID(); | 159 *route_id = GenerateRouteID(); |
144 GpuCommandBufferStub* parent_stub = NULL; | 160 GpuCommandBufferStub* parent_stub = NULL; |
145 if (parent_route_id != 0) | 161 if (parent_route_id != 0) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 #if defined(OS_POSIX) | 242 #if defined(OS_POSIX) |
227 int GpuChannel::GetRendererFileDescriptor() { | 243 int GpuChannel::GetRendererFileDescriptor() { |
228 int fd = -1; | 244 int fd = -1; |
229 if (channel_.get()) { | 245 if (channel_.get()) { |
230 fd = channel_->GetClientFileDescriptor(); | 246 fd = channel_->GetClientFileDescriptor(); |
231 } | 247 } |
232 return fd; | 248 return fd; |
233 } | 249 } |
234 #endif // defined(OS_POSIX) | 250 #endif // defined(OS_POSIX) |
235 | 251 |
OLD | NEW |