| 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" |
| 11 #include "content/browser/gpu/gpu_data_manager_impl.h" | 11 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 12 #include "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h" |
| 12 #include "content/browser/gpu/gpu_process_host.h" | 13 #include "content/browser/gpu/gpu_process_host.h" |
| 13 #include "content/browser/gpu/gpu_surface_tracker.h" | 14 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 14 #include "content/common/child_process_host_impl.h" | 15 #include "content/common/child_process_host_impl.h" |
| 15 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 16 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 16 #include "content/common/gpu/gpu_messages.h" | 17 #include "content/common/gpu/gpu_messages.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/gpu_data_manager.h" | 19 #include "content/public/browser/gpu_data_manager.h" |
| 19 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 21 #include "ipc/ipc_channel_handle.h" |
| 21 #include "ipc/ipc_forwarding_message_filter.h" | 22 #include "ipc/ipc_forwarding_message_filter.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 225 |
| 225 void BrowserGpuChannelHostFactory::Terminate() { | 226 void BrowserGpuChannelHostFactory::Terminate() { |
| 226 DCHECK(instance_); | 227 DCHECK(instance_); |
| 227 delete instance_; | 228 delete instance_; |
| 228 instance_ = NULL; | 229 instance_ = NULL; |
| 229 } | 230 } |
| 230 | 231 |
| 231 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 232 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
| 232 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 233 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 233 shutdown_event_(new base::WaitableEvent(true, false)), | 234 shutdown_event_(new base::WaitableEvent(true, false)), |
| 234 gpu_host_id_(0), | 235 gpu_memory_buffer_factory_host_(new GpuMemoryBufferFactoryHostImpl), |
| 235 next_create_gpu_memory_buffer_request_id_(0) { | 236 gpu_host_id_(0) { |
| 236 } | 237 } |
| 237 | 238 |
| 238 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 239 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
| 239 DCHECK(IsMainThread()); | 240 DCHECK(IsMainThread()); |
| 240 if (pending_request_.get()) | 241 if (pending_request_.get()) |
| 241 pending_request_->Cancel(); | 242 pending_request_->Cancel(); |
| 242 for (size_t n = 0; n < established_callbacks_.size(); n++) | 243 for (size_t n = 0; n < established_callbacks_.size(); n++) |
| 243 established_callbacks_[n].Run(); | 244 established_callbacks_[n].Run(); |
| 244 shutdown_event_->Signal(); | 245 shutdown_event_->Signal(); |
| 245 } | 246 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if (pending_request_->channel_handle().name.empty()) { | 364 if (pending_request_->channel_handle().name.empty()) { |
| 364 DCHECK(!gpu_channel_.get()); | 365 DCHECK(!gpu_channel_.get()); |
| 365 } else { | 366 } else { |
| 366 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); | 367 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); |
| 367 gpu_channel_ = GpuChannelHost::Create(this, | 368 gpu_channel_ = GpuChannelHost::Create(this, |
| 368 pending_request_->gpu_info(), | 369 pending_request_->gpu_info(), |
| 369 pending_request_->channel_handle(), | 370 pending_request_->channel_handle(), |
| 370 shutdown_event_.get()); | 371 shutdown_event_.get()); |
| 371 } | 372 } |
| 372 gpu_host_id_ = pending_request_->gpu_host_id(); | 373 gpu_host_id_ = pending_request_->gpu_host_id(); |
| 374 gpu_memory_buffer_factory_host_->set_gpu_host_id(gpu_host_id_); |
| 373 pending_request_ = NULL; | 375 pending_request_ = NULL; |
| 374 | 376 |
| 375 for (size_t n = 0; n < established_callbacks_.size(); n++) | 377 for (size_t n = 0; n < established_callbacks_.size(); n++) |
| 376 established_callbacks_[n].Run(); | 378 established_callbacks_[n].Run(); |
| 377 | 379 |
| 378 established_callbacks_.clear(); | 380 established_callbacks_.clear(); |
| 379 } | 381 } |
| 380 | 382 |
| 381 scoped_ptr<gfx::GpuMemoryBuffer> | 383 scoped_ptr<gfx::GpuMemoryBuffer> |
| 382 BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width, | 384 BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 402 void BrowserGpuChannelHostFactory::DeleteGpuMemoryBuffer( | 404 void BrowserGpuChannelHostFactory::DeleteGpuMemoryBuffer( |
| 403 scoped_ptr<gfx::GpuMemoryBuffer> buffer) { | 405 scoped_ptr<gfx::GpuMemoryBuffer> buffer) { |
| 404 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 406 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 405 | 407 |
| 406 GetIOLoopProxy()->PostTask( | 408 GetIOLoopProxy()->PostTask( |
| 407 FROM_HERE, | 409 FROM_HERE, |
| 408 base::Bind(&BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO, | 410 base::Bind(&BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO, |
| 409 base::Passed(&buffer))); | 411 base::Passed(&buffer))); |
| 410 } | 412 } |
| 411 | 413 |
| 412 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( | |
| 413 const gfx::GpuMemoryBufferHandle& handle, | |
| 414 const gfx::Size& size, | |
| 415 unsigned internalformat, | |
| 416 unsigned usage, | |
| 417 const CreateGpuMemoryBufferCallback& callback) { | |
| 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 419 | |
| 420 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | |
| 421 if (!host) { | |
| 422 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 423 return; | |
| 424 } | |
| 425 | |
| 426 uint32 request_id = next_create_gpu_memory_buffer_request_id_++; | |
| 427 create_gpu_memory_buffer_requests_[request_id] = callback; | |
| 428 | |
| 429 host->CreateGpuMemoryBuffer( | |
| 430 handle, | |
| 431 size, | |
| 432 internalformat, | |
| 433 usage, | |
| 434 base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated, | |
| 435 base::Unretained(this), | |
| 436 request_id)); | |
| 437 } | |
| 438 | |
| 439 void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer( | |
| 440 const gfx::GpuMemoryBufferHandle& handle, | |
| 441 int32 sync_point) { | |
| 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 443 | |
| 444 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | |
| 445 if (!host) | |
| 446 return; | |
| 447 | |
| 448 host->DestroyGpuMemoryBuffer(handle, sync_point); | |
| 449 } | |
| 450 | |
| 451 // static | 414 // static |
| 452 void BrowserGpuChannelHostFactory::AddFilterOnIO( | 415 void BrowserGpuChannelHostFactory::AddFilterOnIO( |
| 453 int host_id, | 416 int host_id, |
| 454 scoped_refptr<IPC::MessageFilter> filter) { | 417 scoped_refptr<IPC::MessageFilter> filter) { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 456 | 419 |
| 457 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 420 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
| 458 if (host) | 421 if (host) |
| 459 host->AddFilter(filter.get()); | 422 host->AddFilter(filter.get()); |
| 460 } | 423 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 485 // static | 448 // static |
| 486 void BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO( | 449 void BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO( |
| 487 AllocateGpuMemoryBufferRequest* request) { | 450 AllocateGpuMemoryBufferRequest* request) { |
| 488 if (!GpuMemoryBufferImpl::IsFormatValid(request->internalformat) || | 451 if (!GpuMemoryBufferImpl::IsFormatValid(request->internalformat) || |
| 489 !GpuMemoryBufferImpl::IsUsageValid(request->usage)) { | 452 !GpuMemoryBufferImpl::IsUsageValid(request->usage)) { |
| 490 request->result = scoped_ptr<gfx::GpuMemoryBuffer>(); | 453 request->result = scoped_ptr<gfx::GpuMemoryBuffer>(); |
| 491 request->event.Signal(); | 454 request->event.Signal(); |
| 492 return; | 455 return; |
| 493 } | 456 } |
| 494 | 457 |
| 495 request->result = GpuMemoryBufferImpl::Create( | 458 GpuMemoryBufferImpl::Create( |
| 496 gfx::Size(request->width, request->height), | 459 gfx::Size(request->width, request->height), |
| 497 request->internalformat, | 460 request->internalformat, |
| 498 request->usage).PassAs<gfx::GpuMemoryBuffer>(); | 461 request->usage, |
| 499 request->event.Signal(); | 462 base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated, |
| 463 base::Unretained(request))); |
| 500 } | 464 } |
| 501 | 465 |
| 502 // static | 466 // static |
| 503 void BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO( | 467 void BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO( |
| 504 scoped_ptr<gfx::GpuMemoryBuffer> buffer) { | 468 scoped_ptr<gfx::GpuMemoryBuffer> buffer) { |
| 505 } | 469 } |
| 506 | 470 |
| 471 // static |
| 507 void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( | 472 void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( |
| 508 uint32 request_id, | 473 AllocateGpuMemoryBufferRequest* request, |
| 509 const gfx::GpuMemoryBufferHandle& handle) { | 474 scoped_ptr<GpuMemoryBufferImpl> buffer) { |
| 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 511 | 476 |
| 512 CreateGpuMemoryBufferCallbackMap::iterator iter = | 477 request->result = buffer.PassAs<gfx::GpuMemoryBuffer>(); |
| 513 create_gpu_memory_buffer_requests_.find(request_id); | 478 request->event.Signal(); |
| 514 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | |
| 515 iter->second.Run(handle); | |
| 516 create_gpu_memory_buffer_requests_.erase(iter); | |
| 517 } | 479 } |
| 518 | 480 |
| 519 } // namespace content | 481 } // namespace content |
| OLD | NEW |