Chromium Code Reviews| 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 "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_context_egl.h" | 11 #include "ui/gl/gl_context_egl.h" |
| 11 #include "ui/gl/gl_context_stub.h" | 12 #include "ui/gl/gl_context_stub.h" |
| 12 #include "ui/gl/gl_implementation.h" | 13 #include "ui/gl/gl_implementation.h" |
| 13 #include "ui/gl/gl_surface.h" | 14 #include "ui/gl/gl_surface.h" |
| 14 | 15 |
| 16 | |
| 15 namespace gfx { | 17 namespace gfx { |
| 16 | 18 |
| 17 // static | 19 // static |
| 18 scoped_refptr<GLContext> GLContext::CreateGLContext( | 20 scoped_refptr<GLContext> GLContext::CreateGLContext( |
| 19 GLShareGroup* share_group, | 21 GLShareGroup* share_group, |
| 20 GLSurface* compatible_surface, | 22 GLSurface* compatible_surface, |
| 21 GpuPreference gpu_preference) { | 23 GpuPreference gpu_preference) { |
| 22 if (GetGLImplementation() == kGLImplementationMockGL) | 24 if (GetGLImplementation() == kGLImplementationMockGL) |
| 23 return scoped_refptr<GLContext>(new GLContextStub()); | 25 return scoped_refptr<GLContext>(new GLContextStub()); |
| 24 | 26 |
| 25 scoped_refptr<GLContext> context; | 27 scoped_refptr<GLContext> context; |
| 26 if (compatible_surface->GetHandle()) | 28 if (compatible_surface->GetHandle()) |
| 27 context = new GLContextEGL(share_group); | 29 context = new GLContextEGL(share_group); |
| 28 else | 30 else |
| 29 context = new GLContextStub(); | 31 context = new GLContextStub(); |
| 30 if (!context->Initialize(compatible_surface, gpu_preference)) | 32 if (!context->Initialize(compatible_surface, gpu_preference)) |
| 31 return NULL; | 33 return NULL; |
| 32 return context; | 34 return context; |
| 33 } | 35 } |
| 34 | 36 |
| 37 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | |
| 38 DCHECK(bytes); | |
| 39 *bytes = 0; | |
| 40 | |
| 41 // We can't query available GPU memory from the system on Android, | |
| 42 // but the dalvik heap size give us a good estimate of available | |
| 43 // GPU memory on a wide range of devices. | |
| 44 // | |
| 45 // The heap size tends to be about 1/4 of total ram on higher end | |
| 46 // devices, so we use 1/2 of that by default. For example both the | |
| 47 // Nexus 4/10 have 2GB of ram and 512MB Dalvik heap size. For lower | |
| 48 // end devices, 1/2 of the heap size can be too high, but this | |
| 49 // correlates well with having a small heap-growth-limit. So for | |
| 50 // devices with less ram, we factor in the growth limit. | |
| 51 // | |
| 52 // This is the result of the calculation below: | |
| 53 // Droid DNA 1080P 128MB | |
| 54 // Nexus S 56MB | |
| 55 // Galaxy Nexus 112MB | |
| 56 // Nexus 4/10 256MB | |
| 57 // Xoom 88MB | |
| 58 | |
| 59 static uint64 dalvik_limit = 0; | |
| 60 if (!dalvik_limit) { | |
| 61 uint64 heap_size = base::SysInfo::DalvikHeapSizeMB(); | |
|
jar (doing other things)
2013/02/14 01:48:41
Why are we using uint64 here? The range of the fu
epenner
2013/02/14 04:18:36
I think the uint64 crept in from the other code. H
| |
| 62 uint64 heap_growth = base::SysInfo::DalvikHeapGrowthLimitMB(); | |
| 63 uint64 limit = 0; | |
| 64 | |
| 65 if (heap_size >= 350) | |
| 66 limit = heap_size / 2; | |
| 67 else | |
| 68 limit = (heap_size + (heap_growth * 2)) / 4; | |
| 69 | |
| 70 dalvik_limit = limit * 1024 * 1024; | |
| 71 } | |
| 72 | |
| 73 *bytes = dalvik_limit; | |
|
jar (doing other things)
2013/02/14 01:48:41
I'm surprised this assignment didn't generate a co
epenner
2013/02/14 04:18:36
See above, I think size_t is uint64 on both 32/64
| |
| 74 return true; | |
| 35 } | 75 } |
| 76 | |
| 77 } | |
| OLD | NEW |