From ae4a6061fefd930234998c6d81942edeecafbd10 Mon Sep 17 00:00:00 2001
From: Frank Binns <frank.binns@imgtec.com>
Date: Thu, 11 Jan 2018 09:38:47 +0000
Subject: [PATCH] egl/wayland: expose EXT_yuv_surface support

This adds support for YUYV configs.

---
 src/egl/drivers/dri2/egl_dri2.c         |  1 +
 src/egl/drivers/dri2/platform_wayland.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ee3bcda..d511d73 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2769,6 +2769,7 @@ static const struct wl_drm_components_descriptor {
    { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 },
    { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 },
    { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 },
+   { __DRI_IMAGE_COMPONENTS_EXTERNAL, EGL_TEXTURE_EXTERNAL_WL, 1 },
 };
 
 static _EGLImage *
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index a096d95..72456d5 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -135,6 +135,13 @@ static const struct dri2_wl_visual {
       { 11, 5, 0, -1 },
       { 5, 6, 5, 0 },
    },
+   {
+     "YUYV",
+     WL_DRM_FORMAT_YUYV, WL_SHM_FORMAT_YUYV,
+     __DRI_IMAGE_FORMAT_YUYV, __DRI_IMAGE_FORMAT_NONE, 32,
+     { -1, -1, -1, -1 },
+     { 0, 0, 0, 0 },
+   },
 };
 
 static_assert(ARRAY_SIZE(dri2_wl_visuals) <= EGL_DRI2_MAX_FORMATS,
@@ -958,6 +965,7 @@ dri2_wl_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
 {
    switch (cap) {
    case DRI_LOADER_CAP_FP16:
+   case DRI_LOADER_CAP_YUV_SURFACE_IMG:
       return 1;
    default:
       return 0;
@@ -1552,6 +1560,7 @@ dri2_wl_add_configs_for_visuals(_EGLDisplay *disp)
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    unsigned int format_count[ARRAY_SIZE(dri2_wl_visuals)] = { 0 };
    unsigned int count = 0;
+   EGLint surface_type;
    bool assigned;
 
    for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) {
@@ -1563,8 +1572,12 @@ dri2_wl_add_configs_for_visuals(_EGLDisplay *disp)
          if (!BITSET_TEST(dri2_dpy->formats, j))
             continue;
 
+         surface_type = EGL_WINDOW_BIT;
+         if (dri2_wl_visuals[j].wl_drm_format != WL_DRM_FORMAT_YUYV)
+            surface_type |= EGL_PBUFFER_BIT;
+
          dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
-               count + 1, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, NULL, dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes);
+               count + 1, surface_type, NULL, dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes);
          if (dri2_conf) {
             if (dri2_conf->base.ConfigID == count + 1)
                count++;
