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

Commit 327e301a authored by Peiyong Lin's avatar Peiyong Lin Committed by android-build-merger
Browse files

[GL Loader] Split loading logic based on API set and driver choices. am: 8cd204d6

am: 2458ba14

Change-Id: Ieb856ec1bf65aea3cd96e693f8a31d5b48f94b1e
parents 50bf57f7 2458ba14
Loading
Loading
Loading
Loading
+115 −59
Original line number Diff line number Diff line
@@ -39,10 +39,7 @@
#include "egldefs.h"
#include <EGL/eglext_angle.h>

// ----------------------------------------------------------------------------
namespace android {
// ----------------------------------------------------------------------------


/*
 * EGL userspace drivers must be provided either:
@@ -122,8 +119,6 @@ static void* do_android_load_sphal_library(const char* path, int mode) {
    return android_load_sphal_library(path, mode);
}

// ----------------------------------------------------------------------------

Loader::driver_t::driver_t(void* gles)
{
    dso[0] = gles;
@@ -159,8 +154,6 @@ int Loader::driver_t::set(void* hnd, int32_t api)
    return 0;
}

// ----------------------------------------------------------------------------

Loader::Loader()
    : getProcAddress(nullptr)
{
@@ -220,9 +213,6 @@ void* Loader::open(egl_connection_t* cnx)
    ATRACE_CALL();
    const nsecs_t openTime = systemTime();

    void* dso;
    driver_t* hnd = nullptr;

    setEmulatorGlesValue();

    // Check if we should use ANGLE early, so loading each driver doesn't require repeated queries.
@@ -232,19 +222,19 @@ void* Loader::open(egl_connection_t* cnx)
        cnx->shouldUseAngle = false;
    }

    dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2);
    if (dso) {
        hnd = new driver_t(dso);
    } else {
        android::GraphicsEnv::getInstance().clearDriverLoadingInfo(
                android::GraphicsEnv::Api::API_GL);
        // Always load EGL first
        dso = load_driver("EGL", cnx, EGL);
        if (dso) {
            hnd = new driver_t(dso);
            hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM );
            hnd->set( load_driver("GLESv2",    cnx, GLESv2),    GLESv2 );
    // Firstly, try to load ANGLE driver.
    driver_t* hnd = attempt_to_load_angle(cnx);
    if (!hnd) {
        // Secondly, try to load from driver apk.
        hnd = attempt_to_load_updated_driver(cnx);
    }
    if (!hnd) {
        // Thirdly, try to load emulation driver.
        hnd = attempt_to_load_emulation_driver(cnx);
    }
    if (!hnd) {
        // Finally, load system driver.
        hnd = attempt_to_load_system_driver(cnx);
    }

    if (!hnd) {
@@ -360,7 +350,7 @@ void Loader::init_api(void* dso,
    }
}

static void* attempt_to_load_emulation_driver(const char* kind) {
static void* load_emulation_driver(const char* kind) {
    const int emulationStatus = checkGlesEmulationStatus();

    // Invalid emulation status, abort.
@@ -547,11 +537,6 @@ static void* load_angle_from_namespace(const char* kind, android_namespace_t* ns
}

static void* load_angle(const char* kind, android_namespace_t* ns, egl_connection_t* cnx) {
    // Only attempt to load ANGLE libs
    if (strcmp(kind, "EGL") != 0 && strcmp(kind, "GLESv2") != 0 && strcmp(kind, "GLESv1_CM") != 0) {
        return nullptr;
    }

    void* so = nullptr;

    if ((cnx->shouldUseAngle) || android::GraphicsEnv::getInstance().shouldUseAngle()) {
@@ -626,46 +611,119 @@ static void* load_updated_driver(const char* kind, android_namespace_t* ns) {
    return nullptr;
}

void *Loader::load_driver(const char* kind,
        egl_connection_t* cnx, uint32_t mask)
{
Loader::driver_t* Loader::attempt_to_load_angle(egl_connection_t* cnx) {
    ATRACE_CALL();

    void* dso = nullptr;
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    if (ns) {
    if (!ns) {
        return nullptr;
    }

    android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::ANGLE);
        dso = load_angle(kind, ns, cnx);
    driver_t* hnd = nullptr;

    // ANGLE doesn't ship with GLES library, and thus we skip GLES driver.
    void* dso = load_angle("EGL", ns, cnx);
    if (dso) {
            initialize_api(dso, cnx, mask);
            return dso;
        initialize_api(dso, cnx, EGL);
        hnd = new driver_t(dso);

        dso = load_angle("GLESv1_CM", ns, cnx);
        initialize_api(dso, cnx, GLESv1_CM);
        hnd->set(dso, GLESv1_CM);

        dso = load_angle("GLESv2", ns, cnx);
        initialize_api(dso, cnx, GLESv2);
        hnd->set(dso, GLESv2);
    }
    return hnd;
}

Loader::driver_t* Loader::attempt_to_load_updated_driver(egl_connection_t* cnx) {
    ATRACE_CALL();
#ifndef __ANDROID_VNDK__
    ns = android::GraphicsEnv::getInstance().getDriverNamespace();
    if (ns) {
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getDriverNamespace();
    if (!ns) {
        return nullptr;
    }

    android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL_UPDATED);
        dso = load_updated_driver(kind, ns);
    driver_t* hnd = nullptr;
    void* dso = load_updated_driver("GLES", ns);
    if (dso) {
            initialize_api(dso, cnx, mask);
            return dso;
        initialize_api(dso, cnx, EGL | GLESv1_CM | GLESv2);
        hnd = new driver_t(dso);
        return hnd;
    }

    dso = load_updated_driver("EGL", ns);
    if (dso) {
        initialize_api(dso, cnx, EGL);
        hnd = new driver_t(dso);

        dso = load_updated_driver("GLESv1_CM", ns);
        initialize_api(dso, cnx, GLESv1_CM);
        hnd->set(dso, GLESv1_CM);

        dso = load_updated_driver("GLESv2", ns);
        initialize_api(dso, cnx, GLESv2);
        hnd->set(dso, GLESv2);
    }
    return hnd;
#else
    return nullptr;
#endif
}

Loader::driver_t* Loader::attempt_to_load_emulation_driver(egl_connection_t* cnx) {
    ATRACE_CALL();
    android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL);
    dso = attempt_to_load_emulation_driver(kind);
    driver_t* hnd = nullptr;
    void* dso = load_emulation_driver("GLES");
    if (dso) {
        initialize_api(dso, cnx, mask);
        return dso;
        initialize_api(dso, cnx, EGL | GLESv1_CM | GLESv2);
        hnd = new driver_t(dso);
        return hnd;
    }
    dso = load_emulation_driver("EGL");
    if (dso) {
        initialize_api(dso, cnx, EGL);
        hnd = new driver_t(dso);

        dso = load_emulation_driver("GLESv1_CM");
        initialize_api(dso, cnx, GLESv1_CM);
        hnd->set(dso, GLESv1_CM);

        dso = load_emulation_driver("GLESv2");
        initialize_api(dso, cnx, GLESv2);
        hnd->set(dso, GLESv2);
    }
    return hnd;
}

    dso = load_system_driver(kind);
Loader::driver_t* Loader::attempt_to_load_system_driver(egl_connection_t* cnx) {
    ATRACE_CALL();
    android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL);
    driver_t* hnd = nullptr;
    void* dso = load_system_driver("GLES");
    if (dso) {
        initialize_api(dso, cnx, mask);
        return dso;
        initialize_api(dso, cnx, EGL | GLESv1_CM | GLESv2);
        hnd = new driver_t(dso);
        return hnd;
    }
    dso = load_system_driver("EGL");
    if (dso) {
        initialize_api(dso, cnx, EGL);
        hnd = new driver_t(dso);

    return nullptr;
        dso = load_system_driver("GLESv1_CM");
        initialize_api(dso, cnx, GLESv1_CM);
        hnd->set(dso, GLESv1_CM);

        dso = load_system_driver("GLESv2");
        initialize_api(dso, cnx, GLESv2);
        hnd->set(dso, GLESv2);
    }
    return hnd;
}

void Loader::initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask) {
@@ -710,6 +768,4 @@ void Loader::initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask) {
    }
}

// ----------------------------------------------------------------------------
}; // namespace android
// ----------------------------------------------------------------------------
} // namespace android
+4 −1
Original line number Diff line number Diff line
@@ -55,7 +55,10 @@ public:

private:
    Loader();
    void *load_driver(const char* kind, egl_connection_t* cnx, uint32_t mask);
    driver_t* attempt_to_load_angle(egl_connection_t* cnx);
    driver_t* attempt_to_load_updated_driver(egl_connection_t* cnx);
    driver_t* attempt_to_load_emulation_driver(egl_connection_t* cnx);
    driver_t* attempt_to_load_system_driver(egl_connection_t* cnx);
    void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);

    static __attribute__((noinline))