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