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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
407 InitializeBase(driver); | 408 InitializeBase(driver); |
408 } | 409 } |
409 | 410 |
411 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | |
412 if (pname == GL_NUM_EXTENSIONS) { | |
413 BuildFilteredExtensions(); | |
no sievers
2015/04/29 18:48:10
Can we do this once from initialization instead of
David Yen
2015/04/29 19:23:09
Done.
| |
414 *params = static_cast<GLint>(filtered_exts_str_.size()); | |
415 return; | |
416 } | |
417 GLApiBase::glGetIntegervFn(pname, params); | |
418 } | |
419 | |
420 const GLubyte* RealGLApi::glGetStringFn(GLenum name) { | |
no sievers
2015/04/29 18:48:10
You have to do the same thing for VirtualGLApi als
David Yen
2015/04/29 19:23:09
The VirtualGLApi obtains the list of extensions fr
no sievers
2015/04/30 20:45:02
Yes, we should fix those functions too. But that s
David Yen
2015/04/30 22:14:17
Acknowledged.
| |
421 if (name == GL_EXTENSIONS) { | |
422 BuildFilteredExtensions(); | |
423 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str()); | |
424 } | |
425 return GLApiBase::glGetStringFn(name); | |
426 } | |
427 | |
428 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) { | |
429 if (name == GL_EXTENSIONS) { | |
430 BuildFilteredExtensions(); | |
431 if (index >= filtered_exts_.size()) { | |
432 return NULL; | |
433 } | |
434 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | |
435 } | |
436 return GLApiBase::glGetStringiFn(name, index); | |
437 } | |
438 | |
410 void RealGLApi::glFlushFn() { | 439 void RealGLApi::glFlushFn() { |
411 GLApiBase::glFlushFn(); | 440 GLApiBase::glFlushFn(); |
412 } | 441 } |
413 | 442 |
414 void RealGLApi::glFinishFn() { | 443 void RealGLApi::glFinishFn() { |
415 GLApiBase::glFinishFn(); | 444 GLApiBase::glFinishFn(); |
416 } | 445 } |
417 | 446 |
447 void RealGLApi::BuildFilteredExtensions() { | |
448 if (filtered_exts_.empty()) { | |
449 if (gfx::GetGLImplementation() != | |
450 gfx::kGLImplementationDesktopGLCoreProfile) { | |
451 base::SplitString( | |
452 reinterpret_cast<const char*>( | |
453 GLApiBase::glGetStringFn(GL_EXTENSIONS)), | |
454 ' ', | |
455 &filtered_exts_); | |
456 } else { | |
457 GLint num_extensions = 0; | |
458 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | |
459 for (GLint i = 0; i < num_extensions; ++i) { | |
460 const char* extension = reinterpret_cast<const char*>( | |
461 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i)); | |
462 DCHECK(extension != NULL); | |
463 filtered_exts_.push_back(extension); | |
464 } | |
465 } | |
466 | |
467 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
468 const std::string disabled_extensions = cmd_line->GetSwitchValueASCII( | |
469 switches::kDisableGLExtensions); | |
470 if (!disabled_extensions.empty()) { | |
471 std::vector<std::string> disabled_extensions_list; | |
472 Tokenize(disabled_extensions, ", ;", &disabled_extensions_list); | |
473 | |
474 auto ext_iter = filtered_exts_.begin(); | |
475 while (ext_iter != filtered_exts_.end()) { | |
476 bool filtered = false; | |
no sievers
2015/04/29 18:48:10
nit:
Is it maybe slightly simpler to iterate over
David Yen
2015/04/29 19:23:09
I've changed it to use std::remove instead.
| |
477 for (const std::string& disabled_ext : disabled_extensions_list) { | |
478 if (*ext_iter == disabled_ext) { | |
479 filtered = true; | |
480 break; | |
481 } | |
482 } | |
483 | |
484 if (filtered) { | |
485 ext_iter = filtered_exts_.erase(ext_iter); | |
486 } else { | |
487 ++ext_iter; | |
488 } | |
489 } | |
490 } | |
491 | |
492 filtered_exts_str_ = JoinString(filtered_exts_, " "); | |
493 } | |
494 } | |
495 | |
418 TraceGLApi::~TraceGLApi() { | 496 TraceGLApi::~TraceGLApi() { |
419 } | 497 } |
420 | 498 |
421 NoContextGLApi::NoContextGLApi() { | 499 NoContextGLApi::NoContextGLApi() { |
422 } | 500 } |
423 | 501 |
424 NoContextGLApi::~NoContextGLApi() { | 502 NoContextGLApi::~NoContextGLApi() { |
425 } | 503 } |
426 | 504 |
427 VirtualGLApi::VirtualGLApi() | 505 VirtualGLApi::VirtualGLApi() |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() | 610 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() |
533 : old_gl_api_(GetCurrentGLApi()) { | 611 : old_gl_api_(GetCurrentGLApi()) { |
534 SetGLToRealGLApi(); | 612 SetGLToRealGLApi(); |
535 } | 613 } |
536 | 614 |
537 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { | 615 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { |
538 SetGLApi(old_gl_api_); | 616 SetGLApi(old_gl_api_); |
539 } | 617 } |
540 | 618 |
541 } // namespace gfx | 619 } // namespace gfx |
OLD | NEW |