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" |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 845 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
846 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 846 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
847 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 847 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
848 | 848 |
849 if (!ui::LatencyInfo::Verify(params.latency_info, | 849 if (!ui::LatencyInfo::Verify(params.latency_info, |
850 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) | 850 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) |
851 return; | 851 return; |
852 | 852 |
853 gfx::AcceleratedWidget native_widget = | 853 gfx::AcceleratedWidget native_widget = |
854 GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); | 854 GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); |
855 | |
856 // Retrieve the render widget helper to forward this message to on the UI | |
857 // thread. | |
858 RenderWidgetHelper* helper = NULL; | |
859 int render_widget_id = 0; | |
860 if (native_widget) { | 855 if (native_widget) { |
861 int render_process_id = 0; | 856 RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(this, params); |
862 // TODO(ccameron): The render process and widget IDs have a race between | 857 return; |
863 // the UI and the IO threads, and may potentially be wrong. Move the | |
864 // functionality in RenderProcessHost::WaitForBackingStoreMsg to a place | |
865 // where it can accept IPCs from all renderers (rather than this hack where | |
866 // we fake the render process and widget ID of a renderer for the browser). | |
867 // http://crbug.com/392031 | |
868 if (RenderWidgetHelper::GetRenderWidgetIDForWidget( | |
869 native_widget, &render_process_id, &render_widget_id)) { | |
870 helper = RenderWidgetHelper::FromProcessHostID(render_process_id); | |
871 } | |
872 } else { | |
873 int render_process_id = 0; | |
874 if (GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
875 params.surface_id, &render_process_id, &render_widget_id)) { | |
876 helper = RenderWidgetHelper::FromProcessHostID(render_process_id); | |
877 } | |
878 } | 858 } |
879 | 859 |
880 // If this is not targetting a native widget and we don't find a helper, then | 860 gfx::GLSurfaceHandle surface_handle = |
881 // ack immediately and ignore the message. | 861 GpuSurfaceTracker::Get()->GetSurfaceHandle(params.surface_id); |
882 if (!helper && !native_widget) { | 862 // Compositor window is always gfx::kNullPluginWindow. |
883 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 863 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no |
884 ack_params.sync_point = 0; | 864 // plugin windows. |
| 865 if (surface_handle.handle != gfx::kNullPluginWindow || |
| 866 surface_handle.transport_type == gfx::TEXTURE_TRANSPORT) { |
| 867 RouteOnUIThread(GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
| 868 return; |
| 869 } |
| 870 |
| 871 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 872 ack_params.sync_point = 0; |
| 873 |
| 874 int render_process_id = 0; |
| 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, | 885 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, |
886 ack_params)); | 886 ack_params)); |
887 return; | 887 return; |
888 } | 888 } |
889 | 889 |
890 // If this is targetting a native widget, then ack the swap immediately to | |
891 // avoid introducing a deadlock between the browser and GPU processes (rate | |
892 // limiting is done through the compositor). | |
893 if (native_widget) { | |
894 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | |
895 ack_params.sync_point = 0; | |
896 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, | |
897 ack_params)); | |
898 } | |
899 | |
900 // Pass the SwapBuffers on to the RenderWidgetHelper to wake up the UI thread | 890 // Pass the SwapBuffers on to the RenderWidgetHelper to wake up the UI thread |
901 // if the browser is waiting for a new frame. Otherwise the RenderWidgetHelper | 891 // if the browser is waiting for a new frame. Otherwise the RenderWidgetHelper |
902 // will forward to the RenderWidgetHostView via RenderProcessHostImpl and | 892 // will forward to the RenderWidgetHostView via RenderProcessHostImpl and |
903 // RenderWidgetHostImpl. | 893 // RenderWidgetHostImpl. |
904 ViewHostMsg_CompositorSurfaceBuffersSwapped_Params view_params; | 894 ViewHostMsg_CompositorSurfaceBuffersSwapped_Params view_params; |
905 view_params.use_native_widget = native_widget; | |
906 view_params.surface_id = params.surface_id; | 895 view_params.surface_id = params.surface_id; |
907 view_params.surface_handle = params.surface_handle; | 896 view_params.surface_handle = params.surface_handle; |
908 view_params.route_id = params.route_id; | 897 view_params.route_id = params.route_id; |
909 view_params.size = params.size; | 898 view_params.size = params.size; |
910 view_params.scale_factor = params.scale_factor; | 899 view_params.scale_factor = params.scale_factor; |
911 view_params.gpu_process_host_id = host_id_; | 900 view_params.gpu_process_host_id = host_id_; |
912 view_params.latency_info = params.latency_info; | 901 view_params.latency_info = params.latency_info; |
913 if (helper) { | 902 helper->DidReceiveBackingStoreMsg(ViewHostMsg_CompositorSurfaceBuffersSwapped( |
914 helper->DidReceiveBackingStoreMsg( | 903 render_widget_id, |
915 ViewHostMsg_CompositorSurfaceBuffersSwapped( | 904 view_params)); |
916 render_widget_id, | |
917 view_params)); | |
918 } else if (native_widget) { | |
919 BrowserThread::PostTask( | |
920 BrowserThread::UI, | |
921 FROM_HERE, | |
922 base::Bind(&RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnUIThread, | |
923 view_params)); | |
924 } | |
925 } | 905 } |
926 #endif // OS_MACOSX | 906 #endif // OS_MACOSX |
927 | 907 |
928 void GpuProcessHost::OnProcessLaunched() { | 908 void GpuProcessHost::OnProcessLaunched() { |
929 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 909 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
930 base::TimeTicks::Now() - init_start_time_); | 910 base::TimeTicks::Now() - init_start_time_); |
931 } | 911 } |
932 | 912 |
933 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 913 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
934 SendOutstandingReplies(); | 914 SendOutstandingReplies(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1119 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1140 ClientIdToShaderCacheMap::iterator iter = | 1120 ClientIdToShaderCacheMap::iterator iter = |
1141 client_id_to_shader_cache_.find(client_id); | 1121 client_id_to_shader_cache_.find(client_id); |
1142 // If the cache doesn't exist then this is an off the record profile. | 1122 // If the cache doesn't exist then this is an off the record profile. |
1143 if (iter == client_id_to_shader_cache_.end()) | 1123 if (iter == client_id_to_shader_cache_.end()) |
1144 return; | 1124 return; |
1145 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1125 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1146 } | 1126 } |
1147 | 1127 |
1148 } // namespace content | 1128 } // namespace content |
OLD | NEW |