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