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/android/sys_utils.h" | 7 #include "base/android/sys_utils.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_context_egl.h" | 12 #include "ui/gl/gl_context_egl.h" |
| 13 #include "ui/gl/gl_context_osmesa.h" |
13 #include "ui/gl/gl_context_stub.h" | 14 #include "ui/gl/gl_context_stub.h" |
14 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Used to render into an already current context+surface, | 22 // Used to render into an already current context+surface, |
22 // that we do not have ownership of (draw callback). | 23 // that we do not have ownership of (draw callback). |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return GLContext::GetExtensions() + " " + extensions; | 69 return GLContext::GetExtensions() + " " + extensions; |
69 } | 70 } |
70 | 71 |
71 } // anonymous namespace | 72 } // anonymous namespace |
72 | 73 |
73 // static | 74 // static |
74 scoped_refptr<GLContext> GLContext::CreateGLContext( | 75 scoped_refptr<GLContext> GLContext::CreateGLContext( |
75 GLShareGroup* share_group, | 76 GLShareGroup* share_group, |
76 GLSurface* compatible_surface, | 77 GLSurface* compatible_surface, |
77 GpuPreference gpu_preference) { | 78 GpuPreference gpu_preference) { |
78 if (GetGLImplementation() == kGLImplementationMockGL) | 79 scoped_refptr<GLContext> context; |
79 return scoped_refptr<GLContext>(new GLContextStub()); | 80 switch(GetGLImplementation()) { |
| 81 case kGLImplementationMockGL: |
| 82 return scoped_refptr<GLContext>(new GLContextStub()); |
| 83 case kGLImplementationOSMesaGL: |
| 84 context = new GLContextOSMesa(share_group); |
| 85 break; |
| 86 case kGLImplementationEGLGLES2: |
| 87 if (compatible_surface->GetHandle()) |
| 88 context = new GLContextEGL(share_group); |
| 89 else |
| 90 context = new GLNonOwnedContext(share_group); |
| 91 break; |
| 92 default: |
| 93 NOTREACHED(); |
| 94 return NULL; |
| 95 } |
80 | 96 |
81 scoped_refptr<GLContext> context; | |
82 if (compatible_surface->GetHandle()) | |
83 context = new GLContextEGL(share_group); | |
84 else | |
85 context = new GLNonOwnedContext(share_group); | |
86 if (!context->Initialize(compatible_surface, gpu_preference)) | 97 if (!context->Initialize(compatible_surface, gpu_preference)) |
87 return NULL; | 98 return NULL; |
| 99 |
88 return context; | 100 return context; |
89 } | 101 } |
90 | 102 |
91 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 103 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
92 DCHECK(bytes); | 104 DCHECK(bytes); |
93 *bytes = 0; | 105 *bytes = 0; |
94 | 106 |
95 // We can't query available GPU memory from the system on Android. | 107 // We can't query available GPU memory from the system on Android. |
96 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | 108 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
97 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | 109 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
(...skipping 29 matching lines...) Expand all Loading... |
127 } else { | 139 } else { |
128 limit_bytes = physical_memory_mb / 64; | 140 limit_bytes = physical_memory_mb / 64; |
129 } | 141 } |
130 limit_bytes = limit_bytes * 1024 * 1024; | 142 limit_bytes = limit_bytes * 1024 * 1024; |
131 } | 143 } |
132 *bytes = limit_bytes; | 144 *bytes = limit_bytes; |
133 return true; | 145 return true; |
134 } | 146 } |
135 | 147 |
136 } | 148 } |
OLD | NEW |