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_gl_api_implementation.h" | 5 #include "ui/gl/gl_gl_api_implementation.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
13 #include "ui/gl/gl_implementation.h" | 13 #include "ui/gl/gl_implementation.h" |
14 #include "ui/gl/gl_state_restorer.h" | 14 #include "ui/gl/gl_state_restorer.h" |
15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
16 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
| 17 #include "ui/gl/gl_version_info.h" |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 | 20 |
20 // The GL Api being used. This could be g_real_gl or gl_trace_gl | 21 // The GL Api being used. This could be g_real_gl or gl_trace_gl |
21 static GLApi* g_gl; | 22 static GLApi* g_gl; |
22 // A GL Api that calls directly into the driver. | 23 // A GL Api that calls directly into the driver. |
23 static RealGLApi* g_real_gl; | 24 static RealGLApi* g_real_gl; |
24 // A GL Api that calls TRACE and then calls another GL api. | 25 // A GL Api that calls TRACE and then calls another GL api. |
25 static TraceGLApi* g_trace_gl; | 26 static TraceGLApi* g_trace_gl; |
| 27 // GL version used when initializing dynamic bindings. |
| 28 static GLVersionInfo* g_version_info = NULL; |
26 | 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 static inline GLenum GetInternalFormat(GLenum internal_format) { | 32 static inline GLenum GetInternalFormat(GLenum internal_format) { |
30 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 33 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
31 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) | 34 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
32 return GL_RGBA8; | 35 return GL_RGBA8; |
33 } | 36 } |
34 return internal_format; | 37 return internal_format; |
35 } | 38 } |
36 | 39 |
37 // TODO(epenner): Could the above function be merged into this and removed? | 40 // TODO(epenner): Could the above function be merged into this and removed? |
38 static inline GLenum GetTexInternalFormat(GLenum internal_format, | 41 static inline GLenum GetTexInternalFormat(GLenum internal_format, |
39 GLenum format, | 42 GLenum format, |
40 GLenum type) { | 43 GLenum type) { |
41 GLenum gl_internal_format = GetInternalFormat(internal_format); | 44 GLenum gl_internal_format = GetInternalFormat(internal_format); |
42 | 45 |
43 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) | 46 // g_version_info must be initialized when this function is bound. |
| 47 DCHECK(gfx::g_version_info); |
| 48 if (gfx::g_version_info->is_es) |
44 return gl_internal_format; | 49 return gl_internal_format; |
45 | 50 |
46 if (type == GL_FLOAT) { | 51 if (type == GL_FLOAT) { |
47 switch (format) { | 52 switch (format) { |
48 case GL_RGBA: | 53 case GL_RGBA: |
49 gl_internal_format = GL_RGBA32F_ARB; | 54 gl_internal_format = GL_RGBA32F_ARB; |
50 break; | 55 break; |
51 case GL_RGB: | 56 case GL_RGB: |
52 gl_internal_format = GL_RGB32F_ARB; | 57 gl_internal_format = GL_RGB32F_ARB; |
53 break; | 58 break; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 void SetGLApi(GLApi* api) { | 206 void SetGLApi(GLApi* api) { |
202 g_current_gl_context_tls->Set(api); | 207 g_current_gl_context_tls->Set(api); |
203 } | 208 } |
204 | 209 |
205 void SetGLToRealGLApi() { | 210 void SetGLToRealGLApi() { |
206 SetGLApi(g_gl); | 211 SetGLApi(g_gl); |
207 } | 212 } |
208 | 213 |
209 void InitializeDynamicGLBindingsGL(GLContext* context) { | 214 void InitializeDynamicGLBindingsGL(GLContext* context) { |
210 g_driver_gl.InitializeCustomDynamicBindings(context); | 215 g_driver_gl.InitializeCustomDynamicBindings(context); |
| 216 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); |
| 217 g_version_info = new GLVersionInfo(context->GetGLVersion().c_str()); |
211 } | 218 } |
212 | 219 |
213 void InitializeDebugGLBindingsGL() { | 220 void InitializeDebugGLBindingsGL() { |
214 g_driver_gl.InitializeDebugBindings(); | 221 g_driver_gl.InitializeDebugBindings(); |
215 } | 222 } |
216 | 223 |
217 void InitializeNullDrawGLBindingsGL() { | 224 void InitializeNullDrawGLBindingsGL() { |
218 g_driver_gl.InitializeNullDrawBindings(); | 225 g_driver_gl.InitializeNullDrawBindings(); |
219 } | 226 } |
220 | 227 |
221 void ClearGLBindingsGL() { | 228 void ClearGLBindingsGL() { |
222 if (g_real_gl) { | 229 if (g_real_gl) { |
223 delete g_real_gl; | 230 delete g_real_gl; |
224 g_real_gl = NULL; | 231 g_real_gl = NULL; |
225 } | 232 } |
226 if (g_trace_gl) { | 233 if (g_trace_gl) { |
227 delete g_trace_gl; | 234 delete g_trace_gl; |
228 g_trace_gl = NULL; | 235 g_trace_gl = NULL; |
229 } | 236 } |
230 g_gl = NULL; | 237 g_gl = NULL; |
231 g_driver_gl.ClearBindings(); | 238 g_driver_gl.ClearBindings(); |
232 if (g_current_gl_context_tls) { | 239 if (g_current_gl_context_tls) { |
233 delete g_current_gl_context_tls; | 240 delete g_current_gl_context_tls; |
234 g_current_gl_context_tls = NULL; | 241 g_current_gl_context_tls = NULL; |
235 } | 242 } |
| 243 if (g_version_info) { |
| 244 delete g_version_info; |
| 245 g_version_info = NULL; |
| 246 } |
236 } | 247 } |
237 | 248 |
238 GLApi::GLApi() { | 249 GLApi::GLApi() { |
239 } | 250 } |
240 | 251 |
241 GLApi::~GLApi() { | 252 GLApi::~GLApi() { |
242 if (GetCurrentGLApi() == this) | 253 if (GetCurrentGLApi() == this) |
243 SetGLApi(NULL); | 254 SetGLApi(NULL); |
244 } | 255 } |
245 | 256 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | 361 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { |
351 switch (name) { | 362 switch (name) { |
352 case GL_EXTENSIONS: | 363 case GL_EXTENSIONS: |
353 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | 364 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); |
354 default: | 365 default: |
355 return driver_->fn.glGetStringFn(name); | 366 return driver_->fn.glGetStringFn(name); |
356 } | 367 } |
357 } | 368 } |
358 | 369 |
359 } // namespace gfx | 370 } // namespace gfx |
OLD | NEW |