| 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_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; | 243 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
| 244 #endif | 244 #endif |
| 245 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; | 245 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
| 246 | 246 |
| 247 // Maximum allocation size allowed for image scaling filters that | 247 // Maximum allocation size allowed for image scaling filters that |
| 248 // require pre-scaling. Skia will fallback to a filter that doesn't | 248 // require pre-scaling. Skia will fallback to a filter that doesn't |
| 249 // require pre-scaling if the default filter would require an | 249 // require pre-scaling if the default filter would require an |
| 250 // allocation that exceeds this limit. | 250 // allocation that exceeds this limit. |
| 251 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; | 251 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 252 | 252 |
| 253 #if defined(OS_ANDROID) |
| 253 // Unique identifier for each output surface created. | 254 // Unique identifier for each output surface created. |
| 254 uint32_t g_next_compositor_frame_sink_id = 1; | 255 uint32_t g_next_compositor_frame_sink_id = 1; |
| 256 #endif |
| 255 | 257 |
| 256 // An implementation of mojom::RenderMessageFilter which can be mocked out | 258 // An implementation of mojom::RenderMessageFilter which can be mocked out |
| 257 // for tests which may indirectly send messages over this interface. | 259 // for tests which may indirectly send messages over this interface. |
| 258 mojom::RenderMessageFilter* g_render_message_filter_for_testing; | 260 mojom::RenderMessageFilter* g_render_message_filter_for_testing; |
| 259 | 261 |
| 260 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access | 262 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
| 261 // incorrectly from the wrong thread. | 263 // incorrectly from the wrong thread. |
| 262 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit | 264 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit |
| 263 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 265 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
| 264 | 266 |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 needs_to_record_first_active_paint_ = false; | 887 needs_to_record_first_active_paint_ = false; |
| 886 | 888 |
| 887 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 889 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 888 | 890 |
| 889 // If this renderer doesn't run inside the browser process, enable | 891 // If this renderer doesn't run inside the browser process, enable |
| 890 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 892 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 891 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 893 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 892 // redirection experiment concludes https://crbug.com/622400. | 894 // redirection experiment concludes https://crbug.com/622400. |
| 893 if (!command_line.HasSwitch(switches::kSingleProcess)) | 895 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 894 base::SequencedWorkerPool::EnableForProcess(); | 896 base::SequencedWorkerPool::EnableForProcess(); |
| 897 |
| 898 GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 899 mojo::MakeRequest(&frame_sink_provider_)); |
| 895 } | 900 } |
| 896 | 901 |
| 897 RenderThreadImpl::~RenderThreadImpl() { | 902 RenderThreadImpl::~RenderThreadImpl() { |
| 898 } | 903 } |
| 899 | 904 |
| 900 void RenderThreadImpl::Shutdown() { | 905 void RenderThreadImpl::Shutdown() { |
| 901 // In a multi-process mode, we immediately exit the renderer. | 906 // In a multi-process mode, we immediately exit the renderer. |
| 902 // Historically we had a graceful shutdown sequence here but it was | 907 // Historically we had a graceful shutdown sequence here but it was |
| 903 // 1) a waste of performance and 2) a source of lots of complicated | 908 // 1) a waste of performance and 2) a source of lots of complicated |
| 904 // crashes caused by shutdown ordering. Immediate exit eliminates | 909 // crashes caused by shutdown ordering. Immediate exit eliminates |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 return; | 1893 return; |
| 1889 } | 1894 } |
| 1890 RendererWindowTreeClient::Get(routing_id) | 1895 RendererWindowTreeClient::Get(routing_id) |
| 1891 ->RequestCompositorFrameSink( | 1896 ->RequestCompositorFrameSink( |
| 1892 gpu_->CreateContextProvider(std::move(channel)), | 1897 gpu_->CreateContextProvider(std::move(channel)), |
| 1893 GetGpuMemoryBufferManager(), callback); | 1898 GetGpuMemoryBufferManager(), callback); |
| 1894 return; | 1899 return; |
| 1895 } | 1900 } |
| 1896 #endif | 1901 #endif |
| 1897 | 1902 |
| 1898 uint32_t compositor_frame_sink_id = g_next_compositor_frame_sink_id++; | |
| 1899 | |
| 1900 if (command_line.HasSwitch(switches::kEnableVulkan)) { | 1903 if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 1901 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 1904 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 1902 cc::VulkanInProcessContextProvider::Create(); | 1905 cc::VulkanInProcessContextProvider::Create(); |
| 1903 if (vulkan_context_provider) { | 1906 if (vulkan_context_provider) { |
| 1904 DCHECK(!layout_test_mode()); | 1907 DCHECK(!layout_test_mode()); |
| 1905 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( | 1908 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( |
| 1906 routing_id, compositor_frame_sink_id, | 1909 routing_id, std::move(synthetic_begin_frame_source), |
| 1907 std::move(synthetic_begin_frame_source), | |
| 1908 std::move(vulkan_context_provider), | 1910 std::move(vulkan_context_provider), |
| 1909 std::move(frame_swap_message_queue))); | 1911 std::move(frame_swap_message_queue))); |
| 1910 return; | 1912 return; |
| 1911 } | 1913 } |
| 1912 } | 1914 } |
| 1913 | 1915 |
| 1914 // Create a gpu process channel and verify we want to use GPU compositing | 1916 // Create a gpu process channel and verify we want to use GPU compositing |
| 1915 // before creating any context providers. | 1917 // before creating any context providers. |
| 1916 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; | 1918 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
| 1917 if (!use_software) { | 1919 if (!use_software) { |
| 1918 gpu_channel_host = EstablishGpuChannelSync(); | 1920 gpu_channel_host = EstablishGpuChannelSync(); |
| 1919 if (!gpu_channel_host) { | 1921 if (!gpu_channel_host) { |
| 1920 // Cause the compositor to wait and try again. | 1922 // Cause the compositor to wait and try again. |
| 1921 callback.Run(nullptr); | 1923 callback.Run(nullptr); |
| 1922 return; | 1924 return; |
| 1923 } | 1925 } |
| 1924 // We may get a valid channel, but with a software renderer. In that case, | 1926 // We may get a valid channel, but with a software renderer. In that case, |
| 1925 // disable GPU compositing. | 1927 // disable GPU compositing. |
| 1926 if (gpu_channel_host->gpu_info().software_rendering) | 1928 if (gpu_channel_host->gpu_info().software_rendering) |
| 1927 use_software = true; | 1929 use_software = true; |
| 1928 } | 1930 } |
| 1929 | 1931 |
| 1930 if (use_software) { | 1932 if (use_software) { |
| 1931 DCHECK(!layout_test_mode()); | 1933 DCHECK(!layout_test_mode()); |
| 1932 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( | 1934 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( |
| 1933 routing_id, compositor_frame_sink_id, | 1935 routing_id, std::move(synthetic_begin_frame_source), nullptr, nullptr, |
| 1934 std::move(synthetic_begin_frame_source), nullptr, nullptr, nullptr, | 1936 nullptr, shared_bitmap_manager(), std::move(frame_swap_message_queue))); |
| 1935 shared_bitmap_manager(), std::move(frame_swap_message_queue))); | |
| 1936 return; | 1937 return; |
| 1937 } | 1938 } |
| 1938 | 1939 |
| 1939 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = | 1940 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = |
| 1940 SharedCompositorWorkerContextProvider(); | 1941 SharedCompositorWorkerContextProvider(); |
| 1941 if (!worker_context_provider) { | 1942 if (!worker_context_provider) { |
| 1942 // Cause the compositor to wait and try again. | 1943 // Cause the compositor to wait and try again. |
| 1943 callback.Run(nullptr); | 1944 callback.Run(nullptr); |
| 1944 return; | 1945 return; |
| 1945 } | 1946 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 | 1987 |
| 1987 #if defined(OS_ANDROID) | 1988 #if defined(OS_ANDROID) |
| 1988 if (sync_compositor_message_filter_) { | 1989 if (sync_compositor_message_filter_) { |
| 1989 std::unique_ptr<cc::BeginFrameSource> begin_frame_source = | 1990 std::unique_ptr<cc::BeginFrameSource> begin_frame_source = |
| 1990 synthetic_begin_frame_source | 1991 synthetic_begin_frame_source |
| 1991 ? std::move(synthetic_begin_frame_source) | 1992 ? std::move(synthetic_begin_frame_source) |
| 1992 : CreateExternalBeginFrameSource(routing_id); | 1993 : CreateExternalBeginFrameSource(routing_id); |
| 1993 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( | 1994 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( |
| 1994 std::move(context_provider), std::move(worker_context_provider), | 1995 std::move(context_provider), std::move(worker_context_provider), |
| 1995 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, | 1996 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, |
| 1996 compositor_frame_sink_id, std::move(begin_frame_source), | 1997 g_next_compositor_frame_sink_id++, std::move(begin_frame_source), |
| 1997 sync_compositor_message_filter_.get(), | 1998 sync_compositor_message_filter_.get(), |
| 1998 std::move(frame_swap_message_queue))); | 1999 std::move(frame_swap_message_queue))); |
| 1999 return; | 2000 return; |
| 2000 } | 2001 } |
| 2001 #endif | 2002 #endif |
| 2002 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( | 2003 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( |
| 2003 routing_id, compositor_frame_sink_id, | 2004 routing_id, std::move(synthetic_begin_frame_source), |
| 2004 std::move(synthetic_begin_frame_source), std::move(context_provider), | 2005 std::move(context_provider), std::move(worker_context_provider), |
| 2005 std::move(worker_context_provider), GetGpuMemoryBufferManager(), nullptr, | 2006 GetGpuMemoryBufferManager(), nullptr, |
| 2006 std::move(frame_swap_message_queue)))); | 2007 std::move(frame_swap_message_queue)))); |
| 2007 } | 2008 } |
| 2008 | 2009 |
| 2009 AssociatedInterfaceRegistry* | 2010 AssociatedInterfaceRegistry* |
| 2010 RenderThreadImpl::GetAssociatedInterfaceRegistry() { | 2011 RenderThreadImpl::GetAssociatedInterfaceRegistry() { |
| 2011 return &associated_interfaces_; | 2012 return &associated_interfaces_; |
| 2012 } | 2013 } |
| 2013 | 2014 |
| 2014 std::unique_ptr<cc::SwapPromise> | 2015 std::unique_ptr<cc::SwapPromise> |
| 2015 RenderThreadImpl::RequestCopyOfOutputForLayoutTest( | 2016 RenderThreadImpl::RequestCopyOfOutputForLayoutTest( |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 } | 2450 } |
| 2450 } | 2451 } |
| 2451 | 2452 |
| 2452 void RenderThreadImpl::OnRendererInterfaceRequest( | 2453 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2453 mojom::RendererAssociatedRequest request) { | 2454 mojom::RendererAssociatedRequest request) { |
| 2454 DCHECK(!renderer_binding_.is_bound()); | 2455 DCHECK(!renderer_binding_.is_bound()); |
| 2455 renderer_binding_.Bind(std::move(request)); | 2456 renderer_binding_.Bind(std::move(request)); |
| 2456 } | 2457 } |
| 2457 | 2458 |
| 2458 } // namespace content | 2459 } // namespace content |
| OLD | NEW |