Chromium Code Reviews| 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" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "content/browser/browser_child_process_host_impl.h" | 17 #include "content/browser/browser_child_process_host_impl.h" |
| 18 #include "content/browser/gpu/gpu_data_manager_impl.h" | 18 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 19 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 19 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 20 #include "content/browser/gpu/gpu_surface_tracker.h" | 20 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 21 #include "content/browser/renderer_host/render_widget_helper.h" | |
| 21 #include "content/browser/renderer_host/render_widget_host_impl.h" | 22 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 22 #include "content/common/child_process_host_impl.h" | 23 #include "content/common/child_process_host_impl.h" |
| 23 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
| 25 #include "content/common/view_messages.h" | |
| 24 #include "content/gpu/gpu_child_thread.h" | 26 #include "content/gpu/gpu_child_thread.h" |
| 25 #include "content/gpu/gpu_process.h" | 27 #include "content/gpu/gpu_process.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 30 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/result_codes.h" | 32 #include "content/public/common/result_codes.h" |
| 31 #include "gpu/command_buffer/service/gpu_switches.h" | 33 #include "gpu/command_buffer/service/gpu_switches.h" |
| 32 #include "ipc/ipc_channel_handle.h" | 34 #include "ipc/ipc_channel_handle.h" |
| 33 #include "ipc/ipc_switches.h" | 35 #include "ipc/ipc_switches.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 | 405 |
| 404 return process_->Send(msg); | 406 return process_->Send(msg); |
| 405 } | 407 } |
| 406 | 408 |
| 407 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 409 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 408 DCHECK(CalledOnValidThread()); | 410 DCHECK(CalledOnValidThread()); |
| 409 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 411 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 410 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | 412 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
| 411 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) | 413 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) |
| 412 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) | 414 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) |
| 415 #if defined(OS_MACOSX) | |
| 416 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | |
| 417 OnAcceleratedSurfaceBuffersSwapped) | |
| 418 #endif | |
| 413 #if defined(OS_WIN) && !defined(USE_AURA) | 419 #if defined(OS_WIN) && !defined(USE_AURA) |
| 414 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 420 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 415 OnAcceleratedSurfaceBuffersSwapped) | 421 OnAcceleratedSurfaceBuffersSwapped) |
| 416 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfacePostSubBuffer, | 422 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfacePostSubBuffer, |
| 417 OnAcceleratedSurfacePostSubBuffer) | 423 OnAcceleratedSurfacePostSubBuffer) |
| 418 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSuspend, | 424 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSuspend, |
| 419 OnAcceleratedSurfaceSuspend) | 425 OnAcceleratedSurfaceSuspend) |
| 420 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, | 426 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, |
| 421 OnAcceleratedSurfaceRelease) | 427 OnAcceleratedSurfaceRelease) |
| 422 #endif | 428 #endif |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 534 } |
| 529 | 535 |
| 530 void GpuProcessHost::OnDestroyCommandBuffer(int32 surface_id) { | 536 void GpuProcessHost::OnDestroyCommandBuffer(int32 surface_id) { |
| 531 #if defined(TOOLKIT_GTK) | 537 #if defined(TOOLKIT_GTK) |
| 532 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); | 538 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); |
| 533 if (it != surface_refs_.end()) | 539 if (it != surface_refs_.end()) |
| 534 surface_refs_.erase(it); | 540 surface_refs_.erase(it); |
| 535 #endif // defined(TOOLKIT_GTK) | 541 #endif // defined(TOOLKIT_GTK) |
| 536 } | 542 } |
| 537 | 543 |
| 544 #if defined(OS_MACOSX) | |
| 545 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | |
| 546 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | |
| 547 TRACE_EVENT0("renderer", | |
| 548 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | |
| 549 | |
| 550 base::ScopedClosureRunner scoped_completion_runner( | |
| 551 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, | |
| 552 host_id_, params.route_id, true)); | |
| 553 | |
| 554 gfx::PluginWindowHandle handle = | |
| 555 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); | |
| 556 // Compositor window is always gfx::kNullPluginWindow. | |
| 557 // TODO(jbates) This will be removed when there are no plugin windows. | |
|
Ken Russell (switch to Gerrit)
2012/04/18 02:00:27
Here and throughout the review, for these TODOs, p
jbates
2012/04/18 23:01:58
Done.
| |
| 558 if (handle != gfx::kNullPluginWindow) { | |
| 559 scoped_completion_runner.Release(); | |
| 560 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | |
| 561 return; | |
| 562 } | |
| 563 | |
| 564 int render_process_id = 0; | |
| 565 int render_widget_id = 0; | |
| 566 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
| 567 params.surface_id, &render_process_id, &render_widget_id)) { | |
| 568 return; | |
| 569 } | |
| 570 std::map<int, scoped_refptr<RenderWidgetHelper> >::const_iterator ci = | |
| 571 render_widget_helpers_.find(render_process_id); | |
| 572 if (ci == render_widget_helpers_.end()) | |
| 573 return; | |
| 574 | |
| 575 scoped_completion_runner.Release(); | |
| 576 ViewHostMsg_UpdateRect_Params update_rect_params; | |
| 577 update_rect_params.gpu_surface_id = params.surface_id; | |
| 578 update_rect_params.gpu_surface_handle = params.surface_handle; | |
| 579 update_rect_params.gpu_route_id = params.route_id; | |
| 580 update_rect_params.gpu_process_host_id = host_id_; | |
| 581 ci->second->DidReceiveUpdateMsg(ViewHostMsg_UpdateRect(render_widget_id, | |
| 582 update_rect_params)); | |
| 583 } | |
| 584 #endif // OS_MACOSX | |
| 585 | |
| 538 #if defined(OS_WIN) && !defined(USE_AURA) | 586 #if defined(OS_WIN) && !defined(USE_AURA) |
| 539 | 587 |
| 540 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 588 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
| 541 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 589 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 542 TRACE_EVENT0("renderer", | 590 TRACE_EVENT0("renderer", |
| 543 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 591 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
| 544 | 592 |
| 545 base::ScopedClosureRunner scoped_completion_runner( | 593 base::ScopedClosureRunner scoped_completion_runner( |
| 546 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, | 594 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, |
| 547 host_id_, | 595 host_id_, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 | 679 |
| 632 void GpuProcessHost::ForceShutdown() { | 680 void GpuProcessHost::ForceShutdown() { |
| 633 // This is only called on the IO thread so no race against the constructor | 681 // This is only called on the IO thread so no race against the constructor |
| 634 // for another GpuProcessHost. | 682 // for another GpuProcessHost. |
| 635 if (g_gpu_process_hosts[kind_] == this) | 683 if (g_gpu_process_hosts[kind_] == this) |
| 636 g_gpu_process_hosts[kind_] = NULL; | 684 g_gpu_process_hosts[kind_] = NULL; |
| 637 | 685 |
| 638 process_->ForceShutdown(); | 686 process_->ForceShutdown(); |
| 639 } | 687 } |
| 640 | 688 |
| 689 void GpuProcessHost::RegisterRenderWidgetHelper( | |
| 690 int render_process_id, | |
| 691 const scoped_refptr<RenderWidgetHelper>& render_widget_helper) { | |
| 692 render_widget_helpers_[render_process_id] = render_widget_helper; | |
| 693 } | |
| 694 | |
| 695 void GpuProcessHost::UnregisterRenderWidgetHelper(int render_process_id) { | |
| 696 render_widget_helpers_.erase(render_process_id); | |
| 697 } | |
| 698 | |
| 641 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { | 699 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { |
| 642 if (!(gpu_enabled_ && | 700 if (!(gpu_enabled_ && |
| 643 GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && | 701 GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && |
| 644 !hardware_gpu_enabled_) { | 702 !hardware_gpu_enabled_) { |
| 645 SendOutstandingReplies(); | 703 SendOutstandingReplies(); |
| 646 return false; | 704 return false; |
| 647 } | 705 } |
| 648 | 706 |
| 649 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 707 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 650 | 708 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 const IPC::ChannelHandle& channel_handle, | 804 const IPC::ChannelHandle& channel_handle, |
| 747 base::ProcessHandle renderer_process_for_gpu, | 805 base::ProcessHandle renderer_process_for_gpu, |
| 748 const content::GPUInfo& gpu_info) { | 806 const content::GPUInfo& gpu_info) { |
| 749 callback.Run(channel_handle, gpu_info); | 807 callback.Run(channel_handle, gpu_info); |
| 750 } | 808 } |
| 751 | 809 |
| 752 void GpuProcessHost::CreateCommandBufferError( | 810 void GpuProcessHost::CreateCommandBufferError( |
| 753 const CreateCommandBufferCallback& callback, int32 route_id) { | 811 const CreateCommandBufferCallback& callback, int32 route_id) { |
| 754 callback.Run(route_id); | 812 callback.Run(route_id); |
| 755 } | 813 } |
| OLD | NEW |