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