| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; | 244 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
| 245 #endif | 245 #endif |
| 246 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; | 246 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
| 247 | 247 |
| 248 // Maximum allocation size allowed for image scaling filters that | 248 // Maximum allocation size allowed for image scaling filters that |
| 249 // require pre-scaling. Skia will fallback to a filter that doesn't | 249 // require pre-scaling. Skia will fallback to a filter that doesn't |
| 250 // require pre-scaling if the default filter would require an | 250 // require pre-scaling if the default filter would require an |
| 251 // allocation that exceeds this limit. | 251 // allocation that exceeds this limit. |
| 252 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; | 252 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 253 | 253 |
| 254 #if defined(OS_ANDROID) |
| 254 // Unique identifier for each output surface created. | 255 // Unique identifier for each output surface created. |
| 255 uint32_t g_next_compositor_frame_sink_id = 1; | 256 uint32_t g_next_compositor_frame_sink_id = 1; |
| 257 #endif |
| 256 | 258 |
| 257 // An implementation of mojom::RenderMessageFilter which can be mocked out | 259 // An implementation of mojom::RenderMessageFilter which can be mocked out |
| 258 // for tests which may indirectly send messages over this interface. | 260 // for tests which may indirectly send messages over this interface. |
| 259 mojom::RenderMessageFilter* g_render_message_filter_for_testing; | 261 mojom::RenderMessageFilter* g_render_message_filter_for_testing; |
| 260 | 262 |
| 261 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access | 263 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
| 262 // incorrectly from the wrong thread. | 264 // incorrectly from the wrong thread. |
| 263 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit | 265 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl>>::DestructorAtExit |
| 264 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 266 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
| 265 | 267 |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 needs_to_record_first_active_paint_ = false; | 907 needs_to_record_first_active_paint_ = false; |
| 906 | 908 |
| 907 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 909 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 908 | 910 |
| 909 // If this renderer doesn't run inside the browser process, enable | 911 // If this renderer doesn't run inside the browser process, enable |
| 910 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 912 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 911 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 913 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 912 // redirection experiment concludes https://crbug.com/622400. | 914 // redirection experiment concludes https://crbug.com/622400. |
| 913 if (!command_line.HasSwitch(switches::kSingleProcess)) | 915 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 914 base::SequencedWorkerPool::EnableForProcess(); | 916 base::SequencedWorkerPool::EnableForProcess(); |
| 917 |
| 918 GetConnector()->BindInterface(mojom::kBrowserServiceName, |
| 919 mojo::MakeRequest(&frame_sink_provider_)); |
| 915 } | 920 } |
| 916 | 921 |
| 917 RenderThreadImpl::~RenderThreadImpl() { | 922 RenderThreadImpl::~RenderThreadImpl() { |
| 918 } | 923 } |
| 919 | 924 |
| 920 void RenderThreadImpl::Shutdown() { | 925 void RenderThreadImpl::Shutdown() { |
| 921 // In a multi-process mode, we immediately exit the renderer. | 926 // In a multi-process mode, we immediately exit the renderer. |
| 922 // Historically we had a graceful shutdown sequence here but it was | 927 // Historically we had a graceful shutdown sequence here but it was |
| 923 // 1) a waste of performance and 2) a source of lots of complicated | 928 // 1) a waste of performance and 2) a source of lots of complicated |
| 924 // crashes caused by shutdown ordering. Immediate exit eliminates | 929 // crashes caused by shutdown ordering. Immediate exit eliminates |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 return; | 1912 return; |
| 1908 } | 1913 } |
| 1909 RendererWindowTreeClient::Get(routing_id) | 1914 RendererWindowTreeClient::Get(routing_id) |
| 1910 ->RequestCompositorFrameSink( | 1915 ->RequestCompositorFrameSink( |
| 1911 gpu_->CreateContextProvider(std::move(channel)), | 1916 gpu_->CreateContextProvider(std::move(channel)), |
| 1912 GetGpuMemoryBufferManager(), callback); | 1917 GetGpuMemoryBufferManager(), callback); |
| 1913 return; | 1918 return; |
| 1914 } | 1919 } |
| 1915 #endif | 1920 #endif |
| 1916 | 1921 |
| 1917 uint32_t compositor_frame_sink_id = g_next_compositor_frame_sink_id++; | |
| 1918 | |
| 1919 if (command_line.HasSwitch(switches::kEnableVulkan)) { | 1922 if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 1920 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 1923 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 1921 cc::VulkanInProcessContextProvider::Create(); | 1924 cc::VulkanInProcessContextProvider::Create(); |
| 1922 if (vulkan_context_provider) { | 1925 if (vulkan_context_provider) { |
| 1923 DCHECK(!layout_test_mode()); | 1926 DCHECK(!layout_test_mode()); |
| 1924 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( | 1927 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( |
| 1925 routing_id, compositor_frame_sink_id, | 1928 routing_id, std::move(synthetic_begin_frame_source), |
| 1926 std::move(synthetic_begin_frame_source), | |
| 1927 std::move(vulkan_context_provider), | 1929 std::move(vulkan_context_provider), |
| 1928 std::move(frame_swap_message_queue))); | 1930 std::move(frame_swap_message_queue))); |
| 1929 return; | 1931 return; |
| 1930 } | 1932 } |
| 1931 } | 1933 } |
| 1932 | 1934 |
| 1933 // Create a gpu process channel and verify we want to use GPU compositing | 1935 // Create a gpu process channel and verify we want to use GPU compositing |
| 1934 // before creating any context providers. | 1936 // before creating any context providers. |
| 1935 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; | 1937 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
| 1936 if (!use_software) { | 1938 if (!use_software) { |
| 1937 gpu_channel_host = EstablishGpuChannelSync(); | 1939 gpu_channel_host = EstablishGpuChannelSync(); |
| 1938 if (!gpu_channel_host) { | 1940 if (!gpu_channel_host) { |
| 1939 // Cause the compositor to wait and try again. | 1941 // Cause the compositor to wait and try again. |
| 1940 callback.Run(nullptr); | 1942 callback.Run(nullptr); |
| 1941 return; | 1943 return; |
| 1942 } | 1944 } |
| 1943 // We may get a valid channel, but with a software renderer. In that case, | 1945 // We may get a valid channel, but with a software renderer. In that case, |
| 1944 // disable GPU compositing. | 1946 // disable GPU compositing. |
| 1945 if (gpu_channel_host->gpu_info().software_rendering) | 1947 if (gpu_channel_host->gpu_info().software_rendering) |
| 1946 use_software = true; | 1948 use_software = true; |
| 1947 } | 1949 } |
| 1948 | 1950 |
| 1949 if (use_software) { | 1951 if (use_software) { |
| 1950 DCHECK(!layout_test_mode()); | 1952 DCHECK(!layout_test_mode()); |
| 1951 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( | 1953 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( |
| 1952 routing_id, compositor_frame_sink_id, | 1954 routing_id, std::move(synthetic_begin_frame_source), nullptr, nullptr, |
| 1953 std::move(synthetic_begin_frame_source), nullptr, nullptr, nullptr, | 1955 nullptr, shared_bitmap_manager(), std::move(frame_swap_message_queue))); |
| 1954 shared_bitmap_manager(), std::move(frame_swap_message_queue))); | |
| 1955 return; | 1956 return; |
| 1956 } | 1957 } |
| 1957 | 1958 |
| 1958 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = | 1959 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = |
| 1959 SharedCompositorWorkerContextProvider(); | 1960 SharedCompositorWorkerContextProvider(); |
| 1960 if (!worker_context_provider) { | 1961 if (!worker_context_provider) { |
| 1961 // Cause the compositor to wait and try again. | 1962 // Cause the compositor to wait and try again. |
| 1962 callback.Run(nullptr); | 1963 callback.Run(nullptr); |
| 1963 return; | 1964 return; |
| 1964 } | 1965 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 | 2006 |
| 2006 #if defined(OS_ANDROID) | 2007 #if defined(OS_ANDROID) |
| 2007 if (sync_compositor_message_filter_) { | 2008 if (sync_compositor_message_filter_) { |
| 2008 std::unique_ptr<cc::BeginFrameSource> begin_frame_source = | 2009 std::unique_ptr<cc::BeginFrameSource> begin_frame_source = |
| 2009 synthetic_begin_frame_source | 2010 synthetic_begin_frame_source |
| 2010 ? std::move(synthetic_begin_frame_source) | 2011 ? std::move(synthetic_begin_frame_source) |
| 2011 : CreateExternalBeginFrameSource(routing_id); | 2012 : CreateExternalBeginFrameSource(routing_id); |
| 2012 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( | 2013 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( |
| 2013 std::move(context_provider), std::move(worker_context_provider), | 2014 std::move(context_provider), std::move(worker_context_provider), |
| 2014 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, | 2015 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, |
| 2015 compositor_frame_sink_id, std::move(begin_frame_source), | 2016 g_next_compositor_frame_sink_id++, std::move(begin_frame_source), |
| 2016 sync_compositor_message_filter_.get(), | 2017 sync_compositor_message_filter_.get(), |
| 2017 std::move(frame_swap_message_queue))); | 2018 std::move(frame_swap_message_queue))); |
| 2018 return; | 2019 return; |
| 2019 } | 2020 } |
| 2020 #endif | 2021 #endif |
| 2021 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( | 2022 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( |
| 2022 routing_id, compositor_frame_sink_id, | 2023 routing_id, std::move(synthetic_begin_frame_source), |
| 2023 std::move(synthetic_begin_frame_source), std::move(context_provider), | 2024 std::move(context_provider), std::move(worker_context_provider), |
| 2024 std::move(worker_context_provider), GetGpuMemoryBufferManager(), nullptr, | 2025 GetGpuMemoryBufferManager(), nullptr, |
| 2025 std::move(frame_swap_message_queue)))); | 2026 std::move(frame_swap_message_queue)))); |
| 2026 } | 2027 } |
| 2027 | 2028 |
| 2028 AssociatedInterfaceRegistry* | 2029 AssociatedInterfaceRegistry* |
| 2029 RenderThreadImpl::GetAssociatedInterfaceRegistry() { | 2030 RenderThreadImpl::GetAssociatedInterfaceRegistry() { |
| 2030 return &associated_interfaces_; | 2031 return &associated_interfaces_; |
| 2031 } | 2032 } |
| 2032 | 2033 |
| 2033 std::unique_ptr<cc::SwapPromise> | 2034 std::unique_ptr<cc::SwapPromise> |
| 2034 RenderThreadImpl::RequestCopyOfOutputForLayoutTest( | 2035 RenderThreadImpl::RequestCopyOfOutputForLayoutTest( |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2468 } | 2469 } |
| 2469 } | 2470 } |
| 2470 | 2471 |
| 2471 void RenderThreadImpl::OnRendererInterfaceRequest( | 2472 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2472 mojom::RendererAssociatedRequest request) { | 2473 mojom::RendererAssociatedRequest request) { |
| 2473 DCHECK(!renderer_binding_.is_bound()); | 2474 DCHECK(!renderer_binding_.is_bound()); |
| 2474 renderer_binding_.Bind(std::move(request)); | 2475 renderer_binding_.Bind(std::move(request)); |
| 2475 } | 2476 } |
| 2476 | 2477 |
| 2477 } // namespace content | 2478 } // namespace content |
| OLD | NEW |