blob: 9aedc61416eaa0e118888825eda6d99815ce0be0 [file] [log] [blame]
Jesse Hall94cdba92013-07-11 09:40:35 -07001/*
Mathias Agopiande586972009-05-28 17:39:03 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall94cdba92013-07-11 09:40:35 -07004 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
Mathias Agopiande586972009-05-28 17:39:03 -07007 **
Jesse Hall94cdba92013-07-11 09:40:35 -07008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopiande586972009-05-28 17:39:03 -07009 **
Jesse Hall94cdba92013-07-11 09:40:35 -070010 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
Mathias Agopiande586972009-05-28 17:39:03 -070014 ** limitations under the License.
15 */
16
Jesse Hall7a8d83e2016-12-20 15:24:28 -080017//#define LOG_NDEBUG 0
Jesse Hall1508ae62017-01-19 17:43:26 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Jesse Hall7a8d83e2016-12-20 15:24:28 -080019
Mathias Agopian311b4792017-02-28 15:00:49 -080020#include "Loader.h"
21
Mathias Agopian99381422013-04-23 20:52:29 +020022#include <dirent.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070023#include <dlfcn.h>
Mathias Agopiande586972009-05-28 17:39:03 -070024
Jesse Hall7a8d83e2016-12-20 15:24:28 -080025#include <android/dlext.h>
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020026#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070027#include <log/log.h>
Mathias Agopian311b4792017-02-28 15:00:49 -080028
29#include <utils/String8.h>
Jesse Hall1508ae62017-01-19 17:43:26 -080030#include <utils/Trace.h>
Mathias Agopian311b4792017-02-28 15:00:49 -080031
Mathias Agopian991d2542017-02-06 13:51:32 -080032#include <ui/GraphicsEnv.h>
Mathias Agopiande586972009-05-28 17:39:03 -070033
Mathias Agopian1cadb252011-05-23 17:26:14 -070034#include "egldefs.h"
Mathias Agopiande586972009-05-28 17:39:03 -070035
36// ----------------------------------------------------------------------------
37namespace android {
38// ----------------------------------------------------------------------------
39
40
41/*
Mathias Agopian99381422013-04-23 20:52:29 +020042 * EGL userspace drivers must be provided either:
43 * - as a single library:
44 * /vendor/lib/egl/libGLES.so
45 *
46 * - as separate libraries:
47 * /vendor/lib/egl/libEGL.so
48 * /vendor/lib/egl/libGLESv1_CM.so
49 * /vendor/lib/egl/libGLESv2.so
50 *
51 * The software renderer for the emulator must be provided as a single
52 * library at:
53 *
54 * /system/lib/egl/libGLES_android.so
55 *
56 *
57 * For backward compatibility and to facilitate the transition to
58 * this new naming scheme, the loader will additionally look for:
Jesse Hall94cdba92013-07-11 09:40:35 -070059 *
Mathias Agopian99381422013-04-23 20:52:29 +020060 * /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so
Jesse Hall94cdba92013-07-11 09:40:35 -070061 *
Mathias Agopiande586972009-05-28 17:39:03 -070062 */
63
64ANDROID_SINGLETON_STATIC_INSTANCE( Loader )
65
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020066/* This function is called to check whether we run inside the emulator,
67 * and if this is the case whether GLES GPU emulation is supported.
68 *
69 * Returned values are:
70 * -1 -> not running inside the emulator
71 * 0 -> running inside the emulator, but GPU emulation not supported
72 * 1 -> running inside the emulator, GPU emulation is supported
Nicolas Capens776951f2015-11-06 10:10:21 -050073 * through the "emulation" host-side OpenGL ES implementation.
74 * 2 -> running inside the emulator, GPU emulation is supported
75 * through a guest-side vendor driver's OpenGL ES implementation.
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020076 */
77static int
78checkGlesEmulationStatus(void)
79{
80 /* We're going to check for the following kernel parameters:
81 *
82 * qemu=1 -> tells us that we run inside the emulator
83 * android.qemu.gles=<number> -> tells us the GLES GPU emulation status
84 *
85 * Note that we will return <number> if we find it. This let us support
86 * more additionnal emulation modes in the future.
87 */
88 char prop[PROPERTY_VALUE_MAX];
89 int result = -1;
90
91 /* First, check for qemu=1 */
92 property_get("ro.kernel.qemu",prop,"0");
93 if (atoi(prop) != 1)
94 return -1;
95
96 /* We are in the emulator, get GPU status value */
bohu69e5b1a2016-02-19 17:15:20 -080097 property_get("qemu.gles",prop,"0");
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020098 return atoi(prop);
99}
100
Jesse Hall1508ae62017-01-19 17:43:26 -0800101static void* do_dlopen(const char* path, int mode) {
102 ATRACE_CALL();
103 return dlopen(path, mode);
104}
105
Mathias Agopiande586972009-05-28 17:39:03 -0700106// ----------------------------------------------------------------------------
107
Jesse Hall94cdba92013-07-11 09:40:35 -0700108Loader::driver_t::driver_t(void* gles)
Mathias Agopiande586972009-05-28 17:39:03 -0700109{
110 dso[0] = gles;
111 for (size_t i=1 ; i<NELEM(dso) ; i++)
112 dso[i] = 0;
113}
114
Jesse Hall94cdba92013-07-11 09:40:35 -0700115Loader::driver_t::~driver_t()
Mathias Agopiande586972009-05-28 17:39:03 -0700116{
117 for (size_t i=0 ; i<NELEM(dso) ; i++) {
118 if (dso[i]) {
119 dlclose(dso[i]);
120 dso[i] = 0;
121 }
122 }
123}
124
125status_t Loader::driver_t::set(void* hnd, int32_t api)
126{
127 switch (api) {
128 case EGL:
129 dso[0] = hnd;
130 break;
131 case GLESv1_CM:
132 dso[1] = hnd;
133 break;
134 case GLESv2:
135 dso[2] = hnd;
136 break;
137 default:
138 return BAD_INDEX;
139 }
140 return NO_ERROR;
141}
142
143// ----------------------------------------------------------------------------
144
Mathias Agopiande586972009-05-28 17:39:03 -0700145Loader::Loader()
Mathias Agopian991d2542017-02-06 13:51:32 -0800146 : getProcAddress(NULL)
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800147{
Mathias Agopiande586972009-05-28 17:39:03 -0700148}
149
Mathias Agopian99381422013-04-23 20:52:29 +0200150Loader::~Loader() {
Mathias Agopiande586972009-05-28 17:39:03 -0700151}
152
Jesse Hallc07b5202013-07-04 12:08:16 -0700153static void* load_wrapper(const char* path) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800154 void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL);
Jesse Hallc07b5202013-07-04 12:08:16 -0700155 ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror());
156 return so;
157}
158
Evgenii Stepanovc2466e62015-07-08 15:49:52 -0700159#ifndef EGL_WRAPPER_DIR
160#if defined(__LP64__)
161#define EGL_WRAPPER_DIR "/system/lib64"
162#else
163#define EGL_WRAPPER_DIR "/system/lib"
164#endif
165#endif
166
bohu69e5b1a2016-02-19 17:15:20 -0800167static void setEmulatorGlesValue(void) {
168 char prop[PROPERTY_VALUE_MAX];
169 property_get("ro.kernel.qemu", prop, "0");
170 if (atoi(prop) != 1) return;
171
172 property_get("ro.kernel.qemu.gles",prop,"0");
173 if (atoi(prop) == 1) {
174 ALOGD("Emulator has host GPU support, qemu.gles is set to 1.");
175 property_set("qemu.gles", "1");
176 return;
177 }
178
179 // for now, checking the following
180 // directory is good enough for emulator system images
181 const char* vendor_lib_path =
182#if defined(__LP64__)
183 "/vendor/lib64/egl";
184#else
185 "/vendor/lib/egl";
186#endif
187
188 const bool has_vendor_lib = (access(vendor_lib_path, R_OK) == 0);
189 if (has_vendor_lib) {
190 ALOGD("Emulator has vendor provided software renderer, qemu.gles is set to 2.");
191 property_set("qemu.gles", "2");
192 } else {
193 ALOGD("Emulator without GPU support detected. "
194 "Fallback to legacy software renderer, qemu.gles is set to 0.");
195 property_set("qemu.gles", "0");
196 }
197}
198
Mathias Agopianada798b2012-02-13 17:09:30 -0800199void* Loader::open(egl_connection_t* cnx)
Mathias Agopiande586972009-05-28 17:39:03 -0700200{
Jesse Hall1508ae62017-01-19 17:43:26 -0800201 ATRACE_CALL();
202
Mathias Agopiande586972009-05-28 17:39:03 -0700203 void* dso;
Mathias Agopiande586972009-05-28 17:39:03 -0700204 driver_t* hnd = 0;
Jesse Hall94cdba92013-07-11 09:40:35 -0700205
bohu69e5b1a2016-02-19 17:15:20 -0800206 setEmulatorGlesValue();
207
Mathias Agopian99381422013-04-23 20:52:29 +0200208 dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2);
209 if (dso) {
210 hnd = new driver_t(dso);
211 } else {
212 // Always load EGL first
213 dso = load_driver("EGL", cnx, EGL);
Mathias Agopiande586972009-05-28 17:39:03 -0700214 if (dso) {
215 hnd = new driver_t(dso);
Mathias Agopian99381422013-04-23 20:52:29 +0200216 hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM );
217 hnd->set( load_driver("GLESv2", cnx, GLESv2), GLESv2 );
Mathias Agopiande586972009-05-28 17:39:03 -0700218 }
219 }
220
Mathias Agopian99381422013-04-23 20:52:29 +0200221 LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation");
Jesse Hallc07b5202013-07-04 12:08:16 -0700222
Evgenii Stepanovc2466e62015-07-08 15:49:52 -0700223 cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so");
224 cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so");
225 cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so");
226
Michael Chockc0ec5e22014-01-27 08:14:33 -0800227 LOG_ALWAYS_FATAL_IF(!cnx->libEgl,
228 "couldn't load system EGL wrapper libraries");
229
Jesse Hallc07b5202013-07-04 12:08:16 -0700230 LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
231 "couldn't load system OpenGL ES wrapper libraries");
232
Mathias Agopiande586972009-05-28 17:39:03 -0700233 return (void*)hnd;
234}
235
236status_t Loader::close(void* driver)
237{
238 driver_t* hnd = (driver_t*)driver;
239 delete hnd;
240 return NO_ERROR;
241}
242
Jesse Hall94cdba92013-07-11 09:40:35 -0700243void Loader::init_api(void* dso,
244 char const * const * api,
245 __eglMustCastToProperFunctionPointerType* curr,
246 getProcAddressType getProcAddress)
Mathias Agopiande586972009-05-28 17:39:03 -0700247{
Jesse Hall1508ae62017-01-19 17:43:26 -0800248 ATRACE_CALL();
249
Mathias Agopian7773c432012-02-13 20:06:08 -0800250 const ssize_t SIZE = 256;
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700251 char scrap[SIZE];
Mathias Agopiande586972009-05-28 17:39:03 -0700252 while (*api) {
253 char const * name = *api;
Jesse Hall94cdba92013-07-11 09:40:35 -0700254 __eglMustCastToProperFunctionPointerType f =
Mathias Agopiande586972009-05-28 17:39:03 -0700255 (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
256 if (f == NULL) {
257 // couldn't find the entry-point, use eglGetProcAddress()
258 f = getProcAddress(name);
259 }
260 if (f == NULL) {
261 // Try without the OES postfix
262 ssize_t index = ssize_t(strlen(name)) - 3;
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700263 if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) {
Mathias Agopiande586972009-05-28 17:39:03 -0700264 strncpy(scrap, name, index);
265 scrap[index] = 0;
266 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
Steve Block9d453682011-12-20 16:23:08 +0000267 //ALOGD_IF(f, "found <%s> instead", scrap);
Mathias Agopiande586972009-05-28 17:39:03 -0700268 }
269 }
270 if (f == NULL) {
271 // Try with the OES postfix
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700272 ssize_t index = ssize_t(strlen(name)) - 3;
273 if (index>0 && strcmp(name+index, "OES")) {
274 snprintf(scrap, SIZE, "%sOES", name);
Mathias Agopiande586972009-05-28 17:39:03 -0700275 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
Steve Block9d453682011-12-20 16:23:08 +0000276 //ALOGD_IF(f, "found <%s> instead", scrap);
Mathias Agopiande586972009-05-28 17:39:03 -0700277 }
278 }
279 if (f == NULL) {
Steve Block9d453682011-12-20 16:23:08 +0000280 //ALOGD("%s", name);
Mathias Agopiande586972009-05-28 17:39:03 -0700281 f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented;
Mathias Agopian48d438d2012-01-28 21:44:00 -0800282
283 /*
284 * GL_EXT_debug_label is special, we always report it as
285 * supported, it's handled by GLES_trace. If GLES_trace is not
286 * enabled, then these are no-ops.
287 */
288 if (!strcmp(name, "glInsertEventMarkerEXT")) {
289 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
290 } else if (!strcmp(name, "glPushGroupMarkerEXT")) {
291 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
292 } else if (!strcmp(name, "glPopGroupMarkerEXT")) {
293 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
294 }
Mathias Agopiande586972009-05-28 17:39:03 -0700295 }
296 *curr++ = f;
297 api++;
298 }
299}
300
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800301static void* load_system_driver(const char* kind) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800302 ATRACE_CALL();
Mathias Agopian99381422013-04-23 20:52:29 +0200303 class MatchFile {
304 public:
305 static String8 find(const char* kind) {
306 String8 result;
Nicolas Capens776951f2015-11-06 10:10:21 -0500307 int emulationStatus = checkGlesEmulationStatus();
308 switch (emulationStatus) {
309 case 0:
Nicolas Capens776951f2015-11-06 10:10:21 -0500310#if defined(__LP64__)
311 result.setTo("/system/lib64/egl/libGLES_android.so");
312#else
313 result.setTo("/system/lib/egl/libGLES_android.so");
314#endif
315 return result;
316 case 1:
317 // Use host-side OpenGL through the "emulation" library
318#if defined(__LP64__)
319 result.appendFormat("/system/lib64/egl/lib%s_emulation.so", kind);
320#else
321 result.appendFormat("/system/lib/egl/lib%s_emulation.so", kind);
322#endif
323 return result;
324 default:
325 // Not in emulator, or use other guest-side implementation
326 break;
327 }
328
Mathias Agopian99381422013-04-23 20:52:29 +0200329 String8 pattern;
330 pattern.appendFormat("lib%s", kind);
331 const char* const searchPaths[] = {
Dan Willemsen8edb8f52014-02-16 10:23:54 -0800332#if defined(__LP64__)
333 "/vendor/lib64/egl",
334 "/system/lib64/egl"
335#else
Mathias Agopian99381422013-04-23 20:52:29 +0200336 "/vendor/lib/egl",
337 "/system/lib/egl"
Dan Willemsen8edb8f52014-02-16 10:23:54 -0800338#endif
Mathias Agopian99381422013-04-23 20:52:29 +0200339 };
Brian Swetland2b9e4f62010-09-20 12:58:15 -0700340
Mathias Agopian99381422013-04-23 20:52:29 +0200341 // first, we search for the exact name of the GLES userspace
342 // driver in both locations.
343 // i.e.:
344 // libGLES.so, or:
345 // libEGL.so, libGLESv1_CM.so, libGLESv2.so
346
347 for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
348 if (find(result, pattern, searchPaths[i], true)) {
349 return result;
350 }
351 }
352
353 // for compatibility with the old "egl.cfg" naming convention
354 // we look for files that match:
355 // libGLES_*.so, or:
356 // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
357
358 pattern.append("_");
359 for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
360 if (find(result, pattern, searchPaths[i], false)) {
361 return result;
362 }
363 }
364
365 // we didn't find the driver. gah.
366 result.clear();
367 return result;
Brian Swetland2b9e4f62010-09-20 12:58:15 -0700368 }
Mathias Agopian99381422013-04-23 20:52:29 +0200369
370 private:
371 static bool find(String8& result,
372 const String8& pattern, const char* const search, bool exact) {
Mathias Agopian99381422013-04-23 20:52:29 +0200373 if (exact) {
374 String8 absolutePath;
375 absolutePath.appendFormat("%s/%s.so", search, pattern.string());
376 if (!access(absolutePath.string(), R_OK)) {
377 result = absolutePath;
378 return true;
379 }
380 return false;
381 }
382
383 DIR* d = opendir(search);
384 if (d != NULL) {
385 struct dirent cur;
386 struct dirent* e;
387 while (readdir_r(d, &cur, &e) == 0 && e) {
388 if (e->d_type == DT_DIR) {
389 continue;
390 }
391 if (!strcmp(e->d_name, "libGLES_android.so")) {
392 // always skip the software renderer
393 continue;
394 }
395 if (strstr(e->d_name, pattern.string()) == e->d_name) {
396 if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) {
397 result.clear();
398 result.appendFormat("%s/%s", search, e->d_name);
399 closedir(d);
400 return true;
401 }
402 }
403 }
404 closedir(d);
405 }
406 return false;
407 }
408 };
409
410
411 String8 absolutePath = MatchFile::find(kind);
412 if (absolutePath.isEmpty()) {
413 // this happens often, we don't want to log an error
414 return 0;
Mathias Agopian8c173842009-09-20 16:01:02 -0700415 }
Mathias Agopian99381422013-04-23 20:52:29 +0200416 const char* const driver_absolute_path = absolutePath.string();
Mathias Agopiande586972009-05-28 17:39:03 -0700417
Jesse Hall1508ae62017-01-19 17:43:26 -0800418 void* dso = do_dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL);
Mathias Agopian8c173842009-09-20 16:01:02 -0700419 if (dso == 0) {
420 const char* err = dlerror();
Steve Blocke6f43dd2012-01-06 19:20:56 +0000421 ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown");
Mathias Agopian8c173842009-09-20 16:01:02 -0700422 return 0;
423 }
424
Steve Block9d453682011-12-20 16:23:08 +0000425 ALOGD("loaded %s", driver_absolute_path);
Mathias Agopianbaca89c2009-08-20 19:09:34 -0700426
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800427 return dso;
428}
429
Jesse Hall1508ae62017-01-19 17:43:26 -0800430static void* do_android_dlopen_ext(const char* path, int mode, const android_dlextinfo* info) {
431 ATRACE_CALL();
432 return android_dlopen_ext(path, mode, info);
433}
434
Mathias Agopian311b4792017-02-28 15:00:49 -0800435static const char* HAL_SUBNAME_KEY_PROPERTIES[2] = {
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800436 "ro.hardware.egl",
437 "ro.board.platform",
Mathias Agopian311b4792017-02-28 15:00:49 -0800438};
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800439
440static void* load_updated_driver(const char* kind, android_namespace_t* ns) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800441 ATRACE_CALL();
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800442 const android_dlextinfo dlextinfo = {
443 .flags = ANDROID_DLEXT_USE_NAMESPACE,
444 .library_namespace = ns,
445 };
446 void* so = nullptr;
447 char prop[PROPERTY_VALUE_MAX + 1];
448 for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
449 if (property_get(key, prop, nullptr) > 0) {
450 String8 name;
451 name.appendFormat("lib%s_%s.so", kind, prop);
Mathias Agopian311b4792017-02-28 15:00:49 -0800452 so = do_android_dlopen_ext(name.string(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
453 if (so) {
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800454 return so;
Mathias Agopian311b4792017-02-28 15:00:49 -0800455 }
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800456 }
457 }
458 return nullptr;
459}
460
461void *Loader::load_driver(const char* kind,
462 egl_connection_t* cnx, uint32_t mask)
463{
Jesse Hall1508ae62017-01-19 17:43:26 -0800464 ATRACE_CALL();
465
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800466 void* dso = nullptr;
Mathias Agopian991d2542017-02-06 13:51:32 -0800467 android_namespace_t* ns = android_getDriverNamespace();
468 if (ns) {
469 dso = load_updated_driver(kind, ns);
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800470 }
471 if (!dso) {
472 dso = load_system_driver(kind);
473 if (!dso)
474 return NULL;
475 }
476
Mathias Agopiande586972009-05-28 17:39:03 -0700477 if (mask & EGL) {
478 getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress");
479
Jesse Hall94cdba92013-07-11 09:40:35 -0700480 ALOGE_IF(!getProcAddress,
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800481 "can't find eglGetProcAddress() in EGL driver library");
Mathias Agopiande586972009-05-28 17:39:03 -0700482
Mathias Agopian618fa102009-10-14 02:06:37 -0700483 egl_t* egl = &cnx->egl;
Mathias Agopiande586972009-05-28 17:39:03 -0700484 __eglMustCastToProperFunctionPointerType* curr =
485 (__eglMustCastToProperFunctionPointerType*)egl;
486 char const * const * api = egl_names;
487 while (*api) {
488 char const * name = *api;
Jesse Hall94cdba92013-07-11 09:40:35 -0700489 __eglMustCastToProperFunctionPointerType f =
Mathias Agopiande586972009-05-28 17:39:03 -0700490 (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
491 if (f == NULL) {
492 // couldn't find the entry-point, use eglGetProcAddress()
493 f = getProcAddress(name);
494 if (f == NULL) {
495 f = (__eglMustCastToProperFunctionPointerType)0;
496 }
497 }
498 *curr++ = f;
499 api++;
500 }
501 }
Jesse Hall94cdba92013-07-11 09:40:35 -0700502
Mathias Agopiande586972009-05-28 17:39:03 -0700503 if (mask & GLESv1_CM) {
Mathias Agopian618fa102009-10-14 02:06:37 -0700504 init_api(dso, gl_names,
505 (__eglMustCastToProperFunctionPointerType*)
Mathias Agopian7773c432012-02-13 20:06:08 -0800506 &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl,
Mathias Agopian618fa102009-10-14 02:06:37 -0700507 getProcAddress);
Mathias Agopiande586972009-05-28 17:39:03 -0700508 }
509
510 if (mask & GLESv2) {
Mathias Agopian618fa102009-10-14 02:06:37 -0700511 init_api(dso, gl_names,
512 (__eglMustCastToProperFunctionPointerType*)
Mathias Agopian7773c432012-02-13 20:06:08 -0800513 &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl,
Mathias Agopiande586972009-05-28 17:39:03 -0700514 getProcAddress);
515 }
Jesse Hall94cdba92013-07-11 09:40:35 -0700516
Mathias Agopiande586972009-05-28 17:39:03 -0700517 return dso;
518}
519
520// ----------------------------------------------------------------------------
521}; // namespace android
522// ----------------------------------------------------------------------------