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

Commit 4d575538 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android Git Automerger
Browse files

am f589dd29: am e2a3e872: Merge "Fix GLES context version selection" into klp-dev

* commit 'f589dd29':
  Fix GLES context version selection
parents 3473e814 f589dd29
Loading
Loading
Loading
Loading
+17 −7
Original line number Original line Diff line number Diff line
@@ -30,9 +30,25 @@ namespace android {
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


RenderEngine* RenderEngine::create(EGLDisplay display, EGLConfig config) {
RenderEngine* RenderEngine::create(EGLDisplay display, EGLConfig config) {
    EGLint renderableType = 0;
    EGLint contextClientVersion = 0;

    // query the renderable type, setting the EGL_CONTEXT_CLIENT_VERSION accordingly
    if (!eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType)) {
        LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE");
    }

    if (renderableType & EGL_OPENGL_ES2_BIT) {
        contextClientVersion = 2;
    } else if (renderableType & EGL_OPENGL_ES_BIT) {
        contextClientVersion = 1;
    } else {
        LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs");
    }

    // Also create our EGLContext
    // Also create our EGLContext
    EGLint contextAttributes[] = {
    EGLint contextAttributes[] = {
            EGL_CONTEXT_CLIENT_VERSION, 2,      // MUST be first
            EGL_CONTEXT_CLIENT_VERSION, contextClientVersion,      // MUST be first
#ifdef EGL_IMG_context_priority
#ifdef EGL_IMG_context_priority
#ifdef HAS_CONTEXT_PRIORITY
#ifdef HAS_CONTEXT_PRIORITY
#warning "using EGL_IMG_context_priority"
#warning "using EGL_IMG_context_priority"
@@ -41,13 +57,7 @@ RenderEngine* RenderEngine::create(EGLDisplay display, EGLConfig config) {
#endif
#endif
            EGL_NONE, EGL_NONE
            EGL_NONE, EGL_NONE
    };
    };

    EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
    EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
    if (ctxt == EGL_NO_CONTEXT) {
        // maybe ES 2.x is not supported
        ALOGW("can't create an ES 2.x context, trying 1.x");
        ctxt = eglCreateContext(display, config, NULL, contextAttributes + 2);
    }


    // if can't create a GL context, we can only abort.
    // if can't create a GL context, we can only abort.
    LOG_ALWAYS_FATAL_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
    LOG_ALWAYS_FATAL_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
+42 −28
Original line number Original line Diff line number Diff line
@@ -367,43 +367,40 @@ public:
    operator EGLint const* () const { return &mList.keyAt(0).v; }
    operator EGLint const* () const { return &mList.keyAt(0).v; }
};
};


EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId,
    EGLint renderableType) {
    // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
    // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
    // it is to be used with WIFI displays
    // it is to be used with WIFI displays
    EGLConfig config;
    EGLConfig config;
    EGLint dummy;
    EGLint dummy;
    status_t err;
    status_t err;
    EGLint wantedAttribute;
    EGLint wantedAttributeValue;


    EGLAttributeVector attribs;
    EGLAttributeVector attribs;
    // TODO: enable ES2
    if (renderableType) {
    //attribs[EGL_RENDERABLE_TYPE]            = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT;
        attribs[EGL_RENDERABLE_TYPE]            = renderableType;
    attribs[EGL_SURFACE_TYPE]               = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
        attribs[EGL_RECORDABLE_ANDROID]         = EGL_TRUE;
        attribs[EGL_RECORDABLE_ANDROID]         = EGL_TRUE;
        attribs[EGL_SURFACE_TYPE]               = EGL_WINDOW_BIT|EGL_PBUFFER_BIT;
        attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
        attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
        attribs[EGL_RED_SIZE]                   = 8;
        attribs[EGL_RED_SIZE]                   = 8;
        attribs[EGL_GREEN_SIZE]                 = 8;
        attribs[EGL_GREEN_SIZE]                 = 8;
        attribs[EGL_BLUE_SIZE]                  = 8;
        attribs[EGL_BLUE_SIZE]                  = 8;
        wantedAttribute                         = EGL_NONE;
        wantedAttributeValue                    = EGL_NONE;


    err = selectConfigForAttribute(display, attribs, EGL_NONE, EGL_NONE, &config);
    } else {
    if (!err)
        // if no renderable type specified, fallback to a simplified query
        goto success;
        attribs[EGL_RECORDABLE_ANDROID]         = EGL_TRUE;
        wantedAttribute                         = EGL_NATIVE_VISUAL_ID;
        wantedAttributeValue                    = nativeVisualId;
    }


    // this didn't work, probably because we're on the emulator...
    err = selectConfigForAttribute(display, attribs, wantedAttribute,
    // try a simplified query
        wantedAttributeValue, &config);
    ALOGW("no suitable EGLConfig found, trying a simpler query");
    attribs.remove(EGL_RENDERABLE_TYPE);
    attribs.remove(EGL_FRAMEBUFFER_TARGET_ANDROID);
    attribs.remove(EGL_RECORDABLE_ANDROID);
    attribs.remove(EGL_RED_SIZE);
    attribs.remove(EGL_GREEN_SIZE);
    attribs.remove(EGL_BLUE_SIZE);
    err = selectConfigForAttribute(display, attribs,
            EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
    if (!err)
    if (!err)
        goto success;
        goto success;


    // this EGL is too lame for Android
    LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up");
    return 0;
    return 0;


success:
success:
@@ -428,8 +425,25 @@ void SurfaceFlinger::init() {
    mHwc = new HWComposer(this,
    mHwc = new HWComposer(this,
            *static_cast<HWComposer::EventHandler *>(this));
            *static_cast<HWComposer::EventHandler *>(this));


    // initialize the config and context (can't fail)
    // First try to get an ES2 config
    mEGLConfig = selectEGLConfig(mEGLDisplay, mHwc->getVisualID());
    mEGLConfig = selectEGLConfig(mEGLDisplay, mHwc->getVisualID(), EGL_OPENGL_ES2_BIT);

    if (!mEGLConfig) {
        // If ES2 fails, try ES1
        mEGLConfig = selectEGLConfig(mEGLDisplay, mHwc->getVisualID(), EGL_OPENGL_ES_BIT);
    }

    if (!mEGLConfig) {
        // still didn't work, probably because we're on the emulator...
        // try a simplified query
        ALOGW("no suitable EGLConfig found, trying a simpler query");
        mEGLConfig = selectEGLConfig(mEGLDisplay, mHwc->getVisualID(), 0);
    }

    if (!mEGLConfig) {
        // this EGL is too lame for android
        LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up");
    }


    // print some debugging info
    // print some debugging info
    EGLint r,g,b,a;
    EGLint r,g,b,a;
+2 −1
Original line number Original line Diff line number Diff line
@@ -318,7 +318,8 @@ private:
     */
     */
    static status_t selectConfigForAttribute(EGLDisplay dpy,
    static status_t selectConfigForAttribute(EGLDisplay dpy,
        EGLint const* attrs, EGLint attribute, EGLint value, EGLConfig* outConfig);
        EGLint const* attrs, EGLint attribute, EGLint value, EGLConfig* outConfig);
    static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId);
    static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId,
		EGLint renderableType);
    size_t getMaxTextureSize() const;
    size_t getMaxTextureSize() const;
    size_t getMaxViewportDims() const;
    size_t getMaxViewportDims() const;