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