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 #include "content/common/gpu/client/gpu_channel_host.h" | 5 #include "content/common/gpu/client/gpu_channel_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 void GpuChannelHost::SetStateLost() { | 66 void GpuChannelHost::SetStateLost() { |
67 state_ = kLost; | 67 state_ = kLost; |
68 } | 68 } |
69 | 69 |
70 const GPUInfo& GpuChannelHost::gpu_info() const { | 70 const GPUInfo& GpuChannelHost::gpu_info() const { |
71 return gpu_info_; | 71 return gpu_info_; |
72 } | 72 } |
73 | 73 |
| 74 void GpuChannelHost::OnMessageReceived(const IPC::Message& message) { |
| 75 bool handled = true; |
| 76 |
| 77 IPC_BEGIN_MESSAGE_MAP(GpuChannelHost, message) |
| 78 IPC_MESSAGE_HANDLER(GpuChannelMsg_GenerateMailboxNamesReply, |
| 79 OnGenerateMailboxNamesReply) |
| 80 IPC_MESSAGE_UNHANDLED(handled = false) |
| 81 IPC_END_MESSAGE_MAP() |
| 82 |
| 83 DCHECK(handled); |
| 84 } |
| 85 |
74 void GpuChannelHost::OnChannelError() { | 86 void GpuChannelHost::OnChannelError() { |
75 state_ = kLost; | 87 state_ = kLost; |
76 | 88 |
77 // Channel is invalid and will be reinitialized if this host is requested | 89 // Channel is invalid and will be reinitialized if this host is requested |
78 // again. | 90 // again. |
79 channel_.reset(); | 91 channel_.reset(); |
80 } | 92 } |
81 | 93 |
82 bool GpuChannelHost::Send(IPC::Message* message) { | 94 bool GpuChannelHost::Send(IPC::Message* message) { |
83 // The GPU process never sends synchronous IPCs so clear the unblock flag to | 95 // The GPU process never sends synchronous IPCs so clear the unblock flag to |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); | 251 scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); |
240 io_loop->PostTask(FROM_HERE, | 252 io_loop->PostTask(FROM_HERE, |
241 base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, | 253 base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, |
242 channel_filter_.get(), route_id)); | 254 channel_filter_.get(), route_id)); |
243 } | 255 } |
244 | 256 |
245 bool GpuChannelHost::GenerateMailboxNames(unsigned num, | 257 bool GpuChannelHost::GenerateMailboxNames(unsigned num, |
246 std::vector<std::string>* names) { | 258 std::vector<std::string>* names) { |
247 TRACE_EVENT0("gpu", "GenerateMailboxName"); | 259 TRACE_EVENT0("gpu", "GenerateMailboxName"); |
248 AutoLock lock(context_lock_); | 260 AutoLock lock(context_lock_); |
249 return Send(new GpuChannelMsg_GenerateMailboxNames(num, names)); | 261 |
| 262 if (num > mailbox_name_pool_.size()) { |
| 263 if (!Send(new GpuChannelMsg_GenerateMailboxNames(num, names))) |
| 264 return false; |
| 265 } else { |
| 266 names->insert(names->begin(), |
| 267 mailbox_name_pool_.end() - num, |
| 268 mailbox_name_pool_.end()); |
| 269 mailbox_name_pool_.erase(mailbox_name_pool_.end() - num, |
| 270 mailbox_name_pool_.end()); |
| 271 } |
| 272 |
| 273 const unsigned ideal_mailbox_pool_size = 100; |
| 274 if (mailbox_name_pool_.size() < ideal_mailbox_pool_size / 2) { |
| 275 Send(new GpuChannelMsg_GenerateMailboxNamesAsync( |
| 276 ideal_mailbox_pool_size - mailbox_name_pool_.size())); |
| 277 } |
| 278 |
| 279 return true; |
| 280 } |
| 281 |
| 282 void GpuChannelHost::OnGenerateMailboxNamesReply( |
| 283 const std::vector<std::string>& names) { |
| 284 TRACE_EVENT0("gpu", "OnGenerateMailboxNamesReply"); |
| 285 AutoLock lock(context_lock_); |
| 286 |
| 287 mailbox_name_pool_.insert(mailbox_name_pool_.end(), |
| 288 names.begin(), |
| 289 names.end()); |
250 } | 290 } |
251 | 291 |
252 GpuChannelHost::~GpuChannelHost() {} | 292 GpuChannelHost::~GpuChannelHost() {} |
253 | 293 |
254 | 294 |
255 GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) | 295 GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) |
256 : parent_(parent) { | 296 : parent_(parent) { |
257 } | 297 } |
258 | 298 |
259 GpuChannelHost::MessageFilter::~MessageFilter() {} | 299 GpuChannelHost::MessageFilter::~MessageFilter() {} |
(...skipping 13 matching lines...) Expand all Loading... |
273 void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { | 313 void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { |
274 DCHECK(parent_->factory_->IsIOThread()); | 314 DCHECK(parent_->factory_->IsIOThread()); |
275 ListenerMap::iterator it = listeners_.find(route_id); | 315 ListenerMap::iterator it = listeners_.find(route_id); |
276 if (it != listeners_.end()) | 316 if (it != listeners_.end()) |
277 listeners_.erase(it); | 317 listeners_.erase(it); |
278 } | 318 } |
279 | 319 |
280 bool GpuChannelHost::MessageFilter::OnMessageReceived( | 320 bool GpuChannelHost::MessageFilter::OnMessageReceived( |
281 const IPC::Message& message) { | 321 const IPC::Message& message) { |
282 DCHECK(parent_->factory_->IsIOThread()); | 322 DCHECK(parent_->factory_->IsIOThread()); |
| 323 |
283 // Never handle sync message replies or we will deadlock here. | 324 // Never handle sync message replies or we will deadlock here. |
284 if (message.is_reply()) | 325 if (message.is_reply()) |
285 return false; | 326 return false; |
286 | 327 |
287 DCHECK(message.routing_id() != MSG_ROUTING_CONTROL); | 328 if (message.routing_id() == MSG_ROUTING_CONTROL) { |
| 329 MessageLoop* main_loop = parent_->factory_->GetMainLoop(); |
| 330 main_loop->PostTask(FROM_HERE, |
| 331 base::Bind(&GpuChannelHost::OnMessageReceived, |
| 332 parent_, |
| 333 message)); |
| 334 return true; |
| 335 } |
288 | 336 |
289 ListenerMap::iterator it = listeners_.find(message.routing_id()); | 337 ListenerMap::iterator it = listeners_.find(message.routing_id()); |
290 | 338 |
291 if (it != listeners_.end()) { | 339 if (it != listeners_.end()) { |
292 const GpuListenerInfo& info = it->second; | 340 const GpuListenerInfo& info = it->second; |
293 info.loop->PostTask( | 341 info.loop->PostTask( |
294 FROM_HERE, | 342 FROM_HERE, |
295 base::Bind( | 343 base::Bind( |
296 base::IgnoreResult(&IPC::Listener::OnMessageReceived), | 344 base::IgnoreResult(&IPC::Listener::OnMessageReceived), |
297 info.listener, | 345 info.listener, |
(...skipping 20 matching lines...) Expand all Loading... |
318 const GpuListenerInfo& info = it->second; | 366 const GpuListenerInfo& info = it->second; |
319 info.loop->PostTask( | 367 info.loop->PostTask( |
320 FROM_HERE, | 368 FROM_HERE, |
321 base::Bind(&IPC::Listener::OnChannelError, info.listener)); | 369 base::Bind(&IPC::Listener::OnChannelError, info.listener)); |
322 } | 370 } |
323 | 371 |
324 listeners_.clear(); | 372 listeners_.clear(); |
325 } | 373 } |
326 | 374 |
327 } // namespace content | 375 } // namespace content |
OLD | NEW |