egl: Implement EGL_MESA_platform_surfaceless
authorChad Versace <chadversary@chromium.org>
Wed, 12 Oct 2016 22:48:15 +0000 (15:48 -0700)
committerChad Versace <chadversary@chromium.org>
Fri, 14 Oct 2016 18:19:40 +0000 (11:19 -0700)
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
include/EGL/eglmesaext.h
src/egl/main/eglapi.c
src/egl/main/egldisplay.c
src/egl/main/egldisplay.h
src/egl/main/eglglobals.c

index 337dd2cb789e731d68aa41cd206d889f45c0b0c0..188452ee0fe9e5cf6d5c518a35283c667111eada 100644 (file)
@@ -84,6 +84,11 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
 #define EGL_NO_CONFIG_MESA                     ((EGLConfig)0)
 #endif
 
+#ifndef EGL_MESA_platform_surfaceless
+#define EGL_MESA_platform_surfaceless 1
+#define EGL_PLATFORM_SURFACELESS_MESA           0x31DD
+#endif /* EGL_MESA_platform_surfaceless */
+
 #ifdef __cplusplus
 }
 #endif
index 4568b8b9d7465e558c7a6e4810d80a8ec6552897..d8bd76dd12c3816e1c67eb6fd4a2baa8fa4e3c84 100644 (file)
@@ -392,6 +392,11 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
       dpy = _eglGetWaylandDisplay((struct wl_display*) native_display,
                                   attrib_list);
       break;
+#endif
+#ifdef HAVE_SURFACELESS_PLATFORM
+   case EGL_PLATFORM_SURFACELESS_MESA:
+      dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
+      break;
 #endif
    default:
       RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
@@ -837,11 +842,30 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
    _EGLSurface *surf;
    EGLSurface ret;
 
-   _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
 
    if (native_window == NULL)
       RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
 
+#ifdef HAVE_SURFACELESS_PLATFORM
+   if (disp->Platform == _EGL_PLATFORM_SURFACELESS) {
+      /* From the EGL_MESA_platform_surfaceless spec (v1):
+       *
+       *    eglCreatePlatformWindowSurface fails when called with a <display>
+       *    that belongs to the surfaceless platform. It returns
+       *    EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
+       *    justification for this unconditional failure is that the
+       *    surfaceless platform has no native windows, and therefore the
+       *    <native_window> parameter is always invalid.
+       *
+       * This check must occur before checking the EGLConfig, which emits
+       * EGL_BAD_CONFIG.
+       */
+      RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
+   }
+#endif
+
+   _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
+
    surf = drv->API.CreateWindowSurface(drv, disp, conf, native_window,
                                        attrib_list);
    ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE;
@@ -943,6 +967,22 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
    _EGLSurface *surf;
    EGLSurface ret;
 
+#if HAVE_SURFACELESS_PLATFORM
+   if (disp->Platform == _EGL_PLATFORM_SURFACELESS) {
+      /* From the EGL_MESA_platform_surfaceless spec (v1):
+       *
+       *   [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
+       *   also fails when called with a <display> that belongs to the
+       *   surfaceless platform.  It returns EGL_NO_SURFACE and generates
+       *   EGL_BAD_NATIVE_PIXMAP.
+       *
+       * This check must occur before checking the EGLConfig, which emits
+       * EGL_BAD_CONFIG.
+       */
+      RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
+   }
+#endif
+
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
    surf = drv->API.CreatePixmapSurface(drv, disp, conf, native_pixmap,
                                        attrib_list);
index 3d4eb8126fcdcd8e42f73623e9678d838ac0640b..37711bd8695ea744dd18d66053e89d1946a57d0e 100644 (file)
@@ -540,3 +540,24 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
    return _eglFindDisplay(_EGL_PLATFORM_WAYLAND, native_display);
 }
 #endif /* HAVE_WAYLAND_PLATFORM */
+
+#ifdef HAVE_SURFACELESS_PLATFORM
+_EGLDisplay*
+_eglGetSurfacelessDisplay(void *native_display,
+                          const EGLint *attrib_list)
+{
+   /* This platform has no native display. */
+   if (native_display != NULL) {
+      _eglError(EGL_BAD_PARAMETER, "eglGetPlatformDisplay");
+      return NULL;
+   }
+
+   /* This platform recognizes no display attributes. */
+   if (attrib_list != NULL && attrib_list[0] != EGL_NONE) {
+      _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
+      return NULL;
+   }
+
+   return _eglFindDisplay(_EGL_PLATFORM_SURFACELESS, native_display);
+}
+#endif /* HAVE_SURFACELESS_PLATFORM */
index 22fb5c82c6ef6b6d18f4958091abe5b1e11711d6..62d9a112f1f4de2a035e519b88c59d1e2bbe296b 100644 (file)
@@ -274,6 +274,11 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
                       const EGLint *attrib_list);
 #endif
 
+#ifdef HAVE_SURFACELESS_PLATFORM
+_EGLDisplay*
+_eglGetSurfacelessDisplay(void *native_display,
+                          const EGLint *attrib_list);
+#endif
 
 #ifdef __cplusplus
 }
index 8fffa550f56cc8aa994830e1e4d54bb081ab12dc..cb41063e3217e8269ea29db49319be9b0a4c4e18 100644 (file)
@@ -61,6 +61,9 @@ struct _egl_global _eglGlobal =
 #endif
 #ifdef HAVE_DRM_PLATFORM
    " EGL_MESA_platform_gbm"
+#endif
+#ifdef HAVE_SURFACELESS_PLATFORM
+   " EGL_MESA_platform_surfaceless"
 #endif
    " EGL_KHR_client_get_all_proc_addresses"
    " EGL_KHR_debug",