Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 1 | /* |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 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 |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 7 | ** |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 9 | ** |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 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 |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <ctype.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | #include <errno.h> |
| 22 | #include <dlfcn.h> |
| 23 | #include <limits.h> |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 24 | #include <dirent.h> |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 25 | |
| 26 | #include <cutils/log.h> |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 28 | |
| 29 | #include <EGL/egl.h> |
| 30 | |
Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 31 | #include "../glestrace.h" |
| 32 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 33 | #include "egldefs.h" |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 34 | #include "Loader.h" |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 35 | |
| 36 | // ---------------------------------------------------------------------------- |
| 37 | namespace android { |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | |
| 40 | |
| 41 | /* |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 42 | * 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 Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 59 | * |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 60 | * /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 61 | * |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 62 | */ |
| 63 | |
| 64 | ANDROID_SINGLETON_STATIC_INSTANCE( Loader ) |
| 65 | |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 66 | /* 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 |
| 73 | * through the "emulation" config. |
| 74 | */ |
| 75 | static int |
| 76 | checkGlesEmulationStatus(void) |
| 77 | { |
| 78 | /* We're going to check for the following kernel parameters: |
| 79 | * |
| 80 | * qemu=1 -> tells us that we run inside the emulator |
| 81 | * android.qemu.gles=<number> -> tells us the GLES GPU emulation status |
| 82 | * |
| 83 | * Note that we will return <number> if we find it. This let us support |
| 84 | * more additionnal emulation modes in the future. |
| 85 | */ |
| 86 | char prop[PROPERTY_VALUE_MAX]; |
| 87 | int result = -1; |
| 88 | |
| 89 | /* First, check for qemu=1 */ |
| 90 | property_get("ro.kernel.qemu",prop,"0"); |
| 91 | if (atoi(prop) != 1) |
| 92 | return -1; |
| 93 | |
| 94 | /* We are in the emulator, get GPU status value */ |
| 95 | property_get("ro.kernel.qemu.gles",prop,"0"); |
| 96 | return atoi(prop); |
| 97 | } |
| 98 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 99 | // ---------------------------------------------------------------------------- |
| 100 | |
Mathias Agopian | d75f84d | 2012-06-05 21:44:43 -0700 | [diff] [blame] | 101 | static char const * getProcessCmdline() { |
| 102 | long pid = getpid(); |
| 103 | char procPath[128]; |
| 104 | snprintf(procPath, 128, "/proc/%ld/cmdline", pid); |
| 105 | FILE * file = fopen(procPath, "r"); |
| 106 | if (file) { |
| 107 | static char cmdline[256]; |
| 108 | char *str = fgets(cmdline, sizeof(cmdline) - 1, file); |
| 109 | fclose(file); |
| 110 | if (str) { |
| 111 | return cmdline; |
| 112 | } |
| 113 | } |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | // ---------------------------------------------------------------------------- |
| 118 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 119 | Loader::driver_t::driver_t(void* gles) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 120 | { |
| 121 | dso[0] = gles; |
| 122 | for (size_t i=1 ; i<NELEM(dso) ; i++) |
| 123 | dso[i] = 0; |
| 124 | } |
| 125 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 126 | Loader::driver_t::~driver_t() |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 127 | { |
| 128 | for (size_t i=0 ; i<NELEM(dso) ; i++) { |
| 129 | if (dso[i]) { |
| 130 | dlclose(dso[i]); |
| 131 | dso[i] = 0; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | status_t Loader::driver_t::set(void* hnd, int32_t api) |
| 137 | { |
| 138 | switch (api) { |
| 139 | case EGL: |
| 140 | dso[0] = hnd; |
| 141 | break; |
| 142 | case GLESv1_CM: |
| 143 | dso[1] = hnd; |
| 144 | break; |
| 145 | case GLESv2: |
| 146 | dso[2] = hnd; |
| 147 | break; |
| 148 | default: |
| 149 | return BAD_INDEX; |
| 150 | } |
| 151 | return NO_ERROR; |
| 152 | } |
| 153 | |
| 154 | // ---------------------------------------------------------------------------- |
| 155 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 156 | Loader::Loader() |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 157 | : getProcAddress(NULL) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 160 | Loader::~Loader() { |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 161 | GLTrace_stop(); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 164 | static void* load_wrapper(const char* path) { |
| 165 | void* so = dlopen(path, RTLD_NOW | RTLD_LOCAL); |
| 166 | ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror()); |
| 167 | return so; |
| 168 | } |
| 169 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 170 | void* Loader::open(egl_connection_t* cnx) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 171 | { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 172 | void* dso; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 173 | driver_t* hnd = 0; |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 174 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 175 | dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2); |
| 176 | if (dso) { |
| 177 | hnd = new driver_t(dso); |
| 178 | } else { |
| 179 | // Always load EGL first |
| 180 | dso = load_driver("EGL", cnx, EGL); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 181 | if (dso) { |
| 182 | hnd = new driver_t(dso); |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 183 | hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM ); |
| 184 | hnd->set( load_driver("GLESv2", cnx, GLESv2), GLESv2 ); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 188 | LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation"); |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 189 | |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 190 | #if defined(__LP64__) |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame^] | 191 | cnx->libEgl = load_wrapper("/system/lib64/libEGL.so"); |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 192 | cnx->libGles2 = load_wrapper("/system/lib64/libGLESv2.so"); |
| 193 | cnx->libGles1 = load_wrapper("/system/lib64/libGLESv1_CM.so"); |
| 194 | #else |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame^] | 195 | cnx->libEgl = load_wrapper("/system/lib/libEGL.so"); |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 196 | cnx->libGles2 = load_wrapper("/system/lib/libGLESv2.so"); |
| 197 | cnx->libGles1 = load_wrapper("/system/lib/libGLESv1_CM.so"); |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 198 | #endif |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame^] | 199 | LOG_ALWAYS_FATAL_IF(!cnx->libEgl, |
| 200 | "couldn't load system EGL wrapper libraries"); |
| 201 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 202 | LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1, |
| 203 | "couldn't load system OpenGL ES wrapper libraries"); |
| 204 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 205 | return (void*)hnd; |
| 206 | } |
| 207 | |
| 208 | status_t Loader::close(void* driver) |
| 209 | { |
| 210 | driver_t* hnd = (driver_t*)driver; |
| 211 | delete hnd; |
| 212 | return NO_ERROR; |
| 213 | } |
| 214 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 215 | void Loader::init_api(void* dso, |
| 216 | char const * const * api, |
| 217 | __eglMustCastToProperFunctionPointerType* curr, |
| 218 | getProcAddressType getProcAddress) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 219 | { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 220 | const ssize_t SIZE = 256; |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 221 | char scrap[SIZE]; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 222 | while (*api) { |
| 223 | char const * name = *api; |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 224 | __eglMustCastToProperFunctionPointerType f = |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 225 | (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); |
| 226 | if (f == NULL) { |
| 227 | // couldn't find the entry-point, use eglGetProcAddress() |
| 228 | f = getProcAddress(name); |
| 229 | } |
| 230 | if (f == NULL) { |
| 231 | // Try without the OES postfix |
| 232 | ssize_t index = ssize_t(strlen(name)) - 3; |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 233 | if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 234 | strncpy(scrap, name, index); |
| 235 | scrap[index] = 0; |
| 236 | f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 237 | //ALOGD_IF(f, "found <%s> instead", scrap); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | if (f == NULL) { |
| 241 | // Try with the OES postfix |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 242 | ssize_t index = ssize_t(strlen(name)) - 3; |
| 243 | if (index>0 && strcmp(name+index, "OES")) { |
| 244 | snprintf(scrap, SIZE, "%sOES", name); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 245 | f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 246 | //ALOGD_IF(f, "found <%s> instead", scrap); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | if (f == NULL) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 250 | //ALOGD("%s", name); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 251 | f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 252 | |
| 253 | /* |
| 254 | * GL_EXT_debug_label is special, we always report it as |
| 255 | * supported, it's handled by GLES_trace. If GLES_trace is not |
| 256 | * enabled, then these are no-ops. |
| 257 | */ |
| 258 | if (!strcmp(name, "glInsertEventMarkerEXT")) { |
| 259 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 260 | } else if (!strcmp(name, "glPushGroupMarkerEXT")) { |
| 261 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 262 | } else if (!strcmp(name, "glPopGroupMarkerEXT")) { |
| 263 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 264 | } |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 265 | } |
| 266 | *curr++ = f; |
| 267 | api++; |
| 268 | } |
| 269 | } |
| 270 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 271 | void *Loader::load_driver(const char* kind, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 272 | egl_connection_t* cnx, uint32_t mask) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 273 | { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 274 | class MatchFile { |
| 275 | public: |
| 276 | static String8 find(const char* kind) { |
| 277 | String8 result; |
| 278 | String8 pattern; |
| 279 | pattern.appendFormat("lib%s", kind); |
| 280 | const char* const searchPaths[] = { |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 281 | #if defined(__LP64__) |
| 282 | "/vendor/lib64/egl", |
| 283 | "/system/lib64/egl" |
| 284 | #else |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 285 | "/vendor/lib/egl", |
| 286 | "/system/lib/egl" |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 287 | #endif |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 288 | }; |
Brian Swetland | 2b9e4f6 | 2010-09-20 12:58:15 -0700 | [diff] [blame] | 289 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 290 | // first, we search for the exact name of the GLES userspace |
| 291 | // driver in both locations. |
| 292 | // i.e.: |
| 293 | // libGLES.so, or: |
| 294 | // libEGL.so, libGLESv1_CM.so, libGLESv2.so |
| 295 | |
| 296 | for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { |
| 297 | if (find(result, pattern, searchPaths[i], true)) { |
| 298 | return result; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | // for compatibility with the old "egl.cfg" naming convention |
| 303 | // we look for files that match: |
| 304 | // libGLES_*.so, or: |
| 305 | // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so |
| 306 | |
| 307 | pattern.append("_"); |
| 308 | for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { |
| 309 | if (find(result, pattern, searchPaths[i], false)) { |
| 310 | return result; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // we didn't find the driver. gah. |
| 315 | result.clear(); |
| 316 | return result; |
Brian Swetland | 2b9e4f6 | 2010-09-20 12:58:15 -0700 | [diff] [blame] | 317 | } |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 318 | |
| 319 | private: |
| 320 | static bool find(String8& result, |
| 321 | const String8& pattern, const char* const search, bool exact) { |
| 322 | |
| 323 | // in the emulator case, we just return the hardcoded name |
| 324 | // of the software renderer. |
| 325 | if (checkGlesEmulationStatus() == 0) { |
| 326 | ALOGD("Emulator without GPU support detected. " |
| 327 | "Fallback to software renderer."); |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 328 | #if defined(__LP64__) |
| 329 | result.setTo("/system/lib64/egl/libGLES_android.so"); |
| 330 | #else |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 331 | result.setTo("/system/lib/egl/libGLES_android.so"); |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 332 | #endif |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 333 | return true; |
| 334 | } |
| 335 | |
| 336 | if (exact) { |
| 337 | String8 absolutePath; |
| 338 | absolutePath.appendFormat("%s/%s.so", search, pattern.string()); |
| 339 | if (!access(absolutePath.string(), R_OK)) { |
| 340 | result = absolutePath; |
| 341 | return true; |
| 342 | } |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | DIR* d = opendir(search); |
| 347 | if (d != NULL) { |
| 348 | struct dirent cur; |
| 349 | struct dirent* e; |
| 350 | while (readdir_r(d, &cur, &e) == 0 && e) { |
| 351 | if (e->d_type == DT_DIR) { |
| 352 | continue; |
| 353 | } |
| 354 | if (!strcmp(e->d_name, "libGLES_android.so")) { |
| 355 | // always skip the software renderer |
| 356 | continue; |
| 357 | } |
| 358 | if (strstr(e->d_name, pattern.string()) == e->d_name) { |
| 359 | if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) { |
| 360 | result.clear(); |
| 361 | result.appendFormat("%s/%s", search, e->d_name); |
| 362 | closedir(d); |
| 363 | return true; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | closedir(d); |
| 368 | } |
| 369 | return false; |
| 370 | } |
| 371 | }; |
| 372 | |
| 373 | |
| 374 | String8 absolutePath = MatchFile::find(kind); |
| 375 | if (absolutePath.isEmpty()) { |
| 376 | // this happens often, we don't want to log an error |
| 377 | return 0; |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 378 | } |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 379 | const char* const driver_absolute_path = absolutePath.string(); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 380 | |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 381 | void* dso = dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL); |
| 382 | if (dso == 0) { |
| 383 | const char* err = dlerror(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 384 | ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown"); |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 388 | ALOGD("loaded %s", driver_absolute_path); |
Mathias Agopian | baca89c | 2009-08-20 19:09:34 -0700 | [diff] [blame] | 389 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 390 | if (mask & EGL) { |
| 391 | getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress"); |
| 392 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 393 | ALOGE_IF(!getProcAddress, |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 394 | "can't find eglGetProcAddress() in %s", driver_absolute_path); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 395 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 396 | egl_t* egl = &cnx->egl; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 397 | __eglMustCastToProperFunctionPointerType* curr = |
| 398 | (__eglMustCastToProperFunctionPointerType*)egl; |
| 399 | char const * const * api = egl_names; |
| 400 | while (*api) { |
| 401 | char const * name = *api; |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 402 | __eglMustCastToProperFunctionPointerType f = |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 403 | (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); |
| 404 | if (f == NULL) { |
| 405 | // couldn't find the entry-point, use eglGetProcAddress() |
| 406 | f = getProcAddress(name); |
| 407 | if (f == NULL) { |
| 408 | f = (__eglMustCastToProperFunctionPointerType)0; |
| 409 | } |
| 410 | } |
| 411 | *curr++ = f; |
| 412 | api++; |
| 413 | } |
| 414 | } |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 415 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 416 | if (mask & GLESv1_CM) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 417 | init_api(dso, gl_names, |
| 418 | (__eglMustCastToProperFunctionPointerType*) |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 419 | &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 420 | getProcAddress); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | if (mask & GLESv2) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 424 | init_api(dso, gl_names, |
| 425 | (__eglMustCastToProperFunctionPointerType*) |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 426 | &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl, |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 427 | getProcAddress); |
| 428 | } |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 429 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 430 | return dso; |
| 431 | } |
| 432 | |
| 433 | // ---------------------------------------------------------------------------- |
| 434 | }; // namespace android |
| 435 | // ---------------------------------------------------------------------------- |