Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: ui/gl/gl_gl_api_implementation.cc

Issue 1110923003: Added switch to disable specified GL extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added gl_api_unittest under gfx_unittests Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 filtered_exts_.clear();
417 filtered_exts_str_.clear();
no sievers 2015/05/01 21:55:00 Is this because of some unittests? Can we clear th
David Yen 2015/05/01 22:34:38 These are per instance of the class though, ClearG
418
419 const std::string disabled_extensions = command_line->GetSwitchValueASCII(
420 switches::kDisableGLExtensions);
421 if (!disabled_extensions.empty()) {
422 std::vector<std::string> disabled_extensions_vec;
423 Tokenize(disabled_extensions, ", ;", &disabled_extensions_vec);
424
425 // Fill in filtered_exts_ vector first.
426 if (gfx::GetGLImplementation() !=
427 gfx::kGLImplementationDesktopGLCoreProfile) {
428 const char* gl_extensions = reinterpret_cast<const char*>(
429 GLApiBase::glGetStringFn(GL_EXTENSIONS));
430 if (gl_extensions)
431 base::SplitString(gl_extensions, ' ', &filtered_exts_);
432 } else {
433 GLint num_extensions = 0;
434 GLApiBase::glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions);
435 for (GLint i = 0; i < num_extensions; ++i) {
436 const char* gl_extension = reinterpret_cast<const char*>(
437 GLApiBase::glGetStringiFn(GL_EXTENSIONS, i));
438 DCHECK(gl_extension != NULL);
439 filtered_exts_.push_back(gl_extension);
440 }
441 }
442
443 // Filter out extensions from the command line.
444 for (const std::string& disabled_ext : disabled_extensions_vec) {
445 filtered_exts_.erase(std::remove(filtered_exts_.begin(),
446 filtered_exts_.end(),
447 disabled_ext),
448 filtered_exts_.end());
449 }
450
451 // Construct filtered extensions string for GL_EXTENSIONS string lookups.
452 filtered_exts_str_ = JoinString(filtered_exts_, " ");
453 }
454 }
455
456 void RealGLApi::glGetIntegervFn(GLenum pname, GLint* params) {
457 if (!filtered_exts_.empty() && pname == GL_NUM_EXTENSIONS) {
no sievers 2015/05/01 21:55:00 nit: should it be DCHECK(!filtered_exts_.empty())
David Yen 2015/05/01 22:34:38 These are only filled if there are extensions disa
458 *params = static_cast<GLint>(filtered_exts_.size());
459 } else {
460 GLApiBase::glGetIntegervFn(pname, params);
461 }
462 }
463
464 const GLubyte* RealGLApi::glGetStringFn(GLenum name) {
465 if (!filtered_exts_.empty() && name == GL_EXTENSIONS) {
466 return reinterpret_cast<const GLubyte*>(filtered_exts_str_.c_str());
467 }
468 return GLApiBase::glGetStringFn(name);
469 }
470
471 const GLubyte* RealGLApi::glGetStringiFn(GLenum name, GLuint index) {
472 if (!filtered_exts_str_.empty() && name == GL_EXTENSIONS) {
473 if (index >= filtered_exts_.size()) {
474 return NULL;
475 }
476 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str());
477 }
478 return GLApiBase::glGetStringiFn(name, index);
408 } 479 }
409 480
410 void RealGLApi::glFlushFn() { 481 void RealGLApi::glFlushFn() {
411 GLApiBase::glFlushFn(); 482 GLApiBase::glFlushFn();
412 } 483 }
413 484
414 void RealGLApi::glFinishFn() { 485 void RealGLApi::glFinishFn() {
415 GLApiBase::glFinishFn(); 486 GLApiBase::glFinishFn();
416 } 487 }
417 488
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi() 603 ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi()
533 : old_gl_api_(GetCurrentGLApi()) { 604 : old_gl_api_(GetCurrentGLApi()) {
534 SetGLToRealGLApi(); 605 SetGLToRealGLApi();
535 } 606 }
536 607
537 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() { 608 ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() {
538 SetGLApi(old_gl_api_); 609 SetGLApi(old_gl_api_);
539 } 610 }
540 611
541 } // namespace gfx 612 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698