Shorten audio_modem test_support target to just "test_support".
[chromium-blink-merge.git] / ui / gl / gl_glx_api_implementation.cc
blob703563f11251afd0d5e0f4c86309adeb89c474d6
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
3 // found in the LICENSE file.
5 #include "ui/gl/gl_glx_api_implementation.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h"
10 #include "ui/gl/gl_implementation.h"
12 namespace gfx {
14 RealGLXApi* g_real_glx;
16 void InitializeStaticGLBindingsGLX() {
17 g_driver_glx.InitializeStaticBindings();
18 if (!g_real_glx) {
19 g_real_glx = new RealGLXApi();
21 g_real_glx->Initialize(&g_driver_glx);
22 g_current_glx_context = g_real_glx;
23 g_driver_glx.InitializeExtensionBindings();
26 void InitializeDebugGLBindingsGLX() {
27 g_driver_glx.InitializeDebugBindings();
30 void ClearGLBindingsGLX() {
31 if (g_real_glx) {
32 delete g_real_glx;
33 g_real_glx = NULL;
35 g_current_glx_context = NULL;
36 g_driver_glx.ClearBindings();
39 GLXApi::GLXApi() {
42 GLXApi::~GLXApi() {
45 GLXApiBase::GLXApiBase()
46 : driver_(NULL) {
49 GLXApiBase::~GLXApiBase() {
52 void GLXApiBase::InitializeBase(DriverGLX* driver) {
53 driver_ = driver;
56 RealGLXApi::RealGLXApi() {
59 RealGLXApi::~RealGLXApi() {
62 void RealGLXApi::Initialize(DriverGLX* driver) {
63 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess());
66 void RealGLXApi::InitializeWithCommandLine(DriverGLX* driver,
67 base::CommandLine* command_line) {
68 DCHECK(command_line);
69 InitializeBase(driver);
71 const std::string disabled_extensions = command_line->GetSwitchValueASCII(
72 switches::kDisableGLExtensions);
73 disabled_exts_.clear();
74 filtered_exts_ = "";
75 if (!disabled_extensions.empty()) {
76 disabled_exts_ =
77 base::SplitString(disabled_extensions, ", ;",
78 base::KEEP_WHITESPACE,
79 base::SPLIT_WANT_NONEMPTY);
83 const char* RealGLXApi::glXQueryExtensionsStringFn(Display* dpy,
84 int screen) {
85 if (filtered_exts_.size())
86 return filtered_exts_.c_str();
88 if (!driver_->fn.glXQueryExtensionsStringFn)
89 return NULL;
91 const char* str = GLXApiBase::glXQueryExtensionsStringFn(dpy, screen);
92 if (!str)
93 return NULL;
95 filtered_exts_ = FilterGLExtensionList(str, disabled_exts_);
96 return filtered_exts_.c_str();
99 TraceGLXApi::~TraceGLXApi() {
102 bool GetGLWindowSystemBindingInfoGLX(GLWindowSystemBindingInfo* info) {
103 Display* display = glXGetCurrentDisplay();
104 const int kDefaultScreen = 0;
105 const char* vendor =
106 glXQueryServerString(display, kDefaultScreen, GLX_VENDOR);
107 const char* version =
108 glXQueryServerString(display, kDefaultScreen, GLX_VERSION);
109 const char* extensions =
110 glXQueryServerString(display, kDefaultScreen, GLX_EXTENSIONS);
111 *info = GLWindowSystemBindingInfo();
112 if (vendor)
113 info->vendor = vendor;
114 if (version)
115 info->version = version;
116 if (extensions)
117 info->extensions = extensions;
118 info->direct_rendering = !!glXIsDirect(display, glXGetCurrentContext());
119 return true;
122 } // namespace gfx