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() { } |
apatrick_chromium
2012/04/09 18:40:58
nit: drop } to next line so I can set breakpoints
jschuh
2012/04/10 19:02:12
Done.
| |
65 #if defined(OS_WIN) | |
66 if (renderer_process_) | |
67 CloseHandle(renderer_process_); | |
68 #endif | |
69 } | |
70 | 63 |
71 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { | 64 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { |
72 if (log_messages_) { | 65 if (log_messages_) { |
73 DVLOG(1) << "received message @" << &message << " on channel @" << this | 66 DVLOG(1) << "received message @" << &message << " on channel @" << this |
74 << " with type " << message.type(); | 67 << " with type " << message.type(); |
75 } | 68 } |
76 | 69 |
77 // Control messages are not deferred and can be handled out of order with | 70 // Control messages are not deferred and can be handled out of order with |
78 // respect to routed ones. | 71 // respect to routed ones. |
79 if (message.routing_id() == MSG_ROUTING_CONTROL) | 72 if (message.routing_id() == MSG_ROUTING_CONTROL) |
(...skipping 26 matching lines...) Expand all Loading... | |
106 | 99 |
107 OnScheduled(); | 100 OnScheduled(); |
108 | 101 |
109 return true; | 102 return true; |
110 } | 103 } |
111 | 104 |
112 void GpuChannel::OnChannelError() { | 105 void GpuChannel::OnChannelError() { |
113 gpu_channel_manager_->RemoveChannel(client_id_); | 106 gpu_channel_manager_->RemoveChannel(client_id_); |
114 } | 107 } |
115 | 108 |
116 void GpuChannel::OnChannelConnected(int32 peer_pid) { | |
117 renderer_pid_ = peer_pid; | |
118 } | |
119 | |
120 bool GpuChannel::Send(IPC::Message* message) { | 109 bool GpuChannel::Send(IPC::Message* message) { |
121 // The GPU process must never send a synchronous IPC message to the renderer | 110 // The GPU process must never send a synchronous IPC message to the renderer |
122 // process. This could result in deadlock. | 111 // process. This could result in deadlock. |
123 DCHECK(!message->is_sync()); | 112 DCHECK(!message->is_sync()); |
124 if (log_messages_) { | 113 if (log_messages_) { |
125 DVLOG(1) << "sending message @" << message << " on channel @" << this | 114 DVLOG(1) << "sending message @" << message << " on channel @" << this |
126 << " with type " << message->type(); | 115 << " with type " << message->type(); |
127 } | 116 } |
128 | 117 |
129 if (!channel_.get()) { | 118 if (!channel_.get()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 193 |
205 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { | 194 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { |
206 return stubs_.Lookup(route_id); | 195 return stubs_.Lookup(route_id); |
207 } | 196 } |
208 | 197 |
209 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 198 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
210 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 199 // 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. | 200 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
212 bool handled = true; | 201 bool handled = true; |
213 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 202 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
214 IPC_MESSAGE_HANDLER(GpuChannelMsg_Initialize, OnInitialize) | |
215 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, | 203 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, |
216 OnCreateOffscreenCommandBuffer) | 204 OnCreateOffscreenCommandBuffer) |
217 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, | 205 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, |
218 OnDestroyCommandBuffer) | 206 OnDestroyCommandBuffer) |
219 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, | 207 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, |
220 OnWillGpuSwitchOccur) | 208 OnWillGpuSwitchOccur) |
221 IPC_MESSAGE_HANDLER(GpuChannelMsg_CloseChannel, OnCloseChannel) | 209 IPC_MESSAGE_HANDLER(GpuChannelMsg_CloseChannel, OnCloseChannel) |
222 IPC_MESSAGE_UNHANDLED(handled = false) | 210 IPC_MESSAGE_UNHANDLED(handled = false) |
223 IPC_END_MESSAGE_MAP() | 211 IPC_END_MESSAGE_MAP() |
224 DCHECK(handled) << msg.type(); | 212 DCHECK(handled) << msg.type(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 } | 293 } |
306 | 294 |
307 void GpuChannel::RemoveRoute(int32 route_id) { | 295 void GpuChannel::RemoveRoute(int32 route_id) { |
308 router_.RemoveRoute(route_id); | 296 router_.RemoveRoute(route_id); |
309 } | 297 } |
310 | 298 |
311 bool GpuChannel::ShouldPreferDiscreteGpu() const { | 299 bool GpuChannel::ShouldPreferDiscreteGpu() const { |
312 return num_contexts_preferring_discrete_gpu_ > 0; | 300 return num_contexts_preferring_discrete_gpu_ > 0; |
313 } | 301 } |
314 | 302 |
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( | 303 void GpuChannel::OnCreateOffscreenCommandBuffer( |
325 const gfx::Size& size, | 304 const gfx::Size& size, |
326 const GPUCreateCommandBufferConfig& init_params, | 305 const GPUCreateCommandBufferConfig& init_params, |
327 IPC::Message* reply_message) { | 306 IPC::Message* reply_message) { |
328 int32 route_id = MSG_ROUTING_NONE; | 307 int32 route_id = MSG_ROUTING_NONE; |
329 | 308 |
330 content::GetContentClient()->SetActiveURL(init_params.active_url); | 309 content::GetContentClient()->SetActiveURL(init_params.active_url); |
331 #if defined(ENABLE_GPU) | 310 #if defined(ENABLE_GPU) |
332 WillCreateCommandBuffer(init_params.gpu_preference); | 311 WillCreateCommandBuffer(init_params.gpu_preference); |
333 | 312 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 423 |
445 #if defined(OS_POSIX) | 424 #if defined(OS_POSIX) |
446 int GpuChannel::TakeRendererFileDescriptor() { | 425 int GpuChannel::TakeRendererFileDescriptor() { |
447 if (!channel_.get()) { | 426 if (!channel_.get()) { |
448 NOTREACHED(); | 427 NOTREACHED(); |
449 return -1; | 428 return -1; |
450 } | 429 } |
451 return channel_->TakeClientFileDescriptor(); | 430 return channel_->TakeClientFileDescriptor(); |
452 } | 431 } |
453 #endif // defined(OS_POSIX) | 432 #endif // defined(OS_POSIX) |
OLD | NEW |