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_implementation.h" | 5 #include "ui/gl/gl_implementation.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "ui/gl/gl_bindings.h" | 20 #include "ui/gl/gl_bindings.h" |
20 #include "ui/gl/gl_gl_api_implementation.h" | 21 #include "ui/gl/gl_gl_api_implementation.h" |
21 #include "ui/gl/gl_version_info.h" | 22 #include "ui/gl/gl_version_info.h" |
22 | 23 |
23 namespace gl { | 24 namespace gl { |
24 | 25 |
25 namespace { | 26 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
48 // We do not call base::UnloadNativeLibrary() for these libraries as | 49 // We do not call base::UnloadNativeLibrary() for these libraries as |
49 // unloading libGL without closing X display is not allowed. See | 50 // unloading libGL without closing X display is not allowed. See |
50 // crbug.com/250813 for details. | 51 // crbug.com/250813 for details. |
51 delete g_libraries; | 52 delete g_libraries; |
52 g_libraries = NULL; | 53 g_libraries = NULL; |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls = NULL; | 59 base::ThreadLocalPointer<CurrentGL>* g_current_gl_context_tls = NULL; |
59 OSMESAApi* g_current_osmesa_context; | 60 OSMESAApi* g_current_osmesa_context; |
60 | 61 |
61 #if defined(USE_EGL) | 62 #if defined(USE_EGL) |
62 EGLApi* g_current_egl_context; | 63 EGLApi* g_current_egl_context; |
63 #endif | 64 #endif |
64 | 65 |
65 #if defined(OS_WIN) | 66 #if defined(OS_WIN) |
66 WGLApi* g_current_wgl_context; | 67 WGLApi* g_current_wgl_context; |
67 #endif | 68 #endif |
68 | 69 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (g_get_proc_address) { | 138 if (g_get_proc_address) { |
138 GLFunctionPointerType proc = g_get_proc_address(name); | 139 GLFunctionPointerType proc = g_get_proc_address(name); |
139 if (proc) | 140 if (proc) |
140 return proc; | 141 return proc; |
141 } | 142 } |
142 | 143 |
143 return NULL; | 144 return NULL; |
144 } | 145 } |
145 | 146 |
146 void InitializeNullDrawGLBindings() { | 147 void InitializeNullDrawGLBindings() { |
147 // This is platform independent, so it does not need to live in a platform | 148 SetNullDrawGLBindingsEnabled(true); |
148 // specific implementation file. | |
149 InitializeNullDrawGLBindingsGL(); | |
150 } | 149 } |
151 | 150 |
152 bool HasInitializedNullDrawGLBindings() { | 151 bool HasInitializedNullDrawGLBindings() { |
153 return HasInitializedNullDrawGLBindingsGL(); | 152 return GetNullDrawBindingsEnabled(); |
154 } | 153 } |
155 | 154 |
156 std::string FilterGLExtensionList( | 155 std::string FilterGLExtensionList( |
157 const char* extensions, | 156 const char* extensions, |
158 const std::vector<std::string>& disabled_extensions) { | 157 const std::vector<std::string>& disabled_extensions) { |
159 if (extensions == NULL) | 158 if (extensions == NULL) |
160 return ""; | 159 return ""; |
161 | 160 |
162 std::vector<std::string> extension_vec = base::SplitString( | 161 std::vector<std::string> extension_vec = base::SplitString( |
163 extensions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 162 extensions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
164 | 163 |
165 auto is_disabled = [&disabled_extensions](const std::string& ext) { | 164 auto is_disabled = [&disabled_extensions](const std::string& ext) { |
166 return std::find(disabled_extensions.begin(), disabled_extensions.end(), | 165 return std::find(disabled_extensions.begin(), disabled_extensions.end(), |
167 ext) != disabled_extensions.end(); | 166 ext) != disabled_extensions.end(); |
168 }; | 167 }; |
169 extension_vec.erase( | 168 extension_vec.erase( |
170 std::remove_if(extension_vec.begin(), extension_vec.end(), is_disabled), | 169 std::remove_if(extension_vec.begin(), extension_vec.end(), is_disabled), |
171 extension_vec.end()); | 170 extension_vec.end()); |
172 | 171 |
173 return base::JoinString(extension_vec, " "); | 172 return base::JoinString(extension_vec, " "); |
174 } | 173 } |
175 | 174 |
176 DisableNullDrawGLBindings::DisableNullDrawGLBindings() { | 175 DisableNullDrawGLBindings::DisableNullDrawGLBindings() { |
177 initial_enabled_ = SetNullDrawGLBindingsEnabledGL(false); | 176 initial_enabled_ = SetNullDrawGLBindingsEnabled(false); |
178 } | 177 } |
179 | 178 |
180 DisableNullDrawGLBindings::~DisableNullDrawGLBindings() { | 179 DisableNullDrawGLBindings::~DisableNullDrawGLBindings() { |
181 SetNullDrawGLBindingsEnabledGL(initial_enabled_); | 180 SetNullDrawGLBindingsEnabled(initial_enabled_); |
182 } | 181 } |
183 | 182 |
184 GLWindowSystemBindingInfo::GLWindowSystemBindingInfo() | 183 GLWindowSystemBindingInfo::GLWindowSystemBindingInfo() |
185 : direct_rendering(true) {} | 184 : direct_rendering(true) {} |
186 | 185 |
187 std::string GetGLExtensionsFromCurrentContext() { | 186 std::string GetGLExtensionsFromCurrentContext() { |
188 if (WillUseGLGetStringForExtensions()) { | 187 return GetGLExtensionsFromCurrentContext(g_current_gl_context); |
189 return reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); | 188 } |
| 189 |
| 190 std::string GetGLExtensionsFromCurrentContext(GLApi* api) { |
| 191 if (WillUseGLGetStringForExtensions(api)) { |
| 192 const char* extensions = |
| 193 reinterpret_cast<const char*>(api->glGetStringFn(GL_EXTENSIONS)); |
| 194 return extensions ? std::string(extensions) : std::string(); |
190 } | 195 } |
191 | 196 |
192 std::vector<std::string> exts; | |
193 GLint num_extensions = 0; | 197 GLint num_extensions = 0; |
194 glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); | 198 api->glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| 199 |
| 200 std::vector<std::string> exts(num_extensions); |
195 for (GLint i = 0; i < num_extensions; ++i) { | 201 for (GLint i = 0; i < num_extensions; ++i) { |
196 const char* extension = reinterpret_cast<const char*>( | 202 const char* extension = |
197 glGetStringi(GL_EXTENSIONS, i)); | 203 reinterpret_cast<const char*>(api->glGetStringiFn(GL_EXTENSIONS, i)); |
198 DCHECK(extension != NULL); | 204 DCHECK(extension != NULL); |
199 exts.push_back(extension); | 205 exts[i] = extension; |
200 } | 206 } |
201 return base::JoinString(exts, " "); | 207 return base::JoinString(exts, " "); |
202 } | 208 } |
203 | 209 |
204 bool WillUseGLGetStringForExtensions() { | 210 bool WillUseGLGetStringForExtensions() { |
| 211 return WillUseGLGetStringForExtensions(g_current_gl_context); |
| 212 } |
| 213 |
| 214 bool WillUseGLGetStringForExtensions(GLApi* api) { |
205 const char* version_str = | 215 const char* version_str = |
206 reinterpret_cast<const char*>(glGetString(GL_VERSION)); | 216 reinterpret_cast<const char*>(api->glGetStringFn(GL_VERSION)); |
207 unsigned major_version, minor_version; | 217 unsigned major_version, minor_version; |
208 bool is_es, is_es2, is_es3; | 218 bool is_es, is_es2, is_es3; |
209 GLVersionInfo::ParseVersionString(version_str, &major_version, &minor_version, | 219 GLVersionInfo::ParseVersionString(version_str, &major_version, &minor_version, |
210 &is_es, &is_es2, &is_es3); | 220 &is_es, &is_es2, &is_es3); |
211 return is_es || major_version < 3; | 221 return is_es || major_version < 3; |
212 } | 222 } |
213 | 223 |
| 224 std::unique_ptr<GLVersionInfo> GetVersionInfoFromContext(GLApi* api) { |
| 225 std::string extensions = GetGLExtensionsFromCurrentContext(api); |
| 226 return base::MakeUnique<GLVersionInfo>( |
| 227 reinterpret_cast<const char*>(api->glGetStringFn(GL_VERSION)), |
| 228 reinterpret_cast<const char*>(api->glGetStringFn(GL_RENDERER)), |
| 229 extensions.c_str()); |
| 230 } |
| 231 |
214 base::NativeLibrary LoadLibraryAndPrintError( | 232 base::NativeLibrary LoadLibraryAndPrintError( |
215 const base::FilePath::CharType* filename) { | 233 const base::FilePath::CharType* filename) { |
216 return LoadLibraryAndPrintError(base::FilePath(filename)); | 234 return LoadLibraryAndPrintError(base::FilePath(filename)); |
217 } | 235 } |
218 | 236 |
219 base::NativeLibrary LoadLibraryAndPrintError(const base::FilePath& filename) { | 237 base::NativeLibrary LoadLibraryAndPrintError(const base::FilePath& filename) { |
220 base::NativeLibraryLoadError error; | 238 base::NativeLibraryLoadError error; |
221 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); | 239 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); |
222 if (!library) { | 240 if (!library) { |
223 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": " | 241 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": " |
224 << error.ToString(); | 242 << error.ToString(); |
225 return NULL; | 243 return NULL; |
226 } | 244 } |
227 return library; | 245 return library; |
228 } | 246 } |
229 | 247 |
230 } // namespace gl | 248 } // namespace gl |
OLD | NEW |