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

Commit dbccd22e authored by Krzysztof Kosiński's avatar Krzysztof Kosiński
Browse files

Reintroduce EGL mitigations from Android P.

These mitigations are still necessary for GSI images with P vendor
partitions to pass Q CTS. This is essentially a revert of commit
30c1d90f adjusted to match the changes
introduced in the meantime.

Bug: 124411631
Test: Pixel XL boots, CtsVrTestCases passes on Pixel 3 GSI+P
Change-Id: I38bddfddda411337f5ed77b7e4899b922386f331
parent 0e7098cf
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,11 @@ bool findExtension(const char* exts, const char* name, size_t nameLen) {
    return false;
    return false;
}
}


bool needsAndroidPEglMitigation() {
    static const int32_t vndk_version = property_get_int32("ro.vndk.version", -1);
    return vndk_version <= 28;
}

int egl_get_init_count(EGLDisplay dpy) {
int egl_get_init_count(EGLDisplay dpy) {
    egl_display_t* eglDisplay = egl_display_t::get(dpy);
    egl_display_t* eglDisplay = egl_display_t::get(dpy);
    return eglDisplay ? eglDisplay->getRefsCount() : 0;
    return eglDisplay ? eglDisplay->getRefsCount() : 0;
@@ -384,6 +389,13 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
            if (len) {
            if (len) {
                // NOTE: we could avoid the copy if we had strnstr.
                // NOTE: we could avoid the copy if we had strnstr.
                const std::string ext(start, len);
                const std::string ext(start, len);
                // Mitigation for Android P vendor partitions: Adreno 530 driver shipped on
                // some Android P vendor partitions this extension under the draft KHR name,
                // but during Khronos review it was decided to demote it to EXT.
                if (needsAndroidPEglMitigation() && ext == "EGL_EXT_image_gl_colorspace" &&
                    findExtension(disp.queryString.extensions, "EGL_KHR_image_gl_colorspace")) {
                    mExtensionString.append("EGL_EXT_image_gl_colorspace ");
                }
                if (findExtension(disp.queryString.extensions, ext.c_str(), len)) {
                if (findExtension(disp.queryString.extensions, ext.c_str(), len)) {
                    mExtensionString.append(ext + " ");
                    mExtensionString.append(ext + " ");
                }
                }
+1 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ class egl_context_t;
struct egl_connection_t;
struct egl_connection_t;


bool findExtension(const char* exts, const char* name, size_t nameLen = 0);
bool findExtension(const char* exts, const char* name, size_t nameLen = 0);
bool needsAndroidPEglMitigation();


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


+21 −1
Original line number Original line Diff line number Diff line
@@ -1710,6 +1710,26 @@ EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,
    const egl_display_ptr dp = validate_display(dpy);
    const egl_display_ptr dp = validate_display(dpy);
    if (!dp) return EGL_NO_IMAGE_KHR;
    if (!dp) return EGL_NO_IMAGE_KHR;


    std::vector<AttrType> strippedAttribs;
    if (needsAndroidPEglMitigation()) {
        // Mitigation for Android P vendor partitions: eglImageCreateKHR should accept
        // EGL_GL_COLORSPACE_LINEAR_KHR, EGL_GL_COLORSPACE_SRGB_KHR and
        // EGL_GL_COLORSPACE_DEFAULT_EXT if EGL_EXT_image_gl_colorspace is supported,
        // but some drivers don't like the DEFAULT value and generate an error.
        for (const AttrType *attr = attrib_list; attr && attr[0] != EGL_NONE; attr += 2) {
            if (attr[0] == EGL_GL_COLORSPACE_KHR &&
                dp->haveExtension("EGL_EXT_image_gl_colorspace")) {
                if (attr[1] != EGL_GL_COLORSPACE_LINEAR_KHR &&
                    attr[1] != EGL_GL_COLORSPACE_SRGB_KHR) {
                    continue;
                }
            }
            strippedAttribs.push_back(attr[0]);
            strippedAttribs.push_back(attr[1]);
        }
        strippedAttribs.push_back(EGL_NONE);
    }

    ContextRef _c(dp.get(), ctx);
    ContextRef _c(dp.get(), ctx);
    egl_context_t* const c = _c.get();
    egl_context_t* const c = _c.get();


@@ -1717,7 +1737,7 @@ EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,
    egl_connection_t* const cnx = &gEGLImpl;
    egl_connection_t* const cnx = &gEGLImpl;
    if (cnx->dso && eglCreateImageFunc) {
    if (cnx->dso && eglCreateImageFunc) {
        result = eglCreateImageFunc(dp->disp.dpy, c ? c->context : EGL_NO_CONTEXT, target, buffer,
        result = eglCreateImageFunc(dp->disp.dpy, c ? c->context : EGL_NO_CONTEXT, target, buffer,
                                    attrib_list);
                                    needsAndroidPEglMitigation() ? strippedAttribs.data() : attrib_list);
    }
    }
    return result;
    return result;
}
}