Add missing mandoline dependencies.
[chromium-blink-merge.git] / ui / gl / gl_egl_api_implementation.cc
blob8acaf0f460d034f71ace4701402c69fc6e69a3d6
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"
13 namespace gfx {
15 RealEGLApi* g_real_egl;
17 void InitializeStaticGLBindingsEGL() {
18 if (!g_real_egl) {
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() {
33 if (g_real_egl) {
34 delete g_real_egl;
35 g_real_egl = NULL;
37 g_current_egl_context = NULL;
38 g_driver_egl.ClearBindings();
41 EGLApi::EGLApi() {
44 EGLApi::~EGLApi() {
47 EGLApiBase::EGLApiBase()
48 : driver_(NULL) {
51 EGLApiBase::~EGLApiBase() {
54 void EGLApiBase::InitializeBase(DriverEGL* driver) {
55 driver_ = 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) {
70 DCHECK(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(),
94 disabled_ext),
95 platform_extensions_vec.end());
96 client_extensions_vec.erase(std::remove(client_extensions_vec.begin(),
97 client_extensions_vec.end(),
98 disabled_ext),
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();
126 if (vendor)
127 info->vendor = vendor;
128 if (version)
129 info->version = version;
130 if (extensions)
131 info->extensions = extensions;
132 return true;
135 } // namespace gfx