Index: content/renderer/render_widget.cc |
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
index 0f3d037e01178c8a8f87537bb631774f97193678..5f392367254c2b31f9deeb0e1b683ba8899a2fdd 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 |
@@ -647,17 +648,14 @@ bool RenderWidget::ForceCompositingModeEnabled() { |
} |
scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
#if defined(OS_ANDROID) |
- if (SynchronousCompositorFactory* factory = |
- SynchronousCompositorFactory::GetInstance()) { |
+ if (SynchronousCompositorFactory* factory = |
+ SynchronousCompositorFactory::GetInstance()) { |
return factory->CreateOutputSurface(routing_id()); |
} |
#endif |
- uint32 output_surface_id = next_output_surface_id_++; |
- |
// Explicitly disable antialiasing for the compositor. As of the time of |
// this writing, the only platform that supported antialiasing for the |
// compositor was Mac OS X, because the on-screen OpenGL context creation |
@@ -674,14 +672,40 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
attributes.noAutomaticFlushes = true; |
attributes.depth = false; |
attributes.stencil = false; |
+ |
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) |
attributes.stencil = true; |
+ |
scoped_refptr<ContextProviderCommandBuffer> context_provider; |
if (!fallback) { |
+ // If we raster too fast we become upload bound, and pending |
danakj
2013/08/29 20:10:28
Any reason to do this here instead of inside Creat
kaanb
2013/08/30 01:11:35
Done.
|
+ // 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) |
+ 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. |
piman
2013/08/29 21:58:19
This affects more than the Pixel. It affects the c
kaanb
2013/08/30 01:11:35
Please note that this constant also eventually mak
|
+ const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; |
+#endif |
+ |
+ // Assuming a two frame deep pipeline. |
piman
2013/08/29 21:58:19
Between what and what?
kaanb
2013/08/30 01:11:35
Done.
|
+ const size_t kMsPerFrame = 16; |
piman
2013/08/29 21:58:19
What is this number?
kaanb
2013/08/30 01:11:35
Done.
|
+ const size_t max_transfer_buffer_usage_bytes = |
danakj
2013/08/29 20:10:28
nit: no const, or kMaxTransferBufferUsageBytes.
kaanb
2013/08/30 01:11:35
Done.
|
+ 2 * kMsPerFrame * kMaxBytesUploadedPerMs; |
+ |
context_provider = ContextProviderCommandBuffer::Create( |
- CreateGraphicsContext3D(attributes)); |
+ CreateGraphicsContext3D(attributes, max_transfer_buffer_usage_bytes)); |
} |
+ uint32 output_surface_id = next_output_surface_id_++; |
if (!context_provider.get()) { |
if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) |
return scoped_ptr<cc::OutputSurface>(); |
@@ -2510,7 +2534,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( |
@@ -2523,10 +2548,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(); |
} |