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() {
18 g_driver_egl
.InitializeStaticBindings();
20 g_real_egl
= new RealEGLApi();
22 g_real_egl
->Initialize(&g_driver_egl
);
23 g_current_egl_context
= g_real_egl
;
24 g_driver_egl
.InitializeExtensionBindings();
27 void InitializeDebugGLBindingsEGL() {
28 g_driver_egl
.InitializeDebugBindings();
31 void ClearGLBindingsEGL() {
36 g_current_egl_context
= NULL
;
37 g_driver_egl
.ClearBindings();
46 EGLApiBase::EGLApiBase()
50 EGLApiBase::~EGLApiBase() {
53 void EGLApiBase::InitializeBase(DriverEGL
* driver
) {
57 RealEGLApi::RealEGLApi() {
60 RealEGLApi::~RealEGLApi() {
63 void RealEGLApi::Initialize(DriverEGL
* driver
) {
64 InitializeWithCommandLine(driver
, base::CommandLine::ForCurrentProcess());
67 void RealEGLApi::InitializeWithCommandLine(DriverEGL
* driver
,
68 base::CommandLine
* command_line
) {
70 InitializeBase(driver
);
72 const std::string disabled_extensions
= command_line
->GetSwitchValueASCII(
73 switches::kDisableGLExtensions
);
74 disabled_exts_
.clear();
75 filtered_exts_
.clear();
76 if (!disabled_extensions
.empty()) {
77 disabled_exts_
= base::SplitString(
78 disabled_extensions
, ", ;",
79 base::KEEP_WHITESPACE
, base::SPLIT_WANT_NONEMPTY
);
83 const char* RealEGLApi::eglQueryStringFn(EGLDisplay dpy
, EGLint name
) {
84 if (name
== EGL_EXTENSIONS
) {
85 auto it
= filtered_exts_
.find(dpy
);
86 if (it
== filtered_exts_
.end()) {
87 it
= filtered_exts_
.insert(std::make_pair(
88 dpy
, FilterGLExtensionList(EGLApiBase::eglQueryStringFn(dpy
, name
),
89 disabled_exts_
))).first
;
91 return (*it
).second
.c_str();
93 return EGLApiBase::eglQueryStringFn(dpy
, name
);
96 TraceEGLApi::~TraceEGLApi() {
99 bool GetGLWindowSystemBindingInfoEGL(GLWindowSystemBindingInfo
* info
) {
100 EGLDisplay display
= eglGetCurrentDisplay();
101 const char* vendor
= eglQueryString(display
, EGL_VENDOR
);
102 const char* version
= eglQueryString(display
, EGL_VERSION
);
103 const char* extensions
= eglQueryString(display
, EGL_EXTENSIONS
);
104 *info
= GLWindowSystemBindingInfo();
106 info
->vendor
= vendor
;
108 info
->version
= version
;
110 info
->extensions
= extensions
;