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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27709>
This commit is contained in:
Daniel Stone 2023-08-09 14:19:34 +01:00 committed by Marge Bot
parent d8d153d4c2
commit 273e54391a

View file

@ -43,6 +43,7 @@
#include "util/libsync.h" #include "util/libsync.h"
#include "util/os_file.h" #include "util/os_file.h"
#include "main/glconfig.h"
#include "egl_dri2.h" #include "egl_dri2.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "loader.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); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
static const struct { static const struct {
int format; int hal_format;
int rgba_shifts[4]; enum pipe_format pipe_format;
unsigned int rgba_sizes[4];
} visuals[] = { } visuals[] = {
{HAL_PIXEL_FORMAT_RGBA_8888, {0, 8, 16, 24}, {8, 8, 8, 8}}, {HAL_PIXEL_FORMAT_RGBA_8888, PIPE_FORMAT_RGBA8888_UNORM},
{HAL_PIXEL_FORMAT_RGBX_8888, {0, 8, 16, -1}, {8, 8, 8, 0}}, {HAL_PIXEL_FORMAT_RGBX_8888, PIPE_FORMAT_RGBX8888_UNORM},
{HAL_PIXEL_FORMAT_RGB_565, {11, 5, 0, -1}, {5, 6, 5, 0}}, {HAL_PIXEL_FORMAT_RGB_565, PIPE_FORMAT_R5G6B5_UNORM},
/* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA /* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA
* visual if it turns out RGBA visual is not available. * 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}; 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 /* Only enable BGRA configs when RGBA is not available. BGRA configs are
* buggy on stock Android. * 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; continue;
for (int j = 0; dri2_dpy->driver_configs[j]; j++) { 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[] = { const EGLint config_attrs[] = {
EGL_NATIVE_VISUAL_ID, EGL_NATIVE_VISUAL_ID,
visuals[i].format, visuals[i].hal_format,
EGL_NATIVE_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE,
visuals[i].format, visuals[i].hal_format,
EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_FRAMEBUFFER_TARGET_ANDROID,
EGL_TRUE, EGL_TRUE,
EGL_RECORDABLE_ANDROID, EGL_RECORDABLE_ANDROID,
@ -850,19 +855,20 @@ droid_add_configs_for_visuals(_EGLDisplay *disp)
}; };
struct dri2_egl_config *dri2_conf = dri2_add_config( struct dri2_egl_config *dri2_conf = dri2_add_config(
disp, dri2_dpy->driver_configs[j], surface_type, disp, dri2_dpy->driver_configs[j], surface_type, config_attrs,
config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes); NULL, NULL);
if (dri2_conf) if (dri2_conf)
format_count[i]++; 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; has_rgba = true;
} }
for (int i = 0; i < ARRAY_SIZE(format_count); i++) { for (int i = 0; i < ARRAY_SIZE(format_count); i++) {
if (!format_count[i]) { if (!format_count[i]) {
_eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x", _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
visuals[i].format); visuals[i].hal_format);
} }
} }
} }