| 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" | |
| 21 | 20 |
| 22 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
| 23 #include "ipc/ipc_channel_posix.h" | 22 #include "ipc/ipc_channel_posix.h" |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 GpuChannel::GpuChannel(int renderer_id) | 25 GpuChannel::GpuChannel(int renderer_id) |
| 27 : renderer_id_(renderer_id) | 26 : renderer_id_(renderer_id) |
| 28 #if defined(OS_POSIX) | 27 #if defined(OS_POSIX) |
| 29 , renderer_fd_(-1) | 28 , renderer_fd_(-1) |
| 30 #endif | 29 #endif |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 81 } |
| 83 | 82 |
| 84 void GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 83 void GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
| 85 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 84 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
| 86 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, | 85 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, |
| 87 OnCreateViewCommandBuffer) | 86 OnCreateViewCommandBuffer) |
| 88 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, | 87 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, |
| 89 OnCreateOffscreenCommandBuffer) | 88 OnCreateOffscreenCommandBuffer) |
| 90 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 89 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
| 91 OnDestroyCommandBuffer) | 90 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) | |
| 98 IPC_MESSAGE_UNHANDLED_ERROR() | 91 IPC_MESSAGE_UNHANDLED_ERROR() |
| 99 IPC_END_MESSAGE_MAP() | 92 IPC_END_MESSAGE_MAP() |
| 100 } | 93 } |
| 101 | 94 |
| 102 int GpuChannel::GenerateRouteID() { | 95 int GpuChannel::GenerateRouteID() { |
| 103 static int last_id = 0; | 96 static int last_id = 0; |
| 104 return ++last_id; | 97 return ++last_id; |
| 105 } | 98 } |
| 106 | 99 |
| 107 void GpuChannel::OnCreateViewCommandBuffer(gfx::NativeViewId view_id, | 100 void GpuChannel::OnCreateViewCommandBuffer(gfx::NativeViewId view_id, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 #endif | 171 #endif |
| 179 } | 172 } |
| 180 | 173 |
| 181 void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { | 174 void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { |
| 182 #if defined(ENABLE_GPU) | 175 #if defined(ENABLE_GPU) |
| 183 router_.RemoveRoute(route_id); | 176 router_.RemoveRoute(route_id); |
| 184 stubs_.Remove(route_id); | 177 stubs_.Remove(route_id); |
| 185 #endif | 178 #endif |
| 186 } | 179 } |
| 187 | 180 |
| 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 | |
| 232 bool GpuChannel::Init() { | 181 bool GpuChannel::Init() { |
| 233 // Check whether we're already initialized. | 182 // Check whether we're already initialized. |
| 234 if (channel_.get()) | 183 if (channel_.get()) |
| 235 return true; | 184 return true; |
| 236 | 185 |
| 237 // Map renderer ID to a (single) channel to that process. | 186 // Map renderer ID to a (single) channel to that process. |
| 238 std::string channel_name = GetChannelName(); | 187 std::string channel_name = GetChannelName(); |
| 239 #if defined(OS_POSIX) | 188 #if defined(OS_POSIX) |
| 240 // This gets called when the GpuChannel is initially created. At this | 189 // This gets called when the GpuChannel is initially created. At this |
| 241 // point, create the socketpair and assign the GPU side FD to the channel | 190 // point, create the socketpair and assign the GPU side FD to the channel |
| 242 // name. Keep the renderer side FD as a member variable in the PluginChannel | 191 // name. Keep the renderer side FD as a member variable in the PluginChannel |
| 243 // to be able to transmit it through IPC. | 192 // to be able to transmit it through IPC. |
| 244 int gpu_fd; | 193 int gpu_fd; |
| 245 IPC::SocketPair(&gpu_fd, &renderer_fd_); | 194 IPC::SocketPair(&gpu_fd, &renderer_fd_); |
| 246 IPC::AddChannelSocket(channel_name, gpu_fd); | 195 IPC::AddChannelSocket(channel_name, gpu_fd); |
| 247 #endif | 196 #endif |
| 248 channel_.reset(new IPC::SyncChannel( | 197 channel_.reset(new IPC::SyncChannel( |
| 249 channel_name, IPC::Channel::MODE_SERVER, this, NULL, | 198 channel_name, IPC::Channel::MODE_SERVER, this, NULL, |
| 250 ChildProcess::current()->io_message_loop(), false, | 199 ChildProcess::current()->io_message_loop(), false, |
| 251 ChildProcess::current()->GetShutDownEvent())); | 200 ChildProcess::current()->GetShutDownEvent())); |
| 252 | |
| 253 return true; | 201 return true; |
| 254 } | 202 } |
| 255 | 203 |
| 256 std::string GpuChannel::GetChannelName() { | 204 std::string GpuChannel::GetChannelName() { |
| 257 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); | 205 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); |
| 258 } | 206 } |
| OLD | NEW |