| 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/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 g_gpu_process_hosts[kind_] = NULL; | 351 g_gpu_process_hosts[kind_] = NULL; |
| 352 | 352 |
| 353 BrowserThread::PostTask(BrowserThread::UI, | 353 BrowserThread::PostTask(BrowserThread::UI, |
| 354 FROM_HERE, | 354 FROM_HERE, |
| 355 base::Bind(&GpuProcessHostUIShim::Destroy, host_id_)); | 355 base::Bind(&GpuProcessHostUIShim::Destroy, host_id_)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 bool GpuProcessHost::Init() { | 358 bool GpuProcessHost::Init() { |
| 359 init_start_time_ = base::TimeTicks::Now(); | 359 init_start_time_ = base::TimeTicks::Now(); |
| 360 | 360 |
| 361 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess"); |
| 362 |
| 361 std::string channel_id = process_->GetHost()->CreateChannel(); | 363 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 362 if (channel_id.empty()) | 364 if (channel_id.empty()) |
| 363 return false; | 365 return false; |
| 364 | 366 |
| 365 if (in_process_) { | 367 if (in_process_) { |
| 366 CommandLine::ForCurrentProcess()->AppendSwitch( | 368 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 367 switches::kDisableGpuWatchdog); | 369 switches::kDisableGpuWatchdog); |
| 368 | 370 |
| 369 in_process_gpu_thread_.reset(new GpuMainThread(channel_id)); | 371 in_process_gpu_thread_.reset(new GpuMainThread(channel_id)); |
| 370 | 372 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, | 428 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, |
| 427 OnAcceleratedSurfaceRelease) | 429 OnAcceleratedSurfaceRelease) |
| 428 #endif | 430 #endif |
| 429 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 431 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| 430 IPC_END_MESSAGE_MAP() | 432 IPC_END_MESSAGE_MAP() |
| 431 | 433 |
| 432 return true; | 434 return true; |
| 433 } | 435 } |
| 434 | 436 |
| 435 void GpuProcessHost::OnChannelConnected(int32 peer_pid) { | 437 void GpuProcessHost::OnChannelConnected(int32 peer_pid) { |
| 438 TRACE_EVENT0("gpu", "GpuProcessHostUIShim::OnChannelConnected"); |
| 439 |
| 436 while (!queued_messages_.empty()) { | 440 while (!queued_messages_.empty()) { |
| 437 Send(queued_messages_.front()); | 441 Send(queued_messages_.front()); |
| 438 queued_messages_.pop(); | 442 queued_messages_.pop(); |
| 439 } | 443 } |
| 440 } | 444 } |
| 441 | 445 |
| 442 void GpuProcessHost::EstablishGpuChannel( | 446 void GpuProcessHost::EstablishGpuChannel( |
| 443 int client_id, | 447 int client_id, |
| 444 bool share_context, | 448 bool share_context, |
| 445 const EstablishChannelCallback& callback) { | 449 const EstablishChannelCallback& callback) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 base::kNullProcessHandle, content::GPUInfo()); | 466 base::kNullProcessHandle, content::GPUInfo()); |
| 463 } | 467 } |
| 464 } | 468 } |
| 465 | 469 |
| 466 void GpuProcessHost::CreateViewCommandBuffer( | 470 void GpuProcessHost::CreateViewCommandBuffer( |
| 467 const gfx::GLSurfaceHandle& compositing_surface, | 471 const gfx::GLSurfaceHandle& compositing_surface, |
| 468 int surface_id, | 472 int surface_id, |
| 469 int client_id, | 473 int client_id, |
| 470 const GPUCreateCommandBufferConfig& init_params, | 474 const GPUCreateCommandBufferConfig& init_params, |
| 471 const CreateCommandBufferCallback& callback) { | 475 const CreateCommandBufferCallback& callback) { |
| 476 TRACE_EVENT0("gpu", "GpuProcessHostUIShim::CreateViewCommandBuffer"); |
| 477 |
| 472 DCHECK(CalledOnValidThread()); | 478 DCHECK(CalledOnValidThread()); |
| 473 | 479 |
| 474 #if defined(TOOLKIT_GTK) | 480 #if defined(TOOLKIT_GTK) |
| 475 // There should only be one such command buffer (for the compositor). In | 481 // There should only be one such command buffer (for the compositor). In |
| 476 // practice, if the GPU process lost a context, GraphicsContext3D with | 482 // practice, if the GPU process lost a context, GraphicsContext3D with |
| 477 // associated command buffer and view surface will not be gone until new | 483 // associated command buffer and view surface will not be gone until new |
| 478 // one is in place and all layers are reattached. | 484 // one is in place and all layers are reattached. |
| 479 linked_ptr<SurfaceRef> surface_ref; | 485 linked_ptr<SurfaceRef> surface_ref; |
| 480 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); | 486 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); |
| 481 if (it != surface_refs_.end()) | 487 if (it != surface_refs_.end()) |
| 482 surface_ref = (*it).second; | 488 surface_ref = (*it).second; |
| 483 else | 489 else |
| 484 surface_ref.reset(new SurfaceRef(compositing_surface.handle)); | 490 surface_ref.reset(new SurfaceRef(compositing_surface.handle)); |
| 485 #endif // defined(TOOLKIT_GTK) | 491 #endif // defined(TOOLKIT_GTK) |
| 486 | 492 |
| 487 if (!compositing_surface.is_null() && | 493 if (!compositing_surface.is_null() && |
| 488 Send(new GpuMsg_CreateViewCommandBuffer( | 494 Send(new GpuMsg_CreateViewCommandBuffer( |
| 489 compositing_surface, surface_id, client_id, init_params))) { | 495 compositing_surface, surface_id, client_id, init_params))) { |
| 490 create_command_buffer_requests_.push(callback); | 496 create_command_buffer_requests_.push(callback); |
| 491 #if defined(TOOLKIT_GTK) | 497 #if defined(TOOLKIT_GTK) |
| 492 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); | 498 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); |
| 493 #endif | 499 #endif |
| 494 } else { | 500 } else { |
| 495 CreateCommandBufferError(callback, MSG_ROUTING_NONE); | 501 CreateCommandBufferError(callback, MSG_ROUTING_NONE); |
| 496 } | 502 } |
| 497 } | 503 } |
| 498 | 504 |
| 499 void GpuProcessHost::OnChannelEstablished( | 505 void GpuProcessHost::OnChannelEstablished( |
| 500 const IPC::ChannelHandle& channel_handle) { | 506 const IPC::ChannelHandle& channel_handle) { |
| 507 TRACE_EVENT0("gpu", "GpuProcessHostUIShim::OnChannelEstablished"); |
| 508 |
| 501 EstablishChannelCallback callback = channel_requests_.front(); | 509 EstablishChannelCallback callback = channel_requests_.front(); |
| 502 channel_requests_.pop(); | 510 channel_requests_.pop(); |
| 503 | 511 |
| 504 // Currently if any of the GPU features are blacklisted, we don't establish a | 512 // Currently if any of the GPU features are blacklisted, we don't establish a |
| 505 // GPU channel. | 513 // GPU channel. |
| 506 if (!channel_handle.name.empty() && | 514 if (!channel_handle.name.empty() && |
| 507 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { | 515 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { |
| 508 Send(new GpuMsg_CloseChannel(channel_handle)); | 516 Send(new GpuMsg_CloseChannel(channel_handle)); |
| 509 EstablishChannelError(callback, | 517 EstablishChannelError(callback, |
| 510 IPC::ChannelHandle(), | 518 IPC::ChannelHandle(), |
| 511 base::kNullProcessHandle, | 519 base::kNullProcessHandle, |
| 512 content::GPUInfo()); | 520 content::GPUInfo()); |
| 513 RouteOnUIThread(GpuHostMsg_OnLogMessage( | 521 RouteOnUIThread(GpuHostMsg_OnLogMessage( |
| 514 logging::LOG_WARNING, | 522 logging::LOG_WARNING, |
| 515 "WARNING", | 523 "WARNING", |
| 516 "Hardware acceleration is unavailable.")); | 524 "Hardware acceleration is unavailable.")); |
| 517 return; | 525 return; |
| 518 } | 526 } |
| 519 | 527 |
| 520 callback.Run(channel_handle, | 528 callback.Run(channel_handle, |
| 521 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); | 529 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); |
| 522 } | 530 } |
| 523 | 531 |
| 524 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { | 532 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { |
| 533 TRACE_EVENT0("gpu", "GpuProcessHostUIShim::OnCommandBufferCreated"); |
| 534 |
| 525 if (!create_command_buffer_requests_.empty()) { | 535 if (!create_command_buffer_requests_.empty()) { |
| 526 CreateCommandBufferCallback callback = | 536 CreateCommandBufferCallback callback = |
| 527 create_command_buffer_requests_.front(); | 537 create_command_buffer_requests_.front(); |
| 528 create_command_buffer_requests_.pop(); | 538 create_command_buffer_requests_.pop(); |
| 529 if (route_id == MSG_ROUTING_NONE) | 539 if (route_id == MSG_ROUTING_NONE) |
| 530 CreateCommandBufferError(callback, route_id); | 540 CreateCommandBufferError(callback, route_id); |
| 531 else | 541 else |
| 532 callback.Run(route_id); | 542 callback.Run(route_id); |
| 533 } | 543 } |
| 534 } | 544 } |
| 535 | 545 |
| 536 void GpuProcessHost::OnDestroyCommandBuffer(int32 surface_id) { | 546 void GpuProcessHost::OnDestroyCommandBuffer(int32 surface_id) { |
| 547 TRACE_EVENT0("gpu", "GpuProcessHostUIShim::OnDestroyCommandBuffer"); |
| 548 |
| 537 #if defined(TOOLKIT_GTK) | 549 #if defined(TOOLKIT_GTK) |
| 538 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); | 550 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); |
| 539 if (it != surface_refs_.end()) | 551 if (it != surface_refs_.end()) |
| 540 surface_refs_.erase(it); | 552 surface_refs_.erase(it); |
| 541 #endif // defined(TOOLKIT_GTK) | 553 #endif // defined(TOOLKIT_GTK) |
| 542 } | 554 } |
| 543 | 555 |
| 544 #if defined(OS_MACOSX) | 556 #if defined(OS_MACOSX) |
| 545 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 557 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
| 546 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 558 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 547 TRACE_EVENT0("renderer", | 559 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
| 548 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | |
| 549 | 560 |
| 550 gfx::PluginWindowHandle handle = | 561 gfx::PluginWindowHandle handle = |
| 551 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); | 562 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); |
| 552 // Compositor window is always gfx::kNullPluginWindow. | 563 // Compositor window is always gfx::kNullPluginWindow. |
| 553 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no | 564 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no |
| 554 // plugin windows. | 565 // plugin windows. |
| 555 if (handle != gfx::kNullPluginWindow) { | 566 if (handle != gfx::kNullPluginWindow) { |
| 556 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 567 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
| 557 return; | 568 return; |
| 558 } | 569 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 583 params.surface_handle, | 594 params.surface_handle, |
| 584 params.route_id, | 595 params.route_id, |
| 585 host_id_)); | 596 host_id_)); |
| 586 } | 597 } |
| 587 #endif // OS_MACOSX | 598 #endif // OS_MACOSX |
| 588 | 599 |
| 589 #if defined(OS_WIN) && !defined(USE_AURA) | 600 #if defined(OS_WIN) && !defined(USE_AURA) |
| 590 | 601 |
| 591 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 602 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
| 592 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 603 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 593 TRACE_EVENT0("renderer", | 604 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
| 594 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | |
| 595 | 605 |
| 596 base::ScopedClosureRunner scoped_completion_runner( | 606 base::ScopedClosureRunner scoped_completion_runner( |
| 597 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, | 607 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, |
| 598 host_id_, | 608 host_id_, |
| 599 params.route_id, | 609 params.route_id, |
| 600 true)); | 610 true)); |
| 601 | 611 |
| 602 gfx::PluginWindowHandle handle = | 612 gfx::PluginWindowHandle handle = |
| 603 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); | 613 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); |
| 604 if (!handle) | 614 if (!handle) |
| 605 return; | 615 return; |
| 606 | 616 |
| 607 scoped_refptr<AcceleratedPresenter> presenter( | 617 scoped_refptr<AcceleratedPresenter> presenter( |
| 608 AcceleratedPresenter::GetForWindow(handle)); | 618 AcceleratedPresenter::GetForWindow(handle)); |
| 609 if (!presenter) | 619 if (!presenter) |
| 610 return; | 620 return; |
| 611 | 621 |
| 612 scoped_completion_runner.Release(); | 622 scoped_completion_runner.Release(); |
| 613 presenter->AsyncPresentAndAcknowledge( | 623 presenter->AsyncPresentAndAcknowledge( |
| 614 params.size, | 624 params.size, |
| 615 params.surface_handle, | 625 params.surface_handle, |
| 616 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, | 626 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, |
| 617 host_id_, | 627 host_id_, |
| 618 params.route_id)); | 628 params.route_id)); |
| 619 } | 629 } |
| 620 | 630 |
| 621 void GpuProcessHost::OnAcceleratedSurfacePostSubBuffer( | 631 void GpuProcessHost::OnAcceleratedSurfacePostSubBuffer( |
| 622 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { | 632 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { |
| 623 TRACE_EVENT0("renderer", | 633 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfacePostSubBuffer"); |
| 624 "GpuProcessHost::OnAcceleratedSurfacePostSubBuffer"); | |
| 625 | 634 |
| 626 NOTIMPLEMENTED(); | 635 NOTIMPLEMENTED(); |
| 627 } | 636 } |
| 628 | 637 |
| 629 void GpuProcessHost::OnAcceleratedSurfaceSuspend(int32 surface_id) { | 638 void GpuProcessHost::OnAcceleratedSurfaceSuspend(int32 surface_id) { |
| 630 TRACE_EVENT0("renderer", | 639 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceSuspend"); |
| 631 "GpuProcessHost::OnAcceleratedSurfaceSuspend"); | |
| 632 | 640 |
| 633 gfx::PluginWindowHandle handle = | 641 gfx::PluginWindowHandle handle = |
| 634 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(surface_id); | 642 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(surface_id); |
| 635 if (!handle) | 643 if (!handle) |
| 636 return; | 644 return; |
| 637 | 645 |
| 638 scoped_refptr<AcceleratedPresenter> presenter( | 646 scoped_refptr<AcceleratedPresenter> presenter( |
| 639 AcceleratedPresenter::GetForWindow(handle)); | 647 AcceleratedPresenter::GetForWindow(handle)); |
| 640 if (!presenter) | 648 if (!presenter) |
| 641 return; | 649 return; |
| 642 | 650 |
| 643 presenter->Suspend(); | 651 presenter->Suspend(); |
| 644 } | 652 } |
| 645 | 653 |
| 646 void GpuProcessHost::OnAcceleratedSurfaceRelease( | 654 void GpuProcessHost::OnAcceleratedSurfaceRelease( |
| 647 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { | 655 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { |
| 648 TRACE_EVENT0("renderer", | 656 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceRelease"); |
| 649 "GpuProcessHost::OnAcceleratedSurfaceRelease"); | |
| 650 | 657 |
| 651 gfx::PluginWindowHandle handle = | 658 gfx::PluginWindowHandle handle = |
| 652 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); | 659 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); |
| 653 if (!handle) | 660 if (!handle) |
| 654 return; | 661 return; |
| 655 | 662 |
| 656 scoped_refptr<AcceleratedPresenter> presenter( | 663 scoped_refptr<AcceleratedPresenter> presenter( |
| 657 AcceleratedPresenter::GetForWindow(handle)); | 664 AcceleratedPresenter::GetForWindow(handle)); |
| 658 if (!presenter) | 665 if (!presenter) |
| 659 return; | 666 return; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 const IPC::ChannelHandle& channel_handle, | 805 const IPC::ChannelHandle& channel_handle, |
| 799 base::ProcessHandle renderer_process_for_gpu, | 806 base::ProcessHandle renderer_process_for_gpu, |
| 800 const content::GPUInfo& gpu_info) { | 807 const content::GPUInfo& gpu_info) { |
| 801 callback.Run(channel_handle, gpu_info); | 808 callback.Run(channel_handle, gpu_info); |
| 802 } | 809 } |
| 803 | 810 |
| 804 void GpuProcessHost::CreateCommandBufferError( | 811 void GpuProcessHost::CreateCommandBufferError( |
| 805 const CreateCommandBufferCallback& callback, int32 route_id) { | 812 const CreateCommandBufferCallback& callback, int32 route_id) { |
| 806 callback.Run(route_id); | 813 callback.Run(route_id); |
| 807 } | 814 } |
| OLD | NEW |