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/browser/gpu/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 201 |
202 void BrowserGpuChannelHostFactory::Terminate() { | 202 void BrowserGpuChannelHostFactory::Terminate() { |
203 DCHECK(instance_); | 203 DCHECK(instance_); |
204 delete instance_; | 204 delete instance_; |
205 instance_ = NULL; | 205 instance_ = NULL; |
206 } | 206 } |
207 | 207 |
208 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 208 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
209 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 209 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
210 shutdown_event_(new base::WaitableEvent(true, false)), | 210 shutdown_event_(new base::WaitableEvent(true, false)), |
211 gpu_host_id_(0) { | 211 gpu_host_id_(0), |
212 current_create_gpu_memory_buffer_request_id_(0) { | |
212 } | 213 } |
213 | 214 |
214 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 215 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
215 DCHECK(IsMainThread()); | 216 DCHECK(IsMainThread()); |
216 if (pending_request_) | 217 if (pending_request_) |
217 pending_request_->Cancel(); | 218 pending_request_->Cancel(); |
218 for (size_t n = 0; n < established_callbacks_.size(); n++) | 219 for (size_t n = 0; n < established_callbacks_.size(); n++) |
219 established_callbacks_[n].Run(); | 220 established_callbacks_[n].Run(); |
220 shutdown_event_->Signal(); | 221 shutdown_event_->Signal(); |
221 } | 222 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 target_task_runner); | 463 target_task_runner); |
463 filter->AddRoute(MSG_ROUTING_CONTROL, handler); | 464 filter->AddRoute(MSG_ROUTING_CONTROL, handler); |
464 | 465 |
465 GetIOLoopProxy()->PostTask( | 466 GetIOLoopProxy()->PostTask( |
466 FROM_HERE, | 467 FROM_HERE, |
467 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, | 468 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, |
468 gpu_host_id_, | 469 gpu_host_id_, |
469 filter)); | 470 filter)); |
470 } | 471 } |
471 | 472 |
473 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( | |
474 const gfx::GpuMemoryBufferHandle& handle, | |
475 const gfx::Size& size, | |
476 unsigned internalformat, | |
477 unsigned usage, | |
478 const CreateGpuMemoryBufferCallback& callback) { | |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
480 int32 request_id = current_create_gpu_memory_buffer_request_id_++; | |
481 create_gpu_memory_buffer_requests_[request_id] = callback; | |
482 GetIOLoopProxy()->PostTask( | |
483 FROM_HERE, | |
484 base::Bind(&BrowserGpuChannelHostFactory::CreateGpuMemoryBufferOnIO, | |
485 base::Unretained(this), | |
486 handle, | |
487 size, | |
488 internalformat, | |
489 usage, | |
490 request_id)); | |
491 } | |
492 | |
493 void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer( | |
494 const gfx::GpuMemoryBufferHandle& handle, | |
495 int32 sync_point) { | |
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
497 GetIOLoopProxy()->PostTask( | |
498 FROM_HERE, | |
499 base::Bind(&BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO, | |
500 base::Unretained(this), | |
501 handle, | |
502 sync_point)); | |
503 } | |
504 | |
505 void BrowserGpuChannelHostFactory::CreateGpuMemoryBufferOnIO( | |
506 const gfx::GpuMemoryBufferHandle& handle, | |
507 const gfx::Size& size, | |
508 unsigned internalformat, | |
509 unsigned usage, | |
510 int32 request_id) { | |
511 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | |
512 if (!host) { | |
513 GpuMemoryBufferCreatedOnIO(request_id, gfx::GpuMemoryBufferHandle()); | |
514 return; | |
515 } | |
516 | |
517 host->CreateGpuMemoryBuffer( | |
518 handle, | |
519 size, | |
520 internalformat, | |
521 usage, | |
522 base::Bind(&BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO, | |
523 request_id)); | |
524 } | |
525 | |
526 // static | |
527 void BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO( | |
528 int32 request_id, | |
529 const gfx::GpuMemoryBufferHandle& handle) { | |
530 BrowserThread::PostTask( | |
531 BrowserThread::UI, | |
532 FROM_HERE, | |
533 base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated, | |
534 request_id, | |
535 handle)); | |
536 } | |
537 | |
538 // static | |
539 void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( | |
540 int32 request_id, | |
541 const gfx::GpuMemoryBufferHandle& handle) { | |
542 DCHECK(instance_); | |
reveman
2014/06/10 13:39:00
can you avoid the use of |instance_| here by makin
alexst (slow to review)
2014/06/10 14:22:44
Done.
| |
543 CreateGpuMemoryBufferCallbackMap::iterator iter = | |
544 instance_->create_gpu_memory_buffer_requests_.find(request_id); | |
545 DCHECK(iter != instance_->create_gpu_memory_buffer_requests_.end()); | |
546 iter->second.Run(handle); | |
547 instance_->create_gpu_memory_buffer_requests_.erase(iter); | |
548 } | |
549 | |
550 void BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO( | |
551 const gfx::GpuMemoryBufferHandle& handle, | |
552 int32 sync_point) { | |
553 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | |
554 if (!host) { | |
555 return; | |
556 } | |
557 | |
558 host->DestroyGpuMemoryBuffer(handle, sync_point); | |
559 } | |
560 | |
472 } // namespace content | 561 } // namespace content |
OLD | NEW |