Import wine_tsx11_lock/unlock directly from x11drv in opengl32 and
ddraw, so that they don't need to link with libwine_tsx11.
Removed header wine_gl.h.

diff --git a/dlls/ddraw/Makefile.in b/dlls/ddraw/Makefile.in
index 3370155..9e022d4 100644
--- a/dlls/ddraw/Makefile.in
+++ b/dlls/ddraw/Makefile.in
@@ -4,7 +4,7 @@
 VPATH     = @srcdir@
 MODULE    = ddraw.dll
 IMPORTS   = user32 gdi32 kernel32
-EXTRALIBS = $(LIBUUID) $(LIBTSX11) $(X_LIBS) $(XLIB)
+EXTRALIBS = $(LIBUUID) $(X_LIBS) $(XLIB)
 
 LDDLLFLAGS = @LDDLLFLAGS@
 SYMBOLFILE = $(MODULE).tmp.o
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index d3f1a5a..fbb4260 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -43,6 +43,9 @@
 static int DDRAW_num_drivers; /* = 0 */
 static int DDRAW_default_driver;
 
+void (*wine_tsx11_lock_ptr)(void) = NULL;
+void (*wine_tsx11_unlock_ptr)(void) = NULL;
+
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
 /**********************************************************************/
@@ -503,6 +506,16 @@
     DDRAW_HAL_Init(hInstDLL, fdwReason, lpv);
     DDRAW_User_Init(hInstDLL, fdwReason, lpv);
 
+    if (fdwReason == DLL_PROCESS_ATTACH)
+    {
+        HMODULE mod = GetModuleHandleA( "x11drv.dll" );
+        if (mod)
+        {
+            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
+            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
+        }
+    }
+
     if (DDRAW_num_drivers > 0)
 	DDRAW_default_driver = DDRAW_ChooseDefaultDriver();
 
diff --git a/dlls/ddraw/mesa_private.h b/dlls/ddraw/mesa_private.h
index 1120d62..daad8f3 100644
--- a/dlls/ddraw/mesa_private.h
+++ b/dlls/ddraw/mesa_private.h
@@ -24,7 +24,36 @@
 
 #include "d3d_private.h"
 
-#include "wine_gl.h"
+#undef APIENTRY
+#undef CALLBACK
+#undef WINAPI
+
+#define XMD_H /* This is to prevent the Xmd.h inclusion bug :-/ */
+#include <GL/gl.h>
+#include <GL/glx.h>
+#ifdef HAVE_GL_GLEXT_H
+# include <GL/glext.h>
+#endif
+#undef  XMD_H
+
+#undef APIENTRY
+#undef CALLBACK
+#undef WINAPI
+
+/* Redefines the constants */
+#define CALLBACK    __stdcall
+#define WINAPI      __stdcall
+#define APIENTRY    WINAPI
+
+/* X11 locking */
+
+extern void (*wine_tsx11_lock_ptr)(void);
+extern void (*wine_tsx11_unlock_ptr)(void);
+
+/* As GLX relies on X, this is needed */
+#define ENTER_GL() wine_tsx11_lock_ptr()
+#define LEAVE_GL() wine_tsx11_unlock_ptr()
+
 
 /*****************************************************************************
  * IDirect3DLight MESA private structure
diff --git a/dlls/opengl32/Makefile.in b/dlls/opengl32/Makefile.in
index f280b08..9cc0b4a 100644
--- a/dlls/opengl32/Makefile.in
+++ b/dlls/opengl32/Makefile.in
@@ -4,7 +4,7 @@
 VPATH     = @srcdir@
 MODULE    = opengl32.dll
 IMPORTS   = user32 gdi32 kernel32
-EXTRALIBS = $(LIBTSX11) $(X_LIBS) $(XLIB)
+EXTRALIBS = $(X_LIBS) $(XLIB)
 
 LDDLLFLAGS = @LDDLLFLAGS@
 SYMBOLFILE = $(MODULE).tmp.o
diff --git a/dlls/opengl32/make_opengl b/dlls/opengl32/make_opengl
index 268c587..990e9c0 100755
--- a/dlls/opengl32/make_opengl
+++ b/dlls/opengl32/make_opengl
@@ -544,7 +544,7 @@
 /* Auto-generated file... Do not edit ! */
 
 #include \"config.h\"
-#include \"wine_gl.h\"
+#include \"opengl_ext.h\"
 #include \"wine/debug.h\"
 
 typedef const GLubyte * GLstring;
@@ -567,13 +567,11 @@
 /* Auto-generated file... Do not edit ! */
 
 #include \"config.h\"
-#include \"wine_gl.h\"
+#include \"opengl_ext.h\"
 #include \"wine/debug.h\"
 
 typedef const GLubyte * GLstring;
 
-#include \"opengl_ext.h\"
-
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
 
 ";
diff --git a/dlls/opengl32/opengl_ext.c b/dlls/opengl32/opengl_ext.c
index 30ec036..8720e89 100644
--- a/dlls/opengl32/opengl_ext.c
+++ b/dlls/opengl32/opengl_ext.c
@@ -2,13 +2,11 @@
 /* Auto-generated file... Do not edit ! */
 
 #include "config.h"
-#include "wine_gl.h"
+#include "opengl_ext.h"
 #include "wine/debug.h"
 
 typedef const GLubyte * GLstring;
 
-#include "opengl_ext.h"
-
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
 
 void (*func_glActiveTexture)( GLenum ) = (void *) 0xdeadbeef;
diff --git a/dlls/opengl32/opengl_ext.h b/dlls/opengl32/opengl_ext.h
index e0f3d4d..32e81a2 100644
--- a/dlls/opengl32/opengl_ext.h
+++ b/dlls/opengl32/opengl_ext.h
@@ -19,6 +19,37 @@
 #ifndef __DLLS_OPENGL32_OPENGL_EXT_H
 #define __DLLS_OPENGL32_OPENGL_EXT_H
 
+#undef APIENTRY
+#undef CALLBACK
+#undef WINAPI
+
+#define XMD_H /* This is to prevent the Xmd.h inclusion bug :-/ */
+#include <GL/gl.h>
+#include <GL/glx.h>
+#ifdef HAVE_GL_GLEXT_H
+# include <GL/glext.h>
+#endif
+#undef  XMD_H
+
+#undef APIENTRY
+#undef CALLBACK
+#undef WINAPI
+
+/* Redefines the constants */
+#define CALLBACK    __stdcall
+#define WINAPI      __stdcall
+#define APIENTRY    WINAPI
+
+/* X11 locking */
+
+extern void (*wine_tsx11_lock_ptr)(void);
+extern void (*wine_tsx11_unlock_ptr)(void);
+
+/* As GLX relies on X, this is needed */
+#define ENTER_GL() wine_tsx11_lock_ptr()
+#define LEAVE_GL() wine_tsx11_unlock_ptr()
+
+
 typedef struct {
   char  *name;     /* name of the extension */
   char  *glx_name; /* name used on Unix's libGL */
diff --git a/dlls/opengl32/opengl_norm.c b/dlls/opengl32/opengl_norm.c
index 92e9cad..62dda47 100644
--- a/dlls/opengl32/opengl_norm.c
+++ b/dlls/opengl32/opengl_norm.c
@@ -2,7 +2,7 @@
 /* Auto-generated file... Do not edit ! */
 
 #include "config.h"
-#include "wine_gl.h"
+#include "opengl_ext.h"
 #include "wine/debug.h"
 
 typedef const GLubyte * GLstring;
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index 94efd66..c092d6c 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -26,7 +26,6 @@
 #include "winbase.h"
 #include "winuser.h"
 #include "winerror.h"
-#include "wine_gl.h"
 #include "x11drv.h"
 
 #include "wgl.h"
@@ -35,6 +34,9 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
 
+void (*wine_tsx11_lock_ptr)(void) = NULL;
+void (*wine_tsx11_unlock_ptr)(void) = NULL;
+
 static GLXContext default_cx = NULL;
 static Display *default_display;  /* display to use for default context */
 
@@ -586,13 +588,17 @@
   HDC hdc;
   XVisualInfo *vis = NULL;
   Window root = (Window)GetPropA( GetDesktopWindow(), "__wine_x11_whole_window" );
+  HMODULE mod = GetModuleHandleA( "x11drv.dll" );
 
-  if (!root)
+  if (!root || !mod)
   {
       ERR("X11DRV not loaded. Cannot create default context.\n");
       return FALSE;
   }
 
+  wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
+  wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
+
   hdc = GetDC(0);
   default_display = get_display( hdc );
   ReleaseDC( 0, hdc );
diff --git a/dlls/x11drv/x11drv.spec b/dlls/x11drv/x11drv.spec
index c9bd61f..1a03265 100644
--- a/dlls/x11drv/x11drv.spec
+++ b/dlls/x11drv/x11drv.spec
@@ -99,3 +99,7 @@
 @ cdecl GetClipboardFormatName(long str long) X11DRV_GetClipboardFormatName
 @ cdecl IsSelectionOwner() X11DRV_IsSelectionOwner
 @ cdecl ResetSelectionOwner(ptr long) X11DRV_ResetSelectionOwner
+
+# X11 locks
+@ cdecl -norelay wine_tsx11_lock() X11DRV_tsx11_lock
+@ cdecl -norelay wine_tsx11_unlock() X11DRV_tsx11_unlock
diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c
index aaa93bd..f085211 100644
--- a/dlls/x11drv/x11drv_main.c
+++ b/dlls/x11drv/x11drv_main.c
@@ -41,7 +41,6 @@
 #include "gdi.h"
 #include "user.h"
 #include "win.h"
-#include "wine_gl.h"
 #include "x11drv.h"
 #include "xvidmode.h"
 #include "dga2.h"
@@ -137,17 +136,17 @@
 }
 
 /***********************************************************************
- *		lock_tsx11
+ *		X11DRV_tsx11_lock   (X11DRV.@)
  */
-static void lock_tsx11(void)
+void X11DRV_tsx11_lock(void)
 {
     EnterCriticalSection( &X11DRV_CritSection );
 }
 
 /***********************************************************************
- *		unlock_tsx11
+ *		X11DRV_tsx11_unlock   (X11DRV.@)
  */
-static void unlock_tsx11(void)
+void X11DRV_tsx11_unlock(void)
 {
     LeaveCriticalSection( &X11DRV_CritSection );
 }
@@ -262,36 +261,6 @@
 
 
 /***********************************************************************
- *		setup_opengl_visual
- *
- * Setup the default visual used for OpenGL and Direct3D, and the desktop
- * window (if it exists).  If OpenGL isn't available, the visual is simply
- * set to the default visual for the display
- */
-#ifdef HAVE_OPENGL
-static void setup_opengl_visual( Display *display )
-{
-    int err_base, evt_base;
-
-    /* In order to support OpenGL or D3D, we require a double-buffered
-     * visual */
-    wine_tsx11_lock();
-    if (glXQueryExtension(display, &err_base, &evt_base) == True) {
-	  int dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
-
-	  desktop_vi = glXChooseVisual(display, DefaultScreen(display), dblBuf);
-    }
-    wine_tsx11_unlock();
-
-    if (desktop_vi != NULL) {
-      visual       = desktop_vi->visual;
-      screen       = ScreenOfDisplay(display, desktop_vi->screen);
-      screen_depth = desktop_vi->depth;
-    }
-}
-#endif /* HAVE_OPENGL */
-
-/***********************************************************************
  *           X11DRV process initialisation routine
  */
 static void process_attach(void)
@@ -304,8 +273,8 @@
     /* setup TSX11 locking */
     old_tsx11_lock    = wine_tsx11_lock;
     old_tsx11_unlock  = wine_tsx11_unlock;
-    wine_tsx11_lock   = lock_tsx11;
-    wine_tsx11_unlock = unlock_tsx11;
+    wine_tsx11_lock   = X11DRV_tsx11_lock;
+    wine_tsx11_unlock = X11DRV_tsx11_unlock;
 
     /* Open display */
 
@@ -338,9 +307,12 @@
     else screen_depth = DefaultDepthOfScreen( screen );
 
     /* If OpenGL is available, change the default visual, etc as necessary */
-#ifdef HAVE_OPENGL
-    setup_opengl_visual( display );
-#endif /* HAVE_OPENGL */
+    if ((desktop_vi = X11DRV_setup_opengl_visual( display )))
+    {
+        visual       = desktop_vi->visual;
+        screen       = ScreenOfDisplay(display, desktop_vi->screen);
+        screen_depth = desktop_vi->depth;
+    }
 
     /* tell the libX11 that we will do input method handling ourselves
      * that keep libX11 from doing anything whith dead keys, allowing Wine