OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/compositor/blimp_layer_tree_settings.h" | 5 #include "blimp/client/compositor/blimp_layer_tree_settings.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // When pinching in, only show the pinch-viewport overlay scrollbars if the | 98 // When pinching in, only show the pinch-viewport overlay scrollbars if the |
99 // page scale is at least some threshold away from the minimum. i.e. don't | 99 // page scale is at least some threshold away from the minimum. i.e. don't |
100 // show the pinch scrollbars when at minimum scale. | 100 // show the pinch scrollbars when at minimum scale. |
101 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed. | 101 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed. |
102 // settings->scrollbar_show_scale_threshold = 1.05f; | 102 // settings->scrollbar_show_scale_threshold = 1.05f; |
103 #endif | 103 #endif |
104 | 104 |
105 // Blimp always uses new cc::AnimationHost system. | 105 // Blimp always uses new cc::AnimationHost system. |
106 settings->use_compositor_animation_timelines = true; | 106 settings->use_compositor_animation_timelines = true; |
| 107 |
| 108 // Set the GpuMemoryPolicy. |
| 109 cc::ManagedMemoryPolicy memory_policy = settings->memory_policy_; |
| 110 memory_policy.bytes_limit_when_visible = 0; |
| 111 |
| 112 #if defined(OS_ANDROID) |
| 113 // We can't query available GPU memory from the system on Android. |
| 114 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| 115 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| 116 // 128MB java heap size). First we estimate physical memory using both. |
| 117 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| 118 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 119 size_t physical_memory_mb = 0; |
| 120 if (dalvik_mb >= 256) |
| 121 physical_memory_mb = dalvik_mb * 4; |
| 122 else |
| 123 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| 124 |
| 125 // Now we take a default of 1/8th of memory on high-memory devices, |
| 126 // and gradually scale that back for low-memory devices (to be nicer |
| 127 // to other apps so they don't get killed). Examples: |
| 128 // Nexus 4/10(2GB) 256MB (normally 128MB) |
| 129 // Droid Razr M(1GB) 114MB (normally 57MB) |
| 130 // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| 131 // Xoom(1GB) 100MB (normally 50MB) |
| 132 // Nexus S(low-end) 8MB (normally 8MB) |
| 133 // Note that the compositor now uses only some of this memory for |
| 134 // pre-painting and uses the rest only for 'emergencies'. |
| 135 if (memory_policy.bytes_limit_when_visible == 0) { |
| 136 // NOTE: Non-low-end devices use only 50% of these limits, |
| 137 // except during 'emergencies' where 100% can be used. |
| 138 if (!base::SysInfo::IsLowEndDevice()) { |
| 139 if (physical_memory_mb >= 1536) |
| 140 memory_policy.bytes_limit_when_visible = |
| 141 physical_memory_mb / 8; // >192MB |
| 142 else if (physical_memory_mb >= 1152) |
| 143 memory_policy.bytes_limit_when_visible = |
| 144 physical_memory_mb / 8; // >144MB |
| 145 else if (physical_memory_mb >= 768) |
| 146 memory_policy.bytes_limit_when_visible = |
| 147 physical_memory_mb / 10; // >76MB |
| 148 else |
| 149 memory_policy.bytes_limit_when_visible = |
| 150 physical_memory_mb / 12; // <64MB |
| 151 } else { |
| 152 // Low-end devices have 512MB or less memory by definition |
| 153 // so we hard code the limit rather than relying on the heuristics |
| 154 // above. Low-end devices use 4444 textures so we can use a lower limit. |
| 155 memory_policy.bytes_limit_when_visible = 8; |
| 156 } |
| 157 memory_policy.bytes_limit_when_visible = |
| 158 memory_policy.bytes_limit_when_visible * 1024 * 1024; |
| 159 // Clamp the observed value to a specific range on Android. |
| 160 memory_policy.bytes_limit_when_visible = std::max( |
| 161 memory_policy.bytes_limit_when_visible, |
| 162 static_cast<size_t>(8 * 1024 * 1024)); |
| 163 memory_policy.bytes_limit_when_visible = |
| 164 std::min(memory_policy.bytes_limit_when_visible, |
| 165 static_cast<size_t>(256 * 1024 * 1024)); |
| 166 } |
| 167 memory_policy.priority_cutoff_when_visible = |
| 168 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 169 #else |
| 170 // Ignore what the system said and give all clients the same maximum |
| 171 // allocation on desktop platforms. |
| 172 memory_policy.bytes_limit_when_visible = 512 * 1024 * 1024; |
| 173 memory_policy.priority_cutoff_when_visible = |
| 174 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 175 #endif |
107 } | 176 } |
108 | 177 |
109 } // namespace client | 178 } // namespace client |
110 } // namespace blimp | 179 } // namespace blimp |
OLD | NEW |