[PATCH xserver 8/8] glamor: Eliminate EGL stubs

Adam Jackson ajax at redhat.com
Wed Nov 1 20:31:36 UTC 2017


glamor_init is now spelled glamor_api_init, and takes as a new parameter
the winsys API initialization function. A compatibility function is
added for radeon's sake since it's using glamor_init currently; it only
works for EGL, which is fine since Xephyr doesn't need it.

glamor_*_from_pixmap are moved to glamor/glamor_egl.c (i.e. the xfree86
code). This is legitimate because glamor_egl_dri3_fd_name_from_tex was a
stub in Xwayland anyway.

The window system support code is now fairly cleanly split; Xwayland has
no epoxy_glX* references, Xephyr has no epoxy_egl* references.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 glamor/Makefile.am                      |  7 +--
 glamor/glamor.c                         | 78 ++-------------------------------
 glamor/glamor.h                         | 18 ++++----
 glamor/glamor_egl.c                     | 74 ++++++++++++++++++++++++++++---
 glamor/glamor_egl_stubs.c               | 45 -------------------
 glamor/glamor_glx.c                     |  2 +-
 glamor/meson.build                      | 10 +++--
 hw/kdrive/ephyr/Makefile.am             |  1 -
 hw/kdrive/ephyr/hostx.c                 |  2 +-
 hw/kdrive/ephyr/meson.build             |  2 +-
 hw/xfree86/drivers/modesetting/driver.c |  2 +-
 hw/xwayland/xwayland-glamor.c           | 15 ++-----
 12 files changed, 99 insertions(+), 157 deletions(-)
 delete mode 100644 glamor/glamor_egl_stubs.c

diff --git a/glamor/Makefile.am b/glamor/Makefile.am
index 5f57c628c..014696cd3 100644
--- a/glamor/Makefile.am
+++ b/glamor/Makefile.am
@@ -1,4 +1,4 @@
-noinst_LTLIBRARIES = libglamor.la libglamor_egl_stubs.la
+noinst_LTLIBRARIES = libglamor.la
 
 libglamor_la_LIBADD = $(GLAMOR_LIBS)
 
@@ -46,6 +46,7 @@ libglamor_la_SOURCES = \
 	glamor_utils.c\
 	glamor_utils.h\
 	glamor_sync.c \
+	glamor_egl.h \
 	glamor.h
 
 if XV
@@ -54,8 +55,4 @@ libglamor_la_SOURCES += \
 	glamor_xv.h
 endif
 
-libglamor_egl_stubs_la_SOURCES = \
-	glamor_egl_stubs.c \
-	glamor_egl.h
-
 sdk_HEADERS = glamor.h
diff --git a/glamor/glamor.c b/glamor/glamor.c
index 2f15aa222..84810e1e7 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -432,7 +432,8 @@ glamor_setup_debug_output(ScreenPtr screen)
 
 /** Set up glamor for an already-configured GL context. */
 Bool
-glamor_init(ScreenPtr screen, unsigned int flags)
+glamor_api_init(ScreenPtr screen, unsigned int flags,
+                glamor_api_init_t api_init)
 {
     glamor_screen_private *glamor_priv;
     int gl_version;
@@ -484,14 +485,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
     screen->DestroyPixmap = glamor_destroy_pixmap;
 
-    /* If we are using egl screen, call egl screen init to
-     * register correct close screen function. */
-    if (flags & GLAMOR_USE_EGL_SCREEN) {
-        glamor_egl_screen_init(screen, &glamor_priv->ctx);
-    } else {
-        if (!glamor_glx_screen_init(&glamor_priv->ctx))
-            goto fail;
-    }
+    if (!api_init(screen, &glamor_priv->ctx))
+        goto fail;
 
     glamor_make_current(glamor_priv);
 
@@ -794,71 +789,6 @@ glamor_supports_pixmap_import_export(ScreenPtr screen)
     return glamor_priv->dri3_enabled;
 }
 
-_X_EXPORT int
-glamor_fd_from_pixmap(ScreenPtr screen,
-                      PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
-{
-    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-
-    if (!glamor_priv->dri3_enabled)
-        return -1;
-    switch (pixmap_priv->type) {
-    case GLAMOR_TEXTURE_DRM:
-    case GLAMOR_TEXTURE_ONLY:
-        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
-            return -1;
-        return glamor_egl_dri3_fd_name_from_tex(screen,
-                                                pixmap,
-                                                pixmap_priv->fbo->tex,
-                                                FALSE, stride, size);
-    default:
-        break;
-    }
-    return -1;
-}
-
-_X_EXPORT int
-glamor_shareable_fd_from_pixmap(ScreenPtr screen,
-                                PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
-{
-    unsigned orig_usage_hint = pixmap->usage_hint;
-    int ret;
-
-    /*
-     * The actual difference between a sharable and non sharable buffer
-     * is decided 4 call levels deep in glamor_make_pixmap_exportable()
-     * based on pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED
-     * 2 of those calls are also exported API, so we cannot just add a flag.
-     */
-    pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
-    ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
-    pixmap->usage_hint = orig_usage_hint;
-
-    return ret;
-}
-
-int
-glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
-{
-    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-
-    switch (pixmap_priv->type) {
-    case GLAMOR_TEXTURE_DRM:
-    case GLAMOR_TEXTURE_ONLY:
-        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
-            return -1;
-        return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,
-                                                pixmap,
-                                                pixmap_priv->fbo->tex,
-                                                TRUE, stride, size);
-    default:
-        break;
-    }
-    return -1;
-}
-
 void
 glamor_finish(ScreenPtr screen)
 {
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 790f51eab..44ad48788 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -88,11 +88,8 @@ typedef enum glamor_pixmap_type {
 /* @glamor_init: Initialize glamor internal data structure.
  *
  * @screen: Current screen pointer.
- * @flags:  Please refer the flags description above.
- *
- * 	@GLAMOR_USE_EGL_SCREEN:
- * 	If you are using EGL layer, then please set this bit
- * 	on, otherwise, clear it.
+ * @flags: Please refer the flags description above.
+ * @api_init: Window system API init hook
  *
  *      @GLAMOR_NO_DRI3
  *      Disable the built-in DRI3 support
@@ -104,7 +101,11 @@ typedef enum glamor_pixmap_type {
  * be called after the DDX's screen initialization or at the last
  * step of the DDX's screen initialization.
  */
-extern _X_EXPORT Bool glamor_init(ScreenPtr screen, unsigned int flags);
+
+typedef Bool (*glamor_api_init_t)(ScreenPtr screen,
+                                  struct glamor_context *ctx);
+extern _X_EXPORT Bool glamor_api_init(ScreenPtr screen, unsigned int flags,
+                                      glamor_api_init_t api_init);
 extern _X_EXPORT void glamor_fini(ScreenPtr screen);
 
 /* This function is used to free the glamor private screen's
@@ -343,10 +344,11 @@ extern _X_EXPORT Bool
 
 #endif
 
-extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen,
+extern _X_EXPORT Bool glamor_egl_screen_init(ScreenPtr screen,
                                              struct glamor_context *glamor_ctx);
 
-extern _X_EXPORT Bool glamor_glx_screen_init(struct glamor_context *glamor_ctx);
+extern _X_EXPORT Bool glamor_glx_screen_init(ScreenPtr screen,
+                                             struct glamor_context *glamor_ctx);
 
 extern _X_EXPORT int glamor_create_gc(GCPtr gc);
 
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 53a74b8da..6085c4317 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -539,7 +539,7 @@ static dri3_screen_info_rec glamor_dri3_info = {
 };
 #endif /* DRI3 */
 
-void
+Bool
 glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -581,12 +581,11 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
         glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
 #endif
 
-        if (!dri3_screen_init(screen, &glamor_dri3_info)) {
-            xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-                       "Failed to initialize DRI3.\n");
-        }
+        return dri3_screen_init(screen, &glamor_dri3_info);
     }
 #endif
+
+    return TRUE;
 }
 
 static void glamor_egl_cleanup(struct glamor_egl_screen_private *glamor_egl)
@@ -748,3 +747,68 @@ glamor_egl_init_textured_pixmap(ScreenPtr screen)
 {
     return TRUE;
 }
+
+_X_EXPORT int
+glamor_fd_from_pixmap(ScreenPtr screen,
+                      PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+{
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+
+    if (!glamor_priv->dri3_enabled)
+        return -1;
+    switch (pixmap_priv->type) {
+    case GLAMOR_TEXTURE_DRM:
+    case GLAMOR_TEXTURE_ONLY:
+        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
+            return -1;
+        return glamor_egl_dri3_fd_name_from_tex(screen,
+                                                pixmap,
+                                                pixmap_priv->fbo->tex,
+                                                FALSE, stride, size);
+    default:
+        break;
+    }
+    return -1;
+}
+
+_X_EXPORT int
+glamor_shareable_fd_from_pixmap(ScreenPtr screen,
+                                PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+{
+    unsigned orig_usage_hint = pixmap->usage_hint;
+    int ret;
+
+    /*
+     * The actual difference between a sharable and non sharable buffer
+     * is decided 4 call levels deep in glamor_make_pixmap_exportable()
+     * based on pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED
+     * 2 of those calls are also exported API, so we cannot just add a flag.
+     */
+    pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
+    ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
+    pixmap->usage_hint = orig_usage_hint;
+
+    return ret;
+}
+
+int
+glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+{
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
+
+    switch (pixmap_priv->type) {
+    case GLAMOR_TEXTURE_DRM:
+    case GLAMOR_TEXTURE_ONLY:
+        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
+            return -1;
+        return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,
+                                                pixmap,
+                                                pixmap_priv->fbo->tex,
+                                                TRUE, stride, size);
+    default:
+        break;
+    }
+    return -1;
+}
diff --git a/glamor/glamor_egl_stubs.c b/glamor/glamor_egl_stubs.c
deleted file mode 100644
index 40f7fcc01..000000000
--- a/glamor/glamor_egl_stubs.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2013 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/** @file glamor_egl_stubs.c
- *
- * Stubbed out glamor_egl.c functions for servers other than Xorg.
- */
-
-#include "dix-config.h"
-
-#include "glamor.h"
-
-void
-glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
-{
-}
-
-int
-glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
-                                 PixmapPtr pixmap,
-                                 unsigned int tex,
-                                 Bool want_name, CARD16 *stride, CARD32 *size)
-{
-    return 0;
-}
diff --git a/glamor/glamor_glx.c b/glamor/glamor_glx.c
index 091af5213..8a3f7403b 100644
--- a/glamor/glamor_glx.c
+++ b/glamor/glamor_glx.c
@@ -53,7 +53,7 @@ glamor_glx_make_current(struct glamor_context *glamor_ctx)
 
 
 Bool
-glamor_glx_screen_init(struct glamor_context *glamor_ctx)
+glamor_glx_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 {
     glamor_ctx->ctx = glXGetCurrentContext();
     if (!glamor_ctx->ctx)
diff --git a/glamor/meson.build b/glamor/meson.build
index 0b963275e..3fdf94bc4 100644
--- a/glamor/meson.build
+++ b/glamor/meson.build
@@ -4,7 +4,6 @@ srcs_glamor = [
     'glamor_core.c',
     'glamor_dash.c',
     'glamor_font.c',
-    'glamor_glx.c',
     'glamor_composite_glyphs.c',
     'glamor_image.c',
     'glamor_lines.c',
@@ -47,10 +46,13 @@ glamor = static_library('glamor',
     ],
 )
 
-glamor_egl_stubs = static_library('glamor_egl_stubs',
-    'glamor_egl_stubs.c',
+glamor_glx = static_library('glamor_glx',
+    'glamor_glx.c',
     include_directories: inc,
-    dependencies: common_dep,
+    dependencies: [
+        common_dep,
+        dependency('epoxy'),
+    ],
 )
 
 if build_xorg
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index d12559b39..c57d501a6 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -66,7 +66,6 @@ if GLAMOR
 AM_CPPFLAGS += $(XLIB_CFLAGS)
 XEPHYR_GLAMOR_LIB = \
 	$(top_builddir)/glamor/libglamor.la \
-	$(top_builddir)/glamor/libglamor_egl_stubs.la \
 	$()
 endif
 
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index ef8541673..fa424fabb 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1507,7 +1507,7 @@ ephyr_glamor_init(ScreenPtr screen)
     ephyr_glamor_set_window_size(scrpriv->glamor,
                                  scrpriv->win_width, scrpriv->win_height);
 
-    if (!glamor_init(screen, 0)) {
+    if (!glamor_api_init(screen, 0, glamor_glx_screen_init)) {
         FatalError("Failed to initialize glamor\n");
         return FALSE;
     }
diff --git a/hw/kdrive/ephyr/meson.build b/hw/kdrive/ephyr/meson.build
index 615649865..3c22d1dcc 100644
--- a/hw/kdrive/ephyr/meson.build
+++ b/hw/kdrive/ephyr/meson.build
@@ -28,7 +28,7 @@ if build_glamor
         srcs += 'ephyr_glamor_xv.c'
     endif
     xephyr_glamor += glamor
-    xephyr_glamor += glamor_egl_stubs
+    xephyr_glamor += glamor_glx
     xephyr_dep += dependency('x11-xcb')
 endif
 
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 380dbbe17..e1c77be6a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1596,7 +1596,7 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 
 #ifdef GLAMOR_HAS_GBM
     if (ms->drmmode.glamor) {
-        if (!glamor_init(pScreen, GLAMOR_USE_EGL_SCREEN)) {
+        if (!glamor_api_init(pScreen, 0, glamor_egl_screen_init)) {
             xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                        "Failed to initialize glamor at ScreenInit() time.\n");
             return FALSE;
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 31659fb8e..45700d9fc 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -89,7 +89,7 @@ gbm_format_for_depth(int depth)
     }
 }
 
-void
+Bool
 glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 {
     struct xwl_screen *xwl_screen = xwl_screen_get(screen);
@@ -100,6 +100,8 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
     glamor_ctx->make_current = xwl_glamor_egl_make_current;
 
     xwl_screen->glamor_ctx = glamor_ctx;
+
+    return TRUE;
 }
 
 static PixmapPtr
@@ -412,15 +414,6 @@ xwl_screen_init_glamor(struct xwl_screen *xwl_screen,
     return TRUE;
 }
 
-int
-glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
-                                 PixmapPtr pixmap,
-                                 unsigned int tex,
-                                 Bool want_name, CARD16 *stride, CARD32 *size)
-{
-    return 0;
-}
-
 struct xwl_auth_state {
     int fd;
     ClientPtr client;
@@ -589,7 +582,7 @@ xwl_glamor_init(struct xwl_screen *xwl_screen)
         return FALSE;
     }
 
-    if (!glamor_init(xwl_screen->screen, GLAMOR_USE_EGL_SCREEN)) {
+    if (!glamor_api_init(xwl_screen->screen, 0, glamor_egl_screen_init)) {
         ErrorF("Failed to initialize glamor\n");
         return FALSE;
     }
-- 
2.14.3



More information about the xorg-devel mailing list