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

Commit 8db8509e authored by Mathias Agopian's avatar Mathias Agopian
Browse files

remove multiplexing of multiple EGL implementation

from now on, the system can only have one EGL
implementation. this means the software and h/w renderer
cannot be used at the same time on a device. Of course, the
h/w renderer is always prefered; in its absence we
default to the software renderer.

Change-Id: Ib579f58055dd0ce4c4a99144131efa11c16ca3d3
parent cb66aec0
Loading
Loading
Loading
Loading
+13 −36
Original line number Diff line number Diff line
@@ -118,12 +118,6 @@ status_t Loader::driver_t::set(void* hnd, int32_t api)

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

Loader::entry_t::entry_t(int dpy, int impl, const char* tag)
    : dpy(dpy), impl(impl), tag(tag) {
}

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

Loader::Loader()
{
    char line[256];
@@ -131,8 +125,9 @@ Loader::Loader()

    /* Special case for GLES emulation */
    if (checkGlesEmulationStatus() == 0) {
        ALOGD("Emulator without GPU support detected. Fallback to software renderer.");
        gConfig.add( entry_t(0, 0, "android") );
        ALOGD("Emulator without GPU support detected. "
              "Fallback to software renderer.");
        mDriverTag.setTo("android");
        return;
    }

@@ -141,14 +136,16 @@ Loader::Loader()
    if (cfg == NULL) {
        // default config
        ALOGD("egl.cfg not found, using default config");
        gConfig.add( entry_t(0, 0, "android") );
        mDriverTag.setTo("android");
    } else {
        while (fgets(line, 256, cfg)) {
            int dpy;
            int impl;
            int dpy, impl;
            if (sscanf(line, "%u %u %s", &dpy, &impl, tag) == 3) {
                //ALOGD(">>> %u %u %s", dpy, impl, tag);
                gConfig.add( entry_t(dpy, impl, tag) );
                // We only load the h/w accelerated implementation
                if (tag != String8("android")) {
                    mDriverTag = tag;
                }
            }
        }
        fclose(cfg);
@@ -160,30 +157,12 @@ Loader::~Loader()
    GLTrace_stop();
}

const char* Loader::getTag(int dpy, int impl)
void* Loader::open(egl_connection_t* cnx)
{
    const Vector<entry_t>& cfgs(gConfig);    
    const size_t c = cfgs.size();
    for (size_t i=0 ; i<c ; i++) {
        if (dpy == cfgs[i].dpy)
            if (impl == cfgs[i].impl)
                return cfgs[i].tag.string();
    }
    return 0;
}

void* Loader::open(EGLNativeDisplayType display, int impl, egl_connection_t* cnx)
{
    /*
     * TODO: if we don't find display/0, then use 0/0
     * (0/0 should always work)
     */
    
    void* dso;
    int index = int(display);
    driver_t* hnd = 0;
    
    char const* tag = getTag(index, impl);
    char const* tag = mDriverTag.string();
    if (tag) {
        dso = load_driver("GLES", tag, cnx, EGL | GLESv1_CM | GLESv2);
        if (dso) {
@@ -193,16 +172,14 @@ void* Loader::open(EGLNativeDisplayType display, int impl, egl_connection_t* cnx
            dso = load_driver("EGL", tag, cnx, EGL);
            if (dso) {
                hnd = new driver_t(dso);

                // TODO: make this more automated
                hnd->set( load_driver("GLESv1_CM", tag, cnx, GLESv1_CM), GLESv1_CM );

                hnd->set( load_driver("GLESv2",    tag, cnx, GLESv2),    GLESv2 );
            }
        }
    }

    LOG_FATAL_IF(!index && !impl && !hnd, 
    LOG_FATAL_IF(!index && !hnd,
            "couldn't find the default OpenGL ES implementation "
            "for default display");
    
+2 −13
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
#include <utils/Errors.h>
#include <utils/Singleton.h>
#include <utils/String8.h>
#include <utils/Vector.h>

#include <EGL/egl.h>

@@ -53,23 +52,13 @@ class Loader : public Singleton<Loader>
        void* dso[3];
    };
    
    struct entry_t {
        entry_t() { }
        entry_t(int dpy, int impl, const char* tag);
        int dpy;
        int impl;
        String8 tag;
    };

    Vector<entry_t> gConfig;    
    String8 mDriverTag;
    getProcAddressType getProcAddress;
    
    const char* getTag(int dpy, int impl);

public:
    ~Loader();
    
    void* open(EGLNativeDisplayType display, int impl, egl_connection_t* cnx);
    void* open(egl_connection_t* cnx);
    status_t close(void* driver);
    
private:
+10 −29
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@
namespace android {
// ----------------------------------------------------------------------------

egl_connection_t gEGLImpl[IMPL_NUM_IMPLEMENTATIONS];
gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS];
egl_connection_t gEGLImpl;
gl_hooks_t gHooks[2];
gl_hooks_t gHooksNoContext;
pthread_key_t gGLWrapperKey = -1;

@@ -196,7 +196,7 @@ egl_connection_t* validate_display_config(EGLDisplay dpy, EGLConfig config,
    if (intptr_t(config) >= dp->numTotalConfigs) {
        return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
    }
    egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(config)].impl];
    egl_connection_t* const cnx = &gEGLImpl;
    if (cnx->dso == 0) {
        return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
    }
@@ -228,7 +228,7 @@ EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image)
    // EGL.

    egl_image_t const * const i = get_image(image);
    return i->images[c->impl];
    return i->image;
}

// ----------------------------------------------------------------------------
@@ -266,34 +266,15 @@ static EGLBoolean egl_init_drivers_locked() {
    // get our driver loader
    Loader& loader(Loader::getInstance());

    // dynamically load all our EGL implementations
    egl_connection_t* cnx;

    cnx = &gEGLImpl[IMPL_SOFTWARE];
    // dynamically load our EGL implementation
    egl_connection_t* cnx = &gEGLImpl;
    if (cnx->dso == 0) {
        cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_SOFTWARE];
        cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_SOFTWARE];
        cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 0, cnx);
    }

    cnx = &gEGLImpl[IMPL_HARDWARE];
    if (cnx->dso == 0) {
        char value[PROPERTY_VALUE_MAX];
        property_get("debug.egl.hw", value, "1");
        if (atoi(value) != 0) {
            cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_HARDWARE];
            cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_HARDWARE];
            cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 1, cnx);
        } else {
            ALOGD("3D hardware acceleration is disabled");
        }
    }

    if (!gEGLImpl[IMPL_SOFTWARE].dso && !gEGLImpl[IMPL_HARDWARE].dso) {
        return EGL_FALSE;
        cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX];
        cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX];
        cnx->dso = loader.open(cnx);
    }

    return EGL_TRUE;
    return cnx->dso ? EGL_TRUE : EGL_FALSE;
}

static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER;
+128 −219

File changed.

Preview size limit exceeded, changes collapsed.

+27 −27
Original line number Diff line number Diff line
@@ -83,10 +83,10 @@ egl_cache_t* egl_cache_t::get() {

void egl_cache_t::initialize(egl_display_t *display) {
    Mutex::Autolock lock(mMutex);
    for (int i = 0; i < IMPL_NUM_IMPLEMENTATIONS; i++) {
        egl_connection_t* const cnx = &gEGLImpl[i];

    egl_connection_t* const cnx = &gEGLImpl;
    if (cnx->dso && cnx->major >= 0 && cnx->minor >= 0) {
            const char* exts = display->disp[i].queryString.extensions;
        const char* exts = display->disp.queryString.extensions;
        size_t bcExtLen = strlen(BC_EXT_STR);
        size_t extsLen = strlen(exts);
        bool equal = !strcmp(BC_EXT_STR, exts);
@@ -101,12 +101,12 @@ void egl_cache_t::initialize(egl_display_t *display) {
                            cnx->egl.eglGetProcAddress(
                                    "eglSetBlobCacheFuncsANDROID"));
            if (eglSetBlobCacheFuncsANDROID == NULL) {
                    ALOGE("EGL_ANDROID_blob_cache advertised by display %d, "
                            "but unable to get eglSetBlobCacheFuncsANDROID", i);
                    continue;
                ALOGE("EGL_ANDROID_blob_cache advertised, "
                        "but unable to get eglSetBlobCacheFuncsANDROID");
                return;
            }

                eglSetBlobCacheFuncsANDROID(display->disp[i].dpy,
            eglSetBlobCacheFuncsANDROID(display->disp.dpy,
                    android::setBlob, android::getBlob);
            EGLint err = cnx->egl.eglGetError();
            if (err != EGL_SUCCESS) {
@@ -115,7 +115,7 @@ void egl_cache_t::initialize(egl_display_t *display) {
            }
        }
    }
    }

    mInitialized = true;
}

Loading