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

Commit 4f556cbc authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Avoid double initialization of ANGLE platform." into main am: 940e127e

parents 121dd859 940e127e
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -611,8 +611,10 @@ Loader::driver_t* Loader::attempt_to_load_angle(egl_connection_t* cnx) {
}
}


void Loader::attempt_to_init_angle_backend(void* dso, egl_connection_t* cnx) {
void Loader::attempt_to_init_angle_backend(void* dso, egl_connection_t* cnx) {
    void* pANGLEGetDisplayPlatform = dlsym(dso, "ANGLEGetDisplayPlatform");
    cnx->angleGetDisplayPlatformFunc = dlsym(dso, "ANGLEGetDisplayPlatform");
    if (pANGLEGetDisplayPlatform) {
    cnx->angleResetDisplayPlatformFunc = dlsym(dso, "ANGLEResetDisplayPlatform");

    if (cnx->angleGetDisplayPlatformFunc) {
        ALOGV("ANGLE GLES library loaded");
        ALOGV("ANGLE GLES library loaded");
        cnx->angleLoaded = true;
        cnx->angleLoaded = true;
        android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::ANGLE);
        android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::ANGLE);
+9 −44
Original line number Original line Diff line number Diff line
@@ -35,12 +35,6 @@


namespace angle {
namespace angle {


constexpr char kAngleEs2Lib[] = "libGLESv2_angle.so";
constexpr int kAngleDlFlags = RTLD_LOCAL | RTLD_NOW;

static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr;
static ResetDisplayPlatformFunc angleResetDisplayPlatform = nullptr;

static time_t startTime = time(nullptr);
static time_t startTime = time(nullptr);


static const unsigned char* getTraceCategoryEnabledFlag(PlatformMethods* /*platform*/,
static const unsigned char* getTraceCategoryEnabledFlag(PlatformMethods* /*platform*/,
@@ -111,50 +105,19 @@ static void assignAnglePlatformMethods(PlatformMethods* platformMethods) {
}
}


// Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace
// Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace
bool initializeAnglePlatform(EGLDisplay dpy) {
bool initializeAnglePlatform(EGLDisplay dpy, android::egl_connection_t* const cnx) {
    // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform
    if (cnx->angleGetDisplayPlatformFunc == nullptr) {
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
        ALOGE("ANGLEGetDisplayPlatform is not initialized!");
    void* so = nullptr;
    if (ns) {
        const android_dlextinfo dlextinfo = {
                .flags = ANDROID_DLEXT_USE_NAMESPACE,
                .library_namespace = ns,
        };
        so = android_dlopen_ext(kAngleEs2Lib, kAngleDlFlags, &dlextinfo);
        if (so) {
            ALOGD("dlopen_ext from APK (%s) success at %p", kAngleEs2Lib, so);
        } else {
            ALOGE("dlopen_ext(\"%s\") failed: %s", kAngleEs2Lib, dlerror());
            return false;
        }
    } else {
        // If we are here, ANGLE is loaded as the default OpenGL ES driver.
        so = dlopen(kAngleEs2Lib, kAngleDlFlags);
        if (so) {
            ALOGD("dlopen (%s) success at %p", kAngleEs2Lib, so);
        } else {
            ALOGE("%s failed to dlopen %s: %s!", __FUNCTION__, kAngleEs2Lib, dlerror());
            return false;
        }
    }

    angleGetDisplayPlatform =
            reinterpret_cast<GetDisplayPlatformFunc>(dlsym(so, "ANGLEGetDisplayPlatform"));

    if (!angleGetDisplayPlatform) {
        ALOGE("dlsym lookup of ANGLEGetDisplayPlatform in libEGL_angle failed!");
        dlclose(so);
        return false;
        return false;
    }
    }


    angleResetDisplayPlatform =
    GetDisplayPlatformFunc angleGetDisplayPlatform =
            reinterpret_cast<ResetDisplayPlatformFunc>(dlsym(so, "ANGLEResetDisplayPlatform"));
            reinterpret_cast<GetDisplayPlatformFunc>(cnx->angleGetDisplayPlatformFunc);


    PlatformMethods* platformMethods = nullptr;
    PlatformMethods* platformMethods = nullptr;
    if (!((angleGetDisplayPlatform)(dpy, g_PlatformMethodNames, g_NumPlatformMethods, nullptr,
    if (!((angleGetDisplayPlatform)(dpy, g_PlatformMethodNames, g_NumPlatformMethods, nullptr,
                                    &platformMethods))) {
                                    &platformMethods))) {
        ALOGE("ANGLEGetDisplayPlatform call failed!");
        ALOGE("ANGLEGetDisplayPlatform call failed!");
        dlclose(so);
        return false;
        return false;
    }
    }
    if (platformMethods) {
    if (platformMethods) {
@@ -166,8 +129,10 @@ bool initializeAnglePlatform(EGLDisplay dpy) {
    return true;
    return true;
}
}


void resetAnglePlatform(EGLDisplay dpy) {
void resetAnglePlatform(EGLDisplay dpy, android::egl_connection_t* const cnx) {
    if (angleResetDisplayPlatform) {
    if (cnx->angleResetDisplayPlatformFunc) {
        ResetDisplayPlatformFunc angleResetDisplayPlatform =
                reinterpret_cast<ResetDisplayPlatformFunc>(cnx->angleResetDisplayPlatformFunc);
        angleResetDisplayPlatform(dpy);
        angleResetDisplayPlatform(dpy);
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -25,8 +25,8 @@


namespace angle {
namespace angle {


bool initializeAnglePlatform(EGLDisplay dpy);
bool initializeAnglePlatform(EGLDisplay dpy, android::egl_connection_t* const cnx);
void resetAnglePlatform(EGLDisplay dpy);
void resetAnglePlatform(EGLDisplay dpy, android::egl_connection_t* const cnx);


}; // namespace angle
}; // namespace angle


+2 −2
Original line number Original line Diff line number Diff line
@@ -168,7 +168,7 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn
        if (dpy == EGL_NO_DISPLAY) {
        if (dpy == EGL_NO_DISPLAY) {
            ALOGE("eglGetPlatformDisplay failed!");
            ALOGE("eglGetPlatformDisplay failed!");
        } else {
        } else {
            if (!angle::initializeAnglePlatform(dpy)) {
            if (!angle::initializeAnglePlatform(dpy, cnx)) {
                ALOGE("initializeAnglePlatform failed!");
                ALOGE("initializeAnglePlatform failed!");
            }
            }
        }
        }
@@ -433,7 +433,7 @@ EGLBoolean egl_display_t::terminate() {
        if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
        if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
            // If we're using ANGLE reset any custom DisplayPlatform
            // If we're using ANGLE reset any custom DisplayPlatform
            if (cnx->angleLoaded) {
            if (cnx->angleLoaded) {
                angle::resetAnglePlatform(disp.dpy);
                angle::resetAnglePlatform(disp.dpy, cnx);
            }
            }
            if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
            if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
                ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,
                ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,
+6 −1
Original line number Original line Diff line number Diff line
@@ -42,7 +42,9 @@ struct egl_connection_t {
            libGles1(nullptr),
            libGles1(nullptr),
            libGles2(nullptr),
            libGles2(nullptr),
            systemDriverUnloaded(false),
            systemDriverUnloaded(false),
            angleLoaded(false) {
            angleLoaded(false),
            angleGetDisplayPlatformFunc(nullptr),
            angleResetDisplayPlatformFunc(nullptr) {
        const char* const* entries = platform_names;
        const char* const* entries = platform_names;
        EGLFuncPointer* curr = reinterpret_cast<EGLFuncPointer*>(&platform);
        EGLFuncPointer* curr = reinterpret_cast<EGLFuncPointer*>(&platform);
        while (*entries) {
        while (*entries) {
@@ -75,6 +77,9 @@ struct egl_connection_t {


    bool systemDriverUnloaded;
    bool systemDriverUnloaded;
    bool angleLoaded; // Was ANGLE successfully loaded
    bool angleLoaded; // Was ANGLE successfully loaded

    void* angleGetDisplayPlatformFunc;
    void* angleResetDisplayPlatformFunc;
};
};


extern gl_hooks_t gHooks[2];
extern gl_hooks_t gHooks[2];