blob: 01d7bbbd6b0bfb8422f7f8bb4275bba89cb043f0 [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
20#include <array>
Mathias Agopiande586972009-05-28 17:39:03 -070021#include <ctype.h>
Mathias Agopian99381422013-04-23 20:52:29 +020022#include <dirent.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070023#include <dlfcn.h>
24#include <errno.h>
25#include <limits.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
Mathias Agopiande586972009-05-28 17:39:03 -070029
Jesse Hall7a8d83e2016-12-20 15:24:28 -080030#include <android/dlext.h>
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020031#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070032#include <log/log.h>
Jesse Hall1508ae62017-01-19 17:43:26 -080033#include <utils/Trace.h>
Mathias Agopiande586972009-05-28 17:39:03 -070034
35#include <EGL/egl.h>
36
Mathias Agopian1cadb252011-05-23 17:26:14 -070037#include "egldefs.h"
Mathias Agopian1cadb252011-05-23 17:26:14 -070038#include "Loader.h"
Mathias Agopiande586972009-05-28 17:39:03 -070039
40// ----------------------------------------------------------------------------
41namespace android {
42// ----------------------------------------------------------------------------
43
44
45/*
Mathias Agopian99381422013-04-23 20:52:29 +020046 * EGL userspace drivers must be provided either:
47 * - as a single library:
48 * /vendor/lib/egl/libGLES.so
49 *
50 * - as separate libraries:
51 * /vendor/lib/egl/libEGL.so
52 * /vendor/lib/egl/libGLESv1_CM.so
53 * /vendor/lib/egl/libGLESv2.so
54 *
55 * The software renderer for the emulator must be provided as a single
56 * library at:
57 *
58 * /system/lib/egl/libGLES_android.so
59 *
60 *
61 * For backward compatibility and to facilitate the transition to
62 * this new naming scheme, the loader will additionally look for:
Jesse Hall94cdba92013-07-11 09:40:35 -070063 *
Mathias Agopian99381422013-04-23 20:52:29 +020064 * /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so
Jesse Hall94cdba92013-07-11 09:40:35 -070065 *
Mathias Agopiande586972009-05-28 17:39:03 -070066 */
67
68ANDROID_SINGLETON_STATIC_INSTANCE( Loader )
69
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020070/* This function is called to check whether we run inside the emulator,
71 * and if this is the case whether GLES GPU emulation is supported.
72 *
73 * Returned values are:
74 * -1 -> not running inside the emulator
75 * 0 -> running inside the emulator, but GPU emulation not supported
76 * 1 -> running inside the emulator, GPU emulation is supported
Nicolas Capens776951f2015-11-06 10:10:21 -050077 * through the "emulation" host-side OpenGL ES implementation.
78 * 2 -> running inside the emulator, GPU emulation is supported
79 * through a guest-side vendor driver's OpenGL ES implementation.
David 'Digit' Turner80b30c22011-08-26 17:38:47 +020080 */
81static int
82checkGlesEmulationStatus(void)
83{
84 /* We're going to check for the following kernel parameters:
85 *
86 * qemu=1 -> tells us that we run inside the emulator
87 * android.qemu.gles=<number> -> tells us the GLES GPU emulation status
88 *
89 * Note that we will return <number> if we find it. This let us support
90 * more additionnal emulation modes in the future.
91 */
92 char prop[PROPERTY_VALUE_MAX];
93 int result = -1;
94
95 /* First, check for qemu=1 */
96 property_get("ro.kernel.qemu",prop,"0");
97 if (atoi(prop) != 1)
98 return -1;
99
100 /* We are in the emulator, get GPU status value */
bohu69e5b1a2016-02-19 17:15:20 -0800101 property_get("qemu.gles",prop,"0");
David 'Digit' Turner80b30c22011-08-26 17:38:47 +0200102 return atoi(prop);
103}
104
Jesse Hall1508ae62017-01-19 17:43:26 -0800105static void* do_dlopen(const char* path, int mode) {
106 ATRACE_CALL();
107 return dlopen(path, mode);
108}
109
Mathias Agopiande586972009-05-28 17:39:03 -0700110// ----------------------------------------------------------------------------
111
Jesse Hall94cdba92013-07-11 09:40:35 -0700112Loader::driver_t::driver_t(void* gles)
Mathias Agopiande586972009-05-28 17:39:03 -0700113{
114 dso[0] = gles;
115 for (size_t i=1 ; i<NELEM(dso) ; i++)
116 dso[i] = 0;
117}
118
Jesse Hall94cdba92013-07-11 09:40:35 -0700119Loader::driver_t::~driver_t()
Mathias Agopiande586972009-05-28 17:39:03 -0700120{
121 for (size_t i=0 ; i<NELEM(dso) ; i++) {
122 if (dso[i]) {
123 dlclose(dso[i]);
124 dso[i] = 0;
125 }
126 }
127}
128
129status_t Loader::driver_t::set(void* hnd, int32_t api)
130{
131 switch (api) {
132 case EGL:
133 dso[0] = hnd;
134 break;
135 case GLESv1_CM:
136 dso[1] = hnd;
137 break;
138 case GLESv2:
139 dso[2] = hnd;
140 break;
141 default:
142 return BAD_INDEX;
143 }
144 return NO_ERROR;
145}
146
147// ----------------------------------------------------------------------------
148
Mathias Agopiande586972009-05-28 17:39:03 -0700149Loader::Loader()
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800150 : getProcAddress(NULL),
151 mLibGui(nullptr),
152 mGetDriverNamespace(nullptr)
153{
154 // FIXME: See note in GraphicsEnv.h about android_getDriverNamespace().
155 // libgui should already be loaded in any process that uses libEGL, but
156 // if for some reason it isn't, then we're not going to get a driver
157 // namespace anyway, so don't force it to be loaded.
158 mLibGui = dlopen("libgui.so", RTLD_NOLOAD | RTLD_LOCAL | RTLD_LAZY);
159 if (!mLibGui) {
160 ALOGD("failed to load libgui: %s", dlerror());
161 return;
162 }
163 mGetDriverNamespace = reinterpret_cast<decltype(mGetDriverNamespace)>(
164 dlsym(mLibGui, "android_getDriverNamespace"));
Mathias Agopiande586972009-05-28 17:39:03 -0700165}
166
Mathias Agopian99381422013-04-23 20:52:29 +0200167Loader::~Loader() {
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800168 if (mLibGui)
169 dlclose(mLibGui);
Mathias Agopiande586972009-05-28 17:39:03 -0700170}
171
Jesse Hallc07b5202013-07-04 12:08:16 -0700172static void* load_wrapper(const char* path) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800173 void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL);
Jesse Hallc07b5202013-07-04 12:08:16 -0700174 ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror());
175 return so;
176}
177
Evgenii Stepanovc2466e62015-07-08 15:49:52 -0700178#ifndef EGL_WRAPPER_DIR
179#if defined(__LP64__)
180#define EGL_WRAPPER_DIR "/system/lib64"
181#else
182#define EGL_WRAPPER_DIR "/system/lib"
183#endif
184#endif
185
bohu69e5b1a2016-02-19 17:15:20 -0800186static void setEmulatorGlesValue(void) {
187 char prop[PROPERTY_VALUE_MAX];
188 property_get("ro.kernel.qemu", prop, "0");
189 if (atoi(prop) != 1) return;
190
191 property_get("ro.kernel.qemu.gles",prop,"0");
192 if (atoi(prop) == 1) {
193 ALOGD("Emulator has host GPU support, qemu.gles is set to 1.");
194 property_set("qemu.gles", "1");
195 return;
196 }
197
198 // for now, checking the following
199 // directory is good enough for emulator system images
200 const char* vendor_lib_path =
201#if defined(__LP64__)
202 "/vendor/lib64/egl";
203#else
204 "/vendor/lib/egl";
205#endif
206
207 const bool has_vendor_lib = (access(vendor_lib_path, R_OK) == 0);
208 if (has_vendor_lib) {
209 ALOGD("Emulator has vendor provided software renderer, qemu.gles is set to 2.");
210 property_set("qemu.gles", "2");
211 } else {
212 ALOGD("Emulator without GPU support detected. "
213 "Fallback to legacy software renderer, qemu.gles is set to 0.");
214 property_set("qemu.gles", "0");
215 }
216}
217
Mathias Agopianada798b2012-02-13 17:09:30 -0800218void* Loader::open(egl_connection_t* cnx)
Mathias Agopiande586972009-05-28 17:39:03 -0700219{
Jesse Hall1508ae62017-01-19 17:43:26 -0800220 ATRACE_CALL();
221
Mathias Agopiande586972009-05-28 17:39:03 -0700222 void* dso;
Mathias Agopiande586972009-05-28 17:39:03 -0700223 driver_t* hnd = 0;
Jesse Hall94cdba92013-07-11 09:40:35 -0700224
bohu69e5b1a2016-02-19 17:15:20 -0800225 setEmulatorGlesValue();
226
Mathias Agopian99381422013-04-23 20:52:29 +0200227 dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2);
228 if (dso) {
229 hnd = new driver_t(dso);
230 } else {
231 // Always load EGL first
232 dso = load_driver("EGL", cnx, EGL);
Mathias Agopiande586972009-05-28 17:39:03 -0700233 if (dso) {
234 hnd = new driver_t(dso);
Mathias Agopian99381422013-04-23 20:52:29 +0200235 hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM );
236 hnd->set( load_driver("GLESv2", cnx, GLESv2), GLESv2 );
Mathias Agopiande586972009-05-28 17:39:03 -0700237 }
238 }
239
Mathias Agopian99381422013-04-23 20:52:29 +0200240 LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation");
Jesse Hallc07b5202013-07-04 12:08:16 -0700241
Evgenii Stepanovc2466e62015-07-08 15:49:52 -0700242 cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so");
243 cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so");
244 cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so");
245
Michael Chockc0ec5e22014-01-27 08:14:33 -0800246 LOG_ALWAYS_FATAL_IF(!cnx->libEgl,
247 "couldn't load system EGL wrapper libraries");
248
Jesse Hallc07b5202013-07-04 12:08:16 -0700249 LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
250 "couldn't load system OpenGL ES wrapper libraries");
251
Mathias Agopiande586972009-05-28 17:39:03 -0700252 return (void*)hnd;
253}
254
255status_t Loader::close(void* driver)
256{
257 driver_t* hnd = (driver_t*)driver;
258 delete hnd;
259 return NO_ERROR;
260}
261
Jesse Hall94cdba92013-07-11 09:40:35 -0700262void Loader::init_api(void* dso,
263 char const * const * api,
264 __eglMustCastToProperFunctionPointerType* curr,
265 getProcAddressType getProcAddress)
Mathias Agopiande586972009-05-28 17:39:03 -0700266{
Jesse Hall1508ae62017-01-19 17:43:26 -0800267 ATRACE_CALL();
268
Mathias Agopian7773c432012-02-13 20:06:08 -0800269 const ssize_t SIZE = 256;
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700270 char scrap[SIZE];
Mathias Agopiande586972009-05-28 17:39:03 -0700271 while (*api) {
272 char const * name = *api;
Jesse Hall94cdba92013-07-11 09:40:35 -0700273 __eglMustCastToProperFunctionPointerType f =
Mathias Agopiande586972009-05-28 17:39:03 -0700274 (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
275 if (f == NULL) {
276 // couldn't find the entry-point, use eglGetProcAddress()
277 f = getProcAddress(name);
278 }
279 if (f == NULL) {
280 // Try without the OES postfix
281 ssize_t index = ssize_t(strlen(name)) - 3;
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700282 if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) {
Mathias Agopiande586972009-05-28 17:39:03 -0700283 strncpy(scrap, name, index);
284 scrap[index] = 0;
285 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
Steve Block9d453682011-12-20 16:23:08 +0000286 //ALOGD_IF(f, "found <%s> instead", scrap);
Mathias Agopiande586972009-05-28 17:39:03 -0700287 }
288 }
289 if (f == NULL) {
290 // Try with the OES postfix
Mathias Agopian0ad71a92011-05-11 20:37:47 -0700291 ssize_t index = ssize_t(strlen(name)) - 3;
292 if (index>0 && strcmp(name+index, "OES")) {
293 snprintf(scrap, SIZE, "%sOES", name);
Mathias Agopiande586972009-05-28 17:39:03 -0700294 f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
Steve Block9d453682011-12-20 16:23:08 +0000295 //ALOGD_IF(f, "found <%s> instead", scrap);
Mathias Agopiande586972009-05-28 17:39:03 -0700296 }
297 }
298 if (f == NULL) {
Steve Block9d453682011-12-20 16:23:08 +0000299 //ALOGD("%s", name);
Mathias Agopiande586972009-05-28 17:39:03 -0700300 f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented;
Mathias Agopian48d438d2012-01-28 21:44:00 -0800301
302 /*
303 * GL_EXT_debug_label is special, we always report it as
304 * supported, it's handled by GLES_trace. If GLES_trace is not
305 * enabled, then these are no-ops.
306 */
307 if (!strcmp(name, "glInsertEventMarkerEXT")) {
308 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
309 } else if (!strcmp(name, "glPushGroupMarkerEXT")) {
310 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
311 } else if (!strcmp(name, "glPopGroupMarkerEXT")) {
312 f = (__eglMustCastToProperFunctionPointerType)gl_noop;
313 }
Mathias Agopiande586972009-05-28 17:39:03 -0700314 }
315 *curr++ = f;
316 api++;
317 }
318}
319
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800320static void* load_system_driver(const char* kind) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800321 ATRACE_CALL();
Mathias Agopian99381422013-04-23 20:52:29 +0200322 class MatchFile {
323 public:
324 static String8 find(const char* kind) {
325 String8 result;
Nicolas Capens776951f2015-11-06 10:10:21 -0500326 int emulationStatus = checkGlesEmulationStatus();
327 switch (emulationStatus) {
328 case 0:
Nicolas Capens776951f2015-11-06 10:10:21 -0500329#if defined(__LP64__)
330 result.setTo("/system/lib64/egl/libGLES_android.so");
331#else
332 result.setTo("/system/lib/egl/libGLES_android.so");
333#endif
334 return result;
335 case 1:
336 // Use host-side OpenGL through the "emulation" library
337#if defined(__LP64__)
338 result.appendFormat("/system/lib64/egl/lib%s_emulation.so", kind);
339#else
340 result.appendFormat("/system/lib/egl/lib%s_emulation.so", kind);
341#endif
342 return result;
343 default:
344 // Not in emulator, or use other guest-side implementation
345 break;
346 }
347
Mathias Agopian99381422013-04-23 20:52:29 +0200348 String8 pattern;
349 pattern.appendFormat("lib%s", kind);
350 const char* const searchPaths[] = {
Dan Willemsen8edb8f52014-02-16 10:23:54 -0800351#if defined(__LP64__)
352 "/vendor/lib64/egl",
353 "/system/lib64/egl"
354#else
Mathias Agopian99381422013-04-23 20:52:29 +0200355 "/vendor/lib/egl",
356 "/system/lib/egl"
Dan Willemsen8edb8f52014-02-16 10:23:54 -0800357#endif
Mathias Agopian99381422013-04-23 20:52:29 +0200358 };
Brian Swetland2b9e4f62010-09-20 12:58:15 -0700359
Mathias Agopian99381422013-04-23 20:52:29 +0200360 // first, we search for the exact name of the GLES userspace
361 // driver in both locations.
362 // i.e.:
363 // libGLES.so, or:
364 // libEGL.so, libGLESv1_CM.so, libGLESv2.so
365
366 for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
367 if (find(result, pattern, searchPaths[i], true)) {
368 return result;
369 }
370 }
371
372 // for compatibility with the old "egl.cfg" naming convention
373 // we look for files that match:
374 // libGLES_*.so, or:
375 // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
376
377 pattern.append("_");
378 for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
379 if (find(result, pattern, searchPaths[i], false)) {
380 return result;
381 }
382 }
383
384 // we didn't find the driver. gah.
385 result.clear();
386 return result;
Brian Swetland2b9e4f62010-09-20 12:58:15 -0700387 }
Mathias Agopian99381422013-04-23 20:52:29 +0200388
389 private:
390 static bool find(String8& result,
391 const String8& pattern, const char* const search, bool exact) {
Mathias Agopian99381422013-04-23 20:52:29 +0200392 if (exact) {
393 String8 absolutePath;
394 absolutePath.appendFormat("%s/%s.so", search, pattern.string());
395 if (!access(absolutePath.string(), R_OK)) {
396 result = absolutePath;
397 return true;
398 }
399 return false;
400 }
401
402 DIR* d = opendir(search);
403 if (d != NULL) {
404 struct dirent cur;
405 struct dirent* e;
406 while (readdir_r(d, &cur, &e) == 0 && e) {
407 if (e->d_type == DT_DIR) {
408 continue;
409 }
410 if (!strcmp(e->d_name, "libGLES_android.so")) {
411 // always skip the software renderer
412 continue;
413 }
414 if (strstr(e->d_name, pattern.string()) == e->d_name) {
415 if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) {
416 result.clear();
417 result.appendFormat("%s/%s", search, e->d_name);
418 closedir(d);
419 return true;
420 }
421 }
422 }
423 closedir(d);
424 }
425 return false;
426 }
427 };
428
429
430 String8 absolutePath = MatchFile::find(kind);
431 if (absolutePath.isEmpty()) {
432 // this happens often, we don't want to log an error
433 return 0;
Mathias Agopian8c173842009-09-20 16:01:02 -0700434 }
Mathias Agopian99381422013-04-23 20:52:29 +0200435 const char* const driver_absolute_path = absolutePath.string();
Mathias Agopiande586972009-05-28 17:39:03 -0700436
Jesse Hall1508ae62017-01-19 17:43:26 -0800437 void* dso = do_dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL);
Mathias Agopian8c173842009-09-20 16:01:02 -0700438 if (dso == 0) {
439 const char* err = dlerror();
Steve Blocke6f43dd2012-01-06 19:20:56 +0000440 ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown");
Mathias Agopian8c173842009-09-20 16:01:02 -0700441 return 0;
442 }
443
Steve Block9d453682011-12-20 16:23:08 +0000444 ALOGD("loaded %s", driver_absolute_path);
Mathias Agopianbaca89c2009-08-20 19:09:34 -0700445
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800446 return dso;
447}
448
Jesse Hall1508ae62017-01-19 17:43:26 -0800449static void* do_android_dlopen_ext(const char* path, int mode, const android_dlextinfo* info) {
450 ATRACE_CALL();
451 return android_dlopen_ext(path, mode, info);
452}
453
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800454static const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
455 "ro.hardware.egl",
456 "ro.board.platform",
457}};
458
459static void* load_updated_driver(const char* kind, android_namespace_t* ns) {
Jesse Hall1508ae62017-01-19 17:43:26 -0800460 ATRACE_CALL();
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800461 const android_dlextinfo dlextinfo = {
462 .flags = ANDROID_DLEXT_USE_NAMESPACE,
463 .library_namespace = ns,
464 };
465 void* so = nullptr;
466 char prop[PROPERTY_VALUE_MAX + 1];
467 for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
468 if (property_get(key, prop, nullptr) > 0) {
469 String8 name;
470 name.appendFormat("lib%s_%s.so", kind, prop);
Jesse Hall1508ae62017-01-19 17:43:26 -0800471 so = do_android_dlopen_ext(name.string(), RTLD_LOCAL | RTLD_NOW,
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800472 &dlextinfo);
473 if (so)
474 return so;
475 }
476 }
477 return nullptr;
478}
479
480void *Loader::load_driver(const char* kind,
481 egl_connection_t* cnx, uint32_t mask)
482{
Jesse Hall1508ae62017-01-19 17:43:26 -0800483 ATRACE_CALL();
484
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800485 void* dso = nullptr;
486 if (mGetDriverNamespace) {
487 android_namespace_t* ns = mGetDriverNamespace();
488 if (ns) {
489 dso = load_updated_driver(kind, ns);
490 }
491 }
492 if (!dso) {
493 dso = load_system_driver(kind);
494 if (!dso)
495 return NULL;
496 }
497
Mathias Agopiande586972009-05-28 17:39:03 -0700498 if (mask & EGL) {
499 getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress");
500
Jesse Hall94cdba92013-07-11 09:40:35 -0700501 ALOGE_IF(!getProcAddress,
Jesse Hall7a8d83e2016-12-20 15:24:28 -0800502 "can't find eglGetProcAddress() in EGL driver library");
Mathias Agopiande586972009-05-28 17:39:03 -0700503
Mathias Agopian618fa102009-10-14 02:06:37 -0700504 egl_t* egl = &cnx->egl;
Mathias Agopiande586972009-05-28 17:39:03 -0700505 __eglMustCastToProperFunctionPointerType* curr =
506 (__eglMustCastToProperFunctionPointerType*)egl;
507 char const * const * api = egl_names;
508 while (*api) {
509 char const * name = *api;
Jesse Hall94cdba92013-07-11 09:40:35 -0700510 __eglMustCastToProperFunctionPointerType f =
Mathias Agopiande586972009-05-28 17:39:03 -0700511 (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
512 if (f == NULL) {
513 // couldn't find the entry-point, use eglGetProcAddress()
514 f = getProcAddress(name);
515 if (f == NULL) {
516 f = (__eglMustCastToProperFunctionPointerType)0;
517 }
518 }
519 *curr++ = f;
520 api++;
521 }
522 }
Jesse Hall94cdba92013-07-11 09:40:35 -0700523
Mathias Agopiande586972009-05-28 17:39:03 -0700524 if (mask & GLESv1_CM) {
Mathias Agopian618fa102009-10-14 02:06:37 -0700525 init_api(dso, gl_names,
526 (__eglMustCastToProperFunctionPointerType*)
Mathias Agopian7773c432012-02-13 20:06:08 -0800527 &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl,
Mathias Agopian618fa102009-10-14 02:06:37 -0700528 getProcAddress);
Mathias Agopiande586972009-05-28 17:39:03 -0700529 }
530
531 if (mask & GLESv2) {
Mathias Agopian618fa102009-10-14 02:06:37 -0700532 init_api(dso, gl_names,
533 (__eglMustCastToProperFunctionPointerType*)
Mathias Agopian7773c432012-02-13 20:06:08 -0800534 &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl,
Mathias Agopiande586972009-05-28 17:39:03 -0700535 getProcAddress);
536 }
Jesse Hall94cdba92013-07-11 09:40:35 -0700537
Mathias Agopiande586972009-05-28 17:39:03 -0700538 return dso;
539}
540
541// ----------------------------------------------------------------------------
542}; // namespace android
543// ----------------------------------------------------------------------------