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

Commit 0222871b authored by Tim Van Patten's avatar Tim Van Patten
Browse files

Read ro.hardware.egl for ANGLE's filename

The ANGLE shared object filename is currently hardcoded to
libGLESv2_angle.so, which prevents OEMs from specifying their own
filename when using ANGLE as the default OpenGL ES driver.

This CL updates initializeAnglePlatform() to build the ANGLE library
filename using the suffix specified by ro.hardware.egl when loading
ANGLE as the default OpenGL ES driver.

The filename when loading ANGLE from an APK will remain
libGLESv2_angle.so, for compatibilty reasons. This enforces naming
conventions when loading ANGLE APKs on to the device, regardless of the
name of the built-in version of ANGLE.

Bug: 178871212
Test: Build and launch CF
Change-Id: I462e076fc500d84fa2a27abfa491f82db4a9df80
parent 7a2cfcbc
Loading
Loading
Loading
Loading
+25 −6
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <EGL/Platform.h>
#include <EGL/Platform.h>
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop

#include <android-base/properties.h>
#include <android/dlext.h>
#include <android/dlext.h>
#include <dlfcn.h>
#include <dlfcn.h>
#include <graphicsenv/GraphicsEnv.h>
#include <graphicsenv/GraphicsEnv.h>
@@ -33,7 +35,6 @@


namespace angle {
namespace angle {


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


static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr;
static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr;
@@ -107,19 +108,37 @@ bool initializeAnglePlatform(EGLDisplay dpy) {
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    void* so = nullptr;
    void* so = nullptr;
    if (ns) {
    if (ns) {
        // Loading from an APK, so hard-code the suffix to "_angle".
        constexpr char kAngleEs2Lib[] = "libGLESv2_angle.so";
        const android_dlextinfo dlextinfo = {
        const android_dlextinfo dlextinfo = {
                .flags = ANDROID_DLEXT_USE_NAMESPACE,
                .flags = ANDROID_DLEXT_USE_NAMESPACE,
                .library_namespace = ns,
                .library_namespace = ns,
        };
        };
        so = android_dlopen_ext(kAngleEs2Lib, kAngleDlFlags, &dlextinfo);
        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 {
    } else {
        // If we are here, ANGLE is loaded as built-in gl driver in the sphal.
        // If we are here, ANGLE is loaded as built-in gl driver in the sphal.
        so = android_load_sphal_library(kAngleEs2Lib, kAngleDlFlags);
        // Get the specified ANGLE library filename suffix.
        std::string angleEs2LibSuffix = android::base::GetProperty("ro.hardware.egl", "");
        if (angleEs2LibSuffix.empty()) {
            ALOGE("%s failed to get valid ANGLE library filename suffix!", __FUNCTION__);
            return false;
        }
        }
    if (!so) {

        ALOGE("%s failed to dlopen %s!", __FUNCTION__, kAngleEs2Lib);
        std::string angleEs2LibName = "libGLESv2_" + angleEs2LibSuffix + ".so";
        so = android_load_sphal_library(angleEs2LibName.c_str(), kAngleDlFlags);
        if (so) {
            ALOGD("dlopen (%s) success at %p", angleEs2LibName.c_str(), so);
        } else {
            ALOGE("%s failed to dlopen %s!", __FUNCTION__, angleEs2LibName.c_str());
            return false;
            return false;
        }
        }
    }


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