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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_state_restorer.h" | 15 #include "ui/gl/gl_state_restorer.h" |
16 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
17 #include "ui/gl/gl_switches.h" | 17 #include "ui/gl/gl_switches.h" |
18 #include "ui/gl/gl_version_info.h" | 18 #include "ui/gl/gl_version_info.h" |
19 | 19 |
20 namespace gfx { | 20 namespace gl { |
21 | 21 |
22 // 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 |
23 static GLApi* g_gl = NULL; | 23 static GLApi* g_gl = NULL; |
24 // A GL Api that calls directly into the driver. | 24 // A GL Api that calls directly into the driver. |
25 static RealGLApi* g_real_gl = NULL; | 25 static RealGLApi* g_real_gl = NULL; |
26 // A GL Api that does nothing but warn about illegal GL calls without a context | 26 // A GL Api that does nothing but warn about illegal GL calls without a context |
27 // current. | 27 // current. |
28 static NoContextGLApi* g_no_context_gl = NULL; | 28 static NoContextGLApi* g_no_context_gl = NULL; |
29 // A GL Api that calls TRACE and then calls another GL api. | 29 // A GL Api that calls TRACE and then calls another GL api. |
30 static TraceGLApi* g_trace_gl = NULL; | 30 static TraceGLApi* g_trace_gl = NULL; |
31 // GL version used when initializing dynamic bindings. | 31 // GL version used when initializing dynamic bindings. |
32 static GLVersionInfo* g_version_info = NULL; | 32 static GLVersionInfo* g_version_info = NULL; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 static inline GLenum GetInternalFormat(GLenum internal_format) { | 36 static inline GLenum GetInternalFormat(GLenum internal_format) { |
37 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 37 if (gl::GetGLImplementation() != gl::kGLImplementationEGLGLES2) { |
38 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) | 38 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
39 return GL_RGBA8; | 39 return GL_RGBA8; |
40 } | 40 } |
41 return internal_format; | 41 return internal_format; |
42 } | 42 } |
43 | 43 |
44 // TODO(epenner): Could the above function be merged into this and removed? | 44 // TODO(epenner): Could the above function be merged into this and removed? |
45 static inline GLenum GetTexInternalFormat(GLenum internal_format, | 45 static inline GLenum GetTexInternalFormat(GLenum internal_format, |
46 GLenum format, | 46 GLenum format, |
47 GLenum type) { | 47 GLenum type) { |
48 GLenum gl_internal_format = GetInternalFormat(internal_format); | 48 GLenum gl_internal_format = GetInternalFormat(internal_format); |
49 | 49 |
50 // g_version_info must be initialized when this function is bound. | 50 // g_version_info must be initialized when this function is bound. |
51 DCHECK(gfx::g_version_info); | 51 DCHECK(gl::g_version_info); |
52 if (gfx::g_version_info->is_es3) { | 52 if (gl::g_version_info->is_es3) { |
53 if (internal_format == GL_RED_EXT) { | 53 if (internal_format == GL_RED_EXT) { |
54 // GL_EXT_texture_rg case in ES2. | 54 // GL_EXT_texture_rg case in ES2. |
55 switch (type) { | 55 switch (type) { |
56 case GL_UNSIGNED_BYTE: | 56 case GL_UNSIGNED_BYTE: |
57 gl_internal_format = GL_R8_EXT; | 57 gl_internal_format = GL_R8_EXT; |
58 break; | 58 break; |
59 case GL_HALF_FLOAT_OES: | 59 case GL_HALF_FLOAT_OES: |
60 gl_internal_format = GL_R16F_EXT; | 60 gl_internal_format = GL_R16F_EXT; |
61 break; | 61 break; |
62 case GL_FLOAT: | 62 case GL_FLOAT: |
(...skipping 17 matching lines...) Expand all Loading... |
80 gl_internal_format = GL_RG32F_EXT; | 80 gl_internal_format = GL_RG32F_EXT; |
81 break; | 81 break; |
82 default: | 82 default: |
83 NOTREACHED(); | 83 NOTREACHED(); |
84 break; | 84 break; |
85 } | 85 } |
86 return gl_internal_format; | 86 return gl_internal_format; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 if (type == GL_FLOAT && gfx::g_version_info->is_angle && | 90 if (type == GL_FLOAT && gl::g_version_info->is_angle && |
91 gfx::g_version_info->is_es && gfx::g_version_info->major_version == 2) { | 91 gl::g_version_info->is_es && gl::g_version_info->major_version == 2) { |
92 // It's possible that the texture is using a sized internal format, and | 92 // It's possible that the texture is using a sized internal format, and |
93 // ANGLE exposing GLES2 API doesn't support those. | 93 // ANGLE exposing GLES2 API doesn't support those. |
94 // TODO(oetuaho@nvidia.com): Remove these conversions once ANGLE has the | 94 // TODO(oetuaho@nvidia.com): Remove these conversions once ANGLE has the |
95 // support. | 95 // support. |
96 // http://code.google.com/p/angleproject/issues/detail?id=556 | 96 // http://code.google.com/p/angleproject/issues/detail?id=556 |
97 switch (format) { | 97 switch (format) { |
98 case GL_RGBA: | 98 case GL_RGBA: |
99 gl_internal_format = GL_RGBA; | 99 gl_internal_format = GL_RGBA; |
100 break; | 100 break; |
101 case GL_RGB: | 101 case GL_RGB: |
102 gl_internal_format = GL_RGB; | 102 gl_internal_format = GL_RGB; |
103 break; | 103 break; |
104 default: | 104 default: |
105 break; | 105 break; |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 if (gfx::g_version_info->IsAtLeastGL(2, 1) || | 109 if (gl::g_version_info->IsAtLeastGL(2, 1) || |
110 gfx::g_version_info->IsAtLeastGLES(3, 0)) { | 110 gl::g_version_info->IsAtLeastGLES(3, 0)) { |
111 switch (internal_format) { | 111 switch (internal_format) { |
112 case GL_SRGB_EXT: | 112 case GL_SRGB_EXT: |
113 gl_internal_format = GL_SRGB8; | 113 gl_internal_format = GL_SRGB8; |
114 break; | 114 break; |
115 case GL_SRGB_ALPHA_EXT: | 115 case GL_SRGB_ALPHA_EXT: |
116 gl_internal_format = GL_SRGB8_ALPHA8; | 116 gl_internal_format = GL_SRGB8_ALPHA8; |
117 break; | 117 break; |
118 default: | 118 default: |
119 break; | 119 break; |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 if (gfx::g_version_info->is_es) | 123 if (gl::g_version_info->is_es) |
124 return gl_internal_format; | 124 return gl_internal_format; |
125 | 125 |
126 if (type == GL_FLOAT) { | 126 if (type == GL_FLOAT) { |
127 switch (internal_format) { | 127 switch (internal_format) { |
128 // We need to map all the unsized internal formats from ES2 clients. | 128 // We need to map all the unsized internal formats from ES2 clients. |
129 case GL_RGBA: | 129 case GL_RGBA: |
130 gl_internal_format = GL_RGBA32F_ARB; | 130 gl_internal_format = GL_RGBA32F_ARB; |
131 break; | 131 break; |
132 case GL_RGB: | 132 case GL_RGB: |
133 gl_internal_format = GL_RGB32F_ARB; | 133 gl_internal_format = GL_RGB32F_ARB; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 break; | 168 break; |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 return gl_internal_format; | 172 return gl_internal_format; |
173 } | 173 } |
174 | 174 |
175 static inline GLenum GetTexFormat(GLenum format) { | 175 static inline GLenum GetTexFormat(GLenum format) { |
176 GLenum gl_format = format; | 176 GLenum gl_format = format; |
177 | 177 |
178 DCHECK(gfx::g_version_info); | 178 DCHECK(gl::g_version_info); |
179 if (gfx::g_version_info->IsAtLeastGL(2, 1) || | 179 if (gl::g_version_info->IsAtLeastGL(2, 1) || |
180 gfx::g_version_info->IsAtLeastGLES(3, 0)) { | 180 gl::g_version_info->IsAtLeastGLES(3, 0)) { |
181 switch (format) { | 181 switch (format) { |
182 case GL_SRGB_EXT: | 182 case GL_SRGB_EXT: |
183 gl_format = GL_RGB; | 183 gl_format = GL_RGB; |
184 break; | 184 break; |
185 case GL_SRGB_ALPHA_EXT: | 185 case GL_SRGB_ALPHA_EXT: |
186 gl_format = GL_RGBA; | 186 gl_format = GL_RGBA; |
187 break; | 187 break; |
188 default: | 188 default: |
189 break; | 189 break; |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 return gl_format; | 193 return gl_format; |
194 } | 194 } |
195 | 195 |
196 static inline GLenum GetTexType(GLenum type) { | 196 static inline GLenum GetTexType(GLenum type) { |
197 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 197 if (gl::GetGLImplementation() != gl::kGLImplementationEGLGLES2) { |
198 if (type == GL_HALF_FLOAT_OES) | 198 if (type == GL_HALF_FLOAT_OES) |
199 return GL_HALF_FLOAT_ARB; | 199 return GL_HALF_FLOAT_ARB; |
200 } | 200 } |
201 return type; | 201 return type; |
202 } | 202 } |
203 | 203 |
204 static void GL_BINDING_CALL CustomTexImage2D( | 204 static void GL_BINDING_CALL CustomTexImage2D( |
205 GLenum target, GLint level, GLint internalformat, | 205 GLenum target, GLint level, GLint internalformat, |
206 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, | 206 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, |
207 const void* pixels) { | 207 const void* pixels) { |
208 GLenum gl_internal_format = GetTexInternalFormat( | 208 GLenum gl_internal_format = GetTexInternalFormat( |
209 internalformat, format, type); | 209 internalformat, format, type); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 GLApiBase::glFlushFn(); | 509 GLApiBase::glFlushFn(); |
510 } | 510 } |
511 | 511 |
512 void RealGLApi::glFinishFn() { | 512 void RealGLApi::glFinishFn() { |
513 GLApiBase::glFinishFn(); | 513 GLApiBase::glFinishFn(); |
514 } | 514 } |
515 | 515 |
516 void RealGLApi::InitializeFilteredExtensions() { | 516 void RealGLApi::InitializeFilteredExtensions() { |
517 if (disabled_exts_.size()) { | 517 if (disabled_exts_.size()) { |
518 filtered_exts_.clear(); | 518 filtered_exts_.clear(); |
519 if (gfx::WillUseGLGetStringForExtensions()) { | 519 if (gl::WillUseGLGetStringForExtensions()) { |
520 filtered_exts_str_ = | 520 filtered_exts_str_ = |
521 FilterGLExtensionList(reinterpret_cast<const char*>( | 521 FilterGLExtensionList(reinterpret_cast<const char*>( |
522 GLApiBase::glGetStringFn(GL_EXTENSIONS)), | 522 GLApiBase::glGetStringFn(GL_EXTENSIONS)), |
523 disabled_exts_); | 523 disabled_exts_); |
524 filtered_exts_ = base::SplitString( | 524 filtered_exts_ = base::SplitString( |
525 filtered_exts_str_, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 525 filtered_exts_str_, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
526 } else { | 526 } else { |
527 GLint num_extensions = 0; | 527 GLint num_extensions = 0; |
528 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | 528 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
529 for (GLint i = 0; i < num_extensions; ++i) { | 529 for (GLint i = 0; i < num_extensions; ++i) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 665 } |
666 | 666 |
667 void VirtualGLApi::glFlushFn() { | 667 void VirtualGLApi::glFlushFn() { |
668 GLApiBase::glFlushFn(); | 668 GLApiBase::glFlushFn(); |
669 } | 669 } |
670 | 670 |
671 void VirtualGLApi::glFinishFn() { | 671 void VirtualGLApi::glFinishFn() { |
672 GLApiBase::glFinishFn(); | 672 GLApiBase::glFinishFn(); |
673 } | 673 } |
674 | 674 |
675 } // namespace gfx | 675 } // namespace gl |
OLD | NEW |