• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  ** Copyright 2007, The Android Open Source Project
3  **
4  ** 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
7  **
8  **     http://www.apache.org/licenses/LICENSE-2.0
9  **
10  ** 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
14  ** limitations under the License.
15  */
16 
17 //#define LOG_NDEBUG 0
18 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
19 
20 #include "EGL/Loader.h"
21 
22 #include <android-base/properties.h>
23 #include <android/dlext.h>
24 #include <dirent.h>
25 #include <dlfcn.h>
26 #include <graphicsenv/GraphicsEnv.h>
27 #include <log/log.h>
28 #include <utils/Timers.h>
29 #include <vndksupport/linker.h>
30 
31 #include <string>
32 
33 #include "EGL/eglext_angle.h"
34 #include "egl_platform_entries.h"
35 #include "egl_trace.h"
36 #include "egldefs.h"
37 
38 namespace android {
39 
40 /*
41  * EGL userspace drivers must be provided either:
42  * - as a single library:
43  *      /vendor/lib/egl/libGLES.so
44  *
45  * - as separate libraries:
46  *      /vendor/lib/egl/libEGL.so
47  *      /vendor/lib/egl/libGLESv1_CM.so
48  *      /vendor/lib/egl/libGLESv2.so
49  *
50  * For backward compatibility and to facilitate the transition to
51  * this new naming scheme, the loader will additionally look for:
52  *
53  *      /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so
54  *
55  */
56 
getInstance()57 Loader& Loader::getInstance() {
58     static Loader loader;
59     return loader;
60 }
61 
do_dlopen(const char * path,int mode)62 static void* do_dlopen(const char* path, int mode) {
63     ATRACE_CALL();
64     return dlopen(path, mode);
65 }
66 
do_android_dlopen_ext(const char * path,int mode,const android_dlextinfo * info)67 static void* do_android_dlopen_ext(const char* path, int mode, const android_dlextinfo* info) {
68     ATRACE_CALL();
69     return android_dlopen_ext(path, mode, info);
70 }
71 
do_android_load_sphal_library(const char * path,int mode)72 static void* do_android_load_sphal_library(const char* path, int mode) {
73     ATRACE_CALL();
74     return android_load_sphal_library(path, mode);
75 }
76 
do_android_unload_sphal_library(void * dso)77 static int do_android_unload_sphal_library(void* dso) {
78     ATRACE_CALL();
79     return android_unload_sphal_library(dso);
80 }
81 
driver_t(void * gles)82 Loader::driver_t::driver_t(void* gles)
83 {
84     dso[0] = gles;
85     for (size_t i=1 ; i<NELEM(dso) ; i++)
86         dso[i] = nullptr;
87 }
88 
~driver_t()89 Loader::driver_t::~driver_t()
90 {
91     for (size_t i=0 ; i<NELEM(dso) ; i++) {
92         if (dso[i]) {
93             dlclose(dso[i]);
94             dso[i] = nullptr;
95         }
96     }
97 }
98 
set(void * hnd,int32_t api)99 int Loader::driver_t::set(void* hnd, int32_t api)
100 {
101     switch (api) {
102         case EGL:
103             dso[0] = hnd;
104             break;
105         case GLESv1_CM:
106             dso[1] = hnd;
107             break;
108         case GLESv2:
109             dso[2] = hnd;
110             break;
111         default:
112             return -EOVERFLOW;
113     }
114     return 0;
115 }
116 
Loader()117 Loader::Loader()
118     : getProcAddress(nullptr)
119 {
120 }
121 
~Loader()122 Loader::~Loader() {
123 }
124 
load_wrapper(const char * path)125 static void* load_wrapper(const char* path) {
126     void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL);
127     ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror());
128     return so;
129 }
130 
131 #ifndef EGL_WRAPPER_DIR
132 #if defined(__LP64__)
133 #define EGL_WRAPPER_DIR "/system/lib64"
134 #else
135 #define EGL_WRAPPER_DIR "/system/lib"
136 #endif
137 #endif
138 
139 static const char* DRIVER_SUFFIX_PROPERTY = "ro.hardware.egl";
140 
141 static const char* HAL_SUBNAME_KEY_PROPERTIES[2] = {
142     DRIVER_SUFFIX_PROPERTY,
143     "ro.board.platform",
144 };
145 
should_unload_system_driver(egl_connection_t * cnx)146 static bool should_unload_system_driver(egl_connection_t* cnx) {
147     // Return false if the system driver has been unloaded once.
148     if (cnx->systemDriverUnloaded) {
149         return false;
150     }
151 
152     // Return true if Angle namespace is set.
153     android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
154     if (ns) {
155         return true;
156     }
157 
158     // Return true if updated driver namespace is set.
159     ns = android::GraphicsEnv::getInstance().getDriverNamespace();
160     if (ns) {
161         return true;
162     }
163 
164     return false;
165 }
166 
uninit_api(char const * const * api,__eglMustCastToProperFunctionPointerType * curr)167 static void uninit_api(char const* const* api, __eglMustCastToProperFunctionPointerType* curr) {
168     while (*api) {
169         *curr++ = nullptr;
170         api++;
171     }
172 }
173 
unload_system_driver(egl_connection_t * cnx)174 void Loader::unload_system_driver(egl_connection_t* cnx) {
175     ATRACE_CALL();
176 
177     uninit_api(gl_names,
178                (__eglMustCastToProperFunctionPointerType*)&cnx
179                        ->hooks[egl_connection_t::GLESv2_INDEX]
180                        ->gl);
181     uninit_api(gl_names,
182                (__eglMustCastToProperFunctionPointerType*)&cnx
183                        ->hooks[egl_connection_t::GLESv1_INDEX]
184                        ->gl);
185     uninit_api(egl_names, (__eglMustCastToProperFunctionPointerType*)&cnx->egl);
186 
187     if (cnx->dso) {
188         ALOGD("Unload system gl driver.");
189         driver_t* hnd = (driver_t*)cnx->dso;
190         if (hnd->dso[2]) {
191             do_android_unload_sphal_library(hnd->dso[2]);
192         }
193         if (hnd->dso[1]) {
194             do_android_unload_sphal_library(hnd->dso[1]);
195         }
196         if (hnd->dso[0]) {
197             do_android_unload_sphal_library(hnd->dso[0]);
198         }
199         cnx->dso = nullptr;
200     }
201 
202     cnx->systemDriverUnloaded = true;
203 }
204 
open(egl_connection_t * cnx)205 void* Loader::open(egl_connection_t* cnx)
206 {
207     ATRACE_CALL();
208     const nsecs_t openTime = systemTime();
209 
210     if (should_unload_system_driver(cnx)) {
211         unload_system_driver(cnx);
212     }
213 
214     // If a driver has been loaded, return the driver directly.
215     if (cnx->dso) {
216         return cnx->dso;
217     }
218 
219     // Firstly, try to load ANGLE driver.
220     driver_t* hnd = attempt_to_load_angle(cnx);
221     if (!hnd) {
222         // Secondly, try to load from driver apk.
223         hnd = attempt_to_load_updated_driver(cnx);
224     }
225 
226     bool failToLoadFromDriverSuffixProperty = false;
227     if (!hnd) {
228         // If updated driver apk is set but fail to load, abort here.
229         if (android::GraphicsEnv::getInstance().getDriverNamespace()) {
230             LOG_ALWAYS_FATAL("couldn't find an OpenGL ES implementation from %s",
231                              android::GraphicsEnv::getInstance().getDriverPath().c_str());
232         }
233         // Finally, try to load system driver, start by searching for the library name appended by
234         // the system properties of the GLES userspace driver in both locations.
235         // i.e.:
236         //      libGLES_${prop}.so, or:
237         //      libEGL_${prop}.so, libGLESv1_CM_${prop}.so, libGLESv2_${prop}.so
238         for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
239             auto prop = base::GetProperty(key, "");
240             if (prop.empty()) {
241                 continue;
242             }
243             hnd = attempt_to_load_system_driver(cnx, prop.c_str(), true);
244             if (hnd) {
245                 break;
246             } else if (strcmp(key, DRIVER_SUFFIX_PROPERTY) == 0) {
247                 failToLoadFromDriverSuffixProperty = true;
248             }
249         }
250     }
251 
252     if (!hnd) {
253         // Can't find graphics driver by appending system properties, now search for the exact name
254         // without any suffix of the GLES userspace driver in both locations.
255         // i.e.:
256         //      libGLES.so, or:
257         //      libEGL.so, libGLESv1_CM.so, libGLESv2.so
258         hnd = attempt_to_load_system_driver(cnx, nullptr, true);
259     }
260 
261     if (!hnd && !failToLoadFromDriverSuffixProperty) {
262         hnd = attempt_to_load_system_driver(cnx, nullptr, false);
263     }
264 
265     if (!hnd) {
266         android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL,
267                                                             false, systemTime() - openTime);
268     } else {
269         // init_angle_backend will check if loaded driver is ANGLE or not,
270         // will set cnx->useAngle appropriately.
271         // Do this here so that we use ANGLE path when driver is ANGLE (e.g. loaded as native),
272         // not just loading ANGLE as option.
273         init_angle_backend(hnd->dso[2], cnx);
274     }
275 
276     LOG_ALWAYS_FATAL_IF(!hnd,
277                         "couldn't find an OpenGL ES implementation, make sure you set %s or %s",
278                         HAL_SUBNAME_KEY_PROPERTIES[0], HAL_SUBNAME_KEY_PROPERTIES[1]);
279 
280     if (!cnx->libEgl) {
281         cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so");
282     }
283     if (!cnx->libGles1) {
284         cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so");
285     }
286     if (!cnx->libGles2) {
287         cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so");
288     }
289 
290     if (!cnx->libEgl || !cnx->libGles2 || !cnx->libGles1) {
291         android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL,
292                                                             false, systemTime() - openTime);
293     }
294 
295     LOG_ALWAYS_FATAL_IF(!cnx->libEgl,
296             "couldn't load system EGL wrapper libraries");
297 
298     LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
299                         "couldn't load system OpenGL ES wrapper libraries");
300 
301     android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL, true,
302                                                         systemTime() - openTime);
303 
304     return (void*)hnd;
305 }
306 
close(egl_connection_t * cnx)307 void Loader::close(egl_connection_t* cnx)
308 {
309     driver_t* hnd = (driver_t*) cnx->dso;
310     delete hnd;
311     cnx->dso = nullptr;
312 
313     cnx->useAngle = false;
314 }
315 
init_api(void * dso,char const * const * api,char const * const * ref_api,__eglMustCastToProperFunctionPointerType * curr,getProcAddressType getProcAddress)316 void Loader::init_api(void* dso,
317         char const * const * api,
318         char const * const * ref_api,
319         __eglMustCastToProperFunctionPointerType* curr,
320         getProcAddressType getProcAddress)
321 {
322     ATRACE_CALL();
323 
324     const ssize_t SIZE = 256;
325     char scrap[SIZE];
326     while (*api) {
327         char const * name = *api;
328         if (ref_api) {
329             char const * ref_name = *ref_api;
330             if (std::strcmp(name, ref_name) != 0) {
331                 *curr++ = nullptr;
332                 ref_api++;
333                 continue;
334             }
335         }
336 
337         __eglMustCastToProperFunctionPointerType f =
338             (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
339         if (f == nullptr) {
340             // couldn't find the entry-point, use eglGetProcAddress()
341             f = getProcAddress(name);
342         }
343         if (f == nullptr) {
344             // Try without the OES postfix
345             ssize_t index = ssize_t(strlen(name)) - 3;
346             if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) {
347                 strncpy(scrap, name, index);
348                 scrap[index] = 0;
349                 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
350                 //ALOGD_IF(f, "found <%s> instead", scrap);
351             }
352         }
353         if (f == nullptr) {
354             // Try with the OES postfix
355             ssize_t index = ssize_t(strlen(name)) - 3;
356             if (index>0 && strcmp(name+index, "OES")) {
357                 snprintf(scrap, SIZE, "%sOES", name);
358                 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
359                 //ALOGD_IF(f, "found <%s> instead", scrap);
360             }
361         }
362         if (f == nullptr) {
363             //ALOGD("%s", name);
364             f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented;
365 
366             /*
367              * GL_EXT_debug_marker is special, we always report it as
368              * supported, it's handled by GLES_trace. If GLES_trace is not
369              * enabled, then these are no-ops.
370              */
371             if (!strcmp(name, "glInsertEventMarkerEXT")) {
372                 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
373             } else if (!strcmp(name, "glPushGroupMarkerEXT")) {
374                 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
375             } else if (!strcmp(name, "glPopGroupMarkerEXT")) {
376                 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
377             }
378         }
379         *curr++ = f;
380         api++;
381         if (ref_api) ref_api++;
382     }
383 }
384 
load_system_driver(const char * kind,const char * suffix,const bool exact)385 static void* load_system_driver(const char* kind, const char* suffix, const bool exact) {
386     ATRACE_CALL();
387     class MatchFile {
388     public:
389         static std::string find(const char* libraryName, const bool exact) {
390             const char* const searchPaths[] = {
391 #if defined(__LP64__)
392                     "/vendor/lib64/egl",
393                     "/system/lib64/egl"
394 #else
395                     "/vendor/lib/egl",
396                     "/system/lib/egl"
397 #endif
398             };
399 
400             for (auto dir : searchPaths) {
401                 std::string absolutePath;
402                 if (find(absolutePath, libraryName, dir, exact)) {
403                     return absolutePath;
404                 }
405             }
406 
407             // Driver not found. gah.
408             return std::string();
409         }
410     private:
411         static bool find(std::string& result,
412                 const std::string& pattern, const char* const search, bool exact) {
413             if (exact) {
414                 std::string absolutePath = std::string(search) + "/" + pattern + ".so";
415                 if (!access(absolutePath.c_str(), R_OK)) {
416                     result = absolutePath;
417                     return true;
418                 }
419                 return false;
420             }
421 
422             DIR* d = opendir(search);
423             if (d != nullptr) {
424                 struct dirent* e;
425                 while ((e = readdir(d)) != nullptr) {
426                     if (e->d_type == DT_DIR) {
427                         continue;
428                     }
429                     if (!strcmp(e->d_name, "libGLES_android.so")) {
430                         // always skip the software renderer
431                         continue;
432                     }
433                     if (strstr(e->d_name, pattern.c_str()) == e->d_name) {
434                         if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) {
435                             result = std::string(search) + "/" + e->d_name;
436                             closedir(d);
437                             return true;
438                         }
439                     }
440                 }
441                 closedir(d);
442             }
443             return false;
444         }
445     };
446 
447     std::string libraryName = std::string("lib") + kind;
448     if (suffix) {
449         libraryName += std::string("_") + suffix;
450     } else if (!exact) {
451         // Deprecated: we look for files that match
452         //      libGLES_*.so, or:
453         //      libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
454         libraryName += std::string("_");
455     }
456     std::string absolutePath = MatchFile::find(libraryName.c_str(), exact);
457     if (absolutePath.empty()) {
458         // this happens often, we don't want to log an error
459         return nullptr;
460     }
461     const char* const driver_absolute_path = absolutePath.c_str();
462 
463     // Try to load drivers from the 'sphal' namespace, if it exist. Fall back to
464     // the original routine when the namespace does not exist.
465     // See /system/core/rootdir/etc/ld.config.txt for the configuration of the
466     // sphal namespace.
467     void* dso = do_android_load_sphal_library(driver_absolute_path,
468                                               RTLD_NOW | RTLD_LOCAL);
469     if (dso == nullptr) {
470         const char* err = dlerror();
471         ALOGE("load_driver(%s): %s", driver_absolute_path, err ? err : "unknown");
472         return nullptr;
473     }
474 
475     ALOGD("loaded %s", driver_absolute_path);
476 
477     return dso;
478 }
479 
load_angle(const char * kind,android_namespace_t * ns)480 static void* load_angle(const char* kind, android_namespace_t* ns) {
481     const android_dlextinfo dlextinfo = {
482             .flags = ANDROID_DLEXT_USE_NAMESPACE,
483             .library_namespace = ns,
484     };
485 
486     std::string name = std::string("lib") + kind + "_angle.so";
487 
488     void* so = do_android_dlopen_ext(name.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
489 
490     if (so) {
491         ALOGD("dlopen_ext from APK (%s) success at %p", name.c_str(), so);
492         return so;
493     } else {
494         ALOGE("dlopen_ext(\"%s\") failed: %s", name.c_str(), dlerror());
495     }
496 
497     return nullptr;
498 }
499 
load_updated_driver(const char * kind,android_namespace_t * ns)500 static void* load_updated_driver(const char* kind, android_namespace_t* ns) {
501     ATRACE_CALL();
502     const android_dlextinfo dlextinfo = {
503         .flags = ANDROID_DLEXT_USE_NAMESPACE,
504         .library_namespace = ns,
505     };
506     void* so = nullptr;
507     for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
508         auto prop = base::GetProperty(key, "");
509         if (prop.empty()) {
510             continue;
511         }
512         std::string name = std::string("lib") + kind + "_" + prop + ".so";
513         so = do_android_dlopen_ext(name.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
514         if (so) {
515             return so;
516         }
517         ALOGE("Could not load %s from updatable gfx driver namespace: %s.", name.c_str(),
518               dlerror());
519     }
520     return nullptr;
521 }
522 
attempt_to_load_angle(egl_connection_t * cnx)523 Loader::driver_t* Loader::attempt_to_load_angle(egl_connection_t* cnx) {
524     ATRACE_CALL();
525 
526     if (!android::GraphicsEnv::getInstance().shouldUseAngle()) {
527         return nullptr;
528     }
529 
530     android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
531     if (!ns) {
532         return nullptr;
533     }
534 
535     android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::ANGLE);
536     driver_t* hnd = nullptr;
537 
538     // ANGLE doesn't ship with GLES library, and thus we skip GLES driver.
539     void* dso = load_angle("EGL", ns);
540     if (dso) {
541         initialize_api(dso, cnx, EGL);
542         hnd = new driver_t(dso);
543 
544         dso = load_angle("GLESv1_CM", ns);
545         initialize_api(dso, cnx, GLESv1_CM);
546         hnd->set(dso, GLESv1_CM);
547 
548         dso = load_angle("GLESv2", ns);
549         initialize_api(dso, cnx, GLESv2);
550         hnd->set(dso, GLESv2);
551     }
552     return hnd;
553 }
554 
init_angle_backend(void * dso,egl_connection_t * cnx)555 void Loader::init_angle_backend(void* dso, egl_connection_t* cnx) {
556     void* pANGLEGetDisplayPlatform = dlsym(dso, "ANGLEGetDisplayPlatform");
557     if (pANGLEGetDisplayPlatform) {
558         ALOGV("ANGLE GLES library in use");
559         cnx->useAngle = true;
560     } else {
561         ALOGV("Native GLES library in use");
562         cnx->useAngle = false;
563     }
564 }
565 
attempt_to_load_updated_driver(egl_connection_t * cnx)566 Loader::driver_t* Loader::attempt_to_load_updated_driver(egl_connection_t* cnx) {
567     ATRACE_CALL();
568 
569     android_namespace_t* ns = android::GraphicsEnv::getInstance().getDriverNamespace();
570     if (!ns) {
571         return nullptr;
572     }
573 
574     ALOGD("Load updated gl driver.");
575     android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::GL_UPDATED);
576     driver_t* hnd = nullptr;
577     void* dso = load_updated_driver("GLES", ns);
578     if (dso) {
579         initialize_api(dso, cnx, EGL | GLESv1_CM | GLESv2);
580         hnd = new driver_t(dso);
581         return hnd;
582     }
583 
584     dso = load_updated_driver("EGL", ns);
585     if (dso) {
586         initialize_api(dso, cnx, EGL);
587         hnd = new driver_t(dso);
588 
589         dso = load_updated_driver("GLESv1_CM", ns);
590         initialize_api(dso, cnx, GLESv1_CM);
591         hnd->set(dso, GLESv1_CM);
592 
593         dso = load_updated_driver("GLESv2", ns);
594         initialize_api(dso, cnx, GLESv2);
595         hnd->set(dso, GLESv2);
596     }
597     return hnd;
598 }
599 
attempt_to_load_system_driver(egl_connection_t * cnx,const char * suffix,const bool exact)600 Loader::driver_t* Loader::attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix,
601                                                         const bool exact) {
602     ATRACE_CALL();
603     android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::GL);
604     driver_t* hnd = nullptr;
605     void* dso = load_system_driver("GLES", suffix, exact);
606     if (dso) {
607         initialize_api(dso, cnx, EGL | GLESv1_CM | GLESv2);
608         hnd = new driver_t(dso);
609         return hnd;
610     }
611     dso = load_system_driver("EGL", suffix, exact);
612     if (dso) {
613         initialize_api(dso, cnx, EGL);
614         hnd = new driver_t(dso);
615 
616         dso = load_system_driver("GLESv1_CM", suffix, exact);
617         initialize_api(dso, cnx, GLESv1_CM);
618         hnd->set(dso, GLESv1_CM);
619 
620         dso = load_system_driver("GLESv2", suffix, exact);
621         initialize_api(dso, cnx, GLESv2);
622         hnd->set(dso, GLESv2);
623     }
624     return hnd;
625 }
626 
initialize_api(void * dso,egl_connection_t * cnx,uint32_t mask)627 void Loader::initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask) {
628     if (mask & EGL) {
629         getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress");
630 
631         ALOGE_IF(!getProcAddress,
632                 "can't find eglGetProcAddress() in EGL driver library");
633 
634         egl_t* egl = &cnx->egl;
635         __eglMustCastToProperFunctionPointerType* curr =
636             (__eglMustCastToProperFunctionPointerType*)egl;
637         char const * const * api = egl_names;
638         while (*api) {
639             char const * name = *api;
640             __eglMustCastToProperFunctionPointerType f =
641                 (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
642             if (f == nullptr) {
643                 // couldn't find the entry-point, use eglGetProcAddress()
644                 f = getProcAddress(name);
645                 if (f == nullptr) {
646                     f = (__eglMustCastToProperFunctionPointerType)nullptr;
647                 }
648             }
649             *curr++ = f;
650             api++;
651         }
652     }
653 
654     if (mask & GLESv1_CM) {
655         init_api(dso, gl_names_1, gl_names,
656             (__eglMustCastToProperFunctionPointerType*)
657                 &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl,
658             getProcAddress);
659     }
660 
661     if (mask & GLESv2) {
662         init_api(dso, gl_names, nullptr,
663             (__eglMustCastToProperFunctionPointerType*)
664                 &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl,
665             getProcAddress);
666     }
667 }
668 
669 } // namespace android
670