OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 const int64 kHandleMoreWorkPeriodBusyMs = 1; | 33 const int64 kHandleMoreWorkPeriodBusyMs = 1; |
34 } | 34 } |
35 | 35 |
36 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, | 36 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, |
37 GpuWatchdog* watchdog, | 37 GpuWatchdog* watchdog, |
38 gfx::GLShareGroup* share_group, | 38 gfx::GLShareGroup* share_group, |
39 int client_id, | 39 int client_id, |
40 bool software) | 40 bool software) |
41 : gpu_channel_manager_(gpu_channel_manager), | 41 : gpu_channel_manager_(gpu_channel_manager), |
42 client_id_(client_id), | 42 client_id_(client_id), |
43 renderer_process_(base::kNullProcessHandle), | |
44 renderer_pid_(base::kNullProcessId), | |
45 share_group_(share_group ? share_group : new gfx::GLShareGroup), | 43 share_group_(share_group ? share_group : new gfx::GLShareGroup), |
46 watchdog_(watchdog), | 44 watchdog_(watchdog), |
47 software_(software), | 45 software_(software), |
48 handle_messages_scheduled_(false), | 46 handle_messages_scheduled_(false), |
49 processed_get_state_fast_(false), | 47 processed_get_state_fast_(false), |
50 num_contexts_preferring_discrete_gpu_(0), | 48 num_contexts_preferring_discrete_gpu_(0), |
51 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 49 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
52 DCHECK(gpu_channel_manager); | 50 DCHECK(gpu_channel_manager); |
53 DCHECK(client_id); | 51 DCHECK(client_id); |
54 | 52 |
55 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); | 53 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); |
56 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 54 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
57 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 55 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
58 disallowed_features_.multisampling = | 56 disallowed_features_.multisampling = |
59 command_line->HasSwitch(switches::kDisableGLMultisampling); | 57 command_line->HasSwitch(switches::kDisableGLMultisampling); |
60 disallowed_features_.driver_bug_workarounds = | 58 disallowed_features_.driver_bug_workarounds = |
61 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); | 59 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
62 } | 60 } |
63 | 61 |
64 GpuChannel::~GpuChannel() { | 62 GpuChannel::~GpuChannel() { |
65 #if defined(OS_WIN) | |
66 if (renderer_process_) | |
67 CloseHandle(renderer_process_); | |
68 #endif | |
69 } | 63 } |
70 | 64 |
71 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { | 65 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { |
72 if (log_messages_) { | 66 if (log_messages_) { |
73 DVLOG(1) << "received message @" << &message << " on channel @" << this | 67 DVLOG(1) << "received message @" << &message << " on channel @" << this |
74 << " with type " << message.type(); | 68 << " with type " << message.type(); |
75 } | 69 } |
76 | 70 |
77 // Control messages are not deferred and can be handled out of order with | 71 // Control messages are not deferred and can be handled out of order with |
78 // respect to routed ones. | 72 // respect to routed ones. |
(...skipping 27 matching lines...) Expand all Loading... |
106 | 100 |
107 OnScheduled(); | 101 OnScheduled(); |
108 | 102 |
109 return true; | 103 return true; |
110 } | 104 } |
111 | 105 |
112 void GpuChannel::OnChannelError() { | 106 void GpuChannel::OnChannelError() { |
113 gpu_channel_manager_->RemoveChannel(client_id_); | 107 gpu_channel_manager_->RemoveChannel(client_id_); |
114 } | 108 } |
115 | 109 |
116 void GpuChannel::OnChannelConnected(int32 peer_pid) { | |
117 renderer_pid_ = peer_pid; | |
118 } | |
119 | |
120 bool GpuChannel::Send(IPC::Message* message) { | 110 bool GpuChannel::Send(IPC::Message* message) { |
121 // The GPU process must never send a synchronous IPC message to the renderer | 111 // The GPU process must never send a synchronous IPC message to the renderer |
122 // process. This could result in deadlock. | 112 // process. This could result in deadlock. |
123 DCHECK(!message->is_sync()); | 113 DCHECK(!message->is_sync()); |
124 if (log_messages_) { | 114 if (log_messages_) { |
125 DVLOG(1) << "sending message @" << message << " on channel @" << this | 115 DVLOG(1) << "sending message @" << message << " on channel @" << this |
126 << " with type " << message->type(); | 116 << " with type " << message->type(); |
127 } | 117 } |
128 | 118 |
129 if (!channel_.get()) { | 119 if (!channel_.get()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 194 |
205 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { | 195 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { |
206 return stubs_.Lookup(route_id); | 196 return stubs_.Lookup(route_id); |
207 } | 197 } |
208 | 198 |
209 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 199 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
210 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 200 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
211 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 201 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
212 bool handled = true; | 202 bool handled = true; |
213 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 203 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
214 IPC_MESSAGE_HANDLER(GpuChannelMsg_Initialize, OnInitialize) | |
215 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, | 204 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, |
216 OnCreateOffscreenCommandBuffer) | 205 OnCreateOffscreenCommandBuffer) |
217 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, | 206 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, |
218 OnDestroyCommandBuffer) | 207 OnDestroyCommandBuffer) |
219 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, | 208 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, |
220 OnWillGpuSwitchOccur) | 209 OnWillGpuSwitchOccur) |
221 IPC_MESSAGE_HANDLER(GpuChannelMsg_CloseChannel, OnCloseChannel) | 210 IPC_MESSAGE_HANDLER(GpuChannelMsg_CloseChannel, OnCloseChannel) |
222 IPC_MESSAGE_UNHANDLED(handled = false) | 211 IPC_MESSAGE_UNHANDLED(handled = false) |
223 IPC_END_MESSAGE_MAP() | 212 IPC_END_MESSAGE_MAP() |
224 DCHECK(handled) << msg.type(); | 213 DCHECK(handled) << msg.type(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 294 } |
306 | 295 |
307 void GpuChannel::RemoveRoute(int32 route_id) { | 296 void GpuChannel::RemoveRoute(int32 route_id) { |
308 router_.RemoveRoute(route_id); | 297 router_.RemoveRoute(route_id); |
309 } | 298 } |
310 | 299 |
311 bool GpuChannel::ShouldPreferDiscreteGpu() const { | 300 bool GpuChannel::ShouldPreferDiscreteGpu() const { |
312 return num_contexts_preferring_discrete_gpu_ > 0; | 301 return num_contexts_preferring_discrete_gpu_ > 0; |
313 } | 302 } |
314 | 303 |
315 void GpuChannel::OnInitialize(base::ProcessHandle renderer_process) { | |
316 // Initialize should only happen once. | |
317 DCHECK(!renderer_process_); | |
318 | |
319 // Verify that the renderer has passed its own process handle. | |
320 if (base::GetProcId(renderer_process) == renderer_pid_) | |
321 renderer_process_ = renderer_process; | |
322 } | |
323 | |
324 void GpuChannel::OnCreateOffscreenCommandBuffer( | 304 void GpuChannel::OnCreateOffscreenCommandBuffer( |
325 const gfx::Size& size, | 305 const gfx::Size& size, |
326 const GPUCreateCommandBufferConfig& init_params, | 306 const GPUCreateCommandBufferConfig& init_params, |
327 IPC::Message* reply_message) { | 307 IPC::Message* reply_message) { |
328 int32 route_id = MSG_ROUTING_NONE; | 308 int32 route_id = MSG_ROUTING_NONE; |
329 | 309 |
330 content::GetContentClient()->SetActiveURL(init_params.active_url); | 310 content::GetContentClient()->SetActiveURL(init_params.active_url); |
331 #if defined(ENABLE_GPU) | 311 #if defined(ENABLE_GPU) |
332 WillCreateCommandBuffer(init_params.gpu_preference); | 312 WillCreateCommandBuffer(init_params.gpu_preference); |
333 | 313 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 424 |
445 #if defined(OS_POSIX) | 425 #if defined(OS_POSIX) |
446 int GpuChannel::TakeRendererFileDescriptor() { | 426 int GpuChannel::TakeRendererFileDescriptor() { |
447 if (!channel_.get()) { | 427 if (!channel_.get()) { |
448 NOTREACHED(); | 428 NOTREACHED(); |
449 return -1; | 429 return -1; |
450 } | 430 } |
451 return channel_->TakeClientFileDescriptor(); | 431 return channel_->TakeClientFileDescriptor(); |
452 } | 432 } |
453 #endif // defined(OS_POSIX) | 433 #endif // defined(OS_POSIX) |
OLD | NEW |