Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b07384b authored by Peiyong Lin's avatar Peiyong Lin
Browse files

Clean up EGL Loader.

Removes deprecated driver loading path, clean up comments and misc.

Bug: b/293503000
Test: boot
Change-Id: Ibc62bf59ed7b0cb3671583d2af853c457977d1d1
parent 9891d150
Loading
Loading
Loading
Loading
+51 −56
Original line number Diff line number Diff line
@@ -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.
@@ -306,13 +313,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) {
@@ -415,31 +422,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)) {
            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;
@@ -447,7 +442,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) {
@@ -460,7 +455,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;
                        }