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

Commit ada798b7 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 a64366ee
Loading
Loading
Loading
Loading
+13 −36
Original line number Original line 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()
Loader::Loader()
{
{
    char line[256];
    char line[256];
@@ -131,8 +125,9 @@ Loader::Loader()


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


@@ -141,14 +136,16 @@ Loader::Loader()
    if (cfg == NULL) {
    if (cfg == NULL) {
        // default config
        // default config
        ALOGD("egl.cfg not found, using default config");
        ALOGD("egl.cfg not found, using default config");
        gConfig.add( entry_t(0, 0, "android") );
        mDriverTag.setTo("android");
    } else {
    } else {
        while (fgets(line, 256, cfg)) {
        while (fgets(line, 256, cfg)) {
            int dpy;
            int dpy, impl;
            int impl;
            if (sscanf(line, "%u %u %s", &dpy, &impl, tag) == 3) {
            if (sscanf(line, "%u %u %s", &dpy, &impl, tag) == 3) {
                //ALOGD(">>> %u %u %s", dpy, impl, tag);
                //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);
        fclose(cfg);
@@ -160,30 +157,12 @@ Loader::~Loader()
    GLTrace_stop();
    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;
    void* dso;
    int index = int(display);
    driver_t* hnd = 0;
    driver_t* hnd = 0;
    
    
    char const* tag = getTag(index, impl);
    char const* tag = mDriverTag.string();
    if (tag) {
    if (tag) {
        dso = load_driver("GLES", tag, cnx, EGL | GLESv1_CM | GLESv2);
        dso = load_driver("GLES", tag, cnx, EGL | GLESv1_CM | GLESv2);
        if (dso) {
        if (dso) {
@@ -193,16 +172,14 @@ void* Loader::open(EGLNativeDisplayType display, int impl, egl_connection_t* cnx
            dso = load_driver("EGL", tag, cnx, EGL);
            dso = load_driver("EGL", tag, cnx, EGL);
            if (dso) {
            if (dso) {
                hnd = new driver_t(dso);
                hnd = new driver_t(dso);

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

                hnd->set( load_driver("GLESv2",    tag, cnx, GLESv2),    GLESv2 );
                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 "
            "couldn't find the default OpenGL ES implementation "
            "for default display");
            "for default display");
    
    
+2 −13
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/Singleton.h>
#include <utils/Singleton.h>
#include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Vector.h>


#include <EGL/egl.h>
#include <EGL/egl.h>


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

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

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


egl_connection_t gEGLImpl[IMPL_NUM_IMPLEMENTATIONS];
egl_connection_t gEGLImpl;
gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS];
gl_hooks_t gHooks[2];
gl_hooks_t gHooksNoContext;
gl_hooks_t gHooksNoContext;
pthread_key_t gGLWrapperKey = -1;
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) {
    if (intptr_t(config) >= dp->numTotalConfigs) {
        return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
        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) {
    if (cnx->dso == 0) {
        return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
        return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
    }
    }
@@ -228,7 +228,7 @@ EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image)
    // EGL.
    // EGL.


    egl_image_t const * const i = get_image(image);
    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
    // get our driver loader
    Loader& loader(Loader::getInstance());
    Loader& loader(Loader::getInstance());


    // dynamically load all our EGL implementations
    // dynamically load our EGL implementation
    egl_connection_t* cnx;
    egl_connection_t* cnx = &gEGLImpl;

    cnx = &gEGLImpl[IMPL_SOFTWARE];
    if (cnx->dso == 0) {
    if (cnx->dso == 0) {
        cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_SOFTWARE];
        cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX];
        cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_SOFTWARE];
        cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX];
        cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 0, cnx);
        cnx->dso = loader.open(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;
    }
    }


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


static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER;
+128 −219

File changed.

Preview size limit exceeded, changes collapsed.

+27 −27
Original line number Original line 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) {
void egl_cache_t::initialize(egl_display_t *display) {
    Mutex::Autolock lock(mMutex);
    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) {
    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 bcExtLen = strlen(BC_EXT_STR);
        size_t extsLen = strlen(exts);
        size_t extsLen = strlen(exts);
        bool equal = !strcmp(BC_EXT_STR, exts);
        bool equal = !strcmp(BC_EXT_STR, exts);
@@ -101,12 +101,12 @@ void egl_cache_t::initialize(egl_display_t *display) {
                            cnx->egl.eglGetProcAddress(
                            cnx->egl.eglGetProcAddress(
                                    "eglSetBlobCacheFuncsANDROID"));
                                    "eglSetBlobCacheFuncsANDROID"));
            if (eglSetBlobCacheFuncsANDROID == NULL) {
            if (eglSetBlobCacheFuncsANDROID == NULL) {
                    ALOGE("EGL_ANDROID_blob_cache advertised by display %d, "
                ALOGE("EGL_ANDROID_blob_cache advertised, "
                            "but unable to get eglSetBlobCacheFuncsANDROID", i);
                        "but unable to get eglSetBlobCacheFuncsANDROID");
                    continue;
                return;
            }
            }


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

    mInitialized = true;
    mInitialized = true;
}
}


Loading