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_egl_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_context.h"
11 #include "ui/gl/gl_implementation.h"
15 RealEGLApi
* g_real_egl
;
17 void InitializeStaticGLBindingsEGL() {
19 g_real_egl
= new RealEGLApi();
21 g_real_egl
->Initialize(&g_driver_egl
);
22 g_current_egl_context
= g_real_egl
;
23 g_driver_egl
.InitializeStaticBindings();
25 g_real_egl
->InitializeFilteredExtensions();
28 void InitializeDebugGLBindingsEGL() {
29 g_driver_egl
.InitializeDebugBindings();
32 void ClearGLBindingsEGL() {
37 g_current_egl_context
= NULL
;
38 g_driver_egl
.ClearBindings();
47 EGLApiBase::EGLApiBase()
51 EGLApiBase::~EGLApiBase() {
54 void EGLApiBase::InitializeBase(DriverEGL
* driver
) {
58 RealEGLApi::RealEGLApi() {
61 RealEGLApi::~RealEGLApi() {
64 void RealEGLApi::Initialize(DriverEGL
* driver
) {
65 InitializeWithCommandLine(driver
, base::CommandLine::ForCurrentProcess());
68 void RealEGLApi::InitializeWithCommandLine(DriverEGL
* driver
,
69 base::CommandLine
* command_line
) {
71 InitializeBase(driver
);
73 const std::string disabled_extensions
= command_line
->GetSwitchValueASCII(
74 switches::kDisableGLExtensions
);
75 if (!disabled_extensions
.empty()) {
76 Tokenize(disabled_extensions
, ", ;", &disabled_exts_
);
80 void RealEGLApi::InitializeFilteredExtensions() {
81 if (!disabled_exts_
.empty() && filtered_exts_
.empty()) {
82 std::vector
<std::string
> platform_extensions_vec
;
83 std::string platform_ext
= DriverEGL::GetPlatformExtensions();
84 base::SplitString(platform_ext
, ' ', &platform_extensions_vec
);
86 std::vector
<std::string
> client_extensions_vec
;
87 std::string client_ext
= DriverEGL::GetClientExtensions();
88 base::SplitString(client_ext
, ' ', &client_extensions_vec
);
90 // Filter out extensions from the command line.
91 for (const std::string
& disabled_ext
: disabled_exts_
) {
92 platform_extensions_vec
.erase(std::remove(platform_extensions_vec
.begin(),
93 platform_extensions_vec
.end(),
95 platform_extensions_vec
.end());
96 client_extensions_vec
.erase(std::remove(client_extensions_vec
.begin(),
97 client_extensions_vec
.end(),
99 client_extensions_vec
.end());
102 // Construct filtered extensions string for GL_EXTENSIONS string lookups.
103 filtered_exts_
= JoinString(platform_extensions_vec
, " ");
104 if (!platform_extensions_vec
.empty() && !client_extensions_vec
.empty())
105 filtered_exts_
+= " ";
106 filtered_exts_
+= JoinString(client_extensions_vec
, " ");
110 const char* RealEGLApi::eglQueryStringFn(EGLDisplay dpy
, EGLint name
) {
111 if (!filtered_exts_
.empty() && name
== EGL_EXTENSIONS
) {
112 return filtered_exts_
.c_str();
114 return EGLApiBase::eglQueryStringFn(dpy
, name
);
117 TraceEGLApi::~TraceEGLApi() {
120 bool GetGLWindowSystemBindingInfoEGL(GLWindowSystemBindingInfo
* info
) {
121 EGLDisplay display
= eglGetCurrentDisplay();
122 const char* vendor
= eglQueryString(display
, EGL_VENDOR
);
123 const char* version
= eglQueryString(display
, EGL_VERSION
);
124 const char* extensions
= eglQueryString(display
, EGL_EXTENSIONS
);
125 *info
= GLWindowSystemBindingInfo();
127 info
->vendor
= vendor
;
129 info
->version
= version
;
131 info
->extensions
= extensions
;