st/egl: reorganize backend initialization
[mesa.git] / src / gallium / state_trackers / egl / x11 / x11_screen.c
index dd820a369ef8c5e8535cfb73859c8f7ce36a5d6d..f1cc4400ba5b402faeda2858787efb02f9d722dc 100644 (file)
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <xf86drm.h>
 #include <X11/Xlibint.h>
 #include <X11/extensions/XShm.h>
+
 #include "util/u_memory.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "xf86drm.h"
 #include "egllog.h"
 
 #include "x11_screen.h"
@@ -40,9 +39,6 @@
 #include "glxinit.h"
 
 struct x11_screen {
-   /* dummy base class */
-   struct __GLXDRIdisplayRec base;
-
    Display *dpy;
    int number;
 
@@ -104,15 +100,19 @@ x11_screen_destroy(struct x11_screen *xscr)
    if (xscr->dri_device)
       Xfree(xscr->dri_device);
 
+#ifdef GLX_DIRECT_RENDERING
    /* xscr->glx_dpy will be destroyed with the X display */
    if (xscr->glx_dpy)
-      xscr->glx_dpy->dri2Display = NULL;
+      xscr->glx_dpy->xscr = NULL;
+#endif
 
    if (xscr->visuals)
       XFree(xscr->visuals);
-   free(xscr);
+   FREE(xscr);
 }
 
+#ifdef GLX_DIRECT_RENDERING
+
 static boolean
 x11_screen_init_dri2(struct x11_screen *xscr)
 {
@@ -134,6 +134,8 @@ x11_screen_init_glx(struct x11_screen *xscr)
    return (xscr->glx_dpy != NULL);
 }
 
+#endif /* GLX_DIRECT_RENDERING */
+
 /**
  * Return true if the screen supports the extension.
  */
@@ -146,12 +148,14 @@ x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext)
    case X11_SCREEN_EXTENSION_XSHM:
       supported = XShmQueryExtension(xscr->dpy);
       break;
+#ifdef GLX_DIRECT_RENDERING
    case X11_SCREEN_EXTENSION_GLX:
       supported = x11_screen_init_glx(xscr);
       break;
    case X11_SCREEN_EXTENSION_DRI2:
       supported = x11_screen_init_dri2(xscr);
       break;
+#endif
    default:
       break;
    }
@@ -178,24 +182,46 @@ x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals)
 }
 
 /**
- * Return the GLX fbconfigs.
+ * Return the depth of a drawable.
+ *
+ * Unlike other drawable functions, the drawable needs not be a DRI2 drawable.
  */
-const __GLcontextModes *
-x11_screen_get_glx_configs(struct x11_screen *xscr)
+uint
+x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable)
 {
-   return (x11_screen_init_glx(xscr))
-      ? xscr->glx_dpy->screenConfigs[xscr->number].configs
-      : NULL;
+   unsigned int depth;
+
+   if (drawable != xscr->last_drawable) {
+      Window root;
+      int x, y;
+      unsigned int w, h, border;
+      Status ok;
+
+      ok = XGetGeometry(xscr->dpy, drawable, &root,
+            &x, &y, &w, &h, &border, &depth);
+      if (!ok)
+         depth = 0;
+
+      xscr->last_drawable = drawable;
+      xscr->last_depth = depth;
+   }
+   else {
+      depth = xscr->last_depth;
+   }
+
+   return depth;
 }
 
+#ifdef GLX_DIRECT_RENDERING
+
 /**
- * Return the GLX visuals.
+ * Return the GLX fbconfigs.
  */
 const __GLcontextModes *
-x11_screen_get_glx_visuals(struct x11_screen *xscr)
+x11_screen_get_glx_configs(struct x11_screen *xscr)
 {
    return (x11_screen_init_glx(xscr))
-      ? xscr->glx_dpy->screenConfigs[xscr->number].visuals
+      ? xscr->glx_dpy->screenConfigs[xscr->number]->configs
       : NULL;
 }
 
@@ -264,14 +290,14 @@ x11_screen_enable_dri2(struct x11_screen *xscr,
          close(fd);
          return -1;
       }
-      if (xscr->glx_dpy->dri2Display) {
+      if (xscr->glx_dpy->xscr) {
          _eglLog(_EGL_WARNING,
                "display is already managed by another x11 screen");
          close(fd);
          return -1;
       }
 
-      xscr->glx_dpy->dri2Display = (__GLXDRIdisplay *) xscr;
+      xscr->glx_dpy->xscr = xscr;
       xscr->dri_invalidate_buffers = invalidate_buffers;
       xscr->dri_user_data = user_data;
 
@@ -281,6 +307,23 @@ x11_screen_enable_dri2(struct x11_screen *xscr,
    return xscr->dri_fd;
 }
 
+char *
+x11_screen_get_device_name(struct x11_screen *xscr)
+{
+   return xscr->dri_device;
+}
+
+int
+x11_screen_authenticate(struct x11_screen *xscr, uint32_t id)
+{
+   boolean authenticated;
+
+   authenticated = DRI2Authenticate(xscr->dpy,
+         RootWindow(xscr->dpy, xscr->number), id);
+   
+   return authenticated ? 0 : -1;
+}
+
 /**
  * Create/Destroy the DRI drawable.
  */
@@ -335,37 +378,6 @@ x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
    return (struct x11_drawable_buffer *) dri2bufs;
 }
 
-/**
- * Return the depth of a drawable.
- *
- * Unlike other drawable functions, the drawable needs not be a DRI2 drawable.
- */
-uint
-x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable)
-{
-   unsigned int depth;
-
-   if (drawable != xscr->last_drawable) {
-      Window root;
-      int x, y;
-      unsigned int w, h, border;
-      Status ok;
-
-      ok = XGetGeometry(xscr->dpy, drawable, &root,
-            &x, &y, &w, &h, &border, &depth);
-      if (!ok)
-         depth = 0;
-
-      xscr->last_drawable = drawable;
-      xscr->last_depth = depth;
-   }
-   else {
-      depth = xscr->last_depth;
-   }
-
-   return depth;
-}
-
 /**
  * Create a mode list of the given size.
  */
@@ -379,7 +391,7 @@ x11_context_modes_create(unsigned count)
 
    next = &base;
    for (i = 0; i < count; i++) {
-      *next = (__GLcontextModes *) calloc(1, size);
+      *next = (__GLcontextModes *) CALLOC(1, size);
       if (*next == NULL) {
          x11_context_modes_destroy(base);
          base = NULL;
@@ -399,7 +411,7 @@ x11_context_modes_destroy(__GLcontextModes *modes)
 {
    while (modes != NULL) {
       __GLcontextModes *next = modes->next;
-      free(modes);
+      FREE(modes);
       modes = next;
    }
 }
@@ -417,6 +429,9 @@ x11_context_modes_count(const __GLcontextModes *modes)
    return count;
 }
 
+extern void
+dri2InvalidateBuffers(Display *dpy, XID drawable);
+
 /**
  * This is called from src/glx/dri2.c.
  */
@@ -426,10 +441,23 @@ dri2InvalidateBuffers(Display *dpy, XID drawable)
    __GLXdisplayPrivate *priv = __glXInitialize(dpy);
    struct x11_screen *xscr = NULL;
 
-   if (priv && priv->dri2Display)
-      xscr = (struct x11_screen *) priv->dri2Display;
+   if (priv && priv->xscr)
+      xscr = priv->xscr;
    if (!xscr || !xscr->dri_invalidate_buffers)
       return;
 
    xscr->dri_invalidate_buffers(xscr, drawable, xscr->dri_user_data);
 }
+
+extern unsigned
+dri2GetSwapEventType(Display *dpy, XID drawable);
+
+/**
+ * This is also called from src/glx/dri2.c.
+ */
+unsigned dri2GetSwapEventType(Display *dpy, XID drawable)
+{
+   return 0;
+}
+
+#endif /* GLX_DIRECT_RENDERING */