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