Chromium Code Reviews| Index: ui/gl/gl_gl_api_implementation.cc |
| diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc |
| index 6752a25ee5a83644a00495804ffb027d81a54859..3c59a94b4bd0179b41c16c7f6238519f5eadd4a5 100644 |
| --- a/ui/gl/gl_gl_api_implementation.cc |
| +++ b/ui/gl/gl_gl_api_implementation.cc |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| #include "base/command_line.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "ui/gl/gl_context.h" |
| #include "ui/gl/gl_implementation.h" |
| @@ -403,8 +404,73 @@ RealGLApi::RealGLApi() { |
| RealGLApi::~RealGLApi() { |
| } |
| -void RealGLApi::Initialize(DriverGL* driver) { |
| +void RealGLApi::Initialize(DriverGL* driver, base::CommandLine* command_line) { |
| InitializeBase(driver); |
| + if (command_line == nullptr) |
| + command_line = base::CommandLine::ForCurrentProcess(); |
| + |
| + const std::string disabled_extensions = command_line->GetSwitchValueASCII( |
| + switches::kDisableGLExtensions); |
| + if (!disabled_extensions.empty()) { |
| + std::vector<std::string> disabled_extensions_vec; |
| + Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec); |
| + |
| + // Fill in filtered_exts_ vector first. |
| + if (gfx::GetGLImplementation() != |
| + gfx::kGLImplementationDesktopGLCoreProfile) { |
| + const char* gl_extensions = reinterpret_cast<const char*>( |
| + GLApiBase::glGetStringFn(GL_EXTENSIONS)); |
| + if (gl_extensions) |
| + base::SplitString(gl_extensions, ' ', &filtered_exts_); |
| + } else { |
| + GLint num_extensions = 0; |
| + GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| + for (GLint i = 0; i < num_extensions; ++i) { |
| + const char* gl_extension = reinterpret_cast<const char*>( |
| + GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); |
| + DCHECK(gl_extension != NULL); |
| + filtered_exts_.push_back(gl_extension); |
| + } |
| + } |
| + |
| + // Filter out extensions from the command line. |
| + for (const std::string& disabled_ext : disabled_extensions_vec) { |
| + filtered_exts_.erase(std::remove(filtered_exts_.begin(), |
| + filtered_exts_.end(), |
| + disabled_ext), |
| + filtered_exts_.end()); |
| + } |
| + |
| + // Construct filtered extensions string for GL_EXTENSIONS string lookups. |
| + filtered_exts_str_ = JoinString(filtered_exts_, " "); |
| + |
| + extensions_filtered_ = true; |
|
no sievers
2015/04/30 23:49:05
So this can go now?
David Yen
2015/05/01 21:20:37
This is still necessary for mock functions to work
|
| + } |
| +} |
| + |
| +void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { |
| + if (extensions_filtered_ && pname == GL_NUM_EXTENSIONS) { |
| + *params = static_cast<GLint>(filtered_exts_.size()); |
| + } else { |
| + GLApiBase::glGetIntegervFn(pname, params); |
| + } |
| +} |
| + |
| +const GLubyte* RealGLApi::glGetStringFn(GLenum name) { |
| + if (extensions_filtered_ && name == GL_EXTENSIONS) { |
| + return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); |
| + } |
| + return GLApiBase::glGetStringFn(name); |
| +} |
| + |
| +const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { |
| + if (extensions_filtered_ && name == GL_EXTENSIONS) { |
| + if (index >= filtered_exts_.size()) { |
| + return NULL; |
| + } |
| + return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); |
| + } |
| + return GLApiBase::glGetStringiFn(name, index); |
| } |
| void RealGLApi::glFlushFn() { |
| @@ -529,9 +595,12 @@ void VirtualGLApi::glFinishFn() { |
| GLApiBase::glFinishFn(); |
| } |
| -ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
| +ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi(GLApi* set_api) |
| : old_gl_api_(GetCurrentGLApi()) { |
| - SetGLToRealGLApi(); |
| + if (set_api) |
| + SetGLApi(set_api); |
| + else |
| + SetGLToRealGLApi(); |
| } |
| ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |