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 default: |
| 87 if (compatible_surface->GetHandle()) |
| 88 context = new GLContextEGL(share_group); |
| 89 else |
| 90 context = new GLNonOwnedContext(share_group); |
| 91 break; |
| 92 } |
80 | 93 |
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)) | 94 if (!context->Initialize(compatible_surface, gpu_preference)) |
87 return NULL; | 95 return NULL; |
| 96 |
88 return context; | 97 return context; |
89 } | 98 } |
90 | 99 |
91 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 100 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
92 DCHECK(bytes); | 101 DCHECK(bytes); |
93 *bytes = 0; | 102 *bytes = 0; |
94 | 103 |
95 // We can't query available GPU memory from the system on Android. | 104 // We can't query available GPU memory from the system on Android. |
96 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | 105 // 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 | 106 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // increased the limit to 12 (8MB, or 12MB in emergencies). | 145 // increased the limit to 12 (8MB, or 12MB in emergencies). |
137 limit_bytes = 12; | 146 limit_bytes = 12; |
138 } | 147 } |
139 limit_bytes = limit_bytes * 1024 * 1024; | 148 limit_bytes = limit_bytes * 1024 * 1024; |
140 } | 149 } |
141 *bytes = limit_bytes; | 150 *bytes = limit_bytes; |
142 return true; | 151 return true; |
143 } | 152 } |
144 | 153 |
145 } | 154 } |
OLD | NEW |