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