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

Commit 30edd0c3 authored by Courtney Goeltzenleuchter's avatar Courtney Goeltzenleuchter Committed by Android (Google) Code Review
Browse files

Merge "Add support for EGL_EXT_pixel_format_float"

parents 87162c12 0e4e3955
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -651,6 +651,13 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYTIMESTAMPSUPPORTEDANDROID) (EGLDispl
#endif
#endif

#ifndef EGL_KHR_pixel_format_float
#define EGL_KHR_pixel_format_float 1
#define EGL_COLOR_COMPONENT_TYPE_EXT 0x3339  // eglChooseConfig and eglGetConfigAttrib attribute
#define EGL_COLOR_COMPONENT_TYPE_FIXED_EXT 0x333A  // Attribute value for COLOR_COMPONENT_TYPE
#define EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT 0x333B  // Attribute value for COLOR_COMPONENT_TYPE
#endif

#ifdef __cplusplus
}
#endif
+37 −13
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ extern char const * const gExtensionString =
        "EGL_KHR_wait_sync "                    // strongly recommended
        "EGL_ANDROID_recordable "               // mandatory
        "EGL_KHR_partial_update "               // strongly recommended
        "EGL_EXT_pixel_format_float "
        "EGL_EXT_buffer_age "                   // strongly recommended with partial_update
        "EGL_KHR_create_context_no_error "
        "EGL_KHR_mutable_render_buffer "
@@ -477,28 +478,51 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
        // modify the EGLconfig's format before setting the native window's
        // format.

        // TODO: Add support for HAL_PIXEL_FORMAT_RGBA_FP16
        // by default, just pick RGBA_8888
        EGLint componentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_COLOR_COMPONENT_TYPE_EXT,
                                    &componentType);

        // by default, just pick appropriate RGBA
        EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
        if (dp->haveExtension("EGL_EXT_pixel_format_float") &&
            (componentType == EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)) {
            format = HAL_PIXEL_FORMAT_RGBA_FP16;
        }
        android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;

        EGLint a = 0;
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
        if (a > 0) {
            // alpha-channel requested, there's really only one suitable format
            format = HAL_PIXEL_FORMAT_RGBA_8888;
        } else {
        EGLint r, g, b;
        r = g = b = 0;
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE,   &r);
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE,  &b);
        cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
        EGLint colorDepth = r + g + b;

        if (a == 0) {
            if (colorDepth <= 16) {
                format = HAL_PIXEL_FORMAT_RGB_565;
            } else {
                if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
                    if (colorDepth > 24) {
                        format = HAL_PIXEL_FORMAT_RGBA_1010102;
                    } else {
                        format = HAL_PIXEL_FORMAT_RGBX_8888;
                    }
                } else {
                    format = HAL_PIXEL_FORMAT_RGBA_FP16;
                }
            }
        } else {
            if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
                if (colorDepth > 24) {
                    format = HAL_PIXEL_FORMAT_RGBA_1010102;
                } else {
                    format = HAL_PIXEL_FORMAT_RGBA_8888;
                }
            } else {
                format = HAL_PIXEL_FORMAT_RGBA_FP16;
            }
        }

        // now select a corresponding sRGB format if needed
+4 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <stdio.h>

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

#define ATTRIBUTE(_attr) { _attr, #_attr }

@@ -26,6 +27,7 @@ struct Attribute {
    char const* name;
};

// clang-format off
Attribute attributes[] = {
        ATTRIBUTE( EGL_BUFFER_SIZE ),
        ATTRIBUTE( EGL_ALPHA_SIZE ),
@@ -60,8 +62,9 @@ Attribute attributes[] = {
        ATTRIBUTE( EGL_RENDERABLE_TYPE ),
        ATTRIBUTE( EGL_MATCH_NATIVE_PIXMAP ),
        ATTRIBUTE( EGL_CONFORMANT ),
        ATTRIBUTE( EGL_COLOR_COMPONENT_TYPE_EXT ),
};

// clang-format on

int main(int argc, char** argv)
{
+3 −0
Original line number Diff line number Diff line
@@ -720,6 +720,9 @@
        <enum value="0x332D" name="EGL_YUV_PLANE1_TEXTURE_UNIT_NV"/>
        <enum value="0x332E" name="EGL_YUV_PLANE2_TEXTURE_UNIT_NV"/>
            <unused start="0x332F" end="0x339F"/>
        <enum value="0x3339" name="EGL_COLOR_COMPONENT_TYPE_EXT"/>
        <enum value="0x333A" name="EGL_COLOR_COMPONENT_TYPE_FIXED_EXT"/>
        <enum value="0x333B" name="EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT"/>
    </enums>

    <enums namespace="EGL" start="0x33A0" end="0x33AF" vendor="ANGLE" comment="Reserved for Shannon Woods (Bug 13175)">