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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/sha1.h" | 17 #include "base/sha1.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "content/browser/browser_child_process_host_impl.h" | 19 #include "content/browser/browser_child_process_host_impl.h" |
| 20 #include "content/browser/gpu/compositor_util.h" |
20 #include "content/browser/gpu/gpu_data_manager_impl.h" | 21 #include "content/browser/gpu/gpu_data_manager_impl.h" |
21 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 22 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
22 #include "content/browser/gpu/shader_disk_cache.h" | 23 #include "content/browser/gpu/shader_disk_cache.h" |
23 #include "content/browser/renderer_host/render_widget_helper.h" | |
24 #include "content/browser/renderer_host/render_widget_host_impl.h" | 24 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_widget_resize_helper.h" |
25 #include "content/common/child_process_host_impl.h" | 26 #include "content/common/child_process_host_impl.h" |
26 #include "content/common/gpu/gpu_messages.h" | 27 #include "content/common/gpu/gpu_messages.h" |
27 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
30 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_widget_host_view.h" | 32 #include "content/public/browser/render_widget_host_view.h" |
32 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 33 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
33 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
34 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/result_codes.h" | 36 #include "content/public/common/result_codes.h" |
36 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 37 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
37 #include "gpu/command_buffer/service/gpu_switches.h" | 38 #include "gpu/command_buffer/service/gpu_switches.h" |
38 #include "ipc/ipc_channel_handle.h" | 39 #include "ipc/ipc_channel_handle.h" |
39 #include "ipc/ipc_switches.h" | 40 #include "ipc/ipc_switches.h" |
40 #include "ipc/message_filter.h" | 41 #include "ipc/message_filter.h" |
41 #include "media/base/media_switches.h" | 42 #include "media/base/media_switches.h" |
42 #include "ui/events/latency_info.h" | 43 #include "ui/events/latency_info.h" |
43 #include "ui/gl/gl_switches.h" | 44 #include "ui/gl/gl_switches.h" |
44 | 45 |
| 46 #if defined(OS_MACOSX) |
| 47 #include <IOSurface/IOSurfaceAPI.h> |
| 48 #include "base/mac/scoped_cftyperef.h" |
| 49 #include "content/common/gpu/surface_handle_types_mac.h" |
| 50 #endif |
45 | 51 |
46 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
47 #include "base/win/windows_version.h" | 53 #include "base/win/windows_version.h" |
48 #include "content/common/sandbox_win.h" | 54 #include "content/common/sandbox_win.h" |
49 #include "sandbox/win/src/sandbox_policy.h" | 55 #include "sandbox/win/src/sandbox_policy.h" |
50 #include "ui/gfx/switches.h" | 56 #include "ui/gfx/switches.h" |
51 #endif | 57 #endif |
52 | 58 |
53 #if defined(USE_OZONE) | 59 #if defined(USE_OZONE) |
54 #include "ui/ozone/public/ozone_switches.h" | 60 #include "ui/ozone/public/ozone_switches.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, | 575 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
570 OnGpuMemoryBufferCreated) | 576 OnGpuMemoryBufferCreated) |
571 IPC_MESSAGE_HANDLER(GpuHostMsg_DidCreateOffscreenContext, | 577 IPC_MESSAGE_HANDLER(GpuHostMsg_DidCreateOffscreenContext, |
572 OnDidCreateOffscreenContext) | 578 OnDidCreateOffscreenContext) |
573 IPC_MESSAGE_HANDLER(GpuHostMsg_DidLoseContext, OnDidLoseContext) | 579 IPC_MESSAGE_HANDLER(GpuHostMsg_DidLoseContext, OnDidLoseContext) |
574 IPC_MESSAGE_HANDLER(GpuHostMsg_DidDestroyOffscreenContext, | 580 IPC_MESSAGE_HANDLER(GpuHostMsg_DidDestroyOffscreenContext, |
575 OnDidDestroyOffscreenContext) | 581 OnDidDestroyOffscreenContext) |
576 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, | 582 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, |
577 OnGpuMemoryUmaStatsReceived) | 583 OnGpuMemoryUmaStatsReceived) |
578 #if defined(OS_MACOSX) | 584 #if defined(OS_MACOSX) |
579 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 585 IPC_MESSAGE_HANDLER_GENERIC(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
580 OnAcceleratedSurfaceBuffersSwapped) | 586 OnAcceleratedSurfaceBuffersSwapped(message)) |
581 #endif | 587 #endif |
582 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel, | 588 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel, |
583 OnDestroyChannel) | 589 OnDestroyChannel) |
584 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, | 590 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, |
585 OnCacheShader) | 591 OnCacheShader) |
586 | 592 |
587 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 593 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
588 IPC_END_MESSAGE_MAP() | 594 IPC_END_MESSAGE_MAP() |
589 | 595 |
590 return true; | 596 return true; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 843 } |
838 | 844 |
839 void GpuProcessHost::OnGpuMemoryUmaStatsReceived( | 845 void GpuProcessHost::OnGpuMemoryUmaStatsReceived( |
840 const GPUMemoryUmaStats& stats) { | 846 const GPUMemoryUmaStats& stats) { |
841 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryUmaStatsReceived"); | 847 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryUmaStatsReceived"); |
842 uma_memory_stats_received_ = true; | 848 uma_memory_stats_received_ = true; |
843 uma_memory_stats_ = stats; | 849 uma_memory_stats_ = stats; |
844 } | 850 } |
845 | 851 |
846 #if defined(OS_MACOSX) | 852 #if defined(OS_MACOSX) |
| 853 namespace { |
| 854 void HoldIOSurfaceReference(base::ScopedCFTypeRef<IOSurfaceRef> io_surface) {} |
| 855 } // namespace |
| 856 |
847 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 857 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
848 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 858 const IPC::Message& message) { |
849 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 859 RenderWidgetResizeHelper::Get()->PostGpuProcessMsg(host_id_, message); |
850 | 860 |
851 if (!ui::LatencyInfo::Verify(params.latency_info, | 861 if (!IsDelegatedRendererEnabled()) |
852 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) | |
853 return; | 862 return; |
854 | 863 |
855 gfx::AcceleratedWidget native_widget = | 864 GpuHostMsg_AcceleratedSurfaceBuffersSwapped::Param param; |
856 GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); | 865 if (!GpuHostMsg_AcceleratedSurfaceBuffersSwapped::Read(&message, ¶m)) |
857 if (native_widget) { | |
858 RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(this, params); | |
859 return; | 866 return; |
| 867 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params = param.a; |
| 868 |
| 869 if (GetSurfaceHandleType(params.surface_handle) == |
| 870 kSurfaceHandleTypeIOSurface) { |
| 871 // As soon as the frame is acked, the IOSurface may be thrown away by the |
| 872 // GPU process. Open the IOSurface and post a task referencing it to the UI |
| 873 // thread. This will keep the IOSurface from being thrown away until the UI |
| 874 // thread can open another reference to it, if needed. |
| 875 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup( |
| 876 IOSurfaceIDFromSurfaceHandle(params.surface_handle))); |
| 877 BrowserThread::PostTask(BrowserThread::UI, |
| 878 FROM_HERE, |
| 879 base::Bind(HoldIOSurfaceReference, io_surface)); |
860 } | 880 } |
861 | 881 |
862 gfx::GLSurfaceHandle surface_handle = | 882 // If delegated rendering is enabled, then immediately acknowledge this frame |
863 GpuSurfaceTracker::Get()->GetSurfaceHandle(params.surface_id); | 883 // on the IO thread instead of the UI thread. The UI thread will wait on the |
864 // Compositor window is always gfx::kNullPluginWindow. | 884 // GPU process. If the UI thread were to be responsible for acking swaps, |
865 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no | 885 // then there would be a cycle and a potential deadlock. Back-pressure from |
866 // plugin windows. | 886 // the GPU is provided through the compositor's output surface. |
867 if (surface_handle.handle != gfx::kNullPluginWindow || | |
868 surface_handle.transport_type == gfx::TEXTURE_TRANSPORT) { | |
869 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | |
870 return; | |
871 } | |
872 | |
873 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 887 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
874 ack_params.sync_point = 0; | 888 ack_params.sync_point = 0; |
875 | 889 ack_params.renderer_id = 0; |
876 int render_process_id = 0; | 890 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, ack_params)); |
877 int render_widget_id = 0; | |
878 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
879 params.surface_id, &render_process_id, &render_widget_id)) { | |
880 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, | |
881 ack_params)); | |
882 return; | |
883 } | |
884 RenderWidgetHelper* helper = | |
885 RenderWidgetHelper::FromProcessHostID(render_process_id); | |
886 if (!helper) { | |
887 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, | |
888 ack_params)); | |
889 return; | |
890 } | |
891 | |
892 // Pass the SwapBuffers on to the RenderWidgetHelper to wake up the UI thread | |
893 // if the browser is waiting for a new frame. Otherwise the RenderWidgetHelper | |
894 // will forward to the RenderWidgetHostView via RenderProcessHostImpl and | |
895 // RenderWidgetHostImpl. | |
896 ViewHostMsg_CompositorSurfaceBuffersSwapped_Params view_params; | |
897 view_params.surface_id = params.surface_id; | |
898 view_params.surface_handle = params.surface_handle; | |
899 view_params.route_id = params.route_id; | |
900 view_params.size = params.size; | |
901 view_params.scale_factor = params.scale_factor; | |
902 view_params.gpu_process_host_id = host_id_; | |
903 view_params.latency_info = params.latency_info; | |
904 helper->DidReceiveBackingStoreMsg(ViewHostMsg_CompositorSurfaceBuffersSwapped( | |
905 render_widget_id, | |
906 view_params)); | |
907 } | 891 } |
908 #endif // OS_MACOSX | 892 #endif |
909 | 893 |
910 void GpuProcessHost::OnProcessLaunched() { | 894 void GpuProcessHost::OnProcessLaunched() { |
911 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 895 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
912 base::TimeTicks::Now() - init_start_time_); | 896 base::TimeTicks::Now() - init_start_time_); |
913 } | 897 } |
914 | 898 |
915 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 899 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
916 SendOutstandingReplies(); | 900 SendOutstandingReplies(); |
917 GpuDataManagerImpl::GetInstance()->ProcessCrashed( | 901 GpuDataManagerImpl::GetInstance()->ProcessCrashed( |
918 process_->GetTerminationStatus(true /* known_dead */, NULL)); | 902 process_->GetTerminationStatus(true /* known_dead */, NULL)); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1105 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1122 ClientIdToShaderCacheMap::iterator iter = | 1106 ClientIdToShaderCacheMap::iterator iter = |
1123 client_id_to_shader_cache_.find(client_id); | 1107 client_id_to_shader_cache_.find(client_id); |
1124 // If the cache doesn't exist then this is an off the record profile. | 1108 // If the cache doesn't exist then this is an off the record profile. |
1125 if (iter == client_id_to_shader_cache_.end()) | 1109 if (iter == client_id_to_shader_cache_.end()) |
1126 return; | 1110 return; |
1127 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1111 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1128 } | 1112 } |
1129 | 1113 |
1130 } // namespace content | 1114 } // namespace content |
OLD | NEW |