| 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 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() { | 1559 gpu::GpuMemoryBufferManager* RenderThreadImpl::GetGpuMemoryBufferManager() { |
| 1560 return gpu_->gpu_memory_buffer_manager(); | 1560 return gpu_->gpu_memory_buffer_manager(); |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() { | 1563 blink::scheduler::RendererScheduler* RenderThreadImpl::GetRendererScheduler() { |
| 1564 return renderer_scheduler_.get(); | 1564 return renderer_scheduler_.get(); |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 std::unique_ptr<cc::BeginFrameSource> | 1567 std::unique_ptr<cc::BeginFrameSource> |
| 1568 RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) { | 1568 RenderThreadImpl::CreateExternalBeginFrameSource(int routing_id) { |
| 1569 const base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | |
| 1570 if (cmd->HasSwitch(switches::kDisableGpuVsync)) { | |
| 1571 std::string display_vsync_string = | |
| 1572 cmd->GetSwitchValueASCII(switches::kDisableGpuVsync); | |
| 1573 if (display_vsync_string != "gpu") { | |
| 1574 // In disable gpu vsync mode, also let the renderer tick as fast as it | |
| 1575 // can. The top level begin frame source will also be running as a back | |
| 1576 // to back begin frame source, but using a synthetic begin frame source | |
| 1577 // here reduces latency when in this mode (at least for frames | |
| 1578 // starting--it potentially increases it for input on the other hand.) | |
| 1579 base::SingleThreadTaskRunner* compositor_impl_side_task_runner = | |
| 1580 compositor_task_runner_ ? compositor_task_runner_.get() | |
| 1581 : base::ThreadTaskRunnerHandle::Get().get(); | |
| 1582 return base::MakeUnique<cc::BackToBackBeginFrameSource>( | |
| 1583 base::MakeUnique<cc::DelayBasedTimeSource>( | |
| 1584 compositor_impl_side_task_runner)); | |
| 1585 } | |
| 1586 } | |
| 1587 | |
| 1588 return base::MakeUnique<CompositorExternalBeginFrameSource>( | 1569 return base::MakeUnique<CompositorExternalBeginFrameSource>( |
| 1589 compositor_message_filter_.get(), sync_message_filter(), routing_id); | 1570 compositor_message_filter_.get(), sync_message_filter(), routing_id); |
| 1590 } | 1571 } |
| 1591 | 1572 |
| 1573 std::unique_ptr<cc::SyntheticBeginFrameSource> |
| 1574 RenderThreadImpl::CreateSyntheticBeginFrameSource() { |
| 1575 base::SingleThreadTaskRunner* compositor_impl_side_task_runner = |
| 1576 compositor_task_runner_ ? compositor_task_runner_.get() |
| 1577 : base::ThreadTaskRunnerHandle::Get().get(); |
| 1578 return base::MakeUnique<cc::BackToBackBeginFrameSource>( |
| 1579 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 1580 compositor_impl_side_task_runner)); |
| 1581 } |
| 1582 |
| 1592 cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() { | 1583 cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() { |
| 1593 return categorized_worker_pool_->GetTaskGraphRunner(); | 1584 return categorized_worker_pool_->GetTaskGraphRunner(); |
| 1594 } | 1585 } |
| 1595 | 1586 |
| 1596 bool RenderThreadImpl::AreImageDecodeTasksEnabled() { | 1587 bool RenderThreadImpl::AreImageDecodeTasksEnabled() { |
| 1597 return are_image_decode_tasks_enabled_; | 1588 return are_image_decode_tasks_enabled_; |
| 1598 } | 1589 } |
| 1599 | 1590 |
| 1600 bool RenderThreadImpl::IsThreadedAnimationEnabled() { | 1591 bool RenderThreadImpl::IsThreadedAnimationEnabled() { |
| 1601 return is_threaded_animation_enabled_; | 1592 return is_threaded_animation_enabled_; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 bool use_software, | 1862 bool use_software, |
| 1872 int routing_id, | 1863 int routing_id, |
| 1873 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue, | 1864 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue, |
| 1874 const GURL& url, | 1865 const GURL& url, |
| 1875 const CompositorFrameSinkCallback& callback) { | 1866 const CompositorFrameSinkCallback& callback) { |
| 1876 const base::CommandLine& command_line = | 1867 const base::CommandLine& command_line = |
| 1877 *base::CommandLine::ForCurrentProcess(); | 1868 *base::CommandLine::ForCurrentProcess(); |
| 1878 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 1869 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
| 1879 use_software = true; | 1870 use_software = true; |
| 1880 | 1871 |
| 1872 // In disable gpu vsync mode, also let the renderer tick as fast as it |
| 1873 // can. The top level begin frame source will also be running as a back |
| 1874 // to back begin frame source, but using a synthetic begin frame source |
| 1875 // here reduces latency when in this mode (at least for frames |
| 1876 // starting--it potentially increases it for input on the other hand.) |
| 1877 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source; |
| 1878 if (command_line.HasSwitch(switches::kDisableGpuVsync) && |
| 1879 command_line.GetSwitchValueASCII(switches::kDisableGpuVsync) != "gpu") { |
| 1880 synthetic_begin_frame_source = CreateSyntheticBeginFrameSource(); |
| 1881 } |
| 1882 |
| 1881 #if defined(USE_AURA) | 1883 #if defined(USE_AURA) |
| 1882 if (!use_software && IsRunningInMash()) { | 1884 if (!use_software && IsRunningInMash()) { |
| 1883 scoped_refptr<gpu::GpuChannelHost> channel = EstablishGpuChannelSync(); | 1885 scoped_refptr<gpu::GpuChannelHost> channel = EstablishGpuChannelSync(); |
| 1884 // If the channel could not be established correctly, then return null. This | 1886 // If the channel could not be established correctly, then return null. This |
| 1885 // would cause the compositor to wait and try again at a later time. | 1887 // would cause the compositor to wait and try again at a later time. |
| 1886 if (!channel) { | 1888 if (!channel) { |
| 1887 callback.Run(nullptr); | 1889 callback.Run(nullptr); |
| 1888 return; | 1890 return; |
| 1889 } | 1891 } |
| 1890 RendererWindowTreeClient::Get(routing_id) | 1892 RendererWindowTreeClient::Get(routing_id) |
| 1891 ->RequestCompositorFrameSink( | 1893 ->RequestCompositorFrameSink( |
| 1892 gpu_->CreateContextProvider(std::move(channel)), | 1894 gpu_->CreateContextProvider(std::move(channel)), |
| 1893 GetGpuMemoryBufferManager(), callback); | 1895 GetGpuMemoryBufferManager(), callback); |
| 1894 return; | 1896 return; |
| 1895 } | 1897 } |
| 1896 #endif | 1898 #endif |
| 1897 | 1899 |
| 1898 uint32_t compositor_frame_sink_id = g_next_compositor_frame_sink_id++; | 1900 uint32_t compositor_frame_sink_id = g_next_compositor_frame_sink_id++; |
| 1899 | 1901 |
| 1900 if (command_line.HasSwitch(switches::kEnableVulkan)) { | 1902 if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 1901 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 1903 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 1902 cc::VulkanInProcessContextProvider::Create(); | 1904 cc::VulkanInProcessContextProvider::Create(); |
| 1903 if (vulkan_context_provider) { | 1905 if (vulkan_context_provider) { |
| 1904 DCHECK(!layout_test_mode()); | 1906 DCHECK(!layout_test_mode()); |
| 1905 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( | 1907 callback.Run(base::MakeUnique<RendererCompositorFrameSink>( |
| 1906 routing_id, compositor_frame_sink_id, | 1908 routing_id, compositor_frame_sink_id, |
| 1907 CreateExternalBeginFrameSource(routing_id), | 1909 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, compositor_frame_sink_id, |
| 1934 CreateExternalBeginFrameSource(routing_id), nullptr, nullptr, nullptr, | 1936 std::move(synthetic_begin_frame_source), nullptr, nullptr, nullptr, |
| 1935 shared_bitmap_manager(), std::move(frame_swap_message_queue))); | 1937 shared_bitmap_manager(), std::move(frame_swap_message_queue))); |
| 1936 return; | 1938 return; |
| 1937 } | 1939 } |
| 1938 | 1940 |
| 1939 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = | 1941 scoped_refptr<ui::ContextProviderCommandBuffer> worker_context_provider = |
| 1940 SharedCompositorWorkerContextProvider(); | 1942 SharedCompositorWorkerContextProvider(); |
| 1941 if (!worker_context_provider) { | 1943 if (!worker_context_provider) { |
| 1942 // Cause the compositor to wait and try again. | 1944 // Cause the compositor to wait and try again. |
| 1943 callback.Run(nullptr); | 1945 callback.Run(nullptr); |
| 1944 return; | 1946 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 | 1981 |
| 1980 if (layout_test_deps_) { | 1982 if (layout_test_deps_) { |
| 1981 callback.Run(layout_test_deps_->CreateCompositorFrameSink( | 1983 callback.Run(layout_test_deps_->CreateCompositorFrameSink( |
| 1982 routing_id, std::move(gpu_channel_host), std::move(context_provider), | 1984 routing_id, std::move(gpu_channel_host), std::move(context_provider), |
| 1983 std::move(worker_context_provider), GetGpuMemoryBufferManager(), this)); | 1985 std::move(worker_context_provider), GetGpuMemoryBufferManager(), this)); |
| 1984 return; | 1986 return; |
| 1985 } | 1987 } |
| 1986 | 1988 |
| 1987 #if defined(OS_ANDROID) | 1989 #if defined(OS_ANDROID) |
| 1988 if (sync_compositor_message_filter_) { | 1990 if (sync_compositor_message_filter_) { |
| 1991 std::unique_ptr<cc::BeginFrameSource> begin_frame_source_ = |
| 1992 synthetic_begin_frame_source |
| 1993 ? std::move(synthetic_begin_frame_source) |
| 1994 : CreateExternalBeginFrameSource(routing_id); |
| 1989 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( | 1995 callback.Run(base::MakeUnique<SynchronousCompositorFrameSink>( |
| 1990 std::move(context_provider), std::move(worker_context_provider), | 1996 std::move(context_provider), std::move(worker_context_provider), |
| 1991 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, | 1997 GetGpuMemoryBufferManager(), shared_bitmap_manager(), routing_id, |
| 1992 compositor_frame_sink_id, CreateExternalBeginFrameSource(routing_id), | 1998 compositor_frame_sink_id, std::move(begin_frame_source), |
| 1993 sync_compositor_message_filter_.get(), | 1999 sync_compositor_message_filter_.get(), |
| 1994 std::move(frame_swap_message_queue))); | 2000 std::move(frame_swap_message_queue))); |
| 1995 return; | 2001 return; |
| 1996 } | 2002 } |
| 1997 #endif | 2003 #endif |
| 1998 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( | 2004 callback.Run(base::WrapUnique(new RendererCompositorFrameSink( |
| 1999 routing_id, compositor_frame_sink_id, | 2005 routing_id, compositor_frame_sink_id, |
| 2000 CreateExternalBeginFrameSource(routing_id), std::move(context_provider), | 2006 std::move(synthetic_begin_frame_source), std::move(context_provider), |
| 2001 std::move(worker_context_provider), GetGpuMemoryBufferManager(), nullptr, | 2007 std::move(worker_context_provider), GetGpuMemoryBufferManager(), nullptr, |
| 2002 std::move(frame_swap_message_queue)))); | 2008 std::move(frame_swap_message_queue)))); |
| 2003 } | 2009 } |
| 2004 | 2010 |
| 2005 AssociatedInterfaceRegistry* | 2011 AssociatedInterfaceRegistry* |
| 2006 RenderThreadImpl::GetAssociatedInterfaceRegistry() { | 2012 RenderThreadImpl::GetAssociatedInterfaceRegistry() { |
| 2007 return &associated_interfaces_; | 2013 return &associated_interfaces_; |
| 2008 } | 2014 } |
| 2009 | 2015 |
| 2010 std::unique_ptr<cc::SwapPromise> | 2016 std::unique_ptr<cc::SwapPromise> |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2426 } | 2432 } |
| 2427 } | 2433 } |
| 2428 | 2434 |
| 2429 void RenderThreadImpl::OnRendererInterfaceRequest( | 2435 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2430 mojom::RendererAssociatedRequest request) { | 2436 mojom::RendererAssociatedRequest request) { |
| 2431 DCHECK(!renderer_binding_.is_bound()); | 2437 DCHECK(!renderer_binding_.is_bound()); |
| 2432 renderer_binding_.Bind(std::move(request)); | 2438 renderer_binding_.Bind(std::move(request)); |
| 2433 } | 2439 } |
| 2434 | 2440 |
| 2435 } // namespace content | 2441 } // namespace content |
| OLD | NEW |