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" | 5 #include "chrome/gpu/gpu_channel.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/lock.h" | 12 #include "base/lock.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "chrome/common/child_process.h" | 15 #include "chrome/common/child_process.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/gpu_messages.h" | 18 #include "chrome/common/gpu_messages.h" |
19 #include "chrome/gpu/gpu_thread.h" | 19 #include "chrome/gpu/gpu_thread.h" |
| 20 #include "chrome/gpu/gpu_video_service.h" |
20 | 21 |
21 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
22 #include "ipc/ipc_channel_posix.h" | 23 #include "ipc/ipc_channel_posix.h" |
23 #endif | 24 #endif |
24 | 25 |
25 GpuChannel::GpuChannel(int renderer_id) | 26 GpuChannel::GpuChannel(int renderer_id) |
26 : renderer_id_(renderer_id) | 27 : renderer_id_(renderer_id) |
27 #if defined(OS_POSIX) | 28 #if defined(OS_POSIX) |
28 , renderer_fd_(-1) | 29 , renderer_fd_(-1) |
29 #endif | 30 #endif |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 82 } |
82 | 83 |
83 void GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 84 void GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
84 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 85 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
85 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, | 86 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, |
86 OnCreateViewCommandBuffer) | 87 OnCreateViewCommandBuffer) |
87 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, | 88 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, |
88 OnCreateOffscreenCommandBuffer) | 89 OnCreateOffscreenCommandBuffer) |
89 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 90 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
90 OnDestroyCommandBuffer) | 91 OnDestroyCommandBuffer) |
| 92 IPC_MESSAGE_HANDLER(GpuChannelMsg_GetVideoService, |
| 93 OnGetVideoService) |
| 94 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, |
| 95 OnCreateVideoDecoder) |
| 96 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, |
| 97 OnDestroyVideoDecoder) |
91 IPC_MESSAGE_UNHANDLED_ERROR() | 98 IPC_MESSAGE_UNHANDLED_ERROR() |
92 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
93 } | 100 } |
94 | 101 |
95 int GpuChannel::GenerateRouteID() { | 102 int GpuChannel::GenerateRouteID() { |
96 static int last_id = 0; | 103 static int last_id = 0; |
97 return ++last_id; | 104 return ++last_id; |
98 } | 105 } |
99 | 106 |
100 void GpuChannel::OnCreateViewCommandBuffer(gfx::NativeViewId view_id, | 107 void GpuChannel::OnCreateViewCommandBuffer(gfx::NativeViewId view_id, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 #endif | 178 #endif |
172 } | 179 } |
173 | 180 |
174 void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { | 181 void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { |
175 #if defined(ENABLE_GPU) | 182 #if defined(ENABLE_GPU) |
176 router_.RemoveRoute(route_id); | 183 router_.RemoveRoute(route_id); |
177 stubs_.Remove(route_id); | 184 stubs_.Remove(route_id); |
178 #endif | 185 #endif |
179 } | 186 } |
180 | 187 |
| 188 void GpuChannel::OnGetVideoService(GpuVideoServiceInfoParam* info) { |
| 189 info->service_available_ = 0; |
| 190 #if defined(ENABLE_GPU) |
| 191 #if defined(OS_WIN) |
| 192 // TODO(jiesun): Not every windows platforms will support our media |
| 193 // foundation implementation. Add more check here. |
| 194 LOG(INFO) << "GpuChannel::OnGetVideoService"; |
| 195 GpuVideoService* service = GpuVideoService::get(); |
| 196 if (service == NULL) |
| 197 return; |
| 198 |
| 199 info->video_service_host_route_id_ = GenerateRouteID(); |
| 200 info->video_service_route_id_ = GenerateRouteID(); |
| 201 // TODO(jiesun): we could had multiple entries in this routing table. |
| 202 router_.AddRoute(info->video_service_route_id_, service); |
| 203 info->service_available_ = 1; |
| 204 #endif |
| 205 #endif |
| 206 } |
| 207 |
| 208 void GpuChannel::OnCreateVideoDecoder(GpuVideoDecoderInfoParam* info) { |
| 209 #if defined(ENABLE_GPU) |
| 210 LOG(INFO) << "GpuChannel::OnCreateVideoDecoder"; |
| 211 info->decoder_id_ = -1; |
| 212 GpuVideoService* service = GpuVideoService::get(); |
| 213 if (service == NULL) |
| 214 return; |
| 215 |
| 216 info->decoder_host_route_id_ = GenerateRouteID(); |
| 217 info->decoder_route_id_ = GenerateRouteID(); |
| 218 service->CreateVideoDecoder(this, &router_, info); |
| 219 #endif |
| 220 } |
| 221 |
| 222 void GpuChannel::OnDestroyVideoDecoder(int32 decoder_id) { |
| 223 #if defined(ENABLE_GPU) |
| 224 LOG(ERROR) << "GpuChannel::OnDestroyVideoDecoder"; |
| 225 GpuVideoService* service = GpuVideoService::get(); |
| 226 if (service == NULL) |
| 227 return; |
| 228 service->DestroyVideoDecoder(&router_, decoder_id); |
| 229 #endif |
| 230 } |
| 231 |
181 bool GpuChannel::Init() { | 232 bool GpuChannel::Init() { |
182 // Check whether we're already initialized. | 233 // Check whether we're already initialized. |
183 if (channel_.get()) | 234 if (channel_.get()) |
184 return true; | 235 return true; |
185 | 236 |
186 // Map renderer ID to a (single) channel to that process. | 237 // Map renderer ID to a (single) channel to that process. |
187 std::string channel_name = GetChannelName(); | 238 std::string channel_name = GetChannelName(); |
188 #if defined(OS_POSIX) | 239 #if defined(OS_POSIX) |
189 // This gets called when the GpuChannel is initially created. At this | 240 // This gets called when the GpuChannel is initially created. At this |
190 // point, create the socketpair and assign the GPU side FD to the channel | 241 // point, create the socketpair and assign the GPU side FD to the channel |
191 // name. Keep the renderer side FD as a member variable in the PluginChannel | 242 // name. Keep the renderer side FD as a member variable in the PluginChannel |
192 // to be able to transmit it through IPC. | 243 // to be able to transmit it through IPC. |
193 int gpu_fd; | 244 int gpu_fd; |
194 IPC::SocketPair(&gpu_fd, &renderer_fd_); | 245 IPC::SocketPair(&gpu_fd, &renderer_fd_); |
195 IPC::AddChannelSocket(channel_name, gpu_fd); | 246 IPC::AddChannelSocket(channel_name, gpu_fd); |
196 #endif | 247 #endif |
197 channel_.reset(new IPC::SyncChannel( | 248 channel_.reset(new IPC::SyncChannel( |
198 channel_name, IPC::Channel::MODE_SERVER, this, NULL, | 249 channel_name, IPC::Channel::MODE_SERVER, this, NULL, |
199 ChildProcess::current()->io_message_loop(), false, | 250 ChildProcess::current()->io_message_loop(), false, |
200 ChildProcess::current()->GetShutDownEvent())); | 251 ChildProcess::current()->GetShutDownEvent())); |
| 252 |
201 return true; | 253 return true; |
202 } | 254 } |
203 | 255 |
204 std::string GpuChannel::GetChannelName() { | 256 std::string GpuChannel::GetChannelName() { |
205 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); | 257 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); |
206 } | 258 } |
OLD | NEW |