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