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"
14 RealGLXApi
* g_real_glx
;
16 void InitializeStaticGLBindingsGLX() {
17 g_driver_glx
.InitializeStaticBindings();
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() {
35 g_current_glx_context
= NULL
;
36 g_driver_glx
.ClearBindings();
45 GLXApiBase::GLXApiBase()
49 GLXApiBase::~GLXApiBase() {
52 void GLXApiBase::InitializeBase(DriverGLX
* 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
) {
69 InitializeBase(driver
);
71 const std::string disabled_extensions
= command_line
->GetSwitchValueASCII(
72 switches::kDisableGLExtensions
);
73 disabled_exts_
.clear();
75 if (!disabled_extensions
.empty()) {
77 base::SplitString(disabled_extensions
, ", ;",
78 base::KEEP_WHITESPACE
,
79 base::SPLIT_WANT_NONEMPTY
);
83 const char* RealGLXApi::glXQueryExtensionsStringFn(Display
* dpy
,
85 if (filtered_exts_
.size())
86 return filtered_exts_
.c_str();
88 if (!driver_
->fn
.glXQueryExtensionsStringFn
)
91 const char* str
= GLXApiBase::glXQueryExtensionsStringFn(dpy
, screen
);
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;
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();
113 info
->vendor
= vendor
;
115 info
->version
= version
;
117 info
->extensions
= extensions
;
118 info
->direct_rendering
= !!glXIsDirect(display
, glXGetCurrentContext());