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 next_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 uint32 request_id = next_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 uint32 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 base::Unretained(this), |
| 524 request_id)); |
| 525 } |
| 526 |
| 527 void BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO( |
| 528 uint32 request_id, |
| 529 const gfx::GpuMemoryBufferHandle& handle) { |
| 530 BrowserThread::PostTask( |
| 531 BrowserThread::UI, |
| 532 FROM_HERE, |
| 533 base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated, |
| 534 base::Unretained(this), |
| 535 request_id, |
| 536 handle)); |
| 537 } |
| 538 |
| 539 void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( |
| 540 uint32 request_id, |
| 541 const gfx::GpuMemoryBufferHandle& handle) { |
| 542 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 543 create_gpu_memory_buffer_requests_.find(request_id); |
| 544 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 545 iter->second.Run(handle); |
| 546 create_gpu_memory_buffer_requests_.erase(iter); |
| 547 } |
| 548 |
| 549 void BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO( |
| 550 const gfx::GpuMemoryBufferHandle& handle, |
| 551 int32 sync_point) { |
| 552 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 553 if (!host) |
| 554 return; |
| 555 |
| 556 host->DestroyGpuMemoryBuffer(handle, sync_point); |
| 557 } |
| 558 |
472 } // namespace content | 559 } // namespace content |
OLD | NEW |