| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gl/gl_context.h" | 5 #include "ui/gl/gl_context.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 context = new GLNonOwnedContext(share_group); | 88 context = new GLNonOwnedContext(share_group); |
| 89 break; | 89 break; |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (!context->Initialize(compatible_surface, gpu_preference)) | 92 if (!context->Initialize(compatible_surface, gpu_preference)) |
| 93 return nullptr; | 93 return nullptr; |
| 94 | 94 |
| 95 return context; | 95 return context; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | |
| 99 DCHECK(bytes); | |
| 100 *bytes = 0; | |
| 101 | |
| 102 // We can't query available GPU memory from the system on Android. | |
| 103 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | |
| 104 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | |
| 105 // 128MB java heap size). First we estimate physical memory using both. | |
| 106 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); | |
| 107 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
| 108 size_t physical_memory_mb = 0; | |
| 109 if (dalvik_mb >= 256) | |
| 110 physical_memory_mb = dalvik_mb * 4; | |
| 111 else | |
| 112 physical_memory_mb = std::max(dalvik_mb * 4, | |
| 113 (physical_mb * 4) / 3); | |
| 114 | |
| 115 // Now we take a default of 1/8th of memory on high-memory devices, | |
| 116 // and gradually scale that back for low-memory devices (to be nicer | |
| 117 // to other apps so they don't get killed). Examples: | |
| 118 // Nexus 4/10(2GB) 256MB (normally 128MB) | |
| 119 // Droid Razr M(1GB) 114MB (normally 57MB) | |
| 120 // Galaxy Nexus(1GB) 100MB (normally 50MB) | |
| 121 // Xoom(1GB) 100MB (normally 50MB) | |
| 122 // Nexus S(low-end) 8MB (normally 8MB) | |
| 123 // Note that the compositor now uses only some of this memory for | |
| 124 // pre-painting and uses the rest only for 'emergencies'. | |
| 125 static size_t limit_bytes = 0; | |
| 126 if (limit_bytes == 0) { | |
| 127 // NOTE: Non-low-end devices use only 50% of these limits, | |
| 128 // except during 'emergencies' where 100% can be used. | |
| 129 if (!base::SysInfo::IsLowEndDevice()) { | |
| 130 if (physical_memory_mb >= 1536) | |
| 131 limit_bytes = physical_memory_mb / 8; // >192MB | |
| 132 else if (physical_memory_mb >= 1152) | |
| 133 limit_bytes = physical_memory_mb / 8; // >144MB | |
| 134 else if (physical_memory_mb >= 768) | |
| 135 limit_bytes = physical_memory_mb / 10; // >76MB | |
| 136 else | |
| 137 limit_bytes = physical_memory_mb / 12; // <64MB | |
| 138 } else { | |
| 139 // Low-end devices have 512MB or less memory by definition | |
| 140 // so we hard code the limit rather than relying on the heuristics | |
| 141 // above. Low-end devices use 4444 textures so we can use a lower limit. | |
| 142 limit_bytes = 8; | |
| 143 } | |
| 144 limit_bytes = limit_bytes * 1024 * 1024; | |
| 145 } | |
| 146 *bytes = limit_bytes; | |
| 147 return true; | |
| 148 } | 98 } |
| 149 | |
| 150 } | |
| OLD | NEW |