| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 g_real_gl->Initialize(&g_driver_gl); | 303 g_real_gl->Initialize(&g_driver_gl); |
| 303 g_gl = g_real_gl; | 304 g_gl = g_real_gl; |
| 304 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 305 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 305 switches::kEnableGPUServiceTracing)) { | 306 switches::kEnableGPUServiceTracing)) { |
| 306 g_gl = g_trace_gl; | 307 g_gl = g_trace_gl; |
| 307 } | 308 } |
| 308 SetGLToRealGLApi(); | 309 SetGLToRealGLApi(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 GLApi* GetCurrentGLApi() { | 312 GLApi* GetCurrentGLApi() { |
| 312 return g_current_gl_context_tls->Get(); | 313 return g_current_gl_context_tls ? g_current_gl_context_tls->Get() : nullptr; |
| 313 } | 314 } |
| 314 | 315 |
| 315 void SetGLApi(GLApi* api) { | 316 void SetGLApi(GLApi* api) { |
| 316 g_current_gl_context_tls->Set(api); | 317 g_current_gl_context_tls->Set(api); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void SetGLToRealGLApi() { | 320 void SetGLToRealGLApi() { |
| 320 SetGLApi(g_gl); | 321 SetGLApi(g_gl); |
| 321 } | 322 } |
| 322 | 323 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 408 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); |
| 409 } |
| 410 |
| 411 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, |
| 412 base::CommandLine* command_line) { |
| 413 DCHECK(command_line); |
| 407 InitializeBase(driver); | 414 InitializeBase(driver); |
| 415 |
| 416 DCHECK(filtered_exts_.empty() && filtered_exts_str_.empty()); |
| 417 |
| 418 const std::string disabled_extensions = command_line->GetSwitchValueASCII( |
| 419 switches::kDisableGLExtensions); |
| 420 if (!disabled_extensions.empty()) { |
| 421 std::vector<std::string> disabled_extensions_vec; |
| 422 Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec); |
| 423 |
| 424 // Fill in filtered_exts_ vector first. |
| 425 if (gfx::GetGLImplementation() != |
| 426 gfx::kGLImplementationDesktopGLCoreProfile) { |
| 427 const char* gl_extensions = reinterpret_cast<const char*>( |
| 428 GLApiBase::glGetStringFn(GL_EXTENSIONS)); |
| 429 if (gl_extensions) |
| 430 base::SplitString(gl_extensions, ' ', &filtered_exts_); |
| 431 } else { |
| 432 GLint num_extensions = 0; |
| 433 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| 434 for (GLint i = 0; i < num_extensions; ++i) { |
| 435 const char* gl_extension = reinterpret_cast<const char*>( |
| 436 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); |
| 437 DCHECK(gl_extension != NULL); |
| 438 filtered_exts_.push_back(gl_extension); |
| 439 } |
| 440 } |
| 441 |
| 442 // Filter out extensions from the command line. |
| 443 for (const std::string& disabled_ext : disabled_extensions_vec) { |
| 444 filtered_exts_.erase(std::remove(filtered_exts_.begin(), |
| 445 filtered_exts_.end(), |
| 446 disabled_ext), |
| 447 filtered_exts_.end()); |
| 448 } |
| 449 |
| 450 // Construct filtered extensions string for GL_EXTENSIONS string lookups. |
| 451 filtered_exts_str_ = JoinString(filtered_exts_, " "); |
| 452 } |
| 453 } |
| 454 |
| 455 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { |
| 456 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) { |
| 457 *params = static_cast<GLint>(filtered_exts_.size()); |
| 458 } else { |
| 459 GLApiBase::glGetIntegervFn(pname, params); |
| 460 } |
| 461 } |
| 462 |
| 463 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { |
| 464 if (!filtered_exts_.empty() && name == GL_EXTENSIONS) { |
| 465 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); |
| 466 } |
| 467 return GLApiBase::glGetStringFn(name); |
| 468 } |
| 469 |
| 470 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { |
| 471 if (!filtered_exts_str_.empty() && name == GL_EXTENSIONS) { |
| 472 if (index >= filtered_exts_.size()) { |
| 473 return NULL; |
| 474 } |
| 475 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); |
| 476 } |
| 477 return GLApiBase::glGetStringiFn(name, index); |
| 408 } | 478 } |
| 409 | 479 |
| 410 void RealGLApi::glFlushFn() { | 480 void RealGLApi::glFlushFn() { |
| 411 GLApiBase::glFlushFn(); | 481 GLApiBase::glFlushFn(); |
| 412 } | 482 } |
| 413 | 483 |
| 414 void RealGLApi::glFinishFn() { | 484 void RealGLApi::glFinishFn() { |
| 415 GLApiBase::glFinishFn(); | 485 GLApiBase::glFinishFn(); |
| 416 } | 486 } |
| 417 | 487 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 602 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
| 533 : old_gl_api_(GetCurrentGLApi()) { | 603 : old_gl_api_(GetCurrentGLApi()) { |
| 534 SetGLToRealGLApi(); | 604 SetGLToRealGLApi(); |
| 535 } | 605 } |
| 536 | 606 |
| 537 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 607 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
| 538 SetGLApi(old_gl_api_); | 608 SetGLApi(old_gl_api_); |
| 539 } | 609 } |
| 540 | 610 |
| 541 } // namespace gfx | 611 } // namespace gfx |
| OLD | NEW |