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