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