Chromium Code Reviews| 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" |
| 11 #include "base/strings/string_split.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" |
| 17 #include "ui/gl/gl_version_info.h" | 18 #include "ui/gl/gl_version_info.h" |
| 18 | 19 |
| 19 namespace gfx { | 20 namespace gfx { |
| 20 | 21 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 void GLApiBase::InitializeBase(DriverGL* driver) { | 397 void GLApiBase::InitializeBase(DriverGL* driver) { |
| 397 driver_ = driver; | 398 driver_ = driver; |
| 398 } | 399 } |
| 399 | 400 |
| 400 RealGLApi::RealGLApi() { | 401 RealGLApi::RealGLApi() { |
| 401 } | 402 } |
| 402 | 403 |
| 403 RealGLApi::~RealGLApi() { | 404 RealGLApi::~RealGLApi() { |
| 404 } | 405 } |
| 405 | 406 |
| 406 void RealGLApi::Initialize(DriverGL* driver) { | 407 void RealGLApi::Initialize(DriverGL* driver, base::CommandLine* command_line) { |
| 407 InitializeBase(driver); | 408 InitializeBase(driver); |
| 409 if (command_line == nullptr) | |
| 410 command_line = base::CommandLine::ForCurrentProcess(); | |
| 411 | |
| 412 const std::string disabled_extensions = command_line->GetSwitchValueASCII( | |
| 413 switches::kDisableGLExtensions); | |
| 414 if (!disabled_extensions.empty()) { | |
| 415 std::vector<std::string> disabled_extensions_vec; | |
| 416 Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec); | |
| 417 | |
| 418 // Fill in filtered_exts_ vector first. | |
| 419 if (gfx::GetGLImplementation() != | |
| 420 gfx::kGLImplementationDesktopGLCoreProfile) { | |
| 421 const char* gl_extensions = reinterpret_cast<const char*>( | |
| 422 GLApiBase::glGetStringFn(GL_EXTENSIONS)); | |
| 423 if (gl_extensions) | |
| 424 base::SplitString(gl_extensions, ' ', &filtered_exts_); | |
| 425 } else { | |
| 426 GLint num_extensions = 0; | |
| 427 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | |
| 428 for (GLint i = 0; i < num_extensions; ++i) { | |
| 429 const char* gl_extension = reinterpret_cast<const char*>( | |
| 430 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); | |
| 431 DCHECK(gl_extension != NULL); | |
| 432 filtered_exts_.push_back(gl_extension); | |
| 433 } | |
| 434 } | |
| 435 | |
| 436 // Filter out extensions from the command line. | |
| 437 for (const std::string& disabled_ext : disabled_extensions_vec) { | |
| 438 filtered_exts_.erase(std::remove(filtered_exts_.begin(), | |
| 439 filtered_exts_.end(), | |
| 440 disabled_ext), | |
| 441 filtered_exts_.end()); | |
| 442 } | |
| 443 | |
| 444 // Construct filtered extensions string for GL_EXTENSIONS string lookups. | |
| 445 filtered_exts_str_ = JoinString(filtered_exts_, " "); | |
| 446 | |
| 447 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
| |
| 448 } | |
| 449 } | |
| 450 | |
| 451 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | |
| 452 if (extensions_filtered_ && pname == GL_NUM_EXTENSIONS) { | |
| 453 *params = static_cast<GLint>(filtered_exts_.size()); | |
| 454 } else { | |
| 455 GLApiBase::glGetIntegervFn(pname, params); | |
| 456 } | |
| 457 } | |
| 458 | |
| 459 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { | |
| 460 if (extensions_filtered_ && name == GL_EXTENSIONS) { | |
| 461 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); | |
| 462 } | |
| 463 return GLApiBase::glGetStringFn(name); | |
| 464 } | |
| 465 | |
| 466 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { | |
| 467 if (extensions_filtered_ && name == GL_EXTENSIONS) { | |
| 468 if (index >= filtered_exts_.size()) { | |
| 469 return NULL; | |
| 470 } | |
| 471 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | |
| 472 } | |
| 473 return GLApiBase::glGetStringiFn(name, index); | |
| 408 } | 474 } |
| 409 | 475 |
| 410 void RealGLApi::glFlushFn() { | 476 void RealGLApi::glFlushFn() { |
| 411 GLApiBase::glFlushFn(); | 477 GLApiBase::glFlushFn(); |
| 412 } | 478 } |
| 413 | 479 |
| 414 void RealGLApi::glFinishFn() { | 480 void RealGLApi::glFinishFn() { |
| 415 GLApiBase::glFinishFn(); | 481 GLApiBase::glFinishFn(); |
| 416 } | 482 } |
| 417 | 483 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 } | 588 } |
| 523 | 589 |
| 524 void VirtualGLApi::glFlushFn() { | 590 void VirtualGLApi::glFlushFn() { |
| 525 GLApiBase::glFlushFn(); | 591 GLApiBase::glFlushFn(); |
| 526 } | 592 } |
| 527 | 593 |
| 528 void VirtualGLApi::glFinishFn() { | 594 void VirtualGLApi::glFinishFn() { |
| 529 GLApiBase::glFinishFn(); | 595 GLApiBase::glFinishFn(); |
| 530 } | 596 } |
| 531 | 597 |
| 532 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 598 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi(GLApi* set_api) |
| 533 : old_gl_api_(GetCurrentGLApi()) { | 599 : old_gl_api_(GetCurrentGLApi()) { |
| 534 SetGLToRealGLApi(); | 600 if (set_api) |
| 601 SetGLApi(set_api); | |
| 602 else | |
| 603 SetGLToRealGLApi(); | |
| 535 } | 604 } |
| 536 | 605 |
| 537 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 606 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
| 538 SetGLApi(old_gl_api_); | 607 SetGLApi(old_gl_api_); |
| 539 } | 608 } |
| 540 | 609 |
| 541 } // namespace gfx | 610 } // namespace gfx |
| OLD | NEW |