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