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 | |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 19 | |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 20 | #include "Loader.h" |
| 21 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 24 | #include <dirent.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 25 | #include <dlfcn.h> |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 26 | |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 27 | #include <android/dlext.h> |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 28 | #include <cutils/properties.h> |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 29 | #include <log/log.h> |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 30 | |
Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 31 | #ifndef __ANDROID_VNDK__ |
Jiyong Park | 27c39e1 | 2017-05-08 13:00:02 +0900 | [diff] [blame] | 32 | #include <graphicsenv/GraphicsEnv.h> |
Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 33 | #endif |
Justin Yun | b732030 | 2017-05-22 15:13:40 +0900 | [diff] [blame] | 34 | #include <vndksupport/linker.h> |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 35 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 36 | #include "egl_trace.h" |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 37 | #include "egldefs.h" |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 38 | |
Jiyong Park | 5910dc7 | 2017-04-05 14:23:52 +0900 | [diff] [blame] | 39 | extern "C" { |
| 40 | android_namespace_t* android_get_exported_namespace(const char*); |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 41 | |
| 42 | // TODO(ianelliott@): Get this from an ANGLE header: |
| 43 | typedef enum ANGLEPreference { |
| 44 | ANGLE_NO_PREFERENCE = 0, |
| 45 | ANGLE_PREFER_NATIVE = 1, |
| 46 | ANGLE_PREFER_ANGLE = 2, |
| 47 | } ANGLEPreference; |
| 48 | |
| 49 | // TODO(ianelliott@): Get this from an ANGLE header: |
| 50 | typedef bool (*fpANGLEUseForApplication)(const char* appName, const char* deviceMfr, |
| 51 | const char* deviceModel, ANGLEPreference developerOption, |
| 52 | ANGLEPreference appPreference); |
Jiyong Park | 5910dc7 | 2017-04-05 14:23:52 +0900 | [diff] [blame] | 53 | } |
| 54 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 55 | // ---------------------------------------------------------------------------- |
| 56 | namespace android { |
| 57 | // ---------------------------------------------------------------------------- |
| 58 | |
| 59 | |
| 60 | /* |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 61 | * EGL userspace drivers must be provided either: |
| 62 | * - as a single library: |
| 63 | * /vendor/lib/egl/libGLES.so |
| 64 | * |
| 65 | * - as separate libraries: |
| 66 | * /vendor/lib/egl/libEGL.so |
| 67 | * /vendor/lib/egl/libGLESv1_CM.so |
| 68 | * /vendor/lib/egl/libGLESv2.so |
| 69 | * |
| 70 | * The software renderer for the emulator must be provided as a single |
| 71 | * library at: |
| 72 | * |
| 73 | * /system/lib/egl/libGLES_android.so |
| 74 | * |
| 75 | * |
| 76 | * For backward compatibility and to facilitate the transition to |
| 77 | * this new naming scheme, the loader will additionally look for: |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 78 | * |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 79 | * /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 80 | * |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 81 | */ |
| 82 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 83 | Loader& Loader::getInstance() { |
| 84 | static Loader loader; |
| 85 | return loader; |
| 86 | } |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 87 | |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 88 | /* This function is called to check whether we run inside the emulator, |
| 89 | * and if this is the case whether GLES GPU emulation is supported. |
| 90 | * |
| 91 | * Returned values are: |
| 92 | * -1 -> not running inside the emulator |
| 93 | * 0 -> running inside the emulator, but GPU emulation not supported |
| 94 | * 1 -> running inside the emulator, GPU emulation is supported |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 95 | * through the "emulation" host-side OpenGL ES implementation. |
| 96 | * 2 -> running inside the emulator, GPU emulation is supported |
| 97 | * through a guest-side vendor driver's OpenGL ES implementation. |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 98 | */ |
| 99 | static int |
| 100 | checkGlesEmulationStatus(void) |
| 101 | { |
| 102 | /* We're going to check for the following kernel parameters: |
| 103 | * |
| 104 | * qemu=1 -> tells us that we run inside the emulator |
| 105 | * android.qemu.gles=<number> -> tells us the GLES GPU emulation status |
| 106 | * |
| 107 | * Note that we will return <number> if we find it. This let us support |
| 108 | * more additionnal emulation modes in the future. |
| 109 | */ |
| 110 | char prop[PROPERTY_VALUE_MAX]; |
| 111 | int result = -1; |
| 112 | |
| 113 | /* First, check for qemu=1 */ |
| 114 | property_get("ro.kernel.qemu",prop,"0"); |
| 115 | if (atoi(prop) != 1) |
| 116 | return -1; |
| 117 | |
| 118 | /* We are in the emulator, get GPU status value */ |
bohu | 69e5b1a | 2016-02-19 17:15:20 -0800 | [diff] [blame] | 119 | property_get("qemu.gles",prop,"0"); |
David 'Digit' Turner | 80b30c2 | 2011-08-26 17:38:47 +0200 | [diff] [blame] | 120 | return atoi(prop); |
| 121 | } |
| 122 | |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 123 | static void* do_dlopen(const char* path, int mode) { |
| 124 | ATRACE_CALL(); |
| 125 | return dlopen(path, mode); |
| 126 | } |
| 127 | |
Jiyong Park | 5910dc7 | 2017-04-05 14:23:52 +0900 | [diff] [blame] | 128 | static void* do_android_dlopen_ext(const char* path, int mode, const android_dlextinfo* info) { |
| 129 | ATRACE_CALL(); |
| 130 | return android_dlopen_ext(path, mode, info); |
| 131 | } |
| 132 | |
Justin Yun | b732030 | 2017-05-22 15:13:40 +0900 | [diff] [blame] | 133 | static void* do_android_load_sphal_library(const char* path, int mode) { |
| 134 | ATRACE_CALL(); |
| 135 | return android_load_sphal_library(path, mode); |
| 136 | } |
| 137 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 138 | // ---------------------------------------------------------------------------- |
| 139 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 140 | Loader::driver_t::driver_t(void* gles) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 141 | { |
| 142 | dso[0] = gles; |
| 143 | for (size_t i=1 ; i<NELEM(dso) ; i++) |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 144 | dso[i] = nullptr; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 147 | Loader::driver_t::~driver_t() |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 148 | { |
| 149 | for (size_t i=0 ; i<NELEM(dso) ; i++) { |
| 150 | if (dso[i]) { |
| 151 | dlclose(dso[i]); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 152 | dso[i] = nullptr; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 157 | int Loader::driver_t::set(void* hnd, int32_t api) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 158 | { |
| 159 | switch (api) { |
| 160 | case EGL: |
| 161 | dso[0] = hnd; |
| 162 | break; |
| 163 | case GLESv1_CM: |
| 164 | dso[1] = hnd; |
| 165 | break; |
| 166 | case GLESv2: |
| 167 | dso[2] = hnd; |
| 168 | break; |
| 169 | default: |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 170 | return -EOVERFLOW; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 171 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 172 | return 0; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // ---------------------------------------------------------------------------- |
| 176 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 177 | Loader::Loader() |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 178 | : getProcAddress(nullptr) |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 179 | { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 182 | Loader::~Loader() { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 185 | static void* load_wrapper(const char* path) { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 186 | void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL); |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 187 | ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror()); |
| 188 | return so; |
| 189 | } |
| 190 | |
Evgenii Stepanov | c2466e6 | 2015-07-08 15:49:52 -0700 | [diff] [blame] | 191 | #ifndef EGL_WRAPPER_DIR |
| 192 | #if defined(__LP64__) |
| 193 | #define EGL_WRAPPER_DIR "/system/lib64" |
| 194 | #else |
| 195 | #define EGL_WRAPPER_DIR "/system/lib" |
| 196 | #endif |
| 197 | #endif |
| 198 | |
bohu | 69e5b1a | 2016-02-19 17:15:20 -0800 | [diff] [blame] | 199 | static void setEmulatorGlesValue(void) { |
| 200 | char prop[PROPERTY_VALUE_MAX]; |
| 201 | property_get("ro.kernel.qemu", prop, "0"); |
| 202 | if (atoi(prop) != 1) return; |
| 203 | |
| 204 | property_get("ro.kernel.qemu.gles",prop,"0"); |
| 205 | if (atoi(prop) == 1) { |
| 206 | ALOGD("Emulator has host GPU support, qemu.gles is set to 1."); |
| 207 | property_set("qemu.gles", "1"); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | // for now, checking the following |
| 212 | // directory is good enough for emulator system images |
| 213 | const char* vendor_lib_path = |
| 214 | #if defined(__LP64__) |
| 215 | "/vendor/lib64/egl"; |
| 216 | #else |
| 217 | "/vendor/lib/egl"; |
| 218 | #endif |
| 219 | |
| 220 | const bool has_vendor_lib = (access(vendor_lib_path, R_OK) == 0); |
| 221 | if (has_vendor_lib) { |
| 222 | ALOGD("Emulator has vendor provided software renderer, qemu.gles is set to 2."); |
| 223 | property_set("qemu.gles", "2"); |
| 224 | } else { |
| 225 | ALOGD("Emulator without GPU support detected. " |
| 226 | "Fallback to legacy software renderer, qemu.gles is set to 0."); |
| 227 | property_set("qemu.gles", "0"); |
| 228 | } |
| 229 | } |
| 230 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 231 | void* Loader::open(egl_connection_t* cnx) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 232 | { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 233 | ATRACE_CALL(); |
| 234 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 235 | void* dso; |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 236 | driver_t* hnd = nullptr; |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 237 | |
bohu | 69e5b1a | 2016-02-19 17:15:20 -0800 | [diff] [blame] | 238 | setEmulatorGlesValue(); |
| 239 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 240 | dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2); |
| 241 | if (dso) { |
| 242 | hnd = new driver_t(dso); |
| 243 | } else { |
| 244 | // Always load EGL first |
| 245 | dso = load_driver("EGL", cnx, EGL); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 246 | if (dso) { |
| 247 | hnd = new driver_t(dso); |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 248 | hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM ); |
| 249 | hnd->set( load_driver("GLESv2", cnx, GLESv2), GLESv2 ); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 253 | LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation"); |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 254 | |
Evgenii Stepanov | c2466e6 | 2015-07-08 15:49:52 -0700 | [diff] [blame] | 255 | cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so"); |
| 256 | cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so"); |
| 257 | cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so"); |
| 258 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 259 | LOG_ALWAYS_FATAL_IF(!cnx->libEgl, |
| 260 | "couldn't load system EGL wrapper libraries"); |
| 261 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 262 | LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1, |
| 263 | "couldn't load system OpenGL ES wrapper libraries"); |
| 264 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 265 | return (void*)hnd; |
| 266 | } |
| 267 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 268 | void Loader::close(void* driver) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 269 | { |
| 270 | driver_t* hnd = (driver_t*)driver; |
| 271 | delete hnd; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 274 | void Loader::init_api(void* dso, |
| 275 | char const * const * api, |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame^] | 276 | char const * const * ref_api, |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 277 | __eglMustCastToProperFunctionPointerType* curr, |
| 278 | getProcAddressType getProcAddress) |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 279 | { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 280 | ATRACE_CALL(); |
| 281 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 282 | const ssize_t SIZE = 256; |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 283 | char scrap[SIZE]; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 284 | while (*api) { |
| 285 | char const * name = *api; |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame^] | 286 | if (ref_api) { |
| 287 | char const * ref_name = *ref_api; |
| 288 | if (std::strcmp(name, ref_name) != 0) { |
| 289 | *curr++ = nullptr; |
| 290 | ref_api++; |
| 291 | continue; |
| 292 | } |
| 293 | } |
| 294 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 295 | __eglMustCastToProperFunctionPointerType f = |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 296 | (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 297 | if (f == nullptr) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 298 | // couldn't find the entry-point, use eglGetProcAddress() |
| 299 | f = getProcAddress(name); |
| 300 | } |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 301 | if (f == nullptr) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 302 | // Try without the OES postfix |
| 303 | ssize_t index = ssize_t(strlen(name)) - 3; |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 304 | if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 305 | strncpy(scrap, name, index); |
| 306 | scrap[index] = 0; |
| 307 | f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 308 | //ALOGD_IF(f, "found <%s> instead", scrap); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 311 | if (f == nullptr) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 312 | // Try with the OES postfix |
Mathias Agopian | 0ad71a9 | 2011-05-11 20:37:47 -0700 | [diff] [blame] | 313 | ssize_t index = ssize_t(strlen(name)) - 3; |
| 314 | if (index>0 && strcmp(name+index, "OES")) { |
| 315 | snprintf(scrap, SIZE, "%sOES", name); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 316 | f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 317 | //ALOGD_IF(f, "found <%s> instead", scrap); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 320 | if (f == nullptr) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 321 | //ALOGD("%s", name); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 322 | f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * GL_EXT_debug_label is special, we always report it as |
| 326 | * supported, it's handled by GLES_trace. If GLES_trace is not |
| 327 | * enabled, then these are no-ops. |
| 328 | */ |
| 329 | if (!strcmp(name, "glInsertEventMarkerEXT")) { |
| 330 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 331 | } else if (!strcmp(name, "glPushGroupMarkerEXT")) { |
| 332 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 333 | } else if (!strcmp(name, "glPopGroupMarkerEXT")) { |
| 334 | f = (__eglMustCastToProperFunctionPointerType)gl_noop; |
| 335 | } |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 336 | } |
| 337 | *curr++ = f; |
| 338 | api++; |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame^] | 339 | if (ref_api) ref_api++; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 343 | static void* load_system_driver(const char* kind) { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 344 | ATRACE_CALL(); |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 345 | class MatchFile { |
| 346 | public: |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 347 | static std::string find(const char* kind) { |
| 348 | std::string result; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 349 | int emulationStatus = checkGlesEmulationStatus(); |
| 350 | switch (emulationStatus) { |
| 351 | case 0: |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 352 | #if defined(__LP64__) |
bohu | 3adf9e1 | 2017-07-02 22:08:13 -0700 | [diff] [blame] | 353 | result = "/vendor/lib64/egl/libGLES_android.so"; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 354 | #else |
bohu | 3adf9e1 | 2017-07-02 22:08:13 -0700 | [diff] [blame] | 355 | result = "/vendor/lib/egl/libGLES_android.so"; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 356 | #endif |
| 357 | return result; |
| 358 | case 1: |
| 359 | // Use host-side OpenGL through the "emulation" library |
| 360 | #if defined(__LP64__) |
bohu | 3adf9e1 | 2017-07-02 22:08:13 -0700 | [diff] [blame] | 361 | result = std::string("/vendor/lib64/egl/lib") + kind + "_emulation.so"; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 362 | #else |
bohu | 3adf9e1 | 2017-07-02 22:08:13 -0700 | [diff] [blame] | 363 | result = std::string("/vendor/lib/egl/lib") + kind + "_emulation.so"; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 364 | #endif |
| 365 | return result; |
Lingfeng Yang | 0f82d87 | 2017-08-11 01:18:00 -0700 | [diff] [blame] | 366 | case 2: |
| 367 | // Use guest side swiftshader library |
| 368 | #if defined(__LP64__) |
| 369 | result = std::string("/vendor/lib64/egl/lib") + kind + "_swiftshader.so"; |
| 370 | #else |
| 371 | result = std::string("/vendor/lib/egl/lib") + kind + "_swiftshader.so"; |
| 372 | #endif |
| 373 | return result; |
Nicolas Capens | 776951f | 2015-11-06 10:10:21 -0500 | [diff] [blame] | 374 | default: |
| 375 | // Not in emulator, or use other guest-side implementation |
| 376 | break; |
| 377 | } |
| 378 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 379 | std::string pattern = std::string("lib") + kind; |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 380 | const char* const searchPaths[] = { |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 381 | #if defined(__LP64__) |
| 382 | "/vendor/lib64/egl", |
| 383 | "/system/lib64/egl" |
| 384 | #else |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 385 | "/vendor/lib/egl", |
| 386 | "/system/lib/egl" |
Dan Willemsen | 8edb8f5 | 2014-02-16 10:23:54 -0800 | [diff] [blame] | 387 | #endif |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 388 | }; |
Brian Swetland | 2b9e4f6 | 2010-09-20 12:58:15 -0700 | [diff] [blame] | 389 | |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 390 | // first, we search for the exact name of the GLES userspace |
| 391 | // driver in both locations. |
| 392 | // i.e.: |
| 393 | // libGLES.so, or: |
| 394 | // libEGL.so, libGLESv1_CM.so, libGLESv2.so |
| 395 | |
| 396 | for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { |
| 397 | if (find(result, pattern, searchPaths[i], true)) { |
| 398 | return result; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | // for compatibility with the old "egl.cfg" naming convention |
| 403 | // we look for files that match: |
| 404 | // libGLES_*.so, or: |
| 405 | // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so |
| 406 | |
| 407 | pattern.append("_"); |
| 408 | for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { |
| 409 | if (find(result, pattern, searchPaths[i], false)) { |
| 410 | return result; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | // we didn't find the driver. gah. |
| 415 | result.clear(); |
| 416 | return result; |
Brian Swetland | 2b9e4f6 | 2010-09-20 12:58:15 -0700 | [diff] [blame] | 417 | } |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 418 | |
| 419 | private: |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 420 | static bool find(std::string& result, |
| 421 | const std::string& pattern, const char* const search, bool exact) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 422 | if (exact) { |
Jesse Hall | 4aaa960 | 2017-08-29 16:33:54 -0700 | [diff] [blame] | 423 | std::string absolutePath = std::string(search) + "/" + pattern + ".so"; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 424 | if (!access(absolutePath.c_str(), R_OK)) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 425 | result = absolutePath; |
| 426 | return true; |
| 427 | } |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | DIR* d = opendir(search); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 432 | if (d != nullptr) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 433 | struct dirent* e; |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 434 | while ((e = readdir(d)) != nullptr) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 435 | if (e->d_type == DT_DIR) { |
| 436 | continue; |
| 437 | } |
| 438 | if (!strcmp(e->d_name, "libGLES_android.so")) { |
| 439 | // always skip the software renderer |
| 440 | continue; |
| 441 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 442 | if (strstr(e->d_name, pattern.c_str()) == e->d_name) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 443 | if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 444 | result = std::string(search) + "/" + e->d_name; |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 445 | closedir(d); |
| 446 | return true; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | closedir(d); |
| 451 | } |
| 452 | return false; |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 457 | std::string absolutePath = MatchFile::find(kind); |
| 458 | if (absolutePath.empty()) { |
Mathias Agopian | 9938142 | 2013-04-23 20:52:29 +0200 | [diff] [blame] | 459 | // this happens often, we don't want to log an error |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 460 | return nullptr; |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 461 | } |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 462 | const char* const driver_absolute_path = absolutePath.c_str(); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 463 | |
Jiyong Park | 5910dc7 | 2017-04-05 14:23:52 +0900 | [diff] [blame] | 464 | // Try to load drivers from the 'sphal' namespace, if it exist. Fall back to |
Justin Yun | b732030 | 2017-05-22 15:13:40 +0900 | [diff] [blame] | 465 | // the original routine when the namespace does not exist. |
Jiyong Park | 5910dc7 | 2017-04-05 14:23:52 +0900 | [diff] [blame] | 466 | // See /system/core/rootdir/etc/ld.config.txt for the configuration of the |
| 467 | // sphal namespace. |
Justin Yun | b732030 | 2017-05-22 15:13:40 +0900 | [diff] [blame] | 468 | void* dso = do_android_load_sphal_library(driver_absolute_path, |
| 469 | RTLD_NOW | RTLD_LOCAL); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 470 | if (dso == nullptr) { |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 471 | const char* err = dlerror(); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 472 | ALOGE("load_driver(%s): %s", driver_absolute_path, err ? err : "unknown"); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 473 | return nullptr; |
Mathias Agopian | 8c17384 | 2009-09-20 16:01:02 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 476 | ALOGD("loaded %s", driver_absolute_path); |
Mathias Agopian | baca89c | 2009-08-20 19:09:34 -0700 | [diff] [blame] | 477 | |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 478 | return dso; |
| 479 | } |
| 480 | |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 481 | static void* load_angle_from_namespace(const char* kind, android_namespace_t* ns) { |
| 482 | const android_dlextinfo dlextinfo = { |
| 483 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 484 | .library_namespace = ns, |
| 485 | }; |
| 486 | |
| 487 | std::string name = std::string("lib") + kind + "_angle.so"; |
| 488 | |
| 489 | void* so = do_android_dlopen_ext(name.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); |
| 490 | |
| 491 | if (so) { |
| 492 | ALOGD("dlopen_ext from APK (%s) success at %p", name.c_str(), so); |
| 493 | return so; |
| 494 | } else { |
| 495 | ALOGE("dlopen_ext(\"%s\") failed: %s", name.c_str(), dlerror()); |
| 496 | } |
| 497 | |
| 498 | return nullptr; |
| 499 | } |
| 500 | |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 501 | static ANGLEPreference getAnglePref(const char* app_pref) { |
| 502 | if (app_pref == nullptr) |
| 503 | return ANGLE_NO_PREFERENCE; |
| 504 | |
| 505 | if (strcmp(app_pref, "angle") == 0) { |
| 506 | return ANGLE_PREFER_ANGLE; |
| 507 | } else if (strcmp(app_pref, "native") == 0) { |
| 508 | return ANGLE_PREFER_NATIVE; |
| 509 | } |
| 510 | return ANGLE_NO_PREFERENCE; |
| 511 | } |
| 512 | |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 513 | static void* load_angle(const char* kind, egl_connection_t* cnx) { |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 514 | // Only attempt to load ANGLE libs |
| 515 | if (strcmp(kind, "EGL") != 0 && strcmp(kind, "GLESv2") != 0 && strcmp(kind, "GLESv1_CM") != 0) |
| 516 | return nullptr; |
| 517 | |
| 518 | void* so = nullptr; |
| 519 | std::string name; |
Ian Elliott | b058aff | 2018-08-09 12:00:55 -0600 | [diff] [blame] | 520 | char prop[PROPERTY_VALUE_MAX]; |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 521 | |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 522 | android_namespace_t* ns = android_getAngleNamespace(); |
| 523 | const char* app_name = android_getAngleAppName(); |
Cody Northrop | 49d5199 | 2018-08-29 16:37:09 -0600 | [diff] [blame] | 524 | const char* app_pref = android_getAngleAppPref(); |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 525 | bool developer_opt_in = android_getAngleDeveloperOptIn(); |
| 526 | |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 527 | // Determine whether or not to use ANGLE: |
| 528 | ANGLEPreference developer_option = developer_opt_in ? ANGLE_PREFER_ANGLE : ANGLE_NO_PREFERENCE; |
| 529 | bool use_angle = (developer_option == ANGLE_PREFER_ANGLE); |
| 530 | |
| 531 | if (use_angle) { |
| 532 | ALOGV("User set \"Developer Options\" to force the use of ANGLE"); |
| 533 | } else { |
| 534 | // The "Developer Options" value wasn't set to force the use of ANGLE. Need to temporarily |
| 535 | // load ANGLE and call the updatable opt-in/out logic: |
| 536 | std::string app_name_str = app_name ? app_name : ""; |
| 537 | char manufacturer[PROPERTY_VALUE_MAX]; |
| 538 | char model[PROPERTY_VALUE_MAX]; |
| 539 | property_get("ro.product.manufacturer", manufacturer, "UNSET"); |
| 540 | property_get("ro.product.model", model, "UNSET"); |
| 541 | ANGLEPreference app_preference = getAnglePref(android_getAngleAppPref()); |
| 542 | |
| 543 | so = load_angle_from_namespace("GLESv2", ns); |
| 544 | if (so) { |
| 545 | ALOGV("Temporarily loaded ANGLE's opt-in/out logic from namespace"); |
| 546 | fpANGLEUseForApplication fp = |
| 547 | (fpANGLEUseForApplication)dlsym(so, "ANGLEUseForApplication"); |
| 548 | if (fp) { |
| 549 | use_angle = (fp)(app_name_str.c_str(), manufacturer, model, developer_option, |
| 550 | app_preference); |
| 551 | ALOGV("Result of opt-in/out logic is %s", use_angle ? "true" : "false"); |
| 552 | } |
| 553 | |
| 554 | ALOGV("Close temporarily-loaded ANGLE opt-in/out logic"); |
| 555 | dlclose(so); |
| 556 | so = nullptr; |
| 557 | } else { |
| 558 | // We weren't able to load and call the updateable opt-in/out logic. |
| 559 | // If we can't load the library, there is no ANGLE available. |
| 560 | use_angle = false; |
| 561 | ALOGV("Could not temporarily-load the ANGLE opt-in/out logic, cannot use ANGLE."); |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 562 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 563 | } |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 564 | if (use_angle) { |
| 565 | so = load_angle_from_namespace(kind, ns); |
| 566 | } |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 567 | |
| 568 | if (so) { |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 569 | ALOGV("Loaded ANGLE %s library for %s (instead of native)", |
Ian Elliott | b058aff | 2018-08-09 12:00:55 -0600 | [diff] [blame] | 570 | kind, app_name ? app_name : "nullptr"); |
| 571 | property_get("debug.angle.backend", prop, "UNSET"); |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 572 | ALOGV("ANGLE's backend set to %s", prop); |
Ian Elliott | b058aff | 2018-08-09 12:00:55 -0600 | [diff] [blame] | 573 | property_get("debug.hwui.renderer", prop, "UNSET"); |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 574 | ALOGV("Skia's renderer set to %s", prop); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 575 | cnx->useAngle = true; |
| 576 | // Find and load vendor libEGL for ANGLE |
| 577 | if (!cnx->vendorEGL) { |
| 578 | cnx->vendorEGL = load_system_driver("EGL"); |
| 579 | } |
| 580 | return so; |
Ian Elliott | b058aff | 2018-08-09 12:00:55 -0600 | [diff] [blame] | 581 | } else { |
Ian Elliott | 3447447 | 2018-09-05 10:57:07 -0600 | [diff] [blame] | 582 | ALOGV("Loaded native %s library for %s (instead of ANGLE)", |
Ian Elliott | b058aff | 2018-08-09 12:00:55 -0600 | [diff] [blame] | 583 | kind, app_name ? app_name : "nullptr"); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | return nullptr; |
| 587 | } |
| 588 | |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 589 | static const char* HAL_SUBNAME_KEY_PROPERTIES[2] = { |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 590 | "ro.hardware.egl", |
| 591 | "ro.board.platform", |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 592 | }; |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 593 | |
| 594 | static void* load_updated_driver(const char* kind, android_namespace_t* ns) { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 595 | ATRACE_CALL(); |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 596 | const android_dlextinfo dlextinfo = { |
| 597 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 598 | .library_namespace = ns, |
| 599 | }; |
| 600 | void* so = nullptr; |
| 601 | char prop[PROPERTY_VALUE_MAX + 1]; |
| 602 | for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { |
| 603 | if (property_get(key, prop, nullptr) > 0) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 604 | std::string name = std::string("lib") + kind + "_" + prop + ".so"; |
| 605 | so = do_android_dlopen_ext(name.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 606 | if (so) { |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 607 | return so; |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 608 | } |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | return nullptr; |
| 612 | } |
| 613 | |
| 614 | void *Loader::load_driver(const char* kind, |
| 615 | egl_connection_t* cnx, uint32_t mask) |
| 616 | { |
Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 617 | ATRACE_CALL(); |
| 618 | |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 619 | void* dso = nullptr; |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 620 | dso = load_angle(kind, cnx); |
Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 621 | #ifndef __ANDROID_VNDK__ |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 622 | if (!dso) { |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 623 | android_namespace_t* ns = android_getDriverNamespace(); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 624 | if (ns) { |
| 625 | dso = load_updated_driver(kind, ns); |
| 626 | } |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 627 | } |
Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 628 | #endif |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 629 | if (!dso) { |
| 630 | dso = load_system_driver(kind); |
| 631 | if (!dso) |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 632 | return nullptr; |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 635 | if (mask & EGL) { |
| 636 | getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress"); |
| 637 | |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 638 | ALOGE_IF(!getProcAddress, |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 639 | "can't find eglGetProcAddress() in EGL driver library"); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 640 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 641 | egl_t* egl = &cnx->egl; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 642 | __eglMustCastToProperFunctionPointerType* curr = |
| 643 | (__eglMustCastToProperFunctionPointerType*)egl; |
| 644 | char const * const * api = egl_names; |
| 645 | while (*api) { |
| 646 | char const * name = *api; |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 647 | __eglMustCastToProperFunctionPointerType f = |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 648 | (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 649 | if (f == nullptr) { |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 650 | // couldn't find the entry-point, use eglGetProcAddress() |
| 651 | f = getProcAddress(name); |
Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 652 | if (f == nullptr) { |
| 653 | f = (__eglMustCastToProperFunctionPointerType)nullptr; |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | *curr++ = f; |
| 657 | api++; |
| 658 | } |
| 659 | } |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 660 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 661 | if (mask & GLESv1_CM) { |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame^] | 662 | init_api(dso, gl_names_1, gl_names, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 663 | (__eglMustCastToProperFunctionPointerType*) |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 664 | &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 665 | getProcAddress); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if (mask & GLESv2) { |
Yiwei Zhang | 7cc5892 | 2018-10-10 11:37:43 -0700 | [diff] [blame^] | 669 | init_api(dso, gl_names, nullptr, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 670 | (__eglMustCastToProperFunctionPointerType*) |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 671 | &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl, |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 672 | getProcAddress); |
| 673 | } |
Jesse Hall | 94cdba9 | 2013-07-11 09:40:35 -0700 | [diff] [blame] | 674 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 675 | return dso; |
| 676 | } |
| 677 | |
| 678 | // ---------------------------------------------------------------------------- |
| 679 | }; // namespace android |
| 680 | // ---------------------------------------------------------------------------- |