| 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" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 void SetGLApiToNoContext() { | 328 void SetGLApiToNoContext() { |
| 329 SetGLApi(g_no_context_gl); | 329 SetGLApi(g_no_context_gl); |
| 330 } | 330 } |
| 331 | 331 |
| 332 const GLVersionInfo* GetGLVersionInfo() { | 332 const GLVersionInfo* GetGLVersionInfo() { |
| 333 return g_version_info; | 333 return g_version_info; |
| 334 } | 334 } |
| 335 | 335 |
| 336 void InitializeDynamicGLBindingsGL(GLContext* context) { | 336 void InitializeDynamicGLBindingsGL(GLContext* context) { |
| 337 g_real_gl->InitializeFilteredExtensions(); |
| 337 g_driver_gl.InitializeCustomDynamicBindings(context); | 338 g_driver_gl.InitializeCustomDynamicBindings(context); |
| 338 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); | 339 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); |
| 339 g_real_gl->InitializeWithContext(); | |
| 340 g_version_info = new GLVersionInfo( | 340 g_version_info = new GLVersionInfo( |
| 341 context->GetGLVersion().c_str(), | 341 context->GetGLVersion().c_str(), |
| 342 context->GetGLRenderer().c_str(), | 342 context->GetGLRenderer().c_str(), |
| 343 context->GetExtensions().c_str()); | 343 context->GetExtensions().c_str()); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void InitializeDebugGLBindingsGL() { | 346 void InitializeDebugGLBindingsGL() { |
| 347 g_driver_gl.InitializeDebugBindings(); | 347 g_driver_gl.InitializeDebugBindings(); |
| 348 } | 348 } |
| 349 | 349 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 397 } |
| 398 | 398 |
| 399 GLApiBase::~GLApiBase() { | 399 GLApiBase::~GLApiBase() { |
| 400 } | 400 } |
| 401 | 401 |
| 402 void GLApiBase::InitializeBase(DriverGL* driver) { | 402 void GLApiBase::InitializeBase(DriverGL* driver) { |
| 403 driver_ = driver; | 403 driver_ = driver; |
| 404 } | 404 } |
| 405 | 405 |
| 406 RealGLApi::RealGLApi() { | 406 RealGLApi::RealGLApi() { |
| 407 #if DCHECK_IS_ON() |
| 408 filtered_exts_initialized_ = false; |
| 409 #endif |
| 407 } | 410 } |
| 408 | 411 |
| 409 RealGLApi::~RealGLApi() { | 412 RealGLApi::~RealGLApi() { |
| 410 } | 413 } |
| 411 | 414 |
| 412 void RealGLApi::Initialize(DriverGL* driver) { | 415 void RealGLApi::Initialize(DriverGL* driver) { |
| 413 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); | 416 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); |
| 414 } | 417 } |
| 415 | 418 |
| 416 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, | 419 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, |
| 417 base::CommandLine* command_line) { | 420 base::CommandLine* command_line) { |
| 418 DCHECK(command_line); | 421 DCHECK(command_line); |
| 419 InitializeBase(driver); | 422 InitializeBase(driver); |
| 420 | 423 |
| 421 const std::string disabled_extensions = command_line->GetSwitchValueASCII( | 424 const std::string disabled_extensions = command_line->GetSwitchValueASCII( |
| 422 switches::kDisableGLExtensions); | 425 switches::kDisableGLExtensions); |
| 423 if (!disabled_extensions.empty()) { | 426 if (!disabled_extensions.empty()) { |
| 424 disabled_exts_ = base::SplitString( | 427 disabled_exts_ = base::SplitString( |
| 425 disabled_extensions, ", ;", | 428 disabled_extensions, ", ;", |
| 426 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 429 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 427 } | 430 } |
| 428 } | 431 } |
| 429 | 432 |
| 430 void RealGLApi::InitializeWithContext() { | |
| 431 InitializeFilteredExtensions(); | |
| 432 } | |
| 433 | |
| 434 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | 433 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { |
| 435 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) { | 434 if (pname == GL_NUM_EXTENSIONS && disabled_exts_.size()) { |
| 435 #if DCHECK_IS_ON() |
| 436 DCHECK(filtered_exts_initialized_); |
| 437 #endif |
| 436 *params = static_cast<GLint>(filtered_exts_.size()); | 438 *params = static_cast<GLint>(filtered_exts_.size()); |
| 437 } else { | 439 } else { |
| 438 GLApiBase::glGetIntegervFn(pname, params); | 440 GLApiBase::glGetIntegervFn(pname, params); |
| 439 } | 441 } |
| 440 } | 442 } |
| 441 | 443 |
| 442 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { | 444 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { |
| 443 if (!filtered_exts_.empty() && name == GL_EXTENSIONS) { | 445 if (name == GL_EXTENSIONS && disabled_exts_.size()) { |
| 446 #if DCHECK_IS_ON() |
| 447 DCHECK(filtered_exts_initialized_); |
| 448 #endif |
| 444 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); | 449 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); |
| 445 } | 450 } |
| 446 return GLApiBase::glGetStringFn(name); | 451 return GLApiBase::glGetStringFn(name); |
| 447 } | 452 } |
| 448 | 453 |
| 449 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { | 454 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { |
| 450 if (!filtered_exts_str_.empty() && name == GL_EXTENSIONS) { | 455 if (name == GL_EXTENSIONS && disabled_exts_.size()) { |
| 456 #if DCHECK_IS_ON() |
| 457 DCHECK(filtered_exts_initialized_); |
| 458 #endif |
| 451 if (index >= filtered_exts_.size()) { | 459 if (index >= filtered_exts_.size()) { |
| 452 return NULL; | 460 return NULL; |
| 453 } | 461 } |
| 454 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | 462 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); |
| 455 } | 463 } |
| 456 return GLApiBase::glGetStringiFn(name, index); | 464 return GLApiBase::glGetStringiFn(name, index); |
| 457 } | 465 } |
| 458 | 466 |
| 459 void RealGLApi::glFlushFn() { | 467 void RealGLApi::glFlushFn() { |
| 460 GLApiBase::glFlushFn(); | 468 GLApiBase::glFlushFn(); |
| 461 } | 469 } |
| 462 | 470 |
| 463 void RealGLApi::glFinishFn() { | 471 void RealGLApi::glFinishFn() { |
| 464 GLApiBase::glFinishFn(); | 472 GLApiBase::glFinishFn(); |
| 465 } | 473 } |
| 466 | 474 |
| 467 void RealGLApi::InitializeFilteredExtensions() { | 475 void RealGLApi::InitializeFilteredExtensions() { |
| 468 if (!disabled_exts_.empty() && filtered_exts_.empty()) { | 476 if (disabled_exts_.size()) { |
| 469 DCHECK(filtered_exts_.empty() && filtered_exts_str_.empty()); | 477 filtered_exts_.clear(); |
| 470 // Fill in filtered_exts_ vector first. | |
| 471 if (gfx::GetGLImplementation() != | 478 if (gfx::GetGLImplementation() != |
| 472 gfx::kGLImplementationDesktopGLCoreProfile) { | 479 gfx::kGLImplementationDesktopGLCoreProfile) { |
| 473 const char* gl_extensions = reinterpret_cast<const char*>( | 480 filtered_exts_str_ = |
| 474 GLApiBase::glGetStringFn(GL_EXTENSIONS)); | 481 FilterGLExtensionList(reinterpret_cast<const char*>( |
| 475 if (gl_extensions) { | 482 GLApiBase::glGetStringFn(GL_EXTENSIONS)), |
| 476 filtered_exts_ = base::SplitString( | 483 disabled_exts_); |
| 477 gl_extensions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 484 base::SplitString(filtered_exts_str_, ' ', &filtered_exts_); |
| 478 } | |
| 479 } else { | 485 } else { |
| 480 GLint num_extensions = 0; | 486 GLint num_extensions = 0; |
| 481 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | 487 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| 482 for (GLint i = 0; i < num_extensions; ++i) { | 488 for (GLint i = 0; i < num_extensions; ++i) { |
| 483 const char* gl_extension = reinterpret_cast<const char*>( | 489 const char* gl_extension = reinterpret_cast<const char*>( |
| 484 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); | 490 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); |
| 485 DCHECK(gl_extension != NULL); | 491 DCHECK(gl_extension != NULL); |
| 486 filtered_exts_.push_back(gl_extension); | 492 if (std::find(disabled_exts_.begin(), disabled_exts_.end(), |
| 493 gl_extension) == disabled_exts_.end()) { |
| 494 filtered_exts_.push_back(gl_extension); |
| 495 } |
| 487 } | 496 } |
| 497 filtered_exts_str_ = base::JoinString(filtered_exts_, " "); |
| 488 } | 498 } |
| 489 | 499 #if DCHECK_IS_ON() |
| 490 // Filter out extensions from the command line. | 500 filtered_exts_initialized_ = true; |
| 491 for (const std::string& disabled_ext : disabled_exts_) { | 501 #endif |
| 492 filtered_exts_.erase(std::remove(filtered_exts_.begin(), | |
| 493 filtered_exts_.end(), | |
| 494 disabled_ext), | |
| 495 filtered_exts_.end()); | |
| 496 } | |
| 497 | |
| 498 // Construct filtered extensions string for GL_EXTENSIONS string lookups. | |
| 499 filtered_exts_str_ = base::JoinString(filtered_exts_, " "); | |
| 500 } | 502 } |
| 501 } | 503 } |
| 502 | 504 |
| 503 TraceGLApi::~TraceGLApi() { | 505 TraceGLApi::~TraceGLApi() { |
| 504 } | 506 } |
| 505 | 507 |
| 506 NoContextGLApi::NoContextGLApi() { | 508 NoContextGLApi::NoContextGLApi() { |
| 507 } | 509 } |
| 508 | 510 |
| 509 NoContextGLApi::~NoContextGLApi() { | 511 NoContextGLApi::~NoContextGLApi() { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 619 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
| 618 : old_gl_api_(GetCurrentGLApi()) { | 620 : old_gl_api_(GetCurrentGLApi()) { |
| 619 SetGLToRealGLApi(); | 621 SetGLToRealGLApi(); |
| 620 } | 622 } |
| 621 | 623 |
| 622 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 624 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
| 623 SetGLApi(old_gl_api_); | 625 SetGLApi(old_gl_api_); |
| 624 } | 626 } |
| 625 | 627 |
| 626 } // namespace gfx | 628 } // namespace gfx |
| OLD | NEW |