Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: ui/gl/init/gl_initializer_x11.cc

Issue 2099163003: Revert of Move static GL binding initialization to //ui/gl/init. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gl/init/gl_initializer_win.cc ('k') | ui/gl/test/gl_image_test_support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/init/gl_initializer.h" 5 #include "ui/gl/init/gl_initializer.h"
6 6
7 #include "base/command_line.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/path_service.h" 8 #include "ui/gl/gl_implementation.h"
10 #include "base/threading/thread_restrictions.h"
11 #include "build/build_config.h"
12 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_egl_api_implementation.h"
14 #include "ui/gl/gl_gl_api_implementation.h"
15 #include "ui/gl/gl_glx_api_implementation.h"
16 #include "ui/gl/gl_implementation_osmesa.h"
17 #include "ui/gl/gl_osmesa_api_implementation.h"
18 #include "ui/gl/gl_surface_egl.h" 9 #include "ui/gl/gl_surface_egl.h"
19 #include "ui/gl/gl_surface_glx.h" 10 #include "ui/gl/gl_surface_glx.h"
20 #include "ui/gl/gl_surface_osmesa_x11.h" 11 #include "ui/gl/gl_surface_osmesa_x11.h"
21 #include "ui/gl/gl_switches.h"
22 12
23 namespace gl { 13 namespace gl {
24 namespace init { 14 namespace init {
25 15
26 namespace {
27
28 #if defined(OS_OPENBSD)
29 const char kGLLibraryName[] = "libGL.so";
30 #else
31 const char kGLLibraryName[] = "libGL.so.1";
32 #endif
33
34 const char kGLESv2LibraryName[] = "libGLESv2.so.2";
35 const char kEGLLibraryName[] = "libEGL.so.1";
36
37 const char kGLESv2ANGLELibraryName[] = "libGLESv2.so";
38 const char kEGLANGLELibraryName[] = "libEGL.so";
39
40 bool InitializeStaticGLXInternal() {
41 base::NativeLibrary library = NULL;
42 const base::CommandLine* command_line =
43 base::CommandLine::ForCurrentProcess();
44
45 if (command_line->HasSwitch(switches::kTestGLLib))
46 library = LoadLibraryAndPrintError(
47 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str());
48
49 if (!library) {
50 library = LoadLibraryAndPrintError(kGLLibraryName);
51 }
52
53 if (!library)
54 return false;
55
56 GLGetProcAddressProc get_proc_address =
57 reinterpret_cast<GLGetProcAddressProc>(
58 base::GetFunctionPointerFromNativeLibrary(library,
59 "glXGetProcAddress"));
60 if (!get_proc_address) {
61 LOG(ERROR) << "glxGetProcAddress not found.";
62 base::UnloadNativeLibrary(library);
63 return false;
64 }
65
66 SetGLGetProcAddressProc(get_proc_address);
67 AddGLNativeLibrary(library);
68 SetGLImplementation(kGLImplementationDesktopGL);
69
70 InitializeStaticGLBindingsGL();
71 InitializeStaticGLBindingsGLX();
72
73 return true;
74 }
75
76 bool InitializeStaticEGLInternal() {
77 base::FilePath glesv2_path(kGLESv2LibraryName);
78 base::FilePath egl_path(kEGLLibraryName);
79
80 const base::CommandLine* command_line =
81 base::CommandLine::ForCurrentProcess();
82 if (command_line->GetSwitchValueASCII(switches::kUseGL) ==
83 kGLImplementationANGLEName) {
84 base::FilePath module_path;
85 if (!PathService::Get(base::DIR_MODULE, &module_path))
86 return false;
87
88 glesv2_path = module_path.Append(kGLESv2ANGLELibraryName);
89 egl_path = module_path.Append(kEGLANGLELibraryName);
90 }
91
92 base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path);
93 if (!gles_library)
94 return false;
95 base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path);
96 if (!egl_library) {
97 base::UnloadNativeLibrary(gles_library);
98 return false;
99 }
100
101 GLGetProcAddressProc get_proc_address =
102 reinterpret_cast<GLGetProcAddressProc>(
103 base::GetFunctionPointerFromNativeLibrary(egl_library,
104 "eglGetProcAddress"));
105 if (!get_proc_address) {
106 LOG(ERROR) << "eglGetProcAddress not found.";
107 base::UnloadNativeLibrary(egl_library);
108 base::UnloadNativeLibrary(gles_library);
109 return false;
110 }
111
112 SetGLGetProcAddressProc(get_proc_address);
113 AddGLNativeLibrary(egl_library);
114 AddGLNativeLibrary(gles_library);
115 SetGLImplementation(kGLImplementationEGLGLES2);
116
117 InitializeStaticGLBindingsGL();
118 InitializeStaticGLBindingsEGL();
119
120 return true;
121 }
122
123 } // namespace
124
125 bool InitializeGLOneOffPlatform() { 16 bool InitializeGLOneOffPlatform() {
126 switch (GetGLImplementation()) { 17 switch (GetGLImplementation()) {
127 case kGLImplementationDesktopGL: 18 case kGLImplementationDesktopGL:
128 if (!GLSurfaceGLX::InitializeOneOff()) { 19 if (!GLSurfaceGLX::InitializeOneOff()) {
129 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; 20 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
130 return false; 21 return false;
131 } 22 }
132 return true; 23 return true;
133 case kGLImplementationOSMesaGL: 24 case kGLImplementationOSMesaGL:
134 if (!GLSurfaceOSMesaX11::InitializeOneOff()) { 25 if (!GLSurfaceOSMesaX11::InitializeOneOff()) {
135 LOG(ERROR) << "GLSurfaceOSMesaX11::InitializeOneOff failed."; 26 LOG(ERROR) << "GLSurfaceOSMesaX11::InitializeOneOff failed.";
136 return false; 27 return false;
137 } 28 }
138 return true; 29 return true;
139 case kGLImplementationEGLGLES2: 30 case kGLImplementationEGLGLES2:
140 if (!GLSurfaceEGL::InitializeOneOff()) { 31 if (!GLSurfaceEGL::InitializeOneOff()) {
141 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; 32 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
142 return false; 33 return false;
143 } 34 }
144 return true; 35 return true;
145 default: 36 default:
146 return true; 37 return true;
147 } 38 }
148 } 39 }
149 40
150 bool InitializeStaticGLBindings(GLImplementation implementation) {
151 // Prevent reinitialization with a different implementation. Once the gpu
152 // unit tests have initialized with kGLImplementationMock, we don't want to
153 // later switch to another GL implementation.
154 DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
155
156 // Allow the main thread or another to initialize these bindings
157 // after instituting restrictions on I/O. Going forward they will
158 // likely be used in the browser process on most platforms. The
159 // one-time initialization cost is small, between 2 and 5 ms.
160 base::ThreadRestrictions::ScopedAllowIO allow_io;
161
162 switch (implementation) {
163 case kGLImplementationOSMesaGL:
164 return InitializeStaticGLBindingsOSMesaGL();
165 case kGLImplementationDesktopGL:
166 return InitializeStaticGLXInternal();
167 case kGLImplementationEGLGLES2:
168 return InitializeStaticEGLInternal();
169 case kGLImplementationMockGL:
170 SetGLImplementation(kGLImplementationMockGL);
171 InitializeStaticGLBindingsGL();
172 return true;
173 default:
174 NOTREACHED();
175 }
176
177 return false;
178 }
179
180 void InitializeDebugGLBindings() {
181 InitializeDebugGLBindingsEGL();
182 InitializeDebugGLBindingsGL();
183 InitializeDebugGLBindingsGLX();
184 InitializeDebugGLBindingsOSMESA();
185 }
186
187 void ClearGLBindingsPlatform() {
188 ClearGLBindingsEGL();
189 ClearGLBindingsGL();
190 ClearGLBindingsGLX();
191 ClearGLBindingsOSMESA();
192 }
193
194 } // namespace init 41 } // namespace init
195 } // namespace gl 42 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/init/gl_initializer_win.cc ('k') | ui/gl/test/gl_image_test_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698