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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 : driver_(NULL) { | 391 : driver_(NULL) { |
| 391 } | 392 } |
| 392 | 393 |
| 393 GLApiBase::~GLApiBase() { | 394 GLApiBase::~GLApiBase() { |
| 394 } | 395 } |
| 395 | 396 |
| 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() { |
|
no sievers
2015/04/30 20:45:02
That doesn't work. |driver_| will be NULL when Rea
David Yen
2015/04/30 22:14:17
Done.
| |
| 402 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
| 403 const std::string disabled_extensions = cmd_line->GetSwitchValueASCII( | |
| 404 switches::kDisableGLExtensions); | |
| 405 if (!disabled_extensions.empty()) { | |
| 406 std::vector<std::string> disabled_extensions_vec; | |
| 407 Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec); | |
| 408 | |
| 409 // Fill in filtered_exts_ vector first. | |
| 410 if (gfx::GetGLImplementation() != | |
| 411 gfx::kGLImplementationDesktopGLCoreProfile) { | |
| 412 const char* gl_extensions = reinterpret_cast<const char*>( | |
| 413 GLApiBase::glGetStringFn(GL_EXTENSIONS)); | |
| 414 if (gl_extensions) | |
| 415 base::SplitString(gl_extensions, ' ', &filtered_exts_); | |
| 416 } else { | |
| 417 GLint num_extensions = 0; | |
| 418 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | |
| 419 for (GLint i = 0; i < num_extensions; ++i) { | |
| 420 const char* gl_extension = reinterpret_cast<const char*>( | |
| 421 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); | |
| 422 DCHECK(gl_extension != NULL); | |
| 423 filtered_exts_.push_back(gl_extension); | |
| 424 } | |
| 425 } | |
| 426 | |
| 427 // Filter out extensions from the command line. | |
| 428 for (const std::string& disabled_ext : disabled_extensions_vec) { | |
| 429 filtered_exts_.erase(std::remove(filtered_exts_.begin(), | |
|
no sievers
2015/04/30 20:45:02
Actually can you just use std::set<> instead of ve
| |
| 430 filtered_exts_.end(), | |
| 431 disabled_ext), | |
| 432 filtered_exts_.end()); | |
| 433 } | |
| 434 | |
| 435 // Construct filtered extensions string for GL_EXTENSIONS string lookups. | |
| 436 filtered_exts_str_ = JoinString(filtered_exts_, " "); | |
| 437 | |
| 438 extensions_filtered_ = true; | |
|
no sievers
2015/04/30 20:45:02
Why do we need this?
It seems like it would just c
David Yen
2015/04/30 22:14:17
This was originally added to fix the mock interfac
| |
| 439 } | |
| 401 } | 440 } |
| 402 | 441 |
| 403 RealGLApi::~RealGLApi() { | 442 RealGLApi::~RealGLApi() { |
| 404 } | 443 } |
| 405 | 444 |
| 406 void RealGLApi::Initialize(DriverGL* driver) { | 445 void RealGLApi::Initialize(DriverGL* driver) { |
| 407 InitializeBase(driver); | 446 InitializeBase(driver); |
| 408 } | 447 } |
| 409 | 448 |
| 449 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | |
| 450 if (extensions_filtered_ && pname == GL_NUM_EXTENSIONS) { | |
| 451 *params = static_cast<GLint>(filtered_exts_str_.size()); | |
|
Zhenyao Mo
2015/04/29 20:04:23
This is incorrect. I think you mean filtered_ext_.
David Yen
2015/04/30 22:14:17
Ah good catch, Done.
| |
| 452 } else { | |
| 453 GLApiBase::glGetIntegervFn(pname, params); | |
| 454 } | |
| 455 } | |
| 456 | |
| 457 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { | |
| 458 if (extensions_filtered_ && name == GL_EXTENSIONS) { | |
| 459 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); | |
| 460 } | |
| 461 return GLApiBase::glGetStringFn(name); | |
| 462 } | |
| 463 | |
| 464 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { | |
| 465 if (extensions_filtered_ && name == GL_EXTENSIONS) { | |
| 466 if (index >= filtered_exts_.size()) { | |
| 467 return NULL; | |
| 468 } | |
| 469 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | |
| 470 } | |
| 471 return GLApiBase::glGetStringiFn(name, index); | |
| 472 } | |
| 473 | |
| 410 void RealGLApi::glFlushFn() { | 474 void RealGLApi::glFlushFn() { |
| 411 GLApiBase::glFlushFn(); | 475 GLApiBase::glFlushFn(); |
| 412 } | 476 } |
| 413 | 477 |
| 414 void RealGLApi::glFinishFn() { | 478 void RealGLApi::glFinishFn() { |
| 415 GLApiBase::glFinishFn(); | 479 GLApiBase::glFinishFn(); |
| 416 } | 480 } |
| 417 | 481 |
| 418 TraceGLApi::~TraceGLApi() { | 482 TraceGLApi::~TraceGLApi() { |
| 419 } | 483 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 596 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
| 533 : old_gl_api_(GetCurrentGLApi()) { | 597 : old_gl_api_(GetCurrentGLApi()) { |
| 534 SetGLToRealGLApi(); | 598 SetGLToRealGLApi(); |
| 535 } | 599 } |
| 536 | 600 |
| 537 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 601 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
| 538 SetGLApi(old_gl_api_); | 602 SetGLApi(old_gl_api_); |
| 539 } | 603 } |
| 540 | 604 |
| 541 } // namespace gfx | 605 } // namespace gfx |
| OLD | NEW |