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 23 matching lines...) Expand all Loading... |
34 #include "cc/resources/single_release_callback.h" | 34 #include "cc/resources/single_release_callback.h" |
35 #include "cc/scheduler/begin_frame_source.h" | 35 #include "cc/scheduler/begin_frame_source.h" |
36 #include "cc/trees/latency_info_swap_promise_monitor.h" | 36 #include "cc/trees/latency_info_swap_promise_monitor.h" |
37 #include "cc/trees/layer_tree_host.h" | 37 #include "cc/trees/layer_tree_host.h" |
38 #include "components/scheduler/renderer/renderer_scheduler.h" | 38 #include "components/scheduler/renderer/renderer_scheduler.h" |
39 #include "content/common/content_switches_internal.h" | 39 #include "content/common/content_switches_internal.h" |
40 #include "content/common/gpu/client/context_provider_command_buffer.h" | 40 #include "content/common/gpu/client/context_provider_command_buffer.h" |
41 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
42 #include "content/renderer/input/input_handler_manager.h" | 42 #include "content/renderer/input/input_handler_manager.h" |
43 #include "gpu/command_buffer/client/gles2_interface.h" | 43 #include "gpu/command_buffer/client/gles2_interface.h" |
| 44 #include "gpu/command_buffer/service/gpu_switches.h" |
44 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 45 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
45 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 46 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
46 #include "third_party/WebKit/public/platform/WebSize.h" | 47 #include "third_party/WebKit/public/platform/WebSize.h" |
47 #include "third_party/WebKit/public/web/WebKit.h" | 48 #include "third_party/WebKit/public/web/WebKit.h" |
48 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
49 #include "third_party/WebKit/public/web/WebSelection.h" | 50 #include "third_party/WebKit/public/web/WebSelection.h" |
50 #include "third_party/WebKit/public/web/WebWidget.h" | 51 #include "third_party/WebKit/public/web/WebWidget.h" |
51 #include "ui/gl/gl_switches.h" | 52 #include "ui/gl/gl_switches.h" |
52 #include "ui/native_theme/native_theme_switches.h" | 53 #include "ui/native_theme/native_theme_switches.h" |
53 | 54 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. | 452 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. |
452 // See crbug.com/471411. | 453 // See crbug.com/471411. |
453 settings.use_external_begin_frame_source = false; | 454 settings.use_external_begin_frame_source = false; |
454 } | 455 } |
455 | 456 |
456 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB | 457 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB |
457 // Use 1/4th of staging buffers on low-end devices. | 458 // Use 1/4th of staging buffers on low-end devices. |
458 if (base::SysInfo::IsLowEndDevice()) | 459 if (base::SysInfo::IsLowEndDevice()) |
459 settings.max_staging_buffer_usage_in_bytes /= 4; | 460 settings.max_staging_buffer_usage_in_bytes /= 4; |
460 | 461 |
| 462 cc::ManagedMemoryPolicy current = settings.memory_policy_; |
| 463 settings.memory_policy_ = GetGpuMemoryPolicy(current); |
| 464 |
461 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = | 465 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = |
462 compositor_deps_->GetCompositorImplThreadTaskRunner(); | 466 compositor_deps_->GetCompositorImplThreadTaskRunner(); |
463 scoped_refptr<base::SingleThreadTaskRunner> | 467 scoped_refptr<base::SingleThreadTaskRunner> |
464 main_thread_compositor_task_runner = | 468 main_thread_compositor_task_runner = |
465 compositor_deps_->GetCompositorMainThreadTaskRunner(); | 469 compositor_deps_->GetCompositorMainThreadTaskRunner(); |
466 cc::SharedBitmapManager* shared_bitmap_manager = | 470 cc::SharedBitmapManager* shared_bitmap_manager = |
467 compositor_deps_->GetSharedBitmapManager(); | 471 compositor_deps_->GetSharedBitmapManager(); |
468 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 472 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
469 compositor_deps_->GetGpuMemoryBufferManager(); | 473 compositor_deps_->GetGpuMemoryBufferManager(); |
470 cc::TaskGraphRunner* task_graph_runner = | 474 cc::TaskGraphRunner* task_graph_runner = |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 widget_->webwidget()->recordFrameTimingEvent( | 1008 widget_->webwidget()->recordFrameTimingEvent( |
1005 blink::WebWidget::RenderEvent, frameId, webEvents); | 1009 blink::WebWidget::RenderEvent, frameId, webEvents); |
1006 } | 1010 } |
1007 } | 1011 } |
1008 | 1012 |
1009 void RenderWidgetCompositor::SetSurfaceIdNamespace( | 1013 void RenderWidgetCompositor::SetSurfaceIdNamespace( |
1010 uint32_t surface_id_namespace) { | 1014 uint32_t surface_id_namespace) { |
1011 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); | 1015 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); |
1012 } | 1016 } |
1013 | 1017 |
| 1018 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( |
| 1019 const cc::ManagedMemoryPolicy& policy) { |
| 1020 cc::ManagedMemoryPolicy actual = policy; |
| 1021 actual.bytes_limit_when_visible = 0; |
| 1022 |
| 1023 // If the value was overridden on the command line, use the specified value. |
| 1024 static bool client_hard_limit_bytes_overridden = |
| 1025 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1026 switches::kForceGpuMemAvailableMb); |
| 1027 if (client_hard_limit_bytes_overridden) { |
| 1028 if (base::StringToSizeT( |
| 1029 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 1030 switches::kForceGpuMemAvailableMb), |
| 1031 &actual.bytes_limit_when_visible)) |
| 1032 actual.bytes_limit_when_visible *= 1024 * 1024; |
| 1033 return actual; |
| 1034 } |
| 1035 |
| 1036 #if defined(OS_ANDROID) |
| 1037 // We can't query available GPU memory from the system on Android. |
| 1038 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| 1039 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| 1040 // 128MB java heap size). First we estimate physical memory using both. |
| 1041 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| 1042 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 1043 size_t physical_memory_mb = 0; |
| 1044 if (dalvik_mb >= 256) |
| 1045 physical_memory_mb = dalvik_mb * 4; |
| 1046 else |
| 1047 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| 1048 |
| 1049 // Now we take a default of 1/8th of memory on high-memory devices, |
| 1050 // and gradually scale that back for low-memory devices (to be nicer |
| 1051 // to other apps so they don't get killed). Examples: |
| 1052 // Nexus 4/10(2GB) 256MB (normally 128MB) |
| 1053 // Droid Razr M(1GB) 114MB (normally 57MB) |
| 1054 // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| 1055 // Xoom(1GB) 100MB (normally 50MB) |
| 1056 // Nexus S(low-end) 8MB (normally 8MB) |
| 1057 // Note that the compositor now uses only some of this memory for |
| 1058 // pre-painting and uses the rest only for 'emergencies'. |
| 1059 if (actual.bytes_limit_when_visible == 0) { |
| 1060 // NOTE: Non-low-end devices use only 50% of these limits, |
| 1061 // except during 'emergencies' where 100% can be used. |
| 1062 if (!base::SysInfo::IsLowEndDevice()) { |
| 1063 if (physical_memory_mb >= 1536) |
| 1064 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB |
| 1065 else if (physical_memory_mb >= 1152) |
| 1066 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB |
| 1067 else if (physical_memory_mb >= 768) |
| 1068 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB |
| 1069 else |
| 1070 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB |
| 1071 } else { |
| 1072 // Low-end devices have 512MB or less memory by definition |
| 1073 // so we hard code the limit rather than relying on the heuristics |
| 1074 // above. Low-end devices use 4444 textures so we can use a lower limit. |
| 1075 actual.bytes_limit_when_visible = 8; |
| 1076 } |
| 1077 actual.bytes_limit_when_visible = |
| 1078 actual.bytes_limit_when_visible * 1024 * 1024; |
| 1079 // Clamp the observed value to a specific range on Android. |
| 1080 actual.bytes_limit_when_visible = std::max( |
| 1081 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); |
| 1082 actual.bytes_limit_when_visible = |
| 1083 std::min(actual.bytes_limit_when_visible, |
| 1084 static_cast<size_t>(256 * 1024 * 1024)); |
| 1085 } |
| 1086 actual.priority_cutoff_when_visible = |
| 1087 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 1088 #else |
| 1089 // Ignore what the system said and give all clients the same maximum |
| 1090 // allocation on desktop platforms. |
| 1091 actual.bytes_limit_when_visible = 512 * 1024 * 1024; |
| 1092 actual.priority_cutoff_when_visible = |
| 1093 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 1094 #endif |
| 1095 return actual; |
| 1096 } |
| 1097 |
1014 } // namespace content | 1098 } // namespace content |
OLD | NEW |