[Mesa-dev] [PATCH 2/2] egl: implement EGL_MESA_transparent_alpha for x11 and wayland

Jonny Lamb jonny.lamb at collabora.co.uk
Mon Feb 23 06:32:34 PST 2015


Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67676
---
 include/EGL/eglmesaext.h                |  5 +++++
 src/egl/drivers/dri2/platform_wayland.c |  9 +++++++--
 src/egl/drivers/dri2/platform_x11.c     | 22 +++++++++++++---------
 src/egl/main/eglapi.c                   | 13 +++++++++++++
 src/egl/main/eglconfig.c                |  3 ++-
 5 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
index 5fcc527..3fa7c9c 100644
--- a/include/EGL/eglmesaext.h
+++ b/include/EGL/eglmesaext.h
@@ -170,6 +170,11 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
 #define EGL_NO_CONFIG_MESA			((EGLConfig)0)
 #endif
 
+#ifndef EGL_MESA_transparent_alpha
+#define EGL_MESA_transparent_alpha 1
+#define EGL_TRANSPARENT_ALPHA_MESA		0x31E9
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 3c34e07..ba071a5 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -965,6 +965,10 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
       { 0xff0000, 0xff00, 0xff, 0xff000000 };
    static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 };
    static const unsigned int rgb565_masks[4] = { 0xf800, 0x07e0, 0x001f, 0 };
+   static const EGLint argb_attrs[] = {
+       EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_ALPHA_MESA,
+       EGL_NONE
+   };
 
    loader_set_logger(_eglLog);
 
@@ -1044,8 +1048,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
       config = dri2_dpy->driver_configs[i];
       if (dri2_dpy->formats & HAS_XRGB8888)
 	 dri2_add_config(disp, config, i + 1, types, NULL, rgb_masks);
-      if (dri2_dpy->formats & HAS_ARGB8888)
-	 dri2_add_config(disp, config, i + 1, types, NULL, argb_masks);
+      if (dri2_dpy->formats & HAS_ARGB8888) {
+	 dri2_add_config(disp, config, i + 1, types, argb_attrs, argb_masks);
+      }
       if (dri2_dpy->formats & HAS_RGB565)
         dri2_add_config(disp, config, i + 1, types, NULL, rgb565_masks);
    }
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index cbcf6a7..c4c73ac 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -692,18 +692,22 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
 	    dri2_add_config(disp, dri2_dpy->driver_configs[j], id++,
 			    surface_type, config_attrs, rgba_masks);
 
-            /* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
-             * Otherwise it will only match a 32-bit RGBA visual.  On a
-             * composited window manager on X11, this will make all of the
-             * EGLConfigs with destination alpha get blended by the
-             * compositor.  This is probably not what the application
-             * wants... especially on drivers that only have 32-bit RGBA
-             * EGLConfigs! */
+            rgba_masks[3] =
+               ~(rgba_masks[0] | rgba_masks[1] | rgba_masks[2]);
+
             if (d.data->depth == 24) {
-               rgba_masks[3] =
-                  ~(rgba_masks[0] | rgba_masks[1] | rgba_masks[2]);
                dri2_add_config(disp, dri2_dpy->driver_configs[j], id++,
                                surface_type, config_attrs, rgba_masks);
+            } else if (d.data->depth == 32) {
+                EGLint rgba_attrs[] = {
+                        EGL_NATIVE_VISUAL_ID,   config_attrs[1],
+                        EGL_NATIVE_VISUAL_TYPE, config_attrs[3],
+                        EGL_TRANSPARENT_TYPE,   EGL_TRANSPARENT_ALPHA_MESA,
+                        EGL_NONE
+                };
+
+               dri2_add_config(disp, dri2_dpy->driver_configs[j], id++,
+                               surface_type, rgba_attrs, rgba_masks);
             }
 	 }
       }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index db44a26..d84861b 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -646,6 +646,10 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
    EGLSurface ret;
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
+
+   if (conf->TransparentType == EGL_TRANSPARENT_ALPHA_MESA)
+      RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
    surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
                                        attrib_list);
    ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
@@ -701,6 +705,9 @@ eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
 
+   if (conf->TransparentType == EGL_TRANSPARENT_ALPHA_MESA)
+      RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
    surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list);
    ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
 
@@ -1243,6 +1250,9 @@ eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config,
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
 
+   if (conf->TransparentType == EGL_TRANSPARENT_ALPHA_MESA)
+      RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
    surf = drv->API.CreateScreenSurfaceMESA(drv, disp, conf, attrib_list);
    ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
 
@@ -1431,6 +1441,9 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
 
+   if (conf->TransparentType == EGL_TRANSPARENT_ALPHA_MESA)
+      RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
    surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer,
                                                  conf, attrib_list);
    ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index 1ac716c..d8801fe 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -299,7 +299,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
                valid = EGL_FALSE;
             break;
          case EGL_TRANSPARENT_TYPE:
-            if (val != EGL_NONE && val != EGL_TRANSPARENT_RGB)
+            if (val != EGL_NONE && val != EGL_TRANSPARENT_RGB &&
+                val != EGL_TRANSPARENT_ALPHA_MESA)
                valid = EGL_FALSE;
             break;
          case EGL_COLOR_BUFFER_TYPE:
-- 
2.1.4



More information about the mesa-dev mailing list