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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 void RenderWidget::OnRequestMoveAck() { | 951 void RenderWidget::OnRequestMoveAck() { |
952 DCHECK(pending_window_rect_count_); | 952 DCHECK(pending_window_rect_count_); |
953 pending_window_rect_count_--; | 953 pending_window_rect_count_--; |
954 } | 954 } |
955 | 955 |
956 GURL RenderWidget::GetURLForGraphicsContext3D() { | 956 GURL RenderWidget::GetURLForGraphicsContext3D() { |
957 return GURL(); | 957 return GURL(); |
958 } | 958 } |
959 | 959 |
960 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 960 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
961 DCHECK(webwidget_); | |
961 // For widgets that are never visible, we don't start the compositor, so we | 962 // For widgets that are never visible, we don't start the compositor, so we |
962 // never get a request for a cc::OutputSurface. | 963 // never get a request for a cc::OutputSurface. |
963 DCHECK(!compositor_never_visible_); | 964 DCHECK(!compositor_never_visible_); |
964 | 965 |
965 const base::CommandLine& command_line = | 966 const base::CommandLine& command_line = |
966 *base::CommandLine::ForCurrentProcess(); | 967 *base::CommandLine::ForCurrentProcess(); |
967 bool use_software = fallback; | 968 bool use_software = fallback; |
968 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 969 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
969 use_software = true; | 970 use_software = true; |
970 | 971 |
971 #if defined(MOJO_SHELL_CLIENT) | 972 #if defined(MOJO_SHELL_CLIENT) |
972 if (MojoShellConnection::Get() && !use_software) { | 973 if (MojoShellConnection::Get() && !use_software) { |
973 RenderWidgetMusConnection* connection = | 974 RenderWidgetMusConnection* connection = |
974 RenderWidgetMusConnection::GetOrCreate(routing_id()); | 975 RenderWidgetMusConnection::GetOrCreate(routing_id()); |
975 return connection->CreateOutputSurface(); | 976 return connection->CreateOutputSurface(); |
976 } | 977 } |
977 #endif | 978 #endif |
978 | 979 |
980 scoped_refptr<GpuChannelHost> gpu_channel_host; | |
981 if (!use_software) { | |
982 CauseForGpuLaunch cause = | |
983 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
984 gpu_channel_host = | |
985 RenderThreadImpl::current()->EstablishGpuChannelSync(cause); | |
986 if (!gpu_channel_host.get()) { | |
987 // Cause the compositor to wait and try again. | |
988 return nullptr; | |
989 } | |
990 // We may get a valid channel, but with a software renderer. In that case, | |
991 // disable GPU compositing. | |
992 if (gpu_channel_host->gpu_info().software_rendering) | |
993 use_software = true; | |
jbauman
2016/01/12 03:24:57
software_rendering is always false for me because
| |
994 } | |
995 | |
979 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 996 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
980 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider; | 997 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider; |
981 if (!use_software) { | 998 if (!use_software) { |
982 context_provider = ContextProviderCommandBuffer::Create( | 999 context_provider = ContextProviderCommandBuffer::Create( |
983 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT); | 1000 CreateGraphicsContext3D(gpu_channel_host.get()), |
984 if (!context_provider.get()) { | 1001 RENDER_COMPOSITOR_CONTEXT); |
985 // Cause the compositor to wait and try again. | 1002 DCHECK(context_provider); |
986 return nullptr; | |
987 } | |
988 worker_context_provider = | 1003 worker_context_provider = |
989 RenderThreadImpl::current()->SharedWorkerContextProvider(); | 1004 RenderThreadImpl::current()->SharedWorkerContextProvider(); |
990 if (!worker_context_provider) { | 1005 if (!worker_context_provider) { |
991 // Cause the compositor to wait and try again. | 1006 // Cause the compositor to wait and try again. |
992 return nullptr; | 1007 return nullptr; |
993 } | 1008 } |
994 | 1009 |
995 #if defined(OS_ANDROID) | 1010 #if defined(OS_ANDROID) |
996 if (SynchronousCompositorFactory* factory = | 1011 if (SynchronousCompositorFactory* factory = |
997 SynchronousCompositorFactory::GetInstance()) { | 1012 SynchronousCompositorFactory::GetInstance()) { |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2090 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); | 2105 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); |
2091 } | 2106 } |
2092 | 2107 |
2093 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { | 2108 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { |
2094 #if defined(OS_ANDROID) | 2109 #if defined(OS_ANDROID) |
2095 text_field_is_dirty_ = true; | 2110 text_field_is_dirty_ = true; |
2096 #endif | 2111 #endif |
2097 } | 2112 } |
2098 | 2113 |
2099 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 2114 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
2100 RenderWidget::CreateGraphicsContext3D(bool compositor) { | 2115 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { |
2101 if (!webwidget_) | |
2102 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | |
2103 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
2104 switches::kDisableGpuCompositing)) | |
2105 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | |
2106 if (!RenderThreadImpl::current()) | |
2107 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | |
2108 CauseForGpuLaunch cause = | |
2109 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
2110 scoped_refptr<GpuChannelHost> gpu_channel_host( | |
2111 RenderThreadImpl::current()->EstablishGpuChannelSync(cause)); | |
2112 if (!gpu_channel_host.get()) | |
2113 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | |
2114 | |
2115 // Explicitly disable antialiasing for the compositor. As of the time of | 2116 // Explicitly disable antialiasing for the compositor. As of the time of |
2116 // this writing, the only platform that supported antialiasing for the | 2117 // this writing, the only platform that supported antialiasing for the |
2117 // compositor was Mac OS X, because the on-screen OpenGL context creation | 2118 // compositor was Mac OS X, because the on-screen OpenGL context creation |
2118 // code paths on Windows and Linux didn't yet have multisampling support. | 2119 // code paths on Windows and Linux didn't yet have multisampling support. |
2119 // Mac OS X essentially always behaves as though it's rendering offscreen. | 2120 // Mac OS X essentially always behaves as though it's rendering offscreen. |
2120 // Multisampling has a heavy cost especially on devices with relatively low | 2121 // Multisampling has a heavy cost especially on devices with relatively low |
2121 // fill rate like most notebooks, and the Mac implementation would need to | 2122 // fill rate like most notebooks, and the Mac implementation would need to |
2122 // be optimized to resolve directly into the IOSurface shared between the | 2123 // be optimized to resolve directly into the IOSurface shared between the |
2123 // GPU and browser processes. For these reasons and to avoid platform | 2124 // GPU and browser processes. For these reasons and to avoid platform |
2124 // disparities we explicitly disable antialiasing. | 2125 // disparities we explicitly disable antialiasing. |
(...skipping 27 matching lines...) Expand all Loading... | |
2152 const size_t kMillisecondsPerFrame = 16; | 2153 const size_t kMillisecondsPerFrame = 16; |
2153 // Assuming a two frame deep pipeline between the CPU and the GPU. | 2154 // Assuming a two frame deep pipeline between the CPU and the GPU. |
2154 size_t max_transfer_buffer_usage_mb = | 2155 size_t max_transfer_buffer_usage_mb = |
2155 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms); | 2156 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms); |
2156 static const size_t kBytesPerMegabyte = 1024 * 1024; | 2157 static const size_t kBytesPerMegabyte = 1024 * 1024; |
2157 // We keep the MappedMemoryReclaimLimit the same as the upload limit | 2158 // We keep the MappedMemoryReclaimLimit the same as the upload limit |
2158 // to avoid unnecessarily stalling the compositor thread. | 2159 // to avoid unnecessarily stalling the compositor thread. |
2159 limits.mapped_memory_reclaim_limit = | 2160 limits.mapped_memory_reclaim_limit = |
2160 max_transfer_buffer_usage_mb * kBytesPerMegabyte; | 2161 max_transfer_buffer_usage_mb * kBytesPerMegabyte; |
2161 #endif | 2162 #endif |
2162 if (compositor) { | 2163 limits.command_buffer_size = 64 * 1024; |
2163 limits.command_buffer_size = 64 * 1024; | 2164 limits.start_transfer_buffer_size = 64 * 1024; |
2164 limits.start_transfer_buffer_size = 64 * 1024; | 2165 limits.min_transfer_buffer_size = 64 * 1024; |
2165 limits.min_transfer_buffer_size = 64 * 1024; | |
2166 } | |
2167 | 2166 |
2168 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 2167 return make_scoped_ptr(new WebGraphicsContext3DCommandBufferImpl( |
2169 new WebGraphicsContext3DCommandBufferImpl( | 2168 0, GetURLForGraphicsContext3D(), gpu_channel_host, attributes, |
2170 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes, | |
2171 lose_context_when_out_of_memory, limits, NULL)); | 2169 lose_context_when_out_of_memory, limits, NULL)); |
2172 return context; | |
2173 } | 2170 } |
2174 | 2171 |
2175 void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { | 2172 void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { |
2176 render_frame_proxies_.AddObserver(proxy); | 2173 render_frame_proxies_.AddObserver(proxy); |
2177 } | 2174 } |
2178 | 2175 |
2179 void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { | 2176 void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { |
2180 render_frame_proxies_.RemoveObserver(proxy); | 2177 render_frame_proxies_.RemoveObserver(proxy); |
2181 } | 2178 } |
2182 | 2179 |
2183 void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { | 2180 void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { |
2184 render_frames_.AddObserver(frame); | 2181 render_frames_.AddObserver(frame); |
2185 } | 2182 } |
2186 | 2183 |
2187 void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { | 2184 void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { |
2188 render_frames_.RemoveObserver(frame); | 2185 render_frames_.RemoveObserver(frame); |
2189 } | 2186 } |
2190 | 2187 |
2191 #if defined(VIDEO_HOLE) | 2188 #if defined(VIDEO_HOLE) |
2192 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2189 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2193 video_hole_frames_.AddObserver(frame); | 2190 video_hole_frames_.AddObserver(frame); |
2194 } | 2191 } |
2195 | 2192 |
2196 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2193 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2197 video_hole_frames_.RemoveObserver(frame); | 2194 video_hole_frames_.RemoveObserver(frame); |
2198 } | 2195 } |
2199 #endif // defined(VIDEO_HOLE) | 2196 #endif // defined(VIDEO_HOLE) |
2200 | 2197 |
2201 } // namespace content | 2198 } // namespace content |
OLD | NEW |