OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_egl_api_implementation.h" | 5 #include "ui/gl/gl_egl_api_implementation.h" |
6 | |
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" | |
6 #include "ui/gl/gl_implementation.h" | 11 #include "ui/gl/gl_implementation.h" |
7 | 12 |
8 namespace gfx { | 13 namespace gfx { |
9 | 14 |
10 RealEGLApi* g_real_egl; | 15 RealEGLApi* g_real_egl; |
11 | 16 |
12 void InitializeStaticGLBindingsEGL() { | 17 void InitializeStaticGLBindingsEGL() { |
13 if (!g_real_egl) { | 18 if (!g_real_egl) { |
14 g_real_egl = new RealEGLApi(); | 19 g_real_egl = new RealEGLApi(); |
15 } | 20 } |
16 g_real_egl->Initialize(&g_driver_egl); | 21 g_real_egl->Initialize(&g_driver_egl); |
17 g_current_egl_context = g_real_egl; | 22 g_current_egl_context = g_real_egl; |
18 g_driver_egl.InitializeStaticBindings(); | 23 g_driver_egl.InitializeStaticBindings(); |
19 } | 24 } |
20 | 25 |
26 void InitializeDynamicGLBindingsEGL(GLContext* context) { | |
no sievers
2015/05/28 19:25:10
I had actually previously removed the notion of in
David Yen
2015/06/05 23:59:51
Done.
| |
27 DCHECK(context && context->IsCurrent(NULL)); | |
28 g_real_egl->InitializeWithContext(); | |
29 } | |
30 | |
21 void InitializeDebugGLBindingsEGL() { | 31 void InitializeDebugGLBindingsEGL() { |
22 g_driver_egl.InitializeDebugBindings(); | 32 g_driver_egl.InitializeDebugBindings(); |
23 } | 33 } |
24 | 34 |
25 void ClearGLBindingsEGL() { | 35 void ClearGLBindingsEGL() { |
26 if (g_real_egl) { | 36 if (g_real_egl) { |
27 delete g_real_egl; | 37 delete g_real_egl; |
28 g_real_egl = NULL; | 38 g_real_egl = NULL; |
29 } | 39 } |
30 g_current_egl_context = NULL; | 40 g_current_egl_context = NULL; |
(...skipping 17 matching lines...) Expand all Loading... | |
48 driver_ = driver; | 58 driver_ = driver; |
49 } | 59 } |
50 | 60 |
51 RealEGLApi::RealEGLApi() { | 61 RealEGLApi::RealEGLApi() { |
52 } | 62 } |
53 | 63 |
54 RealEGLApi::~RealEGLApi() { | 64 RealEGLApi::~RealEGLApi() { |
55 } | 65 } |
56 | 66 |
57 void RealEGLApi::Initialize(DriverEGL* driver) { | 67 void RealEGLApi::Initialize(DriverEGL* driver) { |
68 InitializeWithCommandLine(driver, base::CommandLine::ForCurrentProcess()); | |
69 } | |
70 | |
71 void RealEGLApi::InitializeWithCommandLine(DriverEGL* driver, | |
72 base::CommandLine* command_line) { | |
73 DCHECK(command_line); | |
58 InitializeBase(driver); | 74 InitializeBase(driver); |
75 | |
76 const std::string disabled_extensions = command_line->GetSwitchValueASCII( | |
77 switches::kDisableExtensions); | |
78 if (!disabled_extensions.empty()) { | |
79 Tokenize(disabled_extensions, ", ;", &disabled_exts_); | |
80 } | |
81 } | |
82 | |
83 void RealEGLApi::InitializeWithContext() { | |
84 InitializeFilteredExtensions(); | |
85 } | |
86 | |
87 const char* RealEGLApi::eglQueryStringFn(EGLDisplay dpy, EGLint name) { | |
88 if (!filtered_exts_.empty() && name == EGL_EXTENSIONS) { | |
89 return filtered_exts_.c_str(); | |
90 } | |
91 return EGLApiBase::eglQueryStringFn(dpy, name); | |
92 } | |
93 | |
94 void RealEGLApi::InitializeFilteredExtensions() { | |
95 if (!disabled_exts_.empty() && filtered_exts_.empty()) { | |
96 EGLDisplay display = EGLApiBase::eglGetCurrentDisplayFn(); | |
97 std::vector<std::string> extensions_vec; | |
98 const char* egl_extensions = EGLApiBase::eglQueryStringFn(display, | |
no sievers
2015/05/28 19:25:10
You can call DriverEGL::GetPlatformExtensions() an
David Yen
2015/06/05 23:59:51
Done, although I had to make RealEGLApi a friend o
| |
99 EGL_EXTENSIONS); | |
100 if (egl_extensions) | |
101 base::SplitString(egl_extensions, ' ', &extensions_vec); | |
102 | |
103 // Filter out extensions from the command line. | |
104 for (const std::string& disabled_ext : disabled_exts_) { | |
105 extensions_vec.erase(std::remove(extensions_vec.begin(), | |
106 extensions_vec.end(), | |
107 disabled_ext), | |
108 extensions_vec.end()); | |
109 } | |
110 | |
111 // Construct filtered extensions string for GL_EXTENSIONS string lookups. | |
112 filtered_exts_ = JoinString(extensions_vec, " "); | |
113 } | |
59 } | 114 } |
60 | 115 |
61 TraceEGLApi::~TraceEGLApi() { | 116 TraceEGLApi::~TraceEGLApi() { |
62 } | 117 } |
63 | 118 |
64 bool GetGLWindowSystemBindingInfoEGL(GLWindowSystemBindingInfo* info) { | 119 bool GetGLWindowSystemBindingInfoEGL(GLWindowSystemBindingInfo* info) { |
65 EGLDisplay display = eglGetCurrentDisplay(); | 120 EGLDisplay display = eglGetCurrentDisplay(); |
66 const char* vendor = eglQueryString(display, EGL_VENDOR); | 121 const char* vendor = eglQueryString(display, EGL_VENDOR); |
67 const char* version = eglQueryString(display, EGL_VERSION); | 122 const char* version = eglQueryString(display, EGL_VERSION); |
68 const char* extensions = eglQueryString(display, EGL_EXTENSIONS); | 123 const char* extensions = eglQueryString(display, EGL_EXTENSIONS); |
69 *info = GLWindowSystemBindingInfo(); | 124 *info = GLWindowSystemBindingInfo(); |
70 if (vendor) | 125 if (vendor) |
71 info->vendor = vendor; | 126 info->vendor = vendor; |
72 if (version) | 127 if (version) |
73 info->version = version; | 128 info->version = version; |
74 if (extensions) | 129 if (extensions) |
75 info->extensions = extensions; | 130 info->extensions = extensions; |
76 return true; | 131 return true; |
77 } | 132 } |
78 | 133 |
79 } // namespace gfx | 134 } // namespace gfx |
80 | 135 |
81 | 136 |
OLD | NEW |