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