From 273e54391af7e0a89daec778980c3f8a800bcd7b Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 9 Aug 2023 14:19:34 +0100 Subject: [PATCH] egl/android: Remove hard-coded color-channel data We don't need to write out tables of the shift/size of every colour channel, because we already have that as part of the format description if we use pipe_format. Part-of: --- src/egl/drivers/dri2/platform_android.c | 36 ++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index c1e305b1f0e..830c088288e 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -43,6 +43,7 @@ #include "util/libsync.h" #include "util/os_file.h" +#include "main/glconfig.h" #include "egl_dri2.h" #include "eglglobals.h" #include "loader.h" @@ -794,17 +795,16 @@ droid_add_configs_for_visuals(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); static const struct { - int format; - int rgba_shifts[4]; - unsigned int rgba_sizes[4]; + int hal_format; + enum pipe_format pipe_format; } visuals[] = { - {HAL_PIXEL_FORMAT_RGBA_8888, {0, 8, 16, 24}, {8, 8, 8, 8}}, - {HAL_PIXEL_FORMAT_RGBX_8888, {0, 8, 16, -1}, {8, 8, 8, 0}}, - {HAL_PIXEL_FORMAT_RGB_565, {11, 5, 0, -1}, {5, 6, 5, 0}}, + {HAL_PIXEL_FORMAT_RGBA_8888, PIPE_FORMAT_RGBA8888_UNORM}, + {HAL_PIXEL_FORMAT_RGBX_8888, PIPE_FORMAT_RGBX8888_UNORM}, + {HAL_PIXEL_FORMAT_RGB_565, PIPE_FORMAT_R5G6B5_UNORM}, /* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA * visual if it turns out RGBA visual is not available. */ - {HAL_PIXEL_FORMAT_BGRA_8888, {16, 8, 0, 24}, {8, 8, 8, 8}}, + {HAL_PIXEL_FORMAT_BGRA_8888, PIPE_FORMAT_BGRA8888_UNORM}, }; unsigned int format_count[ARRAY_SIZE(visuals)] = {0}; @@ -832,16 +832,21 @@ droid_add_configs_for_visuals(_EGLDisplay *disp) /* Only enable BGRA configs when RGBA is not available. BGRA configs are * buggy on stock Android. */ - if (visuals[i].format == HAL_PIXEL_FORMAT_BGRA_8888 && has_rgba) + if (visuals[i].hal_format == HAL_PIXEL_FORMAT_BGRA_8888 && has_rgba) continue; for (int j = 0; dri2_dpy->driver_configs[j]; j++) { - const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; + const struct gl_config *gl_config = + (struct gl_config *) dri2_dpy->driver_configs; + if (gl_config->color_format != visuals[i].pipe_format) + continue; + + const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; const EGLint config_attrs[] = { EGL_NATIVE_VISUAL_ID, - visuals[i].format, + visuals[i].hal_format, EGL_NATIVE_VISUAL_TYPE, - visuals[i].format, + visuals[i].hal_format, EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE, EGL_RECORDABLE_ANDROID, @@ -850,19 +855,20 @@ droid_add_configs_for_visuals(_EGLDisplay *disp) }; struct dri2_egl_config *dri2_conf = dri2_add_config( - disp, dri2_dpy->driver_configs[j], surface_type, - config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes); + disp, dri2_dpy->driver_configs[j], surface_type, config_attrs, + NULL, NULL); if (dri2_conf) format_count[i]++; } - if (visuals[i].format == HAL_PIXEL_FORMAT_RGBA_8888 && format_count[i]) + + if (visuals[i].hal_format == HAL_PIXEL_FORMAT_RGBA_8888 && format_count[i]) has_rgba = true; } for (int i = 0; i < ARRAY_SIZE(format_count); i++) { if (!format_count[i]) { _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x", - visuals[i].format); + visuals[i].hal_format); } } }