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) http://crbug.com/105344 This will be removed when there are no | |
558 // plugin windows. | |
559 if (handle != gfx::kNullPluginWindow) { | |
560 scoped_completion_runner.Release(); | |
darin (slow to review)
2012/04/20 17:11:27
I presume this .Release() call prevents the Scoped
jbates
2012/04/20 23:01:04
Done.
| |
561 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | |
562 return; | |
563 } | |
564 | |
565 int render_process_id = 0; | |
566 int render_widget_id = 0; | |
567 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
568 params.surface_id, &render_process_id, &render_widget_id)) { | |
darin (slow to review)
2012/04/20 17:11:27
nit: indent line continuations by 4 spaces
jbates
2012/04/20 23:01:04
Done.
| |
569 return; | |
570 } | |
571 std::map<int, scoped_refptr<RenderWidgetHelper> >::const_iterator ci = | |
darin (slow to review)
2012/04/20 17:11:27
perhaps this should just be a static map defined b
jbates
2012/04/20 23:01:04
Done.
| |
572 render_widget_helpers_.find(render_process_id); | |
573 if (ci == render_widget_helpers_.end()) | |
574 return; | |
575 | |
576 // Pass the SwapBuffers on to the RenderWidgetHelper to wake up the UI thread | |
577 // if the browser is waiting for a new frame. Otherwise the RenderWidgetHelper | |
578 // will forward to the RenderWidgetHostView via RenderProcessHostImpl and | |
579 // RenderWidgetHostImpl. | |
580 scoped_completion_runner.Release(); | |
581 ci->second->DidReceiveUpdateMsg(ViewHostMsg_CompositorSurfaceBuffersSwapped( | |
darin (slow to review)
2012/04/20 17:11:27
i'm confused to see you passing a message to DidRe
jbates
2012/04/20 23:01:04
Done. Replaced UpdateMsg with BackingStoreMsg (ins
| |
582 render_widget_id, | |
583 params.surface_id, | |
584 params.surface_handle, | |
585 params.route_id, | |
586 host_id_)); | |
587 } | |
588 #endif // OS_MACOSX | |
589 | |
538 #if defined(OS_WIN) && !defined(USE_AURA) | 590 #if defined(OS_WIN) && !defined(USE_AURA) |
539 | 591 |
540 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 592 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
541 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 593 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
542 TRACE_EVENT0("renderer", | 594 TRACE_EVENT0("renderer", |
543 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 595 "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
544 | 596 |
545 base::ScopedClosureRunner scoped_completion_runner( | 597 base::ScopedClosureRunner scoped_completion_runner( |
546 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, | 598 base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, |
547 host_id_, | 599 host_id_, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 | 683 |
632 void GpuProcessHost::ForceShutdown() { | 684 void GpuProcessHost::ForceShutdown() { |
633 // This is only called on the IO thread so no race against the constructor | 685 // This is only called on the IO thread so no race against the constructor |
634 // for another GpuProcessHost. | 686 // for another GpuProcessHost. |
635 if (g_gpu_process_hosts[kind_] == this) | 687 if (g_gpu_process_hosts[kind_] == this) |
636 g_gpu_process_hosts[kind_] = NULL; | 688 g_gpu_process_hosts[kind_] = NULL; |
637 | 689 |
638 process_->ForceShutdown(); | 690 process_->ForceShutdown(); |
639 } | 691 } |
640 | 692 |
693 void GpuProcessHost::RegisterRenderWidgetHelper( | |
694 int render_process_id, | |
695 const scoped_refptr<RenderWidgetHelper>& render_widget_helper) { | |
696 render_widget_helpers_[render_process_id] = render_widget_helper; | |
697 } | |
698 | |
699 void GpuProcessHost::UnregisterRenderWidgetHelper(int render_process_id) { | |
700 render_widget_helpers_.erase(render_process_id); | |
701 } | |
702 | |
641 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { | 703 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { |
642 if (!(gpu_enabled_ && | 704 if (!(gpu_enabled_ && |
643 GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && | 705 GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && |
644 !hardware_gpu_enabled_) { | 706 !hardware_gpu_enabled_) { |
645 SendOutstandingReplies(); | 707 SendOutstandingReplies(); |
646 return false; | 708 return false; |
647 } | 709 } |
648 | 710 |
649 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 711 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
650 | 712 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 const IPC::ChannelHandle& channel_handle, | 808 const IPC::ChannelHandle& channel_handle, |
747 base::ProcessHandle renderer_process_for_gpu, | 809 base::ProcessHandle renderer_process_for_gpu, |
748 const content::GPUInfo& gpu_info) { | 810 const content::GPUInfo& gpu_info) { |
749 callback.Run(channel_handle, gpu_info); | 811 callback.Run(channel_handle, gpu_info); |
750 } | 812 } |
751 | 813 |
752 void GpuProcessHost::CreateCommandBufferError( | 814 void GpuProcessHost::CreateCommandBufferError( |
753 const CreateCommandBufferCallback& callback, int32 route_id) { | 815 const CreateCommandBufferCallback& callback, int32 route_id) { |
754 callback.Run(route_id); | 816 callback.Run(route_id); |
755 } | 817 } |
OLD | NEW |