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 const cc::ManagedMemoryPolicy& policy) { |
| 1056 cc::ManagedMemoryPolicy actual = policy; |
| 1057 actual.bytes_limit_when_visible = 0; |
| 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 &actual.bytes_limit_when_visible); |
| 1067 actual.bytes_limit_when_visible *= 1024 * 1024; |
| 1068 return actual; |
| 1069 } |
| 1070 |
| 1071 #if defined(OS_ANDROID) |
| 1072 // We can't query available GPU memory from the system on Android. |
| 1073 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| 1074 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| 1075 // 128MB java heap size). First we estimate physical memory using both. |
| 1076 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| 1077 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 1078 size_t physical_memory_mb = 0; |
| 1079 if (dalvik_mb >= 256) |
| 1080 physical_memory_mb = dalvik_mb * 4; |
| 1081 else |
| 1082 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| 1083 |
| 1084 // Now we take a default of 1/8th of memory on high-memory devices, |
| 1085 // and gradually scale that back for low-memory devices (to be nicer |
| 1086 // to other apps so they don't get killed). Examples: |
| 1087 // Nexus 4/10(2GB) 256MB (normally 128MB) |
| 1088 // Droid Razr M(1GB) 114MB (normally 57MB) |
| 1089 // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| 1090 // Xoom(1GB) 100MB (normally 50MB) |
| 1091 // Nexus S(low-end) 8MB (normally 8MB) |
| 1092 // Note that the compositor now uses only some of this memory for |
| 1093 // pre-painting and uses the rest only for 'emergencies'. |
| 1094 if (actual.bytes_limit_when_visible == 0) { |
| 1095 // NOTE: Non-low-end devices use only 50% of these limits, |
| 1096 // except during 'emergencies' where 100% can be used. |
| 1097 if (!base::SysInfo::IsLowEndDevice()) { |
| 1098 if (physical_memory_mb >= 1536) |
| 1099 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB |
| 1100 else if (physical_memory_mb >= 1152) |
| 1101 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB |
| 1102 else if (physical_memory_mb >= 768) |
| 1103 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB |
| 1104 else |
| 1105 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB |
| 1106 } else { |
| 1107 // Low-end devices have 512MB or less memory by definition |
| 1108 // so we hard code the limit rather than relying on the heuristics |
| 1109 // above. Low-end devices use 4444 textures so we can use a lower limit. |
| 1110 actual.bytes_limit_when_visible = 8; |
| 1111 } |
| 1112 actual.bytes_limit_when_visible = |
| 1113 actual.bytes_limit_when_visible * 1024 * 1024; |
| 1114 // Clamp the observed value to a specific range on Android. |
| 1115 actual.bytes_limit_when_visible = std::max( |
| 1116 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); |
| 1117 actual.bytes_limit_when_visible = |
| 1118 std::min(actual.bytes_limit_when_visible, |
| 1119 static_cast<size_t>(256 * 1024 * 1024)); |
| 1120 } |
| 1121 actual.priority_cutoff_when_visible = |
| 1122 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 1123 #else |
| 1124 // Ignore what the system said and give all clients the same maximum |
| 1125 // allocation on desktop platforms. |
| 1126 actual.bytes_limit_when_visible = 512 * 1024 * 1024; |
| 1127 actual.priority_cutoff_when_visible = |
| 1128 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 1129 #endif |
| 1130 return actual; |
| 1131 } |
| 1132 |
1050 } // namespace content | 1133 } // namespace content |
OLD | NEW |