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/at_exit.h" | |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
13 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
14 #include "ui/gl/gl_state_restorer.h" | 15 #include "ui/gl/gl_state_restorer.h" |
15 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
16 #include "ui/gl/gl_switches.h" | 17 #include "ui/gl/gl_switches.h" |
18 #include "ui/gl/gl_version_info.h" | |
17 | 19 |
18 namespace gfx { | 20 namespace gfx { |
19 | 21 |
20 // The GL Api being used. This could be g_real_gl or gl_trace_gl | 22 // The GL Api being used. This could be g_real_gl or gl_trace_gl |
21 static GLApi* g_gl; | 23 static GLApi* g_gl; |
22 // A GL Api that calls directly into the driver. | 24 // A GL Api that calls directly into the driver. |
23 static RealGLApi* g_real_gl; | 25 static RealGLApi* g_real_gl; |
24 // A GL Api that calls TRACE and then calls another GL api. | 26 // A GL Api that calls TRACE and then calls another GL api. |
25 static TraceGLApi* g_trace_gl; | 27 static TraceGLApi* g_trace_gl; |
28 // GL version used when initializing dynamic bindings. | |
29 static GLVersionInfo* g_version_info = NULL; | |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 static inline GLenum GetInternalFormat(GLenum internal_format) { | 33 static inline GLenum GetInternalFormat(GLenum internal_format) { |
30 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 34 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
31 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) | 35 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
32 return GL_RGBA8; | 36 return GL_RGBA8; |
33 } | 37 } |
34 return internal_format; | 38 return internal_format; |
35 } | 39 } |
36 | 40 |
37 // TODO(epenner): Could the above function be merged into this and removed? | 41 // TODO(epenner): Could the above function be merged into this and removed? |
38 static inline GLenum GetTexInternalFormat(GLenum internal_format, | 42 static inline GLenum GetTexInternalFormat(GLenum internal_format, |
39 GLenum format, | 43 GLenum format, |
40 GLenum type) { | 44 GLenum type) { |
41 GLenum gl_internal_format = GetInternalFormat(internal_format); | 45 GLenum gl_internal_format = GetInternalFormat(internal_format); |
42 | 46 |
43 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) | 47 if (gfx::g_version_info && gfx::g_version_info->is_es) { |
48 if (gfx::g_version_info->is_es3) { | |
piman
2014/01/21 22:37:12
I think we want to limit the amount of magic that
oetuaho-nv
2014/01/22 09:46:54
Traditionally in OpenGL, the mechanism for the cli
| |
49 // Use sized internal formats from core ES3 to get support for rendering | |
no sievers
2014/01/21 22:21:13
Why is the format being renderable relevant in thi
oetuaho-nv
2014/01/22 09:46:54
When creating textures, it's better to choose a re
| |
50 // to 32-bit float render targets using EXT_color_buffer_float. ES2 | |
51 // extension is still relied on to provide the float LUMINANCE/ALPHA | |
52 // formats missing from ES3. | |
53 if (type == GL_FLOAT) { | |
54 switch(format) { | |
55 case GL_RGBA: | |
56 gl_internal_format = GL_RGBA32F; | |
57 break; | |
58 case GL_RGB: | |
59 gl_internal_format = GL_RGB32F; | |
60 break; | |
61 default: | |
62 break; | |
63 } | |
64 } | |
65 // GL_HALF_FLOAT_OES textures can be renderable with | |
no sievers
2014/01/21 22:21:13
same here
| |
66 // EXT_color_buffer_half_float, GL_HALF_FLOAT textures would require | |
67 // EXT_color_buffer_float and similar enum conversions as above. | |
68 DCHECK(type != GL_HALF_FLOAT); | |
no sievers
2014/01/21 22:21:13
Does this compile? Isn't it GL_HALF_FLOAT_OES?
no sievers
2014/01/21 22:21:13
Don't we need to allow this? Looking at feature_in
oetuaho-nv
2014/01/22 09:46:54
Both of these enums exist, and have different valu
| |
69 } | |
44 return gl_internal_format; | 70 return gl_internal_format; |
71 } | |
45 | 72 |
46 if (type == GL_FLOAT) { | 73 if (type == GL_FLOAT) { |
47 switch (format) { | 74 switch (format) { |
48 case GL_RGBA: | 75 case GL_RGBA: |
49 gl_internal_format = GL_RGBA32F_ARB; | 76 gl_internal_format = GL_RGBA32F_ARB; |
50 break; | 77 break; |
51 case GL_RGB: | 78 case GL_RGB: |
52 gl_internal_format = GL_RGB32F_ARB; | 79 gl_internal_format = GL_RGB32F_ARB; |
53 break; | 80 break; |
54 case GL_LUMINANCE_ALPHA: | 81 case GL_LUMINANCE_ALPHA: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 // GL_CHROMIUM_renderbuffer_format_BGRA8888 support is added to ANGLE then the | 164 // GL_CHROMIUM_renderbuffer_format_BGRA8888 support is added to ANGLE then the |
138 // ANGLE version should also be customized. | 165 // ANGLE version should also be customized. |
139 static void GL_BINDING_CALL CustomRenderbufferStorageMultisampleEXT( | 166 static void GL_BINDING_CALL CustomRenderbufferStorageMultisampleEXT( |
140 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, | 167 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, |
141 GLsizei height) { | 168 GLsizei height) { |
142 GLenum gl_internal_format = GetInternalFormat(internalformat); | 169 GLenum gl_internal_format = GetInternalFormat(internalformat); |
143 return g_driver_gl.orig_fn.glRenderbufferStorageMultisampleEXTFn( | 170 return g_driver_gl.orig_fn.glRenderbufferStorageMultisampleEXTFn( |
144 target, samples, gl_internal_format, width, height); | 171 target, samples, gl_internal_format, width, height); |
145 } | 172 } |
146 | 173 |
174 static void CleanupVersionInfo(void* unused) { | |
175 if (g_version_info) { | |
176 delete g_version_info; | |
177 g_version_info = NULL; | |
178 } | |
179 } | |
180 | |
147 } // anonymous namespace | 181 } // anonymous namespace |
148 | 182 |
149 void DriverGL::InitializeCustomDynamicBindings(GLContext* context) { | 183 void DriverGL::InitializeCustomDynamicBindings(GLContext* context) { |
150 InitializeDynamicBindings(context); | 184 InitializeDynamicBindings(context); |
151 orig_fn = fn; | 185 orig_fn = fn; |
152 fn.glTexImage2DFn = | 186 fn.glTexImage2DFn = |
153 reinterpret_cast<glTexImage2DProc>(CustomTexImage2D); | 187 reinterpret_cast<glTexImage2DProc>(CustomTexImage2D); |
154 fn.glTexSubImage2DFn = | 188 fn.glTexSubImage2DFn = |
155 reinterpret_cast<glTexSubImage2DProc>(CustomTexSubImage2D); | 189 reinterpret_cast<glTexSubImage2DProc>(CustomTexSubImage2D); |
156 fn.glTexStorage2DEXTFn = | 190 fn.glTexStorage2DEXTFn = |
(...skipping 29 matching lines...) Expand all Loading... | |
186 void SetGLApi(GLApi* api) { | 220 void SetGLApi(GLApi* api) { |
187 g_current_gl_context_tls->Set(api); | 221 g_current_gl_context_tls->Set(api); |
188 } | 222 } |
189 | 223 |
190 void SetGLToRealGLApi() { | 224 void SetGLToRealGLApi() { |
191 SetGLApi(g_gl); | 225 SetGLApi(g_gl); |
192 } | 226 } |
193 | 227 |
194 void InitializeDynamicGLBindingsGL(GLContext* context) { | 228 void InitializeDynamicGLBindingsGL(GLContext* context) { |
195 g_driver_gl.InitializeCustomDynamicBindings(context); | 229 g_driver_gl.InitializeCustomDynamicBindings(context); |
230 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); | |
231 g_version_info = new GLVersionInfo(context->GetGLVersion().c_str()); | |
232 base::AtExitManager::RegisterCallback(CleanupVersionInfo, NULL); | |
no sievers
2014/01/21 22:21:13
Hmm, are you doing this because we are actually no
oetuaho-nv
2014/01/22 09:46:54
Ah, I should have realized from the code that putt
| |
196 } | 233 } |
197 | 234 |
198 void InitializeDebugGLBindingsGL() { | 235 void InitializeDebugGLBindingsGL() { |
199 g_driver_gl.InitializeDebugBindings(); | 236 g_driver_gl.InitializeDebugBindings(); |
200 } | 237 } |
201 | 238 |
202 void InitializeNullDrawGLBindingsGL() { | 239 void InitializeNullDrawGLBindingsGL() { |
203 g_driver_gl.InitializeNullDrawBindings(); | 240 g_driver_gl.InitializeNullDrawBindings(); |
204 } | 241 } |
205 | 242 |
206 void ClearGLBindingsGL() { | 243 void ClearGLBindingsGL() { |
207 if (g_real_gl) { | 244 if (g_real_gl) { |
208 delete g_real_gl; | 245 delete g_real_gl; |
209 g_real_gl = NULL; | 246 g_real_gl = NULL; |
210 } | 247 } |
211 if (g_trace_gl) { | 248 if (g_trace_gl) { |
212 delete g_trace_gl; | 249 delete g_trace_gl; |
213 g_trace_gl = NULL; | 250 g_trace_gl = NULL; |
214 } | 251 } |
215 g_gl = NULL; | 252 g_gl = NULL; |
216 g_driver_gl.ClearBindings(); | 253 g_driver_gl.ClearBindings(); |
217 if (g_current_gl_context_tls) { | 254 if (g_current_gl_context_tls) { |
218 delete g_current_gl_context_tls; | 255 delete g_current_gl_context_tls; |
219 g_current_gl_context_tls = NULL; | 256 g_current_gl_context_tls = NULL; |
220 } | 257 } |
258 CleanupVersionInfo(NULL); | |
221 } | 259 } |
222 | 260 |
223 GLApi::GLApi() { | 261 GLApi::GLApi() { |
224 } | 262 } |
225 | 263 |
226 GLApi::~GLApi() { | 264 GLApi::~GLApi() { |
227 if (GetCurrentGLApi() == this) | 265 if (GetCurrentGLApi() == this) |
228 SetGLApi(NULL); | 266 SetGLApi(NULL); |
229 } | 267 } |
230 | 268 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | 373 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { |
336 switch (name) { | 374 switch (name) { |
337 case GL_EXTENSIONS: | 375 case GL_EXTENSIONS: |
338 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | 376 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); |
339 default: | 377 default: |
340 return driver_->fn.glGetStringFn(name); | 378 return driver_->fn.glGetStringFn(name); |
341 } | 379 } |
342 } | 380 } |
343 | 381 |
344 } // namespace gfx | 382 } // namespace gfx |
OLD | NEW |