The first two patches fix two segfaults.  One is in core, and the other
is in egl_softpipe.

The 3rd patches removes libX11 dependency.  The mechanism depending on
libX11 does not work on newer kernel, and no working driver uses it.
The last patch does a minor refactoring and it makes

  $ export EGL_DRIVER=/usr/local/lib/egl_softpipe.so

work.  (It gives egl_softpipe.so.so, double suffix, currently).

-- 
Regards,
olv
>From 775005215656f7b978f6d1cbd5fecac154c38df0 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Wed, 19 Aug 2009 13:00:25 +0800
Subject: [PATCH 1/4] egl: Check for null display in handle checking.

The display may be NULL when checking a handle.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/main/egldisplay.c |   10 ++++++----
 src/egl/main/egldisplay.h |    9 ++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 30a49a2..9b4227f 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -305,9 +305,10 @@ _eglCheckDisplayHandle(EGLDisplay dpy)
 EGLBoolean
 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
 {
-   _EGLContext *cur;
+   _EGLContext *cur = NULL;
 
-   cur = dpy->ContextList;
+   if (dpy)
+      cur = dpy->ContextList;
    while (cur) {
       if (cur == (_EGLContext *) ctx) {
          assert(cur->Display == dpy);
@@ -325,9 +326,10 @@ _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
 EGLBoolean
 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
 {
-   _EGLSurface *cur;
+   _EGLSurface *cur = NULL;
 
-   cur = dpy->SurfaceList;
+   if (dpy)
+      cur = dpy->SurfaceList;
    while (cur) {
       if (cur == (_EGLSurface *) surf) {
          assert(cur->Display == dpy);
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 6394c9c..20651e5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -125,14 +125,17 @@ _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
 /* Only do a quick check.  This is NOT standard compliant. */
 
 static INLINE EGLBoolean
-_eglCheckDisplayHandle(EGLDisplay dpy) { return EGL_TRUE; }
+_eglCheckDisplayHandle(EGLDisplay dpy)
+{
+   return ((_EGLDisplay *) dpy != NULL);
+}
 
 
 static INLINE EGLBoolean
 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
 {
    _EGLContext *c = (_EGLContext *) ctx;
-   return (c && c->Display == dpy);
+   return (dpy && c && c->Display == dpy);
 }
 
 
@@ -140,7 +143,7 @@ static INLINE EGLBoolean
 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
 {
    _EGLSurface *s = (_EGLSurface *) surf;
-   return (s && s->Display == dpy);
+   return (dpy && s && s->Display == dpy);
 }
 
 
-- 
1.6.2.4

>From e2ef2a44948635cb2f7b5dd9afaf51dcb228c8a4 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Thu, 20 Aug 2009 19:35:28 +0800
Subject: [PATCH 2/4] egl_softpipe: Do not flush unlinked context.

An unlinked context is destroyed after _eglMakeCurrent.  Flushing such
context would cause segfault.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/gallium/winsys/egl_xlib/egl_xlib.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c
index 1fcdd2d..96f460f 100644
--- a/src/gallium/winsys/egl_xlib/egl_xlib.c
+++ b/src/gallium/winsys/egl_xlib/egl_xlib.c
@@ -424,14 +424,19 @@ xlib_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy,
    struct xlib_egl_context *context = lookup_context(ctx);
    struct xlib_egl_surface *draw_surf = lookup_surface(draw);
    struct xlib_egl_surface *read_surf = lookup_surface(read);
-   struct st_context *oldctx = st_get_current();
+   struct st_context *oldcontext = NULL;
+   _EGLContext *oldctx;
+
+   oldctx = _eglGetCurrentContext();
+   if (oldctx && _eglIsContextLinked(oldctx))
+      oldcontext = st_get_current();
 
    if (!_eglMakeCurrent(drv, dpy, draw, read, ctx))
       return EGL_FALSE;
 
    /* Flush before switching context.  Check client API? */
-   if (oldctx)
-      st_flush(oldctx, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
+   if (oldcontext)
+      st_flush(oldcontext, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
    st_make_current((context ? context->Context : NULL),
                    (draw_surf ? draw_surf->Framebuffer : NULL),
                    (read_surf ? read_surf->Framebuffer : NULL));
-- 
1.6.2.4

>From 32a72e7485eaf64a4eeea7ae480416014202f3c3 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 21 Aug 2009 13:53:36 +0800
Subject: [PATCH 3/4] egl: Remove dependency on libX11.

libX11 is used to determine the screen number, which is in turned used
to determine the DRI driver.  However, the sysfs interface for
determining the DRI driver is gone, and no working driver depends on
this mechanism.

Display string parsing is moved to a new function,
_eglSplitDisplayString.

Signed-off-by: Chia-I Wu <[email protected]>
---
 configs/default           |    2 +-
 src/egl/main/Makefile     |    6 +--
 src/egl/main/egldisplay.c |   30 +++++++++++++
 src/egl/main/egldisplay.h |    4 ++
 src/egl/main/egldriver.c  |   91 +++-------------------------------------
 src/egl/main/egldriver.h  |    4 --
 src/egl/main/eglx.c       |  100 ---------------------------------------------
 src/egl/main/eglx.h       |   12 -----
 8 files changed, 44 insertions(+), 205 deletions(-)
 delete mode 100644 src/egl/main/eglx.c
 delete mode 100644 src/egl/main/eglx.h

diff --git a/configs/default b/configs/default
index 60638d7..127b98e 100644
--- a/configs/default
+++ b/configs/default
@@ -105,7 +105,7 @@ GALLIUM_STATE_TRACKERS_DIRS = glx
 # Library dependencies
 #EXTRA_LIB_PATH ?=
 GL_LIB_DEPS     = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread
-EGL_LIB_DEPS    = $(EXTRA_LIB_PATH) -lX11 -ldl -lpthread
+EGL_LIB_DEPS    = $(EXTRA_LIB_PATH) -ldl -lpthread
 OSMESA_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB)
 GLU_LIB_DEPS    = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm
 GLUT_LIB_DEPS   = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lm
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index 15cd1d0..c951b07 100644
--- a/src/egl/main/Makefile
+++ b/src/egl/main/Makefile
@@ -22,8 +22,7 @@ HEADERS = \
 	eglmutex.h \
 	eglscreen.h \
 	eglstring.h \
-	eglsurface.h \
-	eglx.h
+	eglsurface.h
 
 SOURCES = \
 	eglapi.c \
@@ -39,8 +38,7 @@ SOURCES = \
 	eglmode.c \
 	eglscreen.c \
 	eglstring.c \
-	eglsurface.c \
-	eglx.c
+	eglsurface.c
 
 OBJECTS = $(SOURCES:.c=.o)
 
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 9b4227f..2c271ef 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -40,6 +40,36 @@ _eglFiniDisplay(void)
 
 
 /**
+ * If the first character is '!' we interpret it as specific driver name
+ * (i.e. "!r200" or "!i830").  Whatever follows ':' is interpreted as
+ * arguments.
+ *
+ * The caller may free() the returned driver name.
+ */
+char *
+_eglSplitDisplayString(const char *dpyString, const char **args)
+{
+   char *drv, *p;
+
+   if (!dpyString || dpyString[0] != '!')
+      return NULL;
+   drv = _eglstrdup(dpyString + 1);
+   if (!drv)
+      return NULL;
+
+   p = strchr(dpyString, ':');
+   if (p) {
+      drv[p - dpyString] = '\0';
+      p++;
+   }
+   if (args)
+      *args = p;
+
+   return drv;
+}
+
+
+/**
  * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
  * We'll also try to determine the device driver name at this time.
  *
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 20651e5..c7a41cd 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -65,6 +65,10 @@ extern void
 _eglFiniDisplay(void);
 
 
+extern char *
+_eglSplitDisplayString(const char *dpyString, const char **args);
+
+
 extern _EGLDisplay *
 _eglNewDisplay(NativeDisplayType displayName);
 
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index a252a9a..06e10f6 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -22,7 +22,6 @@
 
 #if defined(_EGL_PLATFORM_X)
 #include <dlfcn.h>
-#include "eglx.h"
 #elif defined(_EGL_PLATFORM_WINDOWS)
 /* Use static linking on Windows for now */
 #define WINDOWS_STATIC_LINK
@@ -38,7 +37,6 @@
    /* XXX Need to decide how to do dynamic name lookup on Windows */
    static const char *DefaultDriverName = "TBD";
 #endif
-   static const char *SysFS = NULL;
    typedef HMODULE lib_handle;
 
    static HMODULE
@@ -61,8 +59,7 @@
    }
 
 #elif defined(_EGL_PLATFORM_X)
-   static const char *DefaultDriverName = ":0";
-   static const char *SysFS = "/sys/class";
+   static const char *DefaultDriverName = "egl_softpipe";
 
    typedef void * lib_handle;
 
@@ -80,57 +77,9 @@
    
 #endif
 
-/**
- * Given a card number, use sysfs to determine the DRI driver name.
- */
-const char *
-_eglChooseDRMDriver(int card)
-{
-#if 0
-   return _eglstrdup("libEGLdri");
-#else
-   char path[2000], driverName[2000];
-   FILE *f;
-   int length;
-
-   snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card);
-
-   f = fopen(path, "r");
-   if (!f)
-      return NULL;
-
-   fgets(driverName, sizeof(driverName), f);
-   fclose(f);
-
-   if ((length = strlen(driverName)) > 1) {
-      /* remove the trailing newline from sysfs */
-      driverName[length - 1] = '\0';
-      strncat(driverName, "_dri", sizeof(driverName));
-      return _eglstrdup(driverName);
-   }
-   else {
-      return NULL;
-   }   
-#endif
-}
-
 
 /**
- * XXX this function is totally subject change!!!
- *
- *
- * Determine/return the path of the driver to use for the given native display.
- *
- * Try to be clever and determine if nativeDisplay is an Xlib Display
- * ptr or a string (naming a driver or screen number, etc).
- *
- * If the first character is ':' we interpret it as a screen or card index
- * number (i.e. ":0" or ":1", etc)
- * Else if the first character is '!' we interpret it as specific driver name
- * (i.e. "!r200" or "!i830".
- *
- * Whatever follows ':' is interpreted as arguments.
- *
+ * Choose a driver for a given display.
  * The caller may free() the returned strings.
  */
 static char *
@@ -144,42 +93,16 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
       path = _eglstrdup(path);
 
 #if defined(_EGL_PLATFORM_X)
-   (void) DefaultDriverName;
-
    if (!path && dpy->NativeDisplay) {
-      const char *dpyString = (const char *) dpy->NativeDisplay;
-      char *p;
-      /* parse the display string */
-      if (dpyString[0] == '!' || dpyString[0] == ':') {
-         if (dpyString[0] == '!') {
-            path = _eglstrdup(dpyString);
-            p = strchr(path, ':');
-            if (p)
-               *p++ = '\0';
-         } else {
-            p = strchr(dpyString, ':');
-            if (p)
-               p++;
-         }
-
-         if (p) {
-            if (!path && p[0] >= '0' && p[0] <= '9' && !p[1]) {
-               int card = atoi(p);
-               path = (char *) _eglChooseDRMDriver(card);
-            }
-            args = p;
-         }
-      }
-      else {
-         path = (char *) _xeglChooseDriver(dpy);
-      }
+      /* assume (wrongly!) that the native display is a display string */
+      path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args);
    }
-#elif defined(_EGL_PLATFORM_WINDOWS)
+#endif /* _EGL_PLATFORM_X */
+
    if (!path)
       path = _eglstrdup(DefaultDriverName);
-#endif /* _EGL_PLATFORM_X */
 
-   if (path && argsRet)
+   if (argsRet)
       *argsRet = (args) ? _eglstrdup(args) : NULL;
 
    return path;
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 7fba938..6c848eb 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -29,10 +29,6 @@ extern _EGLDriver *_eglMain(const char *args);
 
 
 extern const char *
-_eglChooseDRMDriver(int card);
-
-
-extern const char *
 _eglPreloadDriver(_EGLDisplay *dpy);
 
 
diff --git a/src/egl/main/eglx.c b/src/egl/main/eglx.c
deleted file mode 100644
index 50acc3a..0000000
--- a/src/egl/main/eglx.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- * 
- **************************************************************************/
-
-
-/**
- * X-specific EGL code.
- *
- * Any glue code needed to make EGL work with X is placed in this file.
- */
-
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/Xlib.h>
-
-#include "egldriver.h"
-#include "egllog.h"
-#include "eglstring.h"
-#include "eglx.h"
-
-
-static const char *DefaultGLXDriver = "egl_glx";
-static const char *DefaultSoftDriver = "egl_softpipe";
-
-
-/**
- * Given an X Display ptr (at dpy->Xdpy) try to determine the appropriate
- * device driver.  Return its name.
- *
- * This boils down to whether to use the egl_glx.so driver which will
- * load a DRI driver or the egl_softpipe.so driver that'll do software
- * rendering on Xlib.
- */
-const char *
-_xeglChooseDriver(_EGLDisplay *dpy)
-{
-#ifdef _EGL_PLATFORM_X
-   _XPrivDisplay xdpy;
-   int screen;
-   const char *driverName;
-
-   assert(dpy);
-
-   if (!dpy->Xdpy) {
-      dpy->Xdpy = XOpenDisplay(NULL);
-      if (!dpy->Xdpy) {
-         /* can't open X display -> can't use X-based driver */
-         return NULL;
-      }
-   }
-   xdpy = (_XPrivDisplay) dpy->Xdpy;
-
-   assert(dpy->Xdpy);
-
-   screen = DefaultScreen(dpy->Xdpy);
-
-   /* See if we can choose a DRI/DRM driver */
-   driverName = _eglChooseDRMDriver(screen);
-   if (driverName) {
-      free((void *) driverName);
-      driverName = _eglstrdup(DefaultGLXDriver);
-   }
-   else {
-      driverName = _eglstrdup(DefaultSoftDriver);
-   }
-
-   _eglLog(_EGL_DEBUG, "_xeglChooseDriver: %s", driverName);
-
-   return driverName;
-#else
-   return NULL;
-#endif
-}
-
-
diff --git a/src/egl/main/eglx.h b/src/egl/main/eglx.h
deleted file mode 100644
index 4323d55..0000000
--- a/src/egl/main/eglx.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef EGLX_INCLUDED
-#define EGLX_INCLUDED
-
-
-#include "egldisplay.h"
-
-
-extern const char *
-_xeglChooseDriver(_EGLDisplay *dpy);
-
-
-#endif /* EGLX_INCLUDED */
-- 
1.6.2.4

>From 20aeaded7589333a91ee8f0d1281d1fa8e39ea1f Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 21 Aug 2009 13:55:30 +0800
Subject: [PATCH 4/4] egl: Make _eglChooseDriver return the filename of the driver.

The real difference is that the driver suffix is now appended.  This
also fixes an annoying bug that EGL_DRIVER could not specify the path to
a driver because a suffix was always appended.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/main/egldriver.c |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 06e10f6..87786e3 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -87,6 +87,8 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
 {
    char *path = NULL;
    const char *args = NULL;
+   const char *suffix = NULL;
+   const char *p;
 
    path = getenv("EGL_DRIVER");
    if (path)
@@ -97,11 +99,30 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
       /* assume (wrongly!) that the native display is a display string */
       path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args);
    }
+   suffix = "so";
+#elif defined(_EGL_PLATFORM_WINDOWS)
+   suffix = "dll";
 #endif /* _EGL_PLATFORM_X */
 
    if (!path)
       path = _eglstrdup(DefaultDriverName);
 
+   /* append suffix if there isn't */
+   p = strrchr(path, '.');
+   if (!p && suffix) {
+      size_t len = strlen(path);
+      char *tmp = malloc(len + strlen(suffix) + 2);
+      if (tmp) {
+         memcpy(tmp, path, len);
+         tmp[len++] = '.';
+         tmp[len] = '\0';
+         strcat(tmp + len, suffix);
+
+         free(path);
+         path = tmp;
+      }
+   }
+
    if (argsRet)
       *argsRet = (args) ? _eglstrdup(args) : NULL;
 
@@ -113,13 +134,12 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
  * Open the named driver and find its bootstrap function: _eglMain().
  */
 static _EGLMain_t
-_eglOpenLibrary(const char *driverName, lib_handle *handle)
+_eglOpenLibrary(const char *driverPath, lib_handle *handle)
 {
    _EGLMain_t mainFunc;
    lib_handle lib;
-   char driverFilename[1000];
 
-   assert(driverName);
+   assert(driverPath);
 
 #if defined(_EGL_PLATFORM_WINDOWS)
 /* Use static linking on Windows for now */
@@ -128,31 +148,31 @@ _eglOpenLibrary(const char *driverName, lib_handle *handle)
    mainFunc = (_EGLMain_t)_eglMain;
 #else
    /* XXX untested */
-   sprintf(driverFilename, "%s.dll", driverName);
-   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
-   lib = open_library(driverFilename);
+   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+   lib = open_library(driverPath);
    if (!lib) {
       _eglLog(_EGL_WARNING, "Could not open %s",
-              driverFilename);
+              driverPath);
       return NULL;
    }
    mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
 #endif
 #elif defined(_EGL_PLATFORM_X)
-   /* XXX also prepend a directory path??? */
-   sprintf(driverFilename, "%s.so", driverName);
-   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
-   lib = open_library(driverFilename);
+   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+   lib = open_library(driverPath);
    if (!lib) {
       _eglLog(_EGL_WARNING, "Could not open %s (%s)",
-              driverFilename, dlerror());
+              driverPath, dlerror());
+      if (!getenv("EGL_DRIVER"))
+         _eglLog(_EGL_WARNING,
+                 "The driver can be overridden by setting EGL_DRIVER");
       return NULL;
    }
    mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
 #endif
 
    if (!mainFunc) {
-      _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename);
+      _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverPath);
       if (lib)
          close_library(lib);
       return NULL;
-- 
1.6.2.4

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to