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