diff options
| author | 2023-10-20 19:58:16 +0000 | |
|---|---|---|
| committer | 2023-10-20 19:58:16 +0000 | |
| commit | 1dfcd85da22f1dca96824c60c65b8dd35d3ab084 (patch) | |
| tree | 045bf03e78f7ff7714e0c81bac458d1f21ba0a3b | |
| parent | 1eeacf0ea864964df9a5099772eeb3b5b8d8c9df (diff) | |
| parent | bf8e3666a80365cab461745691f90aaa4a659d5d (diff) | |
Merge "[Cherry-pick] Clean up EGL Loader." into main am: bf8e3666a8
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2797319
Change-Id: I964d447087f5c47aa1fb9583716c9c15795e7259
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | opengl/libs/EGL/Loader.cpp | 107 |
1 files changed, 51 insertions, 56 deletions
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 654e5b7c03..04e2fffaef 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -41,24 +41,44 @@ namespace android { /* * EGL userspace drivers must be provided either: * - as a single library: - * /vendor/lib/egl/libGLES.so + * /vendor/${LIB}/egl/libGLES.so * * - as separate libraries: - * /vendor/lib/egl/libEGL.so - * /vendor/lib/egl/libGLESv1_CM.so - * /vendor/lib/egl/libGLESv2.so + * /vendor/${LIB}/egl/libEGL.so + * /vendor/${LIB}/egl/libGLESv1_CM.so + * /vendor/${LIB}/egl/libGLESv2.so * * For backward compatibility and to facilitate the transition to * this new naming scheme, the loader will additionally look for: * - * /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so + * /vendor/${LIB}/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_${SUFFIX}.so * */ -Loader& Loader::getInstance() { - static Loader loader; - return loader; -} +#ifndef SYSTEM_LIB_PATH +#if defined(__LP64__) +#define SYSTEM_LIB_PATH "/system/lib64" +#else +#define SYSTEM_LIB_PATH "/system/lib" +#endif +#endif + +static const char* PERSIST_DRIVER_SUFFIX_PROPERTY = "persist.graphics.egl"; +static const char* RO_DRIVER_SUFFIX_PROPERTY = "ro.hardware.egl"; +static const char* RO_BOARD_PLATFORM_PROPERTY = "ro.board.platform"; + +static const char* HAL_SUBNAME_KEY_PROPERTIES[3] = { + PERSIST_DRIVER_SUFFIX_PROPERTY, + RO_DRIVER_SUFFIX_PROPERTY, + RO_BOARD_PLATFORM_PROPERTY, +}; + +static const char* const VENDOR_LIB_EGL_DIR = +#if defined(__LP64__) + "/vendor/lib64/egl"; +#else + "/vendor/lib/egl"; +#endif static void* do_dlopen(const char* path, int mode) { ATRACE_CALL(); @@ -80,6 +100,17 @@ static int do_android_unload_sphal_library(void* dso) { return android_unload_sphal_library(dso); } +static void* load_wrapper(const char* path) { + void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL); + ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror()); + return so; +} + +Loader& Loader::getInstance() { + static Loader loader; + return loader; +} + Loader::driver_t::driver_t(void* gles) { dso[0] = gles; @@ -123,30 +154,6 @@ Loader::Loader() Loader::~Loader() { } -static void* load_wrapper(const char* path) { - void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL); - ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror()); - return so; -} - -#ifndef EGL_WRAPPER_DIR -#if defined(__LP64__) -#define EGL_WRAPPER_DIR "/system/lib64" -#else -#define EGL_WRAPPER_DIR "/system/lib" -#endif -#endif - -static const char* PERSIST_DRIVER_SUFFIX_PROPERTY = "persist.graphics.egl"; -static const char* RO_DRIVER_SUFFIX_PROPERTY = "ro.hardware.egl"; -static const char* RO_BOARD_PLATFORM_PROPERTY = "ro.board.platform"; - -static const char* HAL_SUBNAME_KEY_PROPERTIES[3] = { - PERSIST_DRIVER_SUFFIX_PROPERTY, - RO_DRIVER_SUFFIX_PROPERTY, - RO_BOARD_PLATFORM_PROPERTY, -}; - // Check whether the loaded system drivers should be unloaded in order to // load ANGLE or the updatable graphics drivers. // If ANGLE namespace is set, it means the application is identified to run on top of ANGLE. @@ -323,13 +330,13 @@ void* Loader::open(egl_connection_t* cnx) { HAL_SUBNAME_KEY_PROPERTIES[2]); if (!cnx->libEgl) { - cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so"); + cnx->libEgl = load_wrapper(SYSTEM_LIB_PATH "/libEGL.so"); } if (!cnx->libGles1) { - cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so"); + cnx->libGles1 = load_wrapper(SYSTEM_LIB_PATH "/libGLESv1_CM.so"); } if (!cnx->libGles2) { - cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so"); + cnx->libGles2 = load_wrapper(SYSTEM_LIB_PATH "/libGLESv2.so"); } if (!cnx->libEgl || !cnx->libGles2 || !cnx->libGles1) { @@ -432,31 +439,19 @@ static void* load_system_driver(const char* kind, const char* suffix, const bool class MatchFile { public: static std::string find(const char* libraryName, const bool exact) { - const char* const searchPaths[] = { -#if defined(__LP64__) - "/vendor/lib64/egl", - "/system/lib64/egl" -#else - "/vendor/lib/egl", - "/system/lib/egl" -#endif - }; - - for (auto dir : searchPaths) { - std::string absolutePath; - if (find(absolutePath, libraryName, dir, exact)) { - return absolutePath; - } + std::string absolutePath; + if (findLibPath(absolutePath, libraryName, exact)) { + return absolutePath; } // Driver not found. gah. return std::string(); } private: - static bool find(std::string& result, - const std::string& pattern, const char* const search, bool exact) { + static bool findLibPath(std::string& result, const std::string& pattern, bool exact) { + const std::string vendorLibEglDirString = std::string(VENDOR_LIB_EGL_DIR); if (exact) { - std::string absolutePath = std::string(search) + "/" + pattern + ".so"; + std::string absolutePath = vendorLibEglDirString + "/" + pattern + ".so"; if (!access(absolutePath.c_str(), R_OK)) { result = absolutePath; return true; @@ -464,7 +459,7 @@ static void* load_system_driver(const char* kind, const char* suffix, const bool return false; } - DIR* d = opendir(search); + DIR* d = opendir(VENDOR_LIB_EGL_DIR); if (d != nullptr) { struct dirent* e; while ((e = readdir(d)) != nullptr) { @@ -477,7 +472,7 @@ static void* load_system_driver(const char* kind, const char* suffix, const bool } if (strstr(e->d_name, pattern.c_str()) == e->d_name) { if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) { - result = std::string(search) + "/" + e->d_name; + result = vendorLibEglDirString + "/" + e->d_name; closedir(d); return true; } |