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 static bool client_hard_limit_bytes_overridden = | |
1024 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1025 switches::kForceGpuMemAvailableMb); | |
1026 if (client_hard_limit_bytes_overridden) { | |
1027 base::StringToSizeT( | |
dcheng
2015/10/02 18:06:01
It seems like you should at least check the return
sohanjg
2015/10/05 06:08:43
Done.
| |
1028 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
1029 switches::kForceGpuMemAvailableMb), | |
1030 &actual.bytes_limit_when_visible); | |
1031 actual.bytes_limit_when_visible *= 1024 * 1024; | |
1032 return actual; | |
1033 } | |
1034 | |
1035 #if defined(OS_ANDROID) | |
1036 // We can't query available GPU memory from the system on Android. | |
1037 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | |
1038 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | |
1039 // 128MB java heap size). First we estimate physical memory using both. | |
1040 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); | |
1041 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
1042 size_t physical_memory_mb = 0; | |
1043 if (dalvik_mb >= 256) | |
1044 physical_memory_mb = dalvik_mb * 4; | |
1045 else | |
1046 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); | |
1047 | |
1048 // Now we take a default of 1/8th of memory on high-memory devices, | |
1049 // and gradually scale that back for low-memory devices (to be nicer | |
1050 // to other apps so they don't get killed). Examples: | |
1051 // Nexus 4/10(2GB) 256MB (normally 128MB) | |
1052 // Droid Razr M(1GB) 114MB (normally 57MB) | |
1053 // Galaxy Nexus(1GB) 100MB (normally 50MB) | |
1054 // Xoom(1GB) 100MB (normally 50MB) | |
1055 // Nexus S(low-end) 8MB (normally 8MB) | |
1056 // Note that the compositor now uses only some of this memory for | |
1057 // pre-painting and uses the rest only for 'emergencies'. | |
1058 if (actual.bytes_limit_when_visible == 0) { | |
1059 // NOTE: Non-low-end devices use only 50% of these limits, | |
1060 // except during 'emergencies' where 100% can be used. | |
1061 if (!base::SysInfo::IsLowEndDevice()) { | |
1062 if (physical_memory_mb >= 1536) | |
1063 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB | |
1064 else if (physical_memory_mb >= 1152) | |
1065 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB | |
1066 else if (physical_memory_mb >= 768) | |
1067 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB | |
1068 else | |
1069 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB | |
1070 } else { | |
1071 // Low-end devices have 512MB or less memory by definition | |
1072 // so we hard code the limit rather than relying on the heuristics | |
1073 // above. Low-end devices use 4444 textures so we can use a lower limit. | |
1074 actual.bytes_limit_when_visible = 8; | |
1075 } | |
1076 actual.bytes_limit_when_visible = | |
1077 actual.bytes_limit_when_visible * 1024 * 1024; | |
1078 // Clamp the observed value to a specific range on Android. | |
1079 actual.bytes_limit_when_visible = std::max( | |
1080 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); | |
dcheng
2015/10/02 18:06:01
8U * 1024 * 1024 to force signed -> unsigned promo
sohanjg
2015/10/05 06:08:43
Done.
sohanjg
2015/10/05 06:56:44
seems, android_arm64_dbg_recipe still needs the ca
| |
1081 actual.bytes_limit_when_visible = | |
1082 std::min(actual.bytes_limit_when_visible, | |
dcheng
2015/10/02 18:06:01
Ditto.
sohanjg
2015/10/05 06:08:43
Done.
sohanjg
2015/10/05 06:56:44
seems, android_arm64_dbg_recipe still needs the ca
| |
1083 static_cast<size_t>(256 * 1024 * 1024)); | |
1084 } | |
1085 actual.priority_cutoff_when_visible = | |
1086 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; | |
1087 #else | |
1088 // Ignore what the system said and give all clients the same maximum | |
1089 // allocation on desktop platforms. | |
1090 actual.bytes_limit_when_visible = 512 * 1024 * 1024; | |
1091 actual.priority_cutoff_when_visible = | |
1092 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | |
1093 #endif | |
1094 return actual; | |
1095 } | |
1096 | |
1014 } // namespace content | 1097 } // namespace content |
OLD | NEW |