Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "cc/resources/single_release_callback.h" | 35 #include "cc/resources/single_release_callback.h" |
| 36 #include "cc/scheduler/begin_frame_source.h" | 36 #include "cc/scheduler/begin_frame_source.h" |
| 37 #include "cc/trees/latency_info_swap_promise_monitor.h" | 37 #include "cc/trees/latency_info_swap_promise_monitor.h" |
| 38 #include "cc/trees/layer_tree_host.h" | 38 #include "cc/trees/layer_tree_host.h" |
| 39 #include "components/scheduler/renderer/renderer_scheduler.h" | 39 #include "components/scheduler/renderer/renderer_scheduler.h" |
| 40 #include "content/common/content_switches_internal.h" | 40 #include "content/common/content_switches_internal.h" |
| 41 #include "content/common/gpu/client/context_provider_command_buffer.h" | 41 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 43 #include "content/renderer/input/input_handler_manager.h" | 43 #include "content/renderer/input/input_handler_manager.h" |
| 44 #include "gpu/command_buffer/client/gles2_interface.h" | 44 #include "gpu/command_buffer/client/gles2_interface.h" |
| 45 #include "gpu/command_buffer/service/gpu_switches.h" | |
| 45 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" | 46 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" |
| 46 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 47 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
| 47 #include "third_party/WebKit/public/platform/WebSize.h" | 48 #include "third_party/WebKit/public/platform/WebSize.h" |
| 48 #include "third_party/WebKit/public/web/WebKit.h" | 49 #include "third_party/WebKit/public/web/WebKit.h" |
| 49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 50 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 50 #include "third_party/WebKit/public/web/WebSelection.h" | 51 #include "third_party/WebKit/public/web/WebSelection.h" |
| 51 #include "third_party/WebKit/public/web/WebWidget.h" | 52 #include "third_party/WebKit/public/web/WebWidget.h" |
| 52 #include "ui/gl/gl_switches.h" | 53 #include "ui/gl/gl_switches.h" |
| 53 #include "ui/native_theme/native_theme_switches.h" | 54 #include "ui/native_theme/native_theme_switches.h" |
| 54 | 55 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. | 460 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. |
| 460 // See crbug.com/471411. | 461 // See crbug.com/471411. |
| 461 settings.use_external_begin_frame_source = false; | 462 settings.use_external_begin_frame_source = false; |
| 462 } | 463 } |
| 463 | 464 |
| 464 settings.max_staging_buffers = 32; | 465 settings.max_staging_buffers = 32; |
| 465 // Use 1/4th of staging buffers on low-end devices. | 466 // Use 1/4th of staging buffers on low-end devices. |
| 466 if (base::SysInfo::IsLowEndDevice()) | 467 if (base::SysInfo::IsLowEndDevice()) |
| 467 settings.max_staging_buffers /= 4; | 468 settings.max_staging_buffers /= 4; |
| 468 | 469 |
| 470 cc::ManagedMemoryPolicy current = settings.memory_policy_; | |
| 471 settings.memory_policy_ = GetGpuMemoryPolicy(current); | |
| 472 | |
| 469 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = | 473 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = |
| 470 compositor_deps_->GetCompositorImplThreadTaskRunner(); | 474 compositor_deps_->GetCompositorImplThreadTaskRunner(); |
| 471 scoped_refptr<base::SingleThreadTaskRunner> | 475 scoped_refptr<base::SingleThreadTaskRunner> |
| 472 main_thread_compositor_task_runner = | 476 main_thread_compositor_task_runner = |
| 473 compositor_deps_->GetCompositorMainThreadTaskRunner(); | 477 compositor_deps_->GetCompositorMainThreadTaskRunner(); |
| 474 cc::SharedBitmapManager* shared_bitmap_manager = | 478 cc::SharedBitmapManager* shared_bitmap_manager = |
| 475 compositor_deps_->GetSharedBitmapManager(); | 479 compositor_deps_->GetSharedBitmapManager(); |
| 476 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 480 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 477 compositor_deps_->GetGpuMemoryBufferManager(); | 481 compositor_deps_->GetGpuMemoryBufferManager(); |
| 478 cc::TaskGraphRunner* task_graph_runner = | 482 cc::TaskGraphRunner* task_graph_runner = |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 if (!provider) | 1044 if (!provider) |
| 1041 return; | 1045 return; |
| 1042 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); | 1046 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); |
| 1043 } | 1047 } |
| 1044 | 1048 |
| 1045 void RenderWidgetCompositor::SetSurfaceIdNamespace( | 1049 void RenderWidgetCompositor::SetSurfaceIdNamespace( |
| 1046 uint32_t surface_id_namespace) { | 1050 uint32_t surface_id_namespace) { |
| 1047 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); | 1051 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); |
| 1048 } | 1052 } |
| 1049 | 1053 |
| 1054 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( | |
| 1055 cc::ManagedMemoryPolicy& policy) { | |
| 1056 cc::ManagedMemoryPolicy actual = policy; | |
| 1057 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.
| |
| 1058 | |
| 1059 static bool client_hard_limit_bytes_overridden = | |
| 1060 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1061 switches::kForceGpuMemAvailableMb); | |
| 1062 if (client_hard_limit_bytes_overridden) { | |
| 1063 base::StringToSizeT( | |
| 1064 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 1065 switches::kForceGpuMemAvailableMb), | |
| 1066 &limit_bytes); | |
| 1067 limit_bytes *= 1024 * 1024; | |
| 1068 actual.bytes_limit_when_visible = limit_bytes; | |
| 1069 return actual; | |
| 1070 } | |
| 1071 | |
| 1072 #if defined(OS_ANDROID) | |
| 1073 // We can't query available GPU memory from the system on Android. | |
| 1074 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | |
| 1075 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | |
| 1076 // 128MB java heap size). First we estimate physical memory using both. | |
| 1077 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); | |
| 1078 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
| 1079 size_t physical_memory_mb = 0; | |
| 1080 if (dalvik_mb >= 256) | |
| 1081 physical_memory_mb = dalvik_mb * 4; | |
| 1082 else | |
| 1083 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); | |
| 1084 | |
| 1085 // Now we take a default of 1/8th of memory on high-memory devices, | |
| 1086 // and gradually scale that back for low-memory devices (to be nicer | |
| 1087 // to other apps so they don't get killed). Examples: | |
| 1088 // Nexus 4/10(2GB) 256MB (normally 128MB) | |
| 1089 // Droid Razr M(1GB) 114MB (normally 57MB) | |
| 1090 // Galaxy Nexus(1GB) 100MB (normally 50MB) | |
| 1091 // Xoom(1GB) 100MB (normally 50MB) | |
| 1092 // Nexus S(low-end) 8MB (normally 8MB) | |
| 1093 // Note that the compositor now uses only some of this memory for | |
| 1094 // pre-painting and uses the rest only for 'emergencies'. | |
| 1095 if (limit_bytes == 0) { | |
| 1096 // NOTE: Non-low-end devices use only 50% of these limits, | |
| 1097 // except during 'emergencies' where 100% can be used. | |
| 1098 if (!base::SysInfo::IsLowEndDevice()) { | |
| 1099 if (physical_memory_mb >= 1536) | |
| 1100 limit_bytes = physical_memory_mb / 8; // >192MB | |
| 1101 else if (physical_memory_mb >= 1152) | |
| 1102 limit_bytes = physical_memory_mb / 8; // >144MB | |
| 1103 else if (physical_memory_mb >= 768) | |
| 1104 limit_bytes = physical_memory_mb / 10; // >76MB | |
| 1105 else | |
| 1106 limit_bytes = physical_memory_mb / 12; // <64MB | |
| 1107 } else { | |
| 1108 // Low-end devices have 512MB or less memory by definition | |
| 1109 // so we hard code the limit rather than relying on the heuristics | |
| 1110 // above. Low-end devices use 4444 textures so we can use a lower limit. | |
| 1111 limit_bytes = 8; | |
| 1112 } | |
| 1113 limit_bytes = limit_bytes * 1024 * 1024; | |
| 1114 // Clamp the observed value to a specific range on Android. | |
| 1115 limit_bytes = std::max(limit_bytes, static_cast<size_t>(8 * 1024 * 1024)); | |
| 1116 limit_bytes = std::min(limit_bytes, static_cast<size_t>(256 * 1024 * 1024)); | |
| 1117 } | |
| 1118 | |
| 1119 #else | |
| 1120 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.
| |
| 1121 GLint kbytes = 0; | |
| 1122 glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &kbytes); | |
| 1123 limit_bytes = 1024 * kbytes; | |
| 1124 } else { | |
| 1125 // Ignore what the system said and give all clients the same maximum | |
| 1126 // allocation on desktop platforms. | |
| 1127 limit_bytes = 512 * 1024 * 1024; | |
| 1128 } | |
| 1129 #endif | |
| 1130 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.
| |
| 1131 return actual; | |
| 1132 } | |
| 1133 | |
| 1050 } // namespace content | 1134 } // namespace content |
| OLD | NEW |