Chromium Code Reviews| Index: content/renderer/gpu/render_widget_compositor.cc |
| diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc |
| index 7f83ee9415092d775890b5de5b2bc8e46667367a..899e4d76f05880f2e175c01c16f3ca0e55b16d64 100644 |
| --- a/content/renderer/gpu/render_widget_compositor.cc |
| +++ b/content/renderer/gpu/render_widget_compositor.cc |
| @@ -42,6 +42,7 @@ |
| #include "content/public/common/content_switches.h" |
| #include "content/renderer/input/input_handler_manager.h" |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| +#include "gpu/command_buffer/service/gpu_switches.h" |
| #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h" |
| #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
| #include "third_party/WebKit/public/platform/WebSize.h" |
| @@ -466,6 +467,9 @@ void RenderWidgetCompositor::Initialize() { |
| if (base::SysInfo::IsLowEndDevice()) |
| settings.max_staging_buffers /= 4; |
| + cc::ManagedMemoryPolicy current = settings.memory_policy_; |
| + settings.memory_policy_ = GetGpuMemoryPolicy(current); |
| + |
| scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = |
| compositor_deps_->GetCompositorImplThreadTaskRunner(); |
| scoped_refptr<base::SingleThreadTaskRunner> |
| @@ -1047,4 +1051,84 @@ void RenderWidgetCompositor::SetSurfaceIdNamespace( |
| layer_tree_host_->set_surface_id_namespace(surface_id_namespace); |
| } |
| +cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( |
| + cc::ManagedMemoryPolicy& policy) { |
| + cc::ManagedMemoryPolicy actual = policy; |
| + static size_t limit_bytes = 0; |
|
ccameron
2015/09/14 17:44:51
This local variable shouldn't be used (also should
sohanjg
2015/09/15 10:37:48
Done.
|
| + |
| + static bool client_hard_limit_bytes_overridden = |
| + base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kForceGpuMemAvailableMb); |
| + if (client_hard_limit_bytes_overridden) { |
| + base::StringToSizeT( |
| + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| + switches::kForceGpuMemAvailableMb), |
| + &limit_bytes); |
| + limit_bytes *= 1024 * 1024; |
| + actual.bytes_limit_when_visible = limit_bytes; |
| + return actual; |
| + } |
| + |
| +#if defined(OS_ANDROID) |
| + // We can't query available GPU memory from the system on Android. |
| + // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| + // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| + // 128MB java heap size). First we estimate physical memory using both. |
| + size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| + size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| + size_t physical_memory_mb = 0; |
| + if (dalvik_mb >= 256) |
| + physical_memory_mb = dalvik_mb * 4; |
| + else |
| + physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| + |
| + // Now we take a default of 1/8th of memory on high-memory devices, |
| + // and gradually scale that back for low-memory devices (to be nicer |
| + // to other apps so they don't get killed). Examples: |
| + // Nexus 4/10(2GB) 256MB (normally 128MB) |
| + // Droid Razr M(1GB) 114MB (normally 57MB) |
| + // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| + // Xoom(1GB) 100MB (normally 50MB) |
| + // Nexus S(low-end) 8MB (normally 8MB) |
| + // Note that the compositor now uses only some of this memory for |
| + // pre-painting and uses the rest only for 'emergencies'. |
| + if (limit_bytes == 0) { |
| + // NOTE: Non-low-end devices use only 50% of these limits, |
| + // except during 'emergencies' where 100% can be used. |
| + if (!base::SysInfo::IsLowEndDevice()) { |
| + if (physical_memory_mb >= 1536) |
| + limit_bytes = physical_memory_mb / 8; // >192MB |
| + else if (physical_memory_mb >= 1152) |
| + limit_bytes = physical_memory_mb / 8; // >144MB |
| + else if (physical_memory_mb >= 768) |
| + limit_bytes = physical_memory_mb / 10; // >76MB |
| + else |
| + limit_bytes = physical_memory_mb / 12; // <64MB |
| + } else { |
| + // Low-end devices have 512MB or less memory by definition |
| + // so we hard code the limit rather than relying on the heuristics |
| + // above. Low-end devices use 4444 textures so we can use a lower limit. |
| + limit_bytes = 8; |
| + } |
| + limit_bytes = limit_bytes * 1024 * 1024; |
| + // Clamp the observed value to a specific range on Android. |
| + limit_bytes = std::max(limit_bytes, static_cast<size_t>(8 * 1024 * 1024)); |
| + limit_bytes = std::min(limit_bytes, static_cast<size_t>(256 * 1024 * 1024)); |
| + } |
| + |
| +#else |
| + if (HasExtension("GL_NVX_gpu_memory_info")) { |
|
ccameron
2015/09/14 17:44:51
Oh -- don't bother with the NVX extension -- just
sohanjg
2015/09/15 10:37:48
Done.
|
| + GLint kbytes = 0; |
| + glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &kbytes); |
| + limit_bytes = 1024 * kbytes; |
| + } else { |
| + // Ignore what the system said and give all clients the same maximum |
| + // allocation on desktop platforms. |
| + limit_bytes = 512 * 1024 * 1024; |
| + } |
| +#endif |
| + actual.bytes_limit_when_visible = limit_bytes; |
|
ccameron
2015/09/14 17:44:51
Don't forget about |priority_cutoff_when_visible|
sohanjg
2015/09/15 10:37:48
Done.
|
| + return actual; |
| +} |
| + |
| } // namespace content |