[Mesa-dev] [PATCH 17/25] egl/dri2: Consolidate eglTerminate

Chad Versace chad.versace at linux.intel.com
Sun Feb 9 13:37:53 PST 2014


egl_dri2.c:dri2_terminate() handled terminating X11 and DRM displays.
The Wayland platform implemented its own dri2_wl_terminate(), which was
nearly a copy of the common one.

To implement the EGL platform extensions, we either need to dispatch
eglTerminate per display or define a common implementation for all
platforms. This patch chooses consolidation.  It removes
dri2_wl_terminate() by folding it into the common dri2_terminate().

It was necessary to invert the `if (disp->PlatformDisplay == NULL)` and
the switch statement because, unlike DRM and X11, Wayland's terminator
performed action even when EGL didn't own the native display. In the
inversion, I replaced `disp->PlatformDisplay == NULL` with
`dri2_dpy->own_device` because the two expressions are synonymous, but
the latter's meaning is clearer.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c         | 37 +++++++++++++++++++++------------
 src/egl/drivers/dri2/platform_wayland.c | 27 ------------------------
 2 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a3abe83..d1b15f7 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -25,6 +25,8 @@
  *    Kristian Høgsberg <krh at bitplanet.net>
  */
 
+#define WL_HIDE_DEPRECATED
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -42,12 +44,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "egl_dri2.h"
-
 #ifdef HAVE_WAYLAND_PLATFORM
 #include "wayland-drm.h"
+#include "wayland-drm-client-protocol.h"
 #endif
 
+#include "egl_dri2.h"
+
 const __DRIuseInvalidateExtension use_invalidate = {
    { __DRI_USE_INVALIDATE, 1 }
 };
@@ -671,23 +674,31 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
       dlclose(dri2_dpy->driver);
    free(dri2_dpy->device_name);
 
-   if (disp->PlatformDisplay == NULL) {
-      switch (disp->Platform) {
+   switch (disp->Platform) {
 #ifdef HAVE_X11_PLATFORM
-      case _EGL_PLATFORM_X11:
+   case _EGL_PLATFORM_X11:
+      if (dri2_dpy->own_device) {
          xcb_disconnect(dri2_dpy->conn);
-         break;
+      }
+      break;
 #endif
 #ifdef HAVE_DRM_PLATFORM
-      case _EGL_PLATFORM_DRM:
-         if (dri2_dpy->own_device) {
-            gbm_device_destroy(&dri2_dpy->gbm_dri->base.base);
-         }
-         break;
+   case _EGL_PLATFORM_DRM:
+      if (dri2_dpy->own_device) {
+         gbm_device_destroy(&dri2_dpy->gbm_dri->base.base);
+      }
+      break;
 #endif
-      default:
-         break;
+#ifdef HAVE_WAYLAND_PLATFORM
+   case _EGL_PLATFORM_WAYLAND:
+      wl_drm_destroy(dri2_dpy->wl_drm);
+      if (dri2_dpy->own_device) {
+         wl_display_disconnect(dri2_dpy->wl_dpy);
       }
+      break;
+#endif
+   default:
+      break;
    }
 
    free(dri2_dpy);
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index ebd104f..8dc2893 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -780,31 +780,6 @@ dri2_wl_authenticate(_EGLDisplay *disp, uint32_t id)
    return ret;
 }
 
-/**
- * Called via eglTerminate(), drv->API.Terminate().
- */
-static EGLBoolean
-dri2_wl_terminate(_EGLDriver *drv, _EGLDisplay *disp)
-{
-   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-
-   _eglReleaseDisplayResources(drv, disp);
-   _eglCleanupDisplay(disp);
-
-   dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
-   close(dri2_dpy->fd);
-   dlclose(dri2_dpy->driver);
-   free(dri2_dpy->driver_name);
-   free(dri2_dpy->device_name);
-   wl_drm_destroy(dri2_dpy->wl_drm);
-   if (dri2_dpy->own_device)
-      wl_display_disconnect(dri2_dpy->wl_dpy);
-   free(dri2_dpy);
-   disp->DriverData = NULL;
-
-   return EGL_TRUE;
-}
-
 static void
 drm_handle_device(void *data, struct wl_drm *drm, const char *device)
 {
@@ -985,8 +960,6 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
 
    loader_set_logger(_eglLog);
 
-   drv->API.Terminate = dri2_wl_terminate;
-
    drv->API.CreateWaylandBufferFromImageWL =
       dri2_wl_create_wayland_buffer_from_image_wl;
 
-- 
1.8.5.3



More information about the mesa-dev mailing list