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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 SetGLApi(g_no_context_gl); | 325 SetGLApi(g_no_context_gl); |
326 } | 326 } |
327 | 327 |
328 const GLVersionInfo* GetGLVersionInfo() { | 328 const GLVersionInfo* GetGLVersionInfo() { |
329 return g_version_info; | 329 return g_version_info; |
330 } | 330 } |
331 | 331 |
332 void InitializeDynamicGLBindingsGL(GLContext* context) { | 332 void InitializeDynamicGLBindingsGL(GLContext* context) { |
333 g_driver_gl.InitializeCustomDynamicBindings(context); | 333 g_driver_gl.InitializeCustomDynamicBindings(context); |
334 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); | 334 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); |
| 335 g_real_gl->InitializeWithContext(); |
335 g_version_info = new GLVersionInfo( | 336 g_version_info = new GLVersionInfo( |
336 context->GetGLVersion().c_str(), | 337 context->GetGLVersion().c_str(), |
337 context->GetGLRenderer().c_str(), | 338 context->GetGLRenderer().c_str(), |
338 context->GetExtensions().c_str()); | 339 context->GetExtensions().c_str()); |
339 } | 340 } |
340 | 341 |
341 void InitializeDebugGLBindingsGL() { | 342 void InitializeDebugGLBindingsGL() { |
342 g_driver_gl.InitializeDebugBindings(); | 343 g_driver_gl.InitializeDebugBindings(); |
343 } | 344 } |
344 | 345 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 407 |
407 void RealGLApi::Initialize(DriverGL* driver) { | 408 void RealGLApi::Initialize(DriverGL* driver) { |
408 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); | 409 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); |
409 } | 410 } |
410 | 411 |
411 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, | 412 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, |
412 base::CommandLine* command_line) { | 413 base::CommandLine* command_line) { |
413 DCHECK(command_line); | 414 DCHECK(command_line); |
414 InitializeBase(driver); | 415 InitializeBase(driver); |
415 | 416 |
416 DCHECK(filtered_exts_.empty() && filtered_exts_str_.empty()); | |
417 | |
418 const std::string disabled_extensions = command_line->GetSwitchValueASCII( | 417 const std::string disabled_extensions = command_line->GetSwitchValueASCII( |
419 switches::kDisableGLExtensions); | 418 switches::kDisableGLExtensions); |
420 if (!disabled_extensions.empty()) { | 419 if (!disabled_extensions.empty()) { |
421 std::vector<std::string> disabled_extensions_vec; | 420 Tokenize(disabled_extensions, ", ;", &disabled_exts_); |
422 Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec); | 421 } |
| 422 } |
423 | 423 |
424 // Fill in filtered_exts_ vector first. | 424 void RealGLApi::InitializeWithContext() { |
425 if (gfx::GetGLImplementation() != | 425 InitializeFilteredExtensions(); |
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 } | 426 } |
454 | 427 |
455 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | 428 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { |
456 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) { | 429 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) { |
457 *params = static_cast<GLint>(filtered_exts_.size()); | 430 *params = static_cast<GLint>(filtered_exts_.size()); |
458 } else { | 431 } else { |
459 GLApiBase::glGetIntegervFn(pname, params); | 432 GLApiBase::glGetIntegervFn(pname, params); |
460 } | 433 } |
461 } | 434 } |
462 | 435 |
(...skipping 15 matching lines...) Expand all Loading... |
478 } | 451 } |
479 | 452 |
480 void RealGLApi::glFlushFn() { | 453 void RealGLApi::glFlushFn() { |
481 GLApiBase::glFlushFn(); | 454 GLApiBase::glFlushFn(); |
482 } | 455 } |
483 | 456 |
484 void RealGLApi::glFinishFn() { | 457 void RealGLApi::glFinishFn() { |
485 GLApiBase::glFinishFn(); | 458 GLApiBase::glFinishFn(); |
486 } | 459 } |
487 | 460 |
| 461 void RealGLApi::InitializeFilteredExtensions() { |
| 462 if (!disabled_exts_.empty() && filtered_exts_.empty()) { |
| 463 DCHECK(filtered_exts_.empty() && filtered_exts_str_.empty()); |
| 464 // Fill in filtered_exts_ vector first. |
| 465 if (gfx::GetGLImplementation() != |
| 466 gfx::kGLImplementationDesktopGLCoreProfile) { |
| 467 const char* gl_extensions = reinterpret_cast<const char*>( |
| 468 GLApiBase::glGetStringFn(GL_EXTENSIONS)); |
| 469 if (gl_extensions) |
| 470 base::SplitString(gl_extensions, ' ', &filtered_exts_); |
| 471 } else { |
| 472 GLint num_extensions = 0; |
| 473 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| 474 for (GLint i = 0; i < num_extensions; ++i) { |
| 475 const char* gl_extension = reinterpret_cast<const char*>( |
| 476 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); |
| 477 DCHECK(gl_extension != NULL); |
| 478 filtered_exts_.push_back(gl_extension); |
| 479 } |
| 480 } |
| 481 |
| 482 // Filter out extensions from the command line. |
| 483 for (const std::string& disabled_ext : disabled_exts_) { |
| 484 filtered_exts_.erase(std::remove(filtered_exts_.begin(), |
| 485 filtered_exts_.end(), |
| 486 disabled_ext), |
| 487 filtered_exts_.end()); |
| 488 } |
| 489 |
| 490 // Construct filtered extensions string for GL_EXTENSIONS string lookups. |
| 491 filtered_exts_str_ = JoinString(filtered_exts_, " "); |
| 492 } |
| 493 } |
| 494 |
488 TraceGLApi::~TraceGLApi() { | 495 TraceGLApi::~TraceGLApi() { |
489 } | 496 } |
490 | 497 |
491 NoContextGLApi::NoContextGLApi() { | 498 NoContextGLApi::NoContextGLApi() { |
492 } | 499 } |
493 | 500 |
494 NoContextGLApi::~NoContextGLApi() { | 501 NoContextGLApi::~NoContextGLApi() { |
495 } | 502 } |
496 | 503 |
497 VirtualGLApi::VirtualGLApi() | 504 VirtualGLApi::VirtualGLApi() |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 609 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
603 : old_gl_api_(GetCurrentGLApi()) { | 610 : old_gl_api_(GetCurrentGLApi()) { |
604 SetGLToRealGLApi(); | 611 SetGLToRealGLApi(); |
605 } | 612 } |
606 | 613 |
607 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 614 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
608 SetGLApi(old_gl_api_); | 615 SetGLApi(old_gl_api_); |
609 } | 616 } |
610 | 617 |
611 } // namespace gfx | 618 } // namespace gfx |
OLD | NEW |