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/common/child_process_host_impl.h" | 25 #include "content/common/child_process_host_impl.h" |
26 #include "content/common/gpu/gpu_messages.h" | 26 #include "content/common/gpu/gpu_messages.h" |
27 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
32 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 32 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
33 #include "content/public/common/content_client.h" | 33 #include "content/public/common/content_client.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
36 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 36 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
37 #include "gpu/command_buffer/service/gpu_switches.h" | 37 #include "gpu/command_buffer/service/gpu_switches.h" |
38 #include "ipc/ipc_channel_handle.h" | 38 #include "ipc/ipc_channel_handle.h" |
39 #include "ipc/ipc_switches.h" | 39 #include "ipc/ipc_switches.h" |
40 #include "ipc/message_filter.h" | 40 #include "ipc/message_filter.h" |
41 #include "media/base/media_switches.h" | 41 #include "media/base/media_switches.h" |
42 #include "ui/events/latency_info.h" | 42 #include "ui/events/latency_info.h" |
43 #include "ui/gl/gl_switches.h" | 43 #include "ui/gl/gl_switches.h" |
44 | 44 |
45 #if defined(OS_MACOSX) | |
46 #include <IOSurface/IOSurfaceAPI.h> | |
47 #include "base/mac/scoped_cftyperef.h" | |
48 #include "content/browser/renderer_host/render_widget_resize_helper_mac.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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 } | 841 } |
836 | 842 |
837 void GpuProcessHost::OnGpuMemoryUmaStatsReceived( | 843 void GpuProcessHost::OnGpuMemoryUmaStatsReceived( |
838 const GPUMemoryUmaStats& stats) { | 844 const GPUMemoryUmaStats& stats) { |
839 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryUmaStatsReceived"); | 845 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryUmaStatsReceived"); |
840 uma_memory_stats_received_ = true; | 846 uma_memory_stats_received_ = true; |
841 uma_memory_stats_ = stats; | 847 uma_memory_stats_ = stats; |
842 } | 848 } |
843 | 849 |
844 #if defined(OS_MACOSX) | 850 #if defined(OS_MACOSX) |
851 namespace { | |
852 void HoldIOSurfaceReference(base::ScopedCFTypeRef<IOSurfaceRef> io_surface) {} | |
853 } // namespace | |
854 | |
845 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 855 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
846 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 856 const IPC::Message& message) { |
847 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 857 RenderWidgetResizeHelper::Get()->PostGpuProcessMsg(host_id_, message); |
848 | 858 |
849 if (!ui::LatencyInfo::Verify(params.latency_info, | 859 if (!IsDelegatedRendererEnabled()) |
850 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) | |
851 return; | 860 return; |
852 | 861 |
853 gfx::AcceleratedWidget native_widget = | 862 GpuHostMsg_AcceleratedSurfaceBuffersSwapped::Param param; |
854 GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); | 863 if (!GpuHostMsg_AcceleratedSurfaceBuffersSwapped::Read(&message, ¶m)) |
855 if (native_widget) { | |
856 RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(this, params); | |
857 return; | 864 return; |
858 } | 865 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params = param.a; |
859 | 866 |
860 gfx::GLSurfaceHandle surface_handle = | 867 // As soon as the frame is acked, the IOSurface may be thrown away by the GPU |
861 GpuSurfaceTracker::Get()->GetSurfaceHandle(params.surface_id); | 868 // process. Open the IOSurface and post a task referencing it to the UI |
862 // Compositor window is always gfx::kNullPluginWindow. | 869 // thread. This will keep the IOSurface from being thrown away until the UI |
863 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no | 870 // thread can open another reference to it, if needed. |
864 // plugin windows. | 871 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup( |
865 if (surface_handle.handle != gfx::kNullPluginWindow || | 872 IOSurfaceIDFromSurfaceHandle(params.surface_handle))); |
piman
2014/07/15 19:56:00
Will this behave sanely if the GPU process sends a
ccameron
2014/07/15 20:36:24
Yeah, it'll just create a NULL IOSurfaceRef. That
| |
866 surface_handle.transport_type == gfx::TEXTURE_TRANSPORT) { | 873 BrowserThread::PostTask(BrowserThread::UI, |
867 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 874 FROM_HERE, |
868 return; | 875 base::Bind(HoldIOSurfaceReference, io_surface)); |
869 } | |
870 | 876 |
877 // If delegated rendering is enabled, then immediately acknowledge this frame | |
878 // on the IO thread instead of the UI thread. The UI thread will wait on the | |
879 // GPU process. If the UI thread were to be responsible for acking swaps, | |
880 // then there would be a cycle and a potential deadlock. Back-pressure from | |
881 // the GPU is provided through the compositor's output surface. | |
871 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 882 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
872 ack_params.sync_point = 0; | 883 ack_params.sync_point = 0; |
873 | 884 ack_params.renderer_id = 0; |
874 int render_process_id = 0; | 885 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, ack_params)); |
piman
2014/07/15 19:56:00
Is this still be needed after everything is wired
ccameron
2014/07/15 20:36:24
I think so -- we still have the case that any glFi
| |
875 int render_widget_id = 0; | |
876 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
877 params.surface_id, &render_process_id, &render_widget_id)) { | |
878 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, | |
879 ack_params)); | |
880 return; | |
881 } | |
882 RenderWidgetHelper* helper = | |
883 RenderWidgetHelper::FromProcessHostID(render_process_id); | |
884 if (!helper) { | |
885 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, | |
886 ack_params)); | |
887 return; | |
888 } | |
889 | |
890 // Pass the SwapBuffers on to the RenderWidgetHelper to wake up the UI thread | |
891 // if the browser is waiting for a new frame. Otherwise the RenderWidgetHelper | |
892 // will forward to the RenderWidgetHostView via RenderProcessHostImpl and | |
893 // RenderWidgetHostImpl. | |
894 ViewHostMsg_CompositorSurfaceBuffersSwapped_Params view_params; | |
895 view_params.surface_id = params.surface_id; | |
896 view_params.surface_handle = params.surface_handle; | |
897 view_params.route_id = params.route_id; | |
898 view_params.size = params.size; | |
899 view_params.scale_factor = params.scale_factor; | |
900 view_params.gpu_process_host_id = host_id_; | |
901 view_params.latency_info = params.latency_info; | |
902 helper->DidReceiveBackingStoreMsg(ViewHostMsg_CompositorSurfaceBuffersSwapped( | |
903 render_widget_id, | |
904 view_params)); | |
905 } | 886 } |
906 #endif // OS_MACOSX | 887 #endif |
907 | 888 |
908 void GpuProcessHost::OnProcessLaunched() { | 889 void GpuProcessHost::OnProcessLaunched() { |
909 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 890 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
910 base::TimeTicks::Now() - init_start_time_); | 891 base::TimeTicks::Now() - init_start_time_); |
911 } | 892 } |
912 | 893 |
913 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 894 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
914 SendOutstandingReplies(); | 895 SendOutstandingReplies(); |
915 GpuDataManagerImpl::GetInstance()->ProcessCrashed( | 896 GpuDataManagerImpl::GetInstance()->ProcessCrashed( |
916 process_->GetTerminationStatus(true /* known_dead */, NULL)); | 897 process_->GetTerminationStatus(true /* known_dead */, NULL)); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1100 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1120 ClientIdToShaderCacheMap::iterator iter = | 1101 ClientIdToShaderCacheMap::iterator iter = |
1121 client_id_to_shader_cache_.find(client_id); | 1102 client_id_to_shader_cache_.find(client_id); |
1122 // If the cache doesn't exist then this is an off the record profile. | 1103 // If the cache doesn't exist then this is an off the record profile. |
1123 if (iter == client_id_to_shader_cache_.end()) | 1104 if (iter == client_id_to_shader_cache_.end()) |
1124 return; | 1105 return; |
1125 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1106 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1126 } | 1107 } |
1127 | 1108 |
1128 } // namespace content | 1109 } // namespace content |
OLD | NEW |