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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 } | 912 } |
913 #endif | 913 #endif |
914 | 914 |
915 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 915 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
916 bool use_software = fallback; | 916 bool use_software = fallback; |
917 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 917 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
918 use_software = true; | 918 use_software = true; |
919 | 919 |
920 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 920 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
921 if (!use_software) { | 921 if (!use_software) { |
922 // Explicitly disable antialiasing for the compositor. As of the time of | |
923 // this writing, the only platform that supported antialiasing for the | |
924 // compositor was Mac OS X, because the on-screen OpenGL context creation | |
925 // code paths on Windows and Linux didn't yet have multisampling support. | |
926 // Mac OS X essentially always behaves as though it's rendering offscreen. | |
927 // Multisampling has a heavy cost especially on devices with relatively low | |
928 // fill rate like most notebooks, and the Mac implementation would need to | |
929 // be optimized to resolve directly into the IOSurface shared between the | |
930 // GPU and browser processes. For these reasons and to avoid platform | |
931 // disparities we explicitly disable antialiasing. | |
932 blink::WebGraphicsContext3D::Attributes attributes; | |
933 attributes.antialias = false; | |
934 attributes.shareResources = true; | |
935 attributes.noAutomaticFlushes = true; | |
936 attributes.depth = false; | |
937 attributes.stencil = false; | |
938 context_provider = ContextProviderCommandBuffer::Create( | 922 context_provider = ContextProviderCommandBuffer::Create( |
939 CreateGraphicsContext3D(attributes), | 923 CreateGraphicsContext3D(), "RenderCompositor"); |
940 "RenderCompositor"); | |
941 if (!context_provider.get()) { | 924 if (!context_provider.get()) { |
942 // Cause the compositor to wait and try again. | 925 // Cause the compositor to wait and try again. |
943 return scoped_ptr<cc::OutputSurface>(); | 926 return scoped_ptr<cc::OutputSurface>(); |
944 } | 927 } |
945 } | 928 } |
946 | 929 |
947 uint32 output_surface_id = next_output_surface_id_++; | 930 uint32 output_surface_id = next_output_surface_id_++; |
948 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) && | 931 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) && |
949 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) { | 932 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) { |
950 DCHECK(is_threaded_compositing_enabled_); | 933 DCHECK(is_threaded_compositing_enabled_); |
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2831 #if defined(OS_ANDROID) | 2814 #if defined(OS_ANDROID) |
2832 void RenderWidget::UpdateSelectionRootBounds() { | 2815 void RenderWidget::UpdateSelectionRootBounds() { |
2833 } | 2816 } |
2834 #endif | 2817 #endif |
2835 | 2818 |
2836 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { | 2819 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
2837 return true; | 2820 return true; |
2838 } | 2821 } |
2839 | 2822 |
2840 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 2823 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
2841 RenderWidget::CreateGraphicsContext3D( | 2824 RenderWidget::CreateGraphicsContext3D() { |
2842 const blink::WebGraphicsContext3D::Attributes& attributes) { | |
2843 if (!webwidget_) | 2825 if (!webwidget_) |
2844 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2826 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2845 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2827 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2846 switches::kDisableGpuCompositing)) | 2828 switches::kDisableGpuCompositing)) |
2847 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2829 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2848 if (!RenderThreadImpl::current()) | 2830 if (!RenderThreadImpl::current()) |
2849 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2831 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2850 CauseForGpuLaunch cause = | 2832 CauseForGpuLaunch cause = |
2851 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 2833 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
2852 scoped_refptr<GpuChannelHost> gpu_channel_host( | 2834 scoped_refptr<GpuChannelHost> gpu_channel_host( |
2853 RenderThreadImpl::current()->EstablishGpuChannelSync(cause)); | 2835 RenderThreadImpl::current()->EstablishGpuChannelSync(cause)); |
2854 if (!gpu_channel_host) | 2836 if (!gpu_channel_host) |
2855 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 2837 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2856 | 2838 |
| 2839 // Explicitly disable antialiasing for the compositor. As of the time of |
| 2840 // this writing, the only platform that supported antialiasing for the |
| 2841 // compositor was Mac OS X, because the on-screen OpenGL context creation |
| 2842 // code paths on Windows and Linux didn't yet have multisampling support. |
| 2843 // Mac OS X essentially always behaves as though it's rendering offscreen. |
| 2844 // Multisampling has a heavy cost especially on devices with relatively low |
| 2845 // fill rate like most notebooks, and the Mac implementation would need to |
| 2846 // be optimized to resolve directly into the IOSurface shared between the |
| 2847 // GPU and browser processes. For these reasons and to avoid platform |
| 2848 // disparities we explicitly disable antialiasing. |
| 2849 blink::WebGraphicsContext3D::Attributes attributes; |
| 2850 attributes.antialias = false; |
| 2851 attributes.shareResources = true; |
| 2852 attributes.noAutomaticFlushes = true; |
| 2853 attributes.depth = false; |
| 2854 attributes.stencil = false; |
| 2855 bool bind_generates_resources = false; |
| 2856 bool lose_context_when_out_of_memory = true; |
2857 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; | 2857 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; |
2858 #if defined(OS_ANDROID) | 2858 #if defined(OS_ANDROID) |
2859 // If we raster too fast we become upload bound, and pending | 2859 // If we raster too fast we become upload bound, and pending |
2860 // uploads consume memory. For maximum upload throughput, we would | 2860 // uploads consume memory. For maximum upload throughput, we would |
2861 // want to allow for upload_throughput * pipeline_time of pending | 2861 // want to allow for upload_throughput * pipeline_time of pending |
2862 // uploads, after which we are just wasting memory. Since we don't | 2862 // uploads, after which we are just wasting memory. Since we don't |
2863 // know our upload throughput yet, this just caps our memory usage. | 2863 // know our upload throughput yet, this just caps our memory usage. |
2864 size_t divider = 1; | 2864 size_t divider = 1; |
2865 if (base::android::SysUtils::IsLowEndDevice()) | 2865 if (base::android::SysUtils::IsLowEndDevice()) |
2866 divider = 6; | 2866 divider = 6; |
2867 // For reference Nexus10 can upload 1MB in about 2.5ms. | 2867 // For reference Nexus10 can upload 1MB in about 2.5ms. |
2868 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider); | 2868 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider); |
2869 // Deadline to draw a frame to achieve 60 frames per second. | 2869 // Deadline to draw a frame to achieve 60 frames per second. |
2870 const size_t kMillisecondsPerFrame = 16; | 2870 const size_t kMillisecondsPerFrame = 16; |
2871 // Assuming a two frame deep pipeline between the CPU and the GPU. | 2871 // Assuming a two frame deep pipeline between the CPU and the GPU. |
2872 size_t max_transfer_buffer_usage_mb = | 2872 size_t max_transfer_buffer_usage_mb = |
2873 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms); | 2873 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms); |
2874 static const size_t kBytesPerMegabyte = 1024 * 1024; | 2874 static const size_t kBytesPerMegabyte = 1024 * 1024; |
2875 // We keep the MappedMemoryReclaimLimit the same as the upload limit | 2875 // We keep the MappedMemoryReclaimLimit the same as the upload limit |
2876 // to avoid unnecessarily stalling the compositor thread. | 2876 // to avoid unnecessarily stalling the compositor thread. |
2877 limits.mapped_memory_reclaim_limit = | 2877 limits.mapped_memory_reclaim_limit = |
2878 max_transfer_buffer_usage_mb * kBytesPerMegabyte; | 2878 max_transfer_buffer_usage_mb * kBytesPerMegabyte; |
2879 #endif | 2879 #endif |
2880 | 2880 |
2881 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 2881 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
2882 new WebGraphicsContext3DCommandBufferImpl( | 2882 new WebGraphicsContext3DCommandBufferImpl(surface_id(), |
2883 surface_id(), | 2883 GetURLForGraphicsContext3D(), |
2884 GetURLForGraphicsContext3D(), | 2884 gpu_channel_host.get(), |
2885 gpu_channel_host.get(), | 2885 attributes, |
2886 attributes, | 2886 bind_generates_resources, |
2887 false /* bind generates resources */, | 2887 lose_context_when_out_of_memory, |
2888 limits, | 2888 limits, |
2889 NULL)); | 2889 NULL)); |
2890 return context.Pass(); | 2890 return context.Pass(); |
2891 } | 2891 } |
2892 | 2892 |
2893 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2893 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2894 swapped_out_frames_.AddObserver(frame); | 2894 swapped_out_frames_.AddObserver(frame); |
2895 } | 2895 } |
2896 | 2896 |
2897 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2897 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2898 swapped_out_frames_.RemoveObserver(frame); | 2898 swapped_out_frames_.RemoveObserver(frame); |
2899 } | 2899 } |
2900 | 2900 |
2901 } // namespace content | 2901 } // namespace content |
OLD | NEW |