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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); | 53 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); |
54 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 54 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
55 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 55 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
56 disallowed_features_.multisampling = | 56 disallowed_features_.multisampling = |
57 command_line->HasSwitch(switches::kDisableGLMultisampling); | 57 command_line->HasSwitch(switches::kDisableGLMultisampling); |
58 disallowed_features_.driver_bug_workarounds = | 58 disallowed_features_.driver_bug_workarounds = |
59 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); | 59 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
60 } | 60 } |
61 | 61 |
62 GpuChannel::~GpuChannel() { | 62 |
| 63 bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, |
| 64 base::WaitableEvent* shutdown_event) { |
| 65 DCHECK(!channel_.get()); |
| 66 |
| 67 // Map renderer ID to a (single) channel to that process. |
| 68 channel_.reset(new IPC::SyncChannel( |
| 69 channel_id_, |
| 70 IPC::Channel::MODE_SERVER, |
| 71 this, |
| 72 io_message_loop, |
| 73 false, |
| 74 shutdown_event)); |
| 75 |
| 76 return true; |
63 } | 77 } |
64 | 78 |
| 79 std::string GpuChannel::GetChannelName() { |
| 80 return channel_id_; |
| 81 } |
| 82 |
| 83 #if defined(OS_POSIX) |
| 84 int GpuChannel::TakeRendererFileDescriptor() { |
| 85 if (!channel_.get()) { |
| 86 NOTREACHED(); |
| 87 return -1; |
| 88 } |
| 89 return channel_->TakeClientFileDescriptor(); |
| 90 } |
| 91 #endif // defined(OS_POSIX) |
| 92 |
65 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { | 93 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { |
66 if (log_messages_) { | 94 if (log_messages_) { |
67 DVLOG(1) << "received message @" << &message << " on channel @" << this | 95 DVLOG(1) << "received message @" << &message << " on channel @" << this |
68 << " with type " << message.type(); | 96 << " with type " << message.type(); |
69 } | 97 } |
70 | 98 |
71 // Control messages are not deferred and can be handled out of order with | 99 // Control messages are not deferred and can be handled out of order with |
72 // respect to routed ones. | 100 // respect to routed ones. |
73 if (message.routing_id() == MSG_ROUTING_CONTROL) | 101 if (message.routing_id() == MSG_ROUTING_CONTROL) |
74 return OnControlMessageReceived(message); | 102 return OnControlMessageReceived(message); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // not emptied here, which ensures that OnMessageReceived will continue to | 167 // not emptied here, which ensures that OnMessageReceived will continue to |
140 // defer newly received messages until the ones in the queue have all been | 168 // defer newly received messages until the ones in the queue have all been |
141 // handled by HandleMessage. HandleMessage is invoked as a | 169 // handled by HandleMessage. HandleMessage is invoked as a |
142 // task to prevent reentrancy. | 170 // task to prevent reentrancy. |
143 MessageLoop::current()->PostTask( | 171 MessageLoop::current()->PostTask( |
144 FROM_HERE, | 172 FROM_HERE, |
145 base::Bind(&GpuChannel::HandleMessage, weak_factory_.GetWeakPtr())); | 173 base::Bind(&GpuChannel::HandleMessage, weak_factory_.GetWeakPtr())); |
146 handle_messages_scheduled_ = true; | 174 handle_messages_scheduled_ = true; |
147 } | 175 } |
148 | 176 |
149 void GpuChannel::LoseAllContexts() { | |
150 gpu_channel_manager_->LoseAllContexts(); | |
151 } | |
152 | |
153 void GpuChannel::DestroySoon() { | |
154 MessageLoop::current()->PostTask( | |
155 FROM_HERE, base::Bind(&GpuChannel::OnDestroy, this)); | |
156 } | |
157 | |
158 void GpuChannel::OnDestroy() { | |
159 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); | |
160 gpu_channel_manager_->RemoveChannel(client_id_); | |
161 } | |
162 | |
163 void GpuChannel::CreateViewCommandBuffer( | 177 void GpuChannel::CreateViewCommandBuffer( |
164 const gfx::GLSurfaceHandle& window, | 178 const gfx::GLSurfaceHandle& window, |
165 int32 surface_id, | 179 int32 surface_id, |
166 const GPUCreateCommandBufferConfig& init_params, | 180 const GPUCreateCommandBufferConfig& init_params, |
167 int32* route_id) { | 181 int32* route_id) { |
168 *route_id = MSG_ROUTING_NONE; | 182 *route_id = MSG_ROUTING_NONE; |
169 content::GetContentClient()->SetActiveURL(init_params.active_url); | 183 content::GetContentClient()->SetActiveURL(init_params.active_url); |
170 | 184 |
171 #if defined(ENABLE_GPU) | 185 #if defined(ENABLE_GPU) |
172 WillCreateCommandBuffer(init_params.gpu_preference); | 186 WillCreateCommandBuffer(init_params.gpu_preference); |
(...skipping 16 matching lines...) Expand all Loading... |
189 software_)); | 203 software_)); |
190 router_.AddRoute(*route_id, stub.get()); | 204 router_.AddRoute(*route_id, stub.get()); |
191 stubs_.AddWithID(stub.release(), *route_id); | 205 stubs_.AddWithID(stub.release(), *route_id); |
192 #endif // ENABLE_GPU | 206 #endif // ENABLE_GPU |
193 } | 207 } |
194 | 208 |
195 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { | 209 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { |
196 return stubs_.Lookup(route_id); | 210 return stubs_.Lookup(route_id); |
197 } | 211 } |
198 | 212 |
| 213 void GpuChannel::LoseAllContexts() { |
| 214 gpu_channel_manager_->LoseAllContexts(); |
| 215 } |
| 216 |
| 217 void GpuChannel::DestroySoon() { |
| 218 MessageLoop::current()->PostTask( |
| 219 FROM_HERE, base::Bind(&GpuChannel::OnDestroy, this)); |
| 220 } |
| 221 |
| 222 int GpuChannel::GenerateRouteID() { |
| 223 static int last_id = 0; |
| 224 return ++last_id; |
| 225 } |
| 226 |
| 227 void GpuChannel::AddRoute(int32 route_id, IPC::Channel::Listener* listener) { |
| 228 router_.AddRoute(route_id, listener); |
| 229 } |
| 230 |
| 231 void GpuChannel::RemoveRoute(int32 route_id) { |
| 232 router_.RemoveRoute(route_id); |
| 233 } |
| 234 |
| 235 bool GpuChannel::ShouldPreferDiscreteGpu() const { |
| 236 return num_contexts_preferring_discrete_gpu_ > 0; |
| 237 } |
| 238 |
| 239 GpuChannel::~GpuChannel() {} |
| 240 |
| 241 void GpuChannel::OnDestroy() { |
| 242 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); |
| 243 gpu_channel_manager_->RemoveChannel(client_id_); |
| 244 } |
| 245 |
199 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 246 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
200 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 247 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
201 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 248 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
202 bool handled = true; | 249 bool handled = true; |
203 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 250 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
204 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, | 251 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateOffscreenCommandBuffer, |
205 OnCreateOffscreenCommandBuffer) | 252 OnCreateOffscreenCommandBuffer) |
206 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, | 253 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_DestroyCommandBuffer, |
207 OnDestroyCommandBuffer) | 254 OnDestroyCommandBuffer) |
208 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, | 255 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_WillGpuSwitchOccur, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 if (stub->HasMoreWork()) { | 324 if (stub->HasMoreWork()) { |
278 MessageLoop::current()->PostDelayedTask( | 325 MessageLoop::current()->PostDelayedTask( |
279 FROM_HERE, | 326 FROM_HERE, |
280 base::Bind(&GpuChannel::PollWork, | 327 base::Bind(&GpuChannel::PollWork, |
281 weak_factory_.GetWeakPtr(), | 328 weak_factory_.GetWeakPtr(), |
282 stub->route_id()), | 329 stub->route_id()), |
283 base::TimeDelta::FromMilliseconds(delay)); | 330 base::TimeDelta::FromMilliseconds(delay)); |
284 } | 331 } |
285 } | 332 } |
286 | 333 |
287 int GpuChannel::GenerateRouteID() { | |
288 static int last_id = 0; | |
289 return ++last_id; | |
290 } | |
291 | |
292 void GpuChannel::AddRoute(int32 route_id, IPC::Channel::Listener* listener) { | |
293 router_.AddRoute(route_id, listener); | |
294 } | |
295 | |
296 void GpuChannel::RemoveRoute(int32 route_id) { | |
297 router_.RemoveRoute(route_id); | |
298 } | |
299 | |
300 bool GpuChannel::ShouldPreferDiscreteGpu() const { | |
301 return num_contexts_preferring_discrete_gpu_ > 0; | |
302 } | |
303 | |
304 void GpuChannel::OnCreateOffscreenCommandBuffer( | 334 void GpuChannel::OnCreateOffscreenCommandBuffer( |
305 const gfx::Size& size, | 335 const gfx::Size& size, |
306 const GPUCreateCommandBufferConfig& init_params, | 336 const GPUCreateCommandBufferConfig& init_params, |
307 IPC::Message* reply_message) { | 337 IPC::Message* reply_message) { |
308 int32 route_id = MSG_ROUTING_NONE; | 338 int32 route_id = MSG_ROUTING_NONE; |
309 | 339 |
310 content::GetContentClient()->SetActiveURL(init_params.active_url); | 340 content::GetContentClient()->SetActiveURL(init_params.active_url); |
311 #if defined(ENABLE_GPU) | 341 #if defined(ENABLE_GPU) |
312 WillCreateCommandBuffer(init_params.gpu_preference); | 342 WillCreateCommandBuffer(init_params.gpu_preference); |
313 | 343 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 reply_message, | 414 reply_message, |
385 will_switch_occur); | 415 will_switch_occur); |
386 Send(reply_message); | 416 Send(reply_message); |
387 } | 417 } |
388 | 418 |
389 void GpuChannel::OnCloseChannel() { | 419 void GpuChannel::OnCloseChannel() { |
390 gpu_channel_manager_->RemoveChannel(client_id_); | 420 gpu_channel_manager_->RemoveChannel(client_id_); |
391 // At this point "this" is deleted! | 421 // At this point "this" is deleted! |
392 } | 422 } |
393 | 423 |
394 bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, | |
395 base::WaitableEvent* shutdown_event) { | |
396 DCHECK(!channel_.get()); | |
397 | |
398 // Map renderer ID to a (single) channel to that process. | |
399 channel_.reset(new IPC::SyncChannel( | |
400 channel_id_, | |
401 IPC::Channel::MODE_SERVER, | |
402 this, | |
403 io_message_loop, | |
404 false, | |
405 shutdown_event)); | |
406 | |
407 return true; | |
408 } | |
409 | |
410 void GpuChannel::WillCreateCommandBuffer(gfx::GpuPreference gpu_preference) { | 424 void GpuChannel::WillCreateCommandBuffer(gfx::GpuPreference gpu_preference) { |
411 if (gpu_preference == gfx::PreferDiscreteGpu) | 425 if (gpu_preference == gfx::PreferDiscreteGpu) |
412 ++num_contexts_preferring_discrete_gpu_; | 426 ++num_contexts_preferring_discrete_gpu_; |
413 } | 427 } |
414 | 428 |
415 void GpuChannel::DidDestroyCommandBuffer(gfx::GpuPreference gpu_preference) { | 429 void GpuChannel::DidDestroyCommandBuffer(gfx::GpuPreference gpu_preference) { |
416 if (gpu_preference == gfx::PreferDiscreteGpu) | 430 if (gpu_preference == gfx::PreferDiscreteGpu) |
417 --num_contexts_preferring_discrete_gpu_; | 431 --num_contexts_preferring_discrete_gpu_; |
418 DCHECK_GE(num_contexts_preferring_discrete_gpu_, 0); | 432 DCHECK_GE(num_contexts_preferring_discrete_gpu_, 0); |
419 } | 433 } |
420 | |
421 std::string GpuChannel::GetChannelName() { | |
422 return channel_id_; | |
423 } | |
424 | |
425 #if defined(OS_POSIX) | |
426 int GpuChannel::TakeRendererFileDescriptor() { | |
427 if (!channel_.get()) { | |
428 NOTREACHED(); | |
429 return -1; | |
430 } | |
431 return channel_->TakeClientFileDescriptor(); | |
432 } | |
433 #endif // defined(OS_POSIX) | |
OLD | NEW |