Index: content/renderer/render_widget.cc |
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
index 53b8839462b97f2a6fd47a3cf42e0887bef3b4d8..36716ec87b033ccb7a52503e26d32438e14b1ee9 100644 |
--- a/content/renderer/render_widget.cc |
+++ b/content/renderer/render_widget.cc |
@@ -62,6 +62,7 @@ |
#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" |
#if defined(OS_ANDROID) |
+#include "base/android/sys_utils.h" |
#include "content/renderer/android/synchronous_compositor_factory.h" |
#endif |
@@ -643,10 +644,33 @@ bool RenderWidget::ForceCompositingModeEnabled() { |
scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
+ // If we raster too fast we become upload bound, and pending |
+ // uploads consume memory. For maximum upload throughput, we would |
+ // want to allow for upload_throughput * pipeline_time of pending |
+ // uploads, after which we are just wasting memory. Since we don't |
+ // know our upload throughput yet, this just caps our memory usage. |
#if defined(OS_ANDROID) |
- if (SynchronousCompositorFactory* factory = |
- SynchronousCompositorFactory::GetInstance()) { |
- return factory->CreateOutputSurface(routing_id()); |
+ size_t divider = 1; |
+ if (base::android::SysUtils::IsLowEndDevice()) |
+ divider = 3; |
+ |
+ // For reference Nexus10 can upload 1MB in about 2.5ms. |
+ const size_t kMaxBytesUploadedPerMs = (2 * 1024 * 1024) / (5 * divider); |
+#else |
+ // For reference Chromebook Pixel can upload 1MB in about 0.5ms. |
+ const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; |
+#endif |
+ |
+ // Assuming a two frame deep pipeline. |
+ const size_t kMsPerFrame = 16; |
+ const size_t max_transfer_buffer_usage_bytes = |
+ 2 * kMsPerFrame * kMaxBytesUploadedPerMs; |
+ |
+#if defined(OS_ANDROID) |
+ if (SynchronousCompositorFactory* factory = |
+ SynchronousCompositorFactory::GetInstance()) { |
+ return factory->CreateOutputSurface(routing_id(), |
+ max_transfer_buffer_usage_bytes); |
} |
#endif |
@@ -670,10 +694,11 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
attributes.stencil = false; |
if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) |
attributes.stencil = true; |
+ |
scoped_refptr<ContextProviderCommandBuffer> context_provider; |
if (!fallback) { |
context_provider = ContextProviderCommandBuffer::Create( |
- CreateGraphicsContext3D(attributes)); |
+ CreateGraphicsContext3D(attributes, max_transfer_buffer_usage_bytes)); |
} |
if (!context_provider.get()) { |
@@ -688,7 +713,8 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
output_surface_id, |
NULL, |
software_device.Pass(), |
- true)); |
+ true, |
+ max_transfer_buffer_usage_bytes)); |
} |
if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) && |
@@ -699,7 +725,8 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
routing_id(), |
output_surface_id, |
context_provider, |
- scoped_ptr<cc::SoftwareOutputDevice>())); |
+ scoped_ptr<cc::SoftwareOutputDevice>(), |
+ max_transfer_buffer_usage_bytes)); |
} |
if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
DCHECK(is_threaded_compositing_enabled_); |
@@ -708,7 +735,8 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
routing_id(), |
output_surface_id, |
context_provider, |
- scoped_ptr<cc::SoftwareOutputDevice>())); |
+ scoped_ptr<cc::SoftwareOutputDevice>(), |
+ max_transfer_buffer_usage_bytes)); |
} |
bool use_swap_compositor_frame_message = false; |
return scoped_ptr<cc::OutputSurface>( |
@@ -717,7 +745,8 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
output_surface_id, |
context_provider, |
scoped_ptr<cc::SoftwareOutputDevice>(), |
- use_swap_compositor_frame_message)); |
+ use_swap_compositor_frame_message, |
+ max_transfer_buffer_usage_bytes)); |
} |
void RenderWidget::OnViewContextSwapBuffersAborted() { |
@@ -2526,7 +2555,8 @@ bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
RenderWidget::CreateGraphicsContext3D( |
- const WebKit::WebGraphicsContext3D::Attributes& attributes) { |
+ const WebKit::WebGraphicsContext3D::Attributes& attributes, |
+ size_t max_bytes_pending_upload) { |
if (!webwidget_) |
return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
if (CommandLine::ForCurrentProcess()->HasSwitch( |
@@ -2539,10 +2569,19 @@ RenderWidget::CreateGraphicsContext3D( |
RenderThreadImpl::current(), |
weak_ptr_factory_.GetWeakPtr())); |
- if (!context->InitializeWithDefaultBufferSizes( |
+ // We keep the MappedMemoryReclaimLimit the same as the upload limit |
+ // to avoid unnecessarily stalling the compositor thread. |
+ const size_t kMappedMemoryReclaimLimit = max_bytes_pending_upload; |
+ |
+ if (!context->Initialize( |
attributes, |
false /* bind generates resources */, |
- CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
+ CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, |
+ kDefaultCommandBufferSize, |
+ kDefaultStartTransferBufferSize, |
+ kDefaultMinTransferBufferSize, |
+ kDefaultMaxTransferBufferSize, |
+ kMappedMemoryReclaimLimit)) |
return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
return context.Pass(); |
} |