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