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