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_real_gl->InitializeWithContext(); |
340 g_version_info = new GLVersionInfo( | 341 g_version_info = new GLVersionInfo( |
341 context->GetGLVersion().c_str(), | 342 context->GetGLVersion().c_str(), |
342 context->GetGLRenderer().c_str(), | 343 context->GetGLRenderer().c_str(), |
343 context->GetExtensions().c_str()); | 344 context->GetExtensions().c_str()); |
344 } | 345 } |
345 | 346 |
346 void InitializeDebugGLBindingsGL() { | 347 void InitializeDebugGLBindingsGL() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 } | 398 } |
398 | 399 |
399 GLApiBase::~GLApiBase() { | 400 GLApiBase::~GLApiBase() { |
400 } | 401 } |
401 | 402 |
402 void GLApiBase::InitializeBase(DriverGL* driver) { | 403 void GLApiBase::InitializeBase(DriverGL* driver) { |
403 driver_ = driver; | 404 driver_ = driver; |
404 } | 405 } |
405 | 406 |
406 RealGLApi::RealGLApi() { | 407 RealGLApi::RealGLApi() { |
408 #if DCHECK_IS_ON() | |
409 filtered_exts_initialized_ = false; | |
410 #endif | |
407 } | 411 } |
408 | 412 |
409 RealGLApi::~RealGLApi() { | 413 RealGLApi::~RealGLApi() { |
410 } | 414 } |
411 | 415 |
412 void RealGLApi::Initialize(DriverGL* driver) { | 416 void RealGLApi::Initialize(DriverGL* driver) { |
413 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); | 417 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); |
414 } | 418 } |
415 | 419 |
416 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, | 420 void RealGLApi::InitializeWithCommandLine(DriverGL* driver, |
417 base::CommandLine* command_line) { | 421 base::CommandLine* command_line) { |
418 DCHECK(command_line); | 422 DCHECK(command_line); |
419 InitializeBase(driver); | 423 InitializeBase(driver); |
420 | 424 |
421 const std::string disabled_extensions = command_line->GetSwitchValueASCII( | 425 const std::string disabled_extensions = command_line->GetSwitchValueASCII( |
422 switches::kDisableGLExtensions); | 426 switches::kDisableGLExtensions); |
423 if (!disabled_extensions.empty()) { | 427 if (!disabled_extensions.empty()) { |
424 disabled_exts_ = base::SplitString( | 428 disabled_exts_ = base::SplitString( |
425 disabled_extensions, ", ;", | 429 disabled_extensions, ", ;", |
426 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 430 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
427 } | 431 } |
428 } | 432 } |
429 | 433 |
430 void RealGLApi::InitializeWithContext() { | 434 void RealGLApi::InitializeWithContext() { |
no sievers
2015/07/23 23:45:57
So this method can go?
Tobias Sargeant
2015/07/24 09:29:14
Yes.
| |
431 InitializeFilteredExtensions(); | |
432 } | 435 } |
433 | 436 |
434 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | 437 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { |
435 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) { | 438 if (pname == GL_NUM_EXTENSIONS && disabled_exts_.size()) { |
439 #if DCHECK_IS_ON() | |
no sievers
2015/07/23 23:45:57
nit: #if DCHECK_IS_ON is redundant here and below
Tobias Sargeant
2015/07/24 09:29:15
I thought so too, but it turns out that because it
| |
440 DCHECK(filtered_exts_initialized_); | |
441 #endif | |
436 *params = static_cast<GLint>(filtered_exts_.size()); | 442 *params = static_cast<GLint>(filtered_exts_.size()); |
437 } else { | 443 } else { |
438 GLApiBase::glGetIntegervFn(pname, params); | 444 GLApiBase::glGetIntegervFn(pname, params); |
439 } | 445 } |
440 } | 446 } |
441 | 447 |
442 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { | 448 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { |
443 if (!filtered_exts_.empty() && name == GL_EXTENSIONS) { | 449 if (name == GL_EXTENSIONS && disabled_exts_.size()) { |
450 #if DCHECK_IS_ON() | |
451 DCHECK(filtered_exts_initialized_); | |
452 #endif | |
444 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); | 453 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); |
445 } | 454 } |
446 return GLApiBase::glGetStringFn(name); | 455 return GLApiBase::glGetStringFn(name); |
447 } | 456 } |
448 | 457 |
449 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { | 458 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { |
450 if (!filtered_exts_str_.empty() && name == GL_EXTENSIONS) { | 459 if (name == GL_EXTENSIONS && disabled_exts_.size()) { |
460 #if DCHECK_IS_ON() | |
461 DCHECK(filtered_exts_initialized_); | |
462 #endif | |
451 if (index >= filtered_exts_.size()) { | 463 if (index >= filtered_exts_.size()) { |
452 return NULL; | 464 return NULL; |
453 } | 465 } |
454 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | 466 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); |
455 } | 467 } |
456 return GLApiBase::glGetStringiFn(name, index); | 468 return GLApiBase::glGetStringiFn(name, index); |
457 } | 469 } |
458 | 470 |
459 void RealGLApi::glFlushFn() { | 471 void RealGLApi::glFlushFn() { |
460 GLApiBase::glFlushFn(); | 472 GLApiBase::glFlushFn(); |
461 } | 473 } |
462 | 474 |
463 void RealGLApi::glFinishFn() { | 475 void RealGLApi::glFinishFn() { |
464 GLApiBase::glFinishFn(); | 476 GLApiBase::glFinishFn(); |
465 } | 477 } |
466 | 478 |
467 void RealGLApi::InitializeFilteredExtensions() { | 479 void RealGLApi::InitializeFilteredExtensions() { |
468 if (!disabled_exts_.empty() && filtered_exts_.empty()) { | 480 if (disabled_exts_.size()) { |
469 DCHECK(filtered_exts_.empty() && filtered_exts_str_.empty()); | 481 filtered_exts_.clear(); |
470 // Fill in filtered_exts_ vector first. | |
471 if (gfx::GetGLImplementation() != | 482 if (gfx::GetGLImplementation() != |
472 gfx::kGLImplementationDesktopGLCoreProfile) { | 483 gfx::kGLImplementationDesktopGLCoreProfile) { |
473 const char* gl_extensions = reinterpret_cast<const char*>( | 484 filtered_exts_str_ = |
474 GLApiBase::glGetStringFn(GL_EXTENSIONS)); | 485 FilterGLExtensionList(reinterpret_cast<const char*>( |
no sievers
2015/07/23 23:45:57
Hmm a bit back and forth going on in here (vector
Tobias Sargeant
2015/07/24 09:29:14
I agree, but I felt that the smaller code offset t
| |
475 if (gl_extensions) { | 486 GLApiBase::glGetStringFn(GL_EXTENSIONS)), |
476 filtered_exts_ = base::SplitString( | 487 disabled_exts_); |
477 gl_extensions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 488 base::SplitString(filtered_exts_str_, ' ', &filtered_exts_); |
478 } | |
479 } else { | 489 } else { |
480 GLint num_extensions = 0; | 490 GLint num_extensions = 0; |
481 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | 491 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
482 for (GLint i = 0; i < num_extensions; ++i) { | 492 for (GLint i = 0; i < num_extensions; ++i) { |
483 const char* gl_extension = reinterpret_cast<const char*>( | 493 const char* gl_extension = reinterpret_cast<const char*>( |
484 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); | 494 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); |
485 DCHECK(gl_extension != NULL); | 495 DCHECK(gl_extension != NULL); |
486 filtered_exts_.push_back(gl_extension); | 496 if (std::find(disabled_exts_.begin(), disabled_exts_.end(), |
497 gl_extension) == disabled_exts_.end()) { | |
498 filtered_exts_.push_back(gl_extension); | |
499 } | |
487 } | 500 } |
501 filtered_exts_str_ = base::JoinString(filtered_exts_, " "); | |
488 } | 502 } |
489 | 503 #if DCHECK_IS_ON() |
490 // Filter out extensions from the command line. | 504 filtered_exts_initialized_ = true; |
491 for (const std::string& disabled_ext : disabled_exts_) { | 505 #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 } | 506 } |
501 } | 507 } |
502 | 508 |
503 TraceGLApi::~TraceGLApi() { | 509 TraceGLApi::~TraceGLApi() { |
504 } | 510 } |
505 | 511 |
506 NoContextGLApi::NoContextGLApi() { | 512 NoContextGLApi::NoContextGLApi() { |
507 } | 513 } |
508 | 514 |
509 NoContextGLApi::~NoContextGLApi() { | 515 NoContextGLApi::~NoContextGLApi() { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 623 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
618 : old_gl_api_(GetCurrentGLApi()) { | 624 : old_gl_api_(GetCurrentGLApi()) { |
619 SetGLToRealGLApi(); | 625 SetGLToRealGLApi(); |
620 } | 626 } |
621 | 627 |
622 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 628 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
623 SetGLApi(old_gl_api_); | 629 SetGLApi(old_gl_api_); |
624 } | 630 } |
625 | 631 |
626 } // namespace gfx | 632 } // namespace gfx |
OLD | NEW |