Mesa (master): Add EGL xcb platform
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Nov 12 16:57:47 UTC 2020
Module: Mesa
Branch: master
Commit: 53660e4c4ed315d4b2fe5d921861fbfebf2bbe42
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=53660e4c4ed315d4b2fe5d921861fbfebf2bbe42
Author: Yuxuan Shui <yshuiv7 at gmail.com>
Date: Wed Aug 26 19:01:53 2020 +0100
Add EGL xcb platform
This enables GL applications to be written without any involvement of
Xlib.
EGL X11 platform is actually already xcb-only underneath, so this commit
just add the necessary interface changes so eglDisplay can be created
from a xcb_connection_t.
Reviewed-by: Adam Jackson <ajax at redhat.com>
Signed-off-by: Yuxuan Shui <yshuiv7 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6474>
---
docs/relnotes/new_features.txt | 1 +
include/EGL/eglext.h | 6 ++++++
meson.build | 1 +
src/egl/drivers/dri2/egl_dri2.c | 6 ++++++
src/egl/drivers/dri2/platform_x11.c | 9 +++++++--
src/egl/generate/egl.xml | 11 +++++++++--
src/egl/main/eglapi.c | 5 +++++
src/egl/main/egldisplay.c | 22 ++++++++++++++++++++++
src/egl/main/egldisplay.h | 7 +++++++
src/egl/main/eglglobals.c | 3 +++
10 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt
index e69de29bb2d..308563d8779 100644
--- a/docs/relnotes/new_features.txt
+++ b/docs/relnotes/new_features.txt
@@ -0,0 +1 @@
+EGL_MESA_platform_xcb
diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index a1e5e946899..a911e40c933 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -883,6 +883,12 @@ EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy,
#define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6
#endif /* EGL_EXT_platform_x11 */
+#ifndef EGL_MESA_platform_xcb
+#define EGL_MESA_platform_xcb 1
+#define EGL_PLATFORM_XCB_EXT 0x31DC
+#define EGL_PLATFORM_XCB_SCREEN_EXT 0x31DE
+#endif /* EGL_MESA_platform_xcb */
+
#ifndef EGL_EXT_protected_content
#define EGL_EXT_protected_content 1
#define EGL_PROTECTED_CONTENT_EXT 0x32C0
diff --git a/meson.build b/meson.build
index d8ac6e87e06..9bebca0742f 100644
--- a/meson.build
+++ b/meson.build
@@ -827,6 +827,7 @@ gl_pkgconfig_c_flags = []
if with_platform_x11
if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
pre_args += '-DHAVE_X11_PLATFORM'
+ pre_args += '-DHAVE_XCB_PLATFORM'
endif
if with_glx == 'xlib' or with_glx == 'gallium-xlib'
pre_args += '-DUSE_XSHM'
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 82c8442d452..a4164cccb8e 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -183,6 +183,11 @@ dri_is_thread_safe(void *loaderPrivate)
return false;
#endif
+#ifdef HAVE_XCB_PLATFORM
+ if (display->Platform == _EGL_PLATFORM_XCB)
+ return true;
+#endif
+
#ifdef HAVE_WAYLAND_PLATFORM
if (display->Platform == _EGL_PLATFORM_WAYLAND)
return true;
@@ -1178,6 +1183,7 @@ dri2_initialize(_EGLDisplay *disp)
ret = dri2_initialize_device(disp);
break;
case _EGL_PLATFORM_X11:
+ case _EGL_PLATFORM_XCB:
ret = dri2_initialize_x11(disp);
break;
case _EGL_PLATFORM_DRM:
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index af79eb1df6d..f61267af2aa 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -1212,7 +1212,8 @@ dri2_find_screen_for_display(const _EGLDisplay *disp, int fallback_screen)
const EGLAttrib *attr;
for (attr = disp->Options.Attribs; attr; attr += 2) {
- if (attr[0] == EGL_PLATFORM_X11_SCREEN_EXT)
+ if (attr[0] == EGL_PLATFORM_X11_SCREEN_EXT ||
+ attr[0] == EGL_PLATFORM_XCB_SCREEN_EXT)
return attr[1];
}
@@ -1232,10 +1233,14 @@ dri2_get_xcb_connection(_EGLDisplay *disp,
dri2_dpy->conn = xcb_connect(NULL, &screen);
dri2_dpy->own_device = true;
screen = dri2_find_screen_for_display(disp, screen);
- } else {
+ } else if (disp->Platform == _EGL_PLATFORM_X11) {
Display *dpy = disp->PlatformDisplay;
dri2_dpy->conn = XGetXCBConnection(dpy);
screen = DefaultScreen(dpy);
+ } else {
+ /* _EGL_PLATFORM_XCB */
+ dri2_dpy->conn = disp->PlatformDisplay;
+ screen = dri2_find_screen_for_display(disp, 0);
}
if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) {
diff --git a/src/egl/generate/egl.xml b/src/egl/generate/egl.xml
index d354a1ee7aa..106d4f3fadc 100644
--- a/src/egl/generate/egl.xml
+++ b/src/egl/generate/egl.xml
@@ -590,9 +590,10 @@
<enum value="0x31D7" name="EGL_PLATFORM_GBM_MESA" alias="EGL_PLATFORM_GBM_KHR"/>
<enum value="0x31D8" name="EGL_PLATFORM_WAYLAND_KHR"/>
<enum value="0x31D8" name="EGL_PLATFORM_WAYLAND_EXT" alias="EGL_PLATFORM_WAYLAND_KHR"/>
- <unused start="0x31DC" end="0x31DC"/>
+ <enum value="0x31DC" name="EGL_PLATFORM_XCB_EXT"/>
<enum value="0x31DD" name="EGL_PLATFORM_SURFACELESS_MESA"/>
- <unused start="0x31DE" end="0x31DF"/>
+ <enum value="0x31DE" name="EGL_PLATFORM_XCB_SCREEN_EXT"/>
+ <unused start="0x31DF" end="0x31DF"/>
</enums>
<!-- Due to an oversight in development, these enums alias the above MESA
@@ -2546,6 +2547,12 @@
<enum name="EGL_PLATFORM_X11_SCREEN_EXT"/>
</require>
</extension>
+ <extension name="EGL_EXT_platform_xcb" supported="egl">
+ <require>
+ <enum name="EGL_PLATFORM_XCB_EXT"/>
+ <enum name="EGL_PLATFORM_XCB_SCREEN_EXT"/>
+ </require>
+ </extension>
<extension name="EGL_EXT_protected_content" supported="egl">
<require>
<enum name="EGL_PROTECTED_CONTENT_EXT"/>
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 56dafca0d11..78d84f1c9b9 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -388,6 +388,11 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
disp = _eglGetX11Display((Display*) native_display, attrib_list);
break;
#endif
+#ifdef HAVE_XCB_PLATFORM
+ case EGL_PLATFORM_XCB_EXT:
+ disp = _eglGetXcbDisplay((xcb_connection_t*) native_display, attrib_list);
+ break;
+#endif
#ifdef HAVE_DRM_PLATFORM
case EGL_PLATFORM_GBM_MESA:
disp = _eglGetGbmDisplay((struct gbm_device*) native_display,
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 83a47c6b877..765618f0dd0 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
const char *name;
} egl_platforms[] = {
{ _EGL_PLATFORM_X11, "x11" },
+ { _EGL_PLATFORM_XCB, "xcb" },
{ _EGL_PLATFORM_WAYLAND, "wayland" },
{ _EGL_PLATFORM_DRM, "drm" },
{ _EGL_PLATFORM_ANDROID, "android" },
@@ -506,6 +507,27 @@ _eglGetX11Display(Display *native_display,
}
#endif /* HAVE_X11_PLATFORM */
+#ifdef HAVE_XCB_PLATFORM
+_EGLDisplay*
+_eglGetXcbDisplay(xcb_connection_t *native_display,
+ const EGLAttrib *attrib_list)
+{
+ /* EGL_EXT_platform_xcb recognizes exactly one attribute,
+ * EGL_PLATFORM_XCB_SCREEN_EXT, which is optional.
+ */
+ if (attrib_list != NULL) {
+ for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
+ if (attrib_list[i] != EGL_PLATFORM_XCB_SCREEN_EXT) {
+ _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
+ return NULL;
+ }
+ }
+ }
+
+ return _eglFindDisplay(_EGL_PLATFORM_XCB, native_display, attrib_list);
+}
+#endif /* HAVE_XCB_PLATFORM */
+
#ifdef HAVE_DRM_PLATFORM
_EGLDisplay*
_eglGetGbmDisplay(struct gbm_device *native_display,
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 46c3008b658..c377d02461f 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -45,6 +45,7 @@ extern "C" {
enum _egl_platform_type {
_EGL_PLATFORM_X11,
+ _EGL_PLATFORM_XCB,
_EGL_PLATFORM_WAYLAND,
_EGL_PLATFORM_DRM,
_EGL_PLATFORM_ANDROID,
@@ -294,6 +295,12 @@ _EGLDisplay*
_eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
#endif
+#ifdef HAVE_XCB_PLATFORM
+typedef struct xcb_connection_t xcb_connection_t;
+_EGLDisplay*
+_eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list);
+#endif
+
#ifdef HAVE_DRM_PLATFORM
struct gbm_device;
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 36d0c79bcd4..dd2b07c0da4 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -89,6 +89,9 @@ struct _egl_global _eglGlobal =
" EGL_EXT_platform_x11"
" EGL_KHR_platform_x11"
#endif
+#ifdef HAVE_XCB_PLATFORM
+ " EGL_MESA_platform_xcb"
+#endif
#ifdef HAVE_DRM_PLATFORM
" EGL_MESA_platform_gbm"
" EGL_KHR_platform_gbm"
More information about the mesa-commit
mailing list