Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: content/renderer/gpu/render_widget_compositor.cc

Issue 1324413003: Move gpu memory calculations to Compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/gpu/render_widget_compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. 459 // TODO(simonhong): Apply BeginFrame scheduling for OOPIF.
460 // See crbug.com/471411. 460 // See crbug.com/471411.
461 settings.use_external_begin_frame_source = false; 461 settings.use_external_begin_frame_source = false;
462 } 462 }
463 463
464 settings.max_staging_buffers = 32; 464 settings.max_staging_buffers = 32;
465 // Use 1/4th of staging buffers on low-end devices. 465 // Use 1/4th of staging buffers on low-end devices.
466 if (base::SysInfo::IsLowEndDevice()) 466 if (base::SysInfo::IsLowEndDevice())
467 settings.max_staging_buffers /= 4; 467 settings.max_staging_buffers /= 4;
468 468
469 cc::ManagedMemoryPolicy current = settings.memory_policy_;
470 settings.memory_policy_ = GetGpuMemoryPolicy(current);
471
469 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = 472 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner =
470 compositor_deps_->GetCompositorImplThreadTaskRunner(); 473 compositor_deps_->GetCompositorImplThreadTaskRunner();
471 scoped_refptr<base::SingleThreadTaskRunner> 474 scoped_refptr<base::SingleThreadTaskRunner>
472 main_thread_compositor_task_runner = 475 main_thread_compositor_task_runner =
473 compositor_deps_->GetCompositorMainThreadTaskRunner(); 476 compositor_deps_->GetCompositorMainThreadTaskRunner();
474 cc::SharedBitmapManager* shared_bitmap_manager = 477 cc::SharedBitmapManager* shared_bitmap_manager =
475 compositor_deps_->GetSharedBitmapManager(); 478 compositor_deps_->GetSharedBitmapManager();
476 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = 479 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager =
477 compositor_deps_->GetGpuMemoryBufferManager(); 480 compositor_deps_->GetGpuMemoryBufferManager();
478 cc::TaskGraphRunner* task_graph_runner = 481 cc::TaskGraphRunner* task_graph_runner =
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 if (!provider) 1043 if (!provider)
1041 return; 1044 return;
1042 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); 1045 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM();
1043 } 1046 }
1044 1047
1045 void RenderWidgetCompositor::SetSurfaceIdNamespace( 1048 void RenderWidgetCompositor::SetSurfaceIdNamespace(
1046 uint32_t surface_id_namespace) { 1049 uint32_t surface_id_namespace) {
1047 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); 1050 layer_tree_host_->set_surface_id_namespace(surface_id_namespace);
1048 } 1051 }
1049 1052
1053 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy(
1054 cc::ManagedMemoryPolicy& policy) {
1055 cc::ManagedMemoryPolicy actual = policy;
ccameron 2015/09/11 18:22:58 This needs an #if android around it.
sohanjg 2015/09/14 14:32:39 Done.
1056
1057 // We can't query available GPU memory from the system on Android.
1058 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports
1059 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports
1060 // 128MB java heap size). First we estimate physical memory using both.
1061 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
1062 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
1063 size_t physical_memory_mb = 0;
1064 if (dalvik_mb >= 256)
1065 physical_memory_mb = dalvik_mb * 4;
1066 else
1067 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3);
1068
1069 // Now we take a default of 1/8th of memory on high-memory devices,
1070 // and gradually scale that back for low-memory devices (to be nicer
1071 // to other apps so they don't get killed). Examples:
1072 // Nexus 4/10(2GB) 256MB (normally 128MB)
1073 // Droid Razr M(1GB) 114MB (normally 57MB)
1074 // Galaxy Nexus(1GB) 100MB (normally 50MB)
1075 // Xoom(1GB) 100MB (normally 50MB)
1076 // Nexus S(low-end) 8MB (normally 8MB)
1077 // Note that the compositor now uses only some of this memory for
1078 // pre-painting and uses the rest only for 'emergencies'.
1079 static size_t limit_bytes = 0;
1080 if (limit_bytes == 0) {
1081 // NOTE: Non-low-end devices use only 50% of these limits,
1082 // except during 'emergencies' where 100% can be used.
1083 if (!base::SysInfo::IsLowEndDevice()) {
1084 if (physical_memory_mb >= 1536)
1085 limit_bytes = physical_memory_mb / 8; // >192MB
1086 else if (physical_memory_mb >= 1152)
1087 limit_bytes = physical_memory_mb / 8; // >144MB
1088 else if (physical_memory_mb >= 768)
1089 limit_bytes = physical_memory_mb / 10; // >76MB
1090 else
1091 limit_bytes = physical_memory_mb / 12; // <64MB
1092 } else {
1093 // Low-end devices have 512MB or less memory by definition
1094 // so we hard code the limit rather than relying on the heuristics
1095 // above. Low-end devices use 4444 textures so we can use a lower limit.
1096 limit_bytes = 8;
1097 }
1098 limit_bytes = limit_bytes * 1024 * 1024;
1099 }
1100 actual.bytes_limit_when_visible = limit_bytes;
1101 return actual;
1102 }
1103
1050 } // namespace content 1104 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/render_widget_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698