[PATCH mesa] refactor out dri2 proto code into libdri2

walter harms wharms at bfs.de
Wed Nov 16 05:02:35 PST 2011



Am 15.11.2011 23:49, schrieb Rob Clark:
> Since I was working on some extensions to DRI2 protocol for handling
> video, it occurred to me that it might be easier to extend the
> protocol if there weren't N different copies of dri2.c floating around
> in various different src trees..  also, for video, with one or two
> other small extensions (ie. standard way to mmap() GEM buffers), I
> think it should eventually be possible for DRI2 to be directly used
> by end applications (ie. for sw video decoders, etc).  So refactoring
> this out into a shared library pretty much seemed like the right-
> thing-to-do.
> 
> This patch updates mesa to remove two nearly identical copies of DRI2
> protocol code.  The error, wire->event, and event->wire stuff is split
> out into some callbacks, as this was really the only differences
> between the two copies of dri2.c (and also, other than name changes,
> the main difference between what is in mesa and vaapi).  Also, from
> looking at the git history, it appears that these callbacks are the
> main place where there have been any changes to this code in the last
> couple years.
> 
> Temporary home for libdri2 tree is here:
> 
>   git://people.freedesktop.org/~robclark/libdri2
> 
> Eventually I can make patches for libva and libvdpau.. but I started
> with mesa because that was something I actually had a way to test.
> 
> v1: original version
> v2: split driverType out into parameter to DRI2Connect() so same API
>     can be used for either video or traditional 3d..
> ---
>  bin/mklib                                       |    4 +-
>  configure.ac                                    |    4 +-
>  src/gallium/state_trackers/egl/x11/x11_screen.c |   20 +-
>  src/gallium/winsys/g3dvl/dri/dri2.c             |  555 +----------------------
>  src/gallium/winsys/g3dvl/dri/dri2.h             |  106 -----
>  src/gallium/winsys/g3dvl/dri/dri_winsys.c       |    4 +-
>  src/gallium/winsys/g3dvl/dri/driclient.c        |    3 +-
>  src/glx/Makefile                                |    2 +-
>  src/glx/dri2.c                                  |  563 +----------------------
>  src/glx/dri2.h                                  |  106 -----
>  src/glx/dri2_glx.c                              |   11 +-
>  src/glx/dri_glx.c                               |    5 +-
>  12 files changed, 55 insertions(+), 1328 deletions(-)
>  delete mode 100644 src/gallium/winsys/g3dvl/dri/dri2.h
>  delete mode 100644 src/glx/dri2.h
> 
> diff --git a/bin/mklib b/bin/mklib
> index fd87aad..2ac4df9 100755
> --- a/bin/mklib
> +++ b/bin/mklib
> @@ -344,7 +344,7 @@ case $ARCH in
>  
>              rm -f ${LIBNAME}
>              # make lib
> -            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
> +            ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} ${LDFLAGS}
>              # finish up
>              FINAL_LIBS="${LIBNAME}"
>          elif [ $STATIC = 1 ] ; then
> @@ -412,7 +412,7 @@ case $ARCH in
>              rm -f ${LIBNAME}.so
>  
>              # make lib
> -            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
> +            ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} ${LDFLAGS}
>              # make usual symlinks
>              ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
>              ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
> diff --git a/configure.ac b/configure.ac
> index 02452e7..76d4b3f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -988,7 +988,7 @@ xyesno)
>          if test "x$have_libdrm" != xyes; then
>              AC_MSG_ERROR([Direct rendering requires libdrm >= $LIBDRM_REQUIRED])
>          fi
> -        PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
> +        PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED dri2])
>          GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED"
>      fi
>  
> @@ -1257,7 +1257,7 @@ if test "x$enable_dri" = xyes; then
>      fi
>  
>      # put all the necessary libs together, including possibly libdricore
> -    DRI_LIB_DEPS="$DRI_LIB_DEPS $SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS"
> +    DRI_LIB_DEPS="$DRI_LIB_DEPS $DRI2PROTO_LIBS $SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS"
>  fi
>  AC_SUBST([DRI_DIRS])
>  AC_SUBST([EXPAT_INCLUDES])
> diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c
> index 6155b4d..23a5813 100644
> --- a/src/gallium/state_trackers/egl/x11/x11_screen.c
> +++ b/src/gallium/state_trackers/egl/x11/x11_screen.c
> @@ -119,7 +119,8 @@ x11_screen_init_dri2(struct x11_screen *xscr)
>     if (xscr->dri_major < 0) {
>        int eventBase, errorBase;
>  
> -      if (!DRI2QueryExtension(xscr->dpy, &eventBase, &errorBase) ||
> +      if (!DRI2Init(xscr->dpy) ||
> +          !DRI2QueryExtension(xscr->dpy, &eventBase, &errorBase) ||
>            !DRI2QueryVersion(xscr->dpy, &xscr->dri_major, &xscr->dri_minor))
>           xscr->dri_major = -1;
>     }
> @@ -237,7 +238,7 @@ x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor)
>     /* get the driver name and the device name */
>     if (!xscr->dri_driver) {
>        if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number),
> -               &xscr->dri_driver, &xscr->dri_device))
> +               DRI2DriverDRI, &xscr->dri_driver, &xscr->dri_device))
>           xscr->dri_driver = xscr->dri_device = NULL;
>     }
>     if (major)
> @@ -367,6 +368,8 @@ x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
>                           boolean with_format, int num_ins, int *num_outs)
>  {
>     DRI2Buffer *dri2bufs;
> +   struct x11_drawable_buffer *bufs;
> +   int i;
>  
>     if (with_format)
>        dri2bufs = DRI2GetBuffersWithFormat(xscr->dpy, drawable, width, height,
> @@ -375,7 +378,18 @@ x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable,
>        dri2bufs = DRI2GetBuffers(xscr->dpy, drawable, width, height,
>              attachments, num_ins, num_outs);
>  
> -   return (struct x11_drawable_buffer *) dri2bufs;
> +   bufs = malloc(*num_outs * sizeof(*bufs));

I would suggest using calloc() here:
1. it feels more natural
2. it will set all params to 0 by default


> +   for (i = 0; i < *num_outs; i++) {
> +	   bufs[i].attachment = dri2bufs[i].attachment;
> +	   bufs[i].name = dri2bufs[i].names[0];
> +	   bufs[i].pitch = dri2bufs[i].pitch[0];
> +	   bufs[i].cpp = dri2bufs[i].cpp;
> +	   bufs[i].flags = dri2bufs[i].flags;
> +   }
> +
> +   free(dri2bufs);
> +
> +   return bufs;
>  }
>  
>  /**
> diff --git a/src/gallium/winsys/g3dvl/dri/dri2.c b/src/gallium/winsys/g3dvl/dri/dri2.c
> index 12ed6d0..1822408 100644
> --- a/src/gallium/winsys/g3dvl/dri/dri2.c
> +++ b/src/gallium/winsys/g3dvl/dri/dri2.c
> @@ -37,6 +37,7 @@
>  #include <X11/extensions/Xext.h>
>  #include <X11/extensions/extutil.h>
>  #include <X11/extensions/dri2proto.h>
> +#include <X11/extensions/dri2.h>
>  #include "xf86drm.h"
>  #include "dri2.h"
>  #if 0
> @@ -44,54 +45,12 @@
>  #include "GL/glxext.h"
>  #endif
>  
> -/* Allow the build to work with an older versions of dri2proto.h and
> - * dri2tokens.h.
> - */
> -#if DRI2_MINOR < 1
> -#undef DRI2_MINOR
> -#define DRI2_MINOR 1
> -#define X_DRI2GetBuffersWithFormat 7
> -#endif
> -
> -
> -static char dri2ExtensionName[] = DRI2_NAME;
> -static XExtensionInfo *dri2Info;
> -static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info)
> -
> -static Bool
> -DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire);
> -static Status
> -DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire);
> -
> -static /* const */ XExtensionHooks dri2ExtensionHooks = {
> -  NULL,                   /* create_gc */
> -  NULL,                   /* copy_gc */
> -  NULL,                   /* flush_gc */
> -  NULL,                   /* free_gc */
> -  NULL,                   /* create_font */
> -  NULL,                   /* free_font */
> -  DRI2CloseDisplay,       /* close_display */
> -  DRI2WireToEvent,        /* wire_to_event */
> -  DRI2EventToWire,        /* event_to_wire */
> -  NULL,                   /* error */
> -  NULL,                   /* error_string */
> -};
> -
> -static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
> -                                   dri2Info,
> -                                   dri2ExtensionName,
> -                                   &dri2ExtensionHooks,
> -                                   0, NULL)
> -
>  static Bool
> -DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
> +DRI2WireToEvent(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire)
>  {
>  #if 0
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
>     XExtDisplayInfo *glx_info = __glXFindDisplay(dpy);
>  
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
>     switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
>  
>  #ifdef X_DRI2SwapBuffers
> @@ -146,12 +105,8 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
>   * send each other DRI2 events.
>   */
>  static Status
> -DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
> +DRI2EventToWire(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire)
>  {
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
>     switch (event->type) {
>     default:
>        /* client doesn't support server event */
> @@ -161,506 +116,14 @@ DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
>     return Success;
>  }
>  
> -Bool
> -DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -
> -   if (XextHasExtension(info)) {
> -      *eventBase = info->codes->first_event;
> -      *errorBase = info->codes->first_error;
> -      return True;
> -   }
> -
> -   return False;
> -}
> -
> -Bool
> -DRI2QueryVersion(Display * dpy, int *major, int *minor)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2QueryVersionReply rep;
> -   xDRI2QueryVersionReq *req;
> -   int i, nevents;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2QueryVersion, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2QueryVersion;
> -   req->majorVersion = DRI2_MAJOR;
> -   req->minorVersion = DRI2_MINOR;
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   *major = rep.majorVersion;
> -   *minor = rep.minorVersion;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   switch (rep.minorVersion) {
> -   case 1:
> -	   nevents = 0;
> -	   break;
> -   case 2:
> -	   nevents = 1;
> -	   break;
> -   case 3:
> -   default:
> -	   nevents = 2;
> -	   break;
> -   }
> -
> -   for (i = 0; i < nevents; i++) {
> -       XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent);
> -       XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire);
> -   }
> -
> -   return True;
> -}
> -
> -Bool
> -DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2ConnectReply rep;
> -   xDRI2ConnectReq *req;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2Connect, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2Connect;
> -   req->window = window;
> -   req->driverType = DRI2DriverDRI;
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   *driverName = Xmalloc(rep.driverNameLength + 1);
> -   if (*driverName == NULL) {
> -      _XEatData(dpy,
> -                ((rep.driverNameLength + 3) & ~3) +
> -                ((rep.deviceNameLength + 3) & ~3));
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   _XReadPad(dpy, *driverName, rep.driverNameLength);
> -   (*driverName)[rep.driverNameLength] = '\0';
> -
> -   *deviceName = Xmalloc(rep.deviceNameLength + 1);
> -   if (*deviceName == NULL) {
> -      Xfree(*driverName);
> -      _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   _XReadPad(dpy, *deviceName, rep.deviceNameLength);
> -   (*deviceName)[rep.deviceNameLength] = '\0';
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
>  
> -   return True;
> -}
> +static const DRI2EventOps ops = {
> +		.WireToEvent = DRI2WireToEvent,
> +		.EventToWire = DRI2EventToWire,
> +};
>  
>  Bool
> -DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2AuthenticateReq *req;
> -   xDRI2AuthenticateReply rep;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2Authenticate, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2Authenticate;
> -   req->window = window;
> -   req->magic = magic;
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return rep.authenticated;
> -}
> -
> -void
> -DRI2CreateDrawable(Display * dpy, XID drawable)
> +DRI2Init(Display * dpy)
>  {
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2CreateDrawableReq *req;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2CreateDrawable, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2CreateDrawable;
> -   req->drawable = drawable;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> +	return DRI2InitDisplay(dpy, &ops);
>  }
> -
> -void
> -DRI2DestroyDrawable(Display * dpy, XID drawable)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2DestroyDrawableReq *req;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   XSync(dpy, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2DestroyDrawable, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2DestroyDrawable;
> -   req->drawable = drawable;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -}
> -
> -DRI2Buffer *
> -DRI2GetBuffers(Display * dpy, XID drawable,
> -               int *width, int *height,
> -               unsigned int *attachments, int count, int *outCount)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2GetBuffersReply rep;
> -   xDRI2GetBuffersReq *req;
> -   DRI2Buffer *buffers;
> -   xDRI2Buffer repBuffer;
> -   CARD32 *p;
> -   int i;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReqExtra(DRI2GetBuffers, count * 4, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2GetBuffers;
> -   req->drawable = drawable;
> -   req->count = count;
> -   p = (CARD32 *) & req[1];
> -   for (i = 0; i < count; i++)
> -      p[i] = attachments[i];
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   *width = rep.width;
> -   *height = rep.height;
> -   *outCount = rep.count;
> -
> -   buffers = Xmalloc(rep.count * sizeof buffers[0]);
> -   if (buffers == NULL) {
> -      _XEatData(dpy, rep.count * sizeof repBuffer);
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   for (i = 0; i < rep.count; i++) {
> -      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
> -      buffers[i].attachment = repBuffer.attachment;
> -      buffers[i].name = repBuffer.name;
> -      buffers[i].pitch = repBuffer.pitch;
> -      buffers[i].cpp = repBuffer.cpp;
> -      buffers[i].flags = repBuffer.flags;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return buffers;
> -}
> -
> -
> -DRI2Buffer *
> -DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
> -                         int *width, int *height,
> -                         unsigned int *attachments, int count, int *outCount)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2GetBuffersReply rep;
> -   xDRI2GetBuffersReq *req;
> -   DRI2Buffer *buffers;
> -   xDRI2Buffer repBuffer;
> -   CARD32 *p;
> -   int i;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReqExtra(DRI2GetBuffers, count * (4 * 2), req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2GetBuffersWithFormat;
> -   req->drawable = drawable;
> -   req->count = count;
> -   p = (CARD32 *) & req[1];
> -   for (i = 0; i < (count * 2); i++)
> -      p[i] = attachments[i];
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   *width = rep.width;
> -   *height = rep.height;
> -   *outCount = rep.count;
> -
> -   buffers = Xmalloc(rep.count * sizeof buffers[0]);
> -   if (buffers == NULL) {
> -      _XEatData(dpy, rep.count * sizeof repBuffer);
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   for (i = 0; i < rep.count; i++) {
> -      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
> -      buffers[i].attachment = repBuffer.attachment;
> -      buffers[i].name = repBuffer.name;
> -      buffers[i].pitch = repBuffer.pitch;
> -      buffers[i].cpp = repBuffer.cpp;
> -      buffers[i].flags = repBuffer.flags;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return buffers;
> -}
> -
> -
> -void
> -DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
> -               CARD32 dest, CARD32 src)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2CopyRegionReq *req;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2CopyRegion, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2CopyRegion;
> -   req->drawable = drawable;
> -   req->region = region;
> -   req->dest = dest;
> -   req->src = src;
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -}
> -
> -#ifdef X_DRI2SwapBuffers
> -static void
> -load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor,
> -	     CARD64 remainder)
> -{
> -    req->target_msc_hi = target >> 32;
> -    req->target_msc_lo = target & 0xffffffff;
> -    req->divisor_hi = divisor >> 32;
> -    req->divisor_lo = divisor & 0xffffffff;
> -    req->remainder_hi = remainder >> 32;
> -    req->remainder_lo = remainder & 0xffffffff;
> -}
> -
> -static CARD64
> -vals_to_card64(CARD32 lo, CARD32 hi)
> -{
> -    return (CARD64)hi << 32 | lo;
> -}
> -
> -void DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc,
> -		     CARD64 divisor, CARD64 remainder, CARD64 *count)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2SwapBuffersReq *req;
> -    xDRI2SwapBuffersReply rep;
> -
> -    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2SwapBuffers, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2SwapBuffers;
> -    req->drawable = drawable;
> -    load_swap_req(req, target_msc, divisor, remainder);
> -
> -    _XReply(dpy, (xReply *)&rep, 0, xFalse);
> -
> -    *count = vals_to_card64(rep.swap_lo, rep.swap_hi);
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -}
> -#endif
> -
> -#ifdef X_DRI2GetMSC
> -Bool DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc,
> -		CARD64 *sbc)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2GetMSCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2GetMSC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2GetMSC;
> -    req->drawable = drawable;
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = vals_to_card64(rep.ust_lo, rep.ust_hi);
> -    *msc = vals_to_card64(rep.msc_lo, rep.msc_hi);
> -    *sbc = vals_to_card64(rep.sbc_lo, rep.sbc_hi);
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> -}
> -#endif
> -
> -#ifdef X_DRI2WaitMSC
> -static void
> -load_msc_req(xDRI2WaitMSCReq *req, CARD64 target, CARD64 divisor,
> -	     CARD64 remainder)
> -{
> -    req->target_msc_hi = target >> 32;
> -    req->target_msc_lo = target & 0xffffffff;
> -    req->divisor_hi = divisor >> 32;
> -    req->divisor_lo = divisor & 0xffffffff;
> -    req->remainder_hi = remainder >> 32;
> -    req->remainder_lo = remainder & 0xffffffff;
> -}
> -
> -Bool DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -		 CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2WaitMSCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2WaitMSC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2WaitMSC;
> -    req->drawable = drawable;
> -    load_msc_req(req, target_msc, divisor, remainder);
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = ((CARD64)rep.ust_hi << 32) | (CARD64)rep.ust_lo;
> -    *msc = ((CARD64)rep.msc_hi << 32) | (CARD64)rep.msc_lo;
> -    *sbc = ((CARD64)rep.sbc_hi << 32) | (CARD64)rep.sbc_lo;
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> -}
> -#endif
> -
> -#ifdef X_DRI2WaitSBC
> -static void
> -load_sbc_req(xDRI2WaitSBCReq *req, CARD64 target)
> -{
> -    req->target_sbc_hi = target >> 32;
> -    req->target_sbc_lo = target & 0xffffffff;
> -}
> -
> -Bool DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
> -		 CARD64 *msc, CARD64 *sbc)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2WaitSBCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2WaitSBC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2WaitSBC;
> -    req->drawable = drawable;
> -    load_sbc_req(req, target_sbc);
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = ((CARD64)rep.ust_hi << 32) | rep.ust_lo;
> -    *msc = ((CARD64)rep.msc_hi << 32) | rep.msc_lo;
> -    *sbc = ((CARD64)rep.sbc_hi << 32) | rep.sbc_lo;
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> -}
> -#endif
> -
> -#ifdef X_DRI2SwapInterval
> -void DRI2SwapInterval(Display *dpy, XID drawable, int interval)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2SwapIntervalReq *req;
> -
> -    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2SwapInterval, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2SwapInterval;
> -    req->drawable = drawable;
> -    req->interval = interval;
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -}
> -#endif
> diff --git a/src/gallium/winsys/g3dvl/dri/dri2.h b/src/gallium/winsys/g3dvl/dri/dri2.h
> deleted file mode 100644
> index 114e9f8..0000000
> --- a/src/gallium/winsys/g3dvl/dri/dri2.h
> +++ /dev/null
> @@ -1,106 +0,0 @@
> -/*
> - * Copyright © 2007,2008 Red Hat, Inc.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a
> - * copy of this software and associated documentation files (the "Soft-
> - * ware"), to deal in the Software without restriction, including without
> - * limitation the rights to use, copy, modify, merge, publish, distribute,
> - * and/or sell copies of the Software, and to permit persons to whom the
> - * Software is furnished to do so, provided that the above copyright
> - * notice(s) and this permission notice appear in all copies of the Soft-
> - * ware and that both the above copyright notice(s) and this permission
> - * notice appear in supporting documentation.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
> - * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
> - * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
> - * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
> - * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
> - * MANCE OF THIS SOFTWARE.
> - *
> - * Except as contained in this notice, the name of a copyright holder shall
> - * not be used in advertising or otherwise to promote the sale, use or
> - * other dealings in this Software without prior written authorization of
> - * the copyright holder.
> - *
> - * Authors:
> - *   Kristian Høgsberg (krh at redhat.com)
> - */
> -
> -#ifndef _DRI2_H_
> -#define _DRI2_H_
> -
> -#include <X11/extensions/Xfixes.h>
> -#include <X11/extensions/dri2tokens.h>
> -
> -typedef struct
> -{
> -   unsigned int attachment;
> -   unsigned int name;
> -   unsigned int pitch;
> -   unsigned int cpp;
> -   unsigned int flags;
> -} DRI2Buffer;
> -
> -extern Bool
> -DRI2QueryExtension(Display * display, int *eventBase, int *errorBase);
> -
> -extern Bool
> -DRI2QueryVersion(Display * display, int *major, int *minor);
> -
> -extern Bool
> -DRI2Connect(Display * display, XID window,
> -            char **driverName, char **deviceName);
> -
> -extern Bool
> -DRI2Authenticate(Display * display, XID window, drm_magic_t magic);
> -
> -extern void
> -DRI2CreateDrawable(Display * display, XID drawable);
> -
> -extern void
> -DRI2DestroyDrawable(Display * display, XID handle);
> -
> -extern DRI2Buffer*
> -DRI2GetBuffers(Display * dpy, XID drawable,
> -               int *width, int *height,
> -               unsigned int *attachments, int count,
> -               int *outCount);
> -
> -/**
> - * \note
> - * This function is only supported with DRI2 version 1.1 or later.
> - */
> -extern DRI2Buffer*
> -DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
> -                         int *width, int *height,
> -                         unsigned int *attachments,
> -                         int count, int *outCount);
> -
> -extern void
> -DRI2CopyRegion(Display * dpy, XID drawable,
> -               XserverRegion region,
> -               CARD32 dest, CARD32 src);
> -
> -extern void
> -DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -		CARD64 remainder, CARD64 *count);
> -
> -extern Bool
> -DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc, CARD64 *sbc);
> -
> -extern Bool
> -DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -	    CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc);
> -
> -extern Bool
> -DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
> -	    CARD64 *msc, CARD64 *sbc);
> -
> -extern void
> -DRI2SwapInterval(Display *dpy, XID drawable, int interval);
> -
> -#endif
> diff --git a/src/gallium/winsys/g3dvl/dri/dri_winsys.c b/src/gallium/winsys/g3dvl/dri/dri_winsys.c
> index aef88f2..75d1271 100644
> --- a/src/gallium/winsys/g3dvl/dri/dri_winsys.c
> +++ b/src/gallium/winsys/g3dvl/dri/dri_winsys.c
> @@ -75,8 +75,8 @@ vl_dri2_get_front(struct vl_context *vctx, Drawable drawable)
>        struct winsys_handle dri2_front_handle =
>        {
>           .type = DRM_API_HANDLE_TYPE_SHARED,
> -         .handle = dri2_front->name,
> -         .stride = dri2_front->pitch
> +         .handle = dri2_front->names[0],
> +         .stride = dri2_front->pitch[0],
>        };
>        struct pipe_resource template;
>        struct pipe_surface surf_template;
> diff --git a/src/gallium/winsys/g3dvl/dri/driclient.c b/src/gallium/winsys/g3dvl/dri/driclient.c
> index 90e48a7..e7857cf 100644
> --- a/src/gallium/winsys/g3dvl/dri/driclient.c
> +++ b/src/gallium/winsys/g3dvl/dri/driclient.c
> @@ -323,7 +323,8 @@ int dri2CreateScreen(Display *display, int screen, dri_screen_t **dri_screen)
>  	if (!dri_scrn)
>  		return 1;
>  
> -	if (!DRI2Connect(display, XRootWindow(display, screen), &drvName, &devName))
> +	if (!DRI2Connect(display, XRootWindow(display, screen), DRI2DriverDRI,
> +			&drvName, &devName))
>  		goto free_screen;
>  
>  	dri_scrn->fd = open(devName, O_RDWR);
> diff --git a/src/glx/Makefile b/src/glx/Makefile
> index dd96973..30022ec 100644
> --- a/src/glx/Makefile
> +++ b/src/glx/Makefile
> @@ -82,7 +82,7 @@ default: depend $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
>  
>  # Make libGL
>  $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(OBJECTS) $(GLAPI_LIB) Makefile
> -	$(MKLIB) -o $(GL_LIB) -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
> +	$(MKLIB) -o $(GL_LIB) -linker '$(CXX)' -ldflags '$(LDFLAGS) $(DRI_LIB_DEPS)' \
>  		-major 1 -minor 2 \
>  		-cplusplus $(MKLIB_OPTIONS) \
>  		-install $(TOP)/$(LIB_DIR) -id $(INSTALL_LIB_DIR)/lib$(GL_LIB).1.dylib \
> diff --git a/src/glx/dri2.c b/src/glx/dri2.c
> index b1b5013..d609906 100644
> --- a/src/glx/dri2.c
> +++ b/src/glx/dri2.c
> @@ -38,60 +38,16 @@
>  #include <X11/extensions/Xext.h>
>  #include <X11/extensions/extutil.h>
>  #include <X11/extensions/dri2proto.h>
> +#include <X11/extensions/dri2.h>
>  #include "xf86drm.h"
> -#include "dri2.h"
>  #include "glxclient.h"
>  #include "GL/glxext.h"
>  
> -/* Allow the build to work with an older versions of dri2proto.h and
> - * dri2tokens.h.
> - */
> -#if DRI2_MINOR < 1
> -#undef DRI2_MINOR
> -#define DRI2_MINOR 1
> -#define X_DRI2GetBuffersWithFormat 7
> -#endif
> -
> -
> -static char dri2ExtensionName[] = DRI2_NAME;
> -static XExtensionInfo *dri2Info;
> -static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info)
> -
> -static Bool
> -DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire);
> -static Status
> -DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire);
> -static int
> -DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code);
> -
> -static /* const */ XExtensionHooks dri2ExtensionHooks = {
> -  NULL,                   /* create_gc */
> -  NULL,                   /* copy_gc */
> -  NULL,                   /* flush_gc */
> -  NULL,                   /* free_gc */
> -  NULL,                   /* create_font */
> -  NULL,                   /* free_font */
> -  DRI2CloseDisplay,       /* close_display */
> -  DRI2WireToEvent,        /* wire_to_event */
> -  DRI2EventToWire,        /* event_to_wire */
> -  DRI2Error,              /* error */
> -  NULL,                   /* error_string */
> -};
> -
> -static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
> -                                   dri2Info,
> -                                   dri2ExtensionName,
> -                                   &dri2ExtensionHooks,
> -                                   0, NULL)
> -
>  static Bool
> -DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
> +DRI2WireToEvent(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire)
>  {
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
>     struct glx_drawable *glxDraw;
>  
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
>     switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
>  
>  #ifdef X_DRI2SwapBuffers
> @@ -159,12 +115,8 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
>   * send each other DRI2 events.
>   */
>  static Status
> -DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
> +DRI2EventToWire(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire)
>  {
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
>     switch (event->type) {
>     default:
>        /* client doesn't support server event */
> @@ -202,511 +154,16 @@ DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code)
>      return False;
>  }
>  
> -Bool
> -DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -
> -   if (XextHasExtension(info)) {
> -      *eventBase = info->codes->first_event;
> -      *errorBase = info->codes->first_error;
> -      return True;
> -   }
> -
> -   return False;
> -}
> -
> -Bool
> -DRI2QueryVersion(Display * dpy, int *major, int *minor)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2QueryVersionReply rep;
> -   xDRI2QueryVersionReq *req;
> -   int i, nevents;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2QueryVersion, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2QueryVersion;
> -   req->majorVersion = DRI2_MAJOR;
> -   req->minorVersion = DRI2_MINOR;
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   *major = rep.majorVersion;
> -   *minor = rep.minorVersion;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   switch (rep.minorVersion) {
> -   case 1:
> -	   nevents = 0;
> -	   break;
> -   case 2:
> -	   nevents = 1;
> -	   break;
> -   case 3:
> -   default:
> -	   nevents = 2;
> -	   break;
> -   }
> -	
> -   for (i = 0; i < nevents; i++) {
> -       XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent);
> -       XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire);
> -   }
> -
> -   return True;
> -}
> -
> -Bool
> -DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2ConnectReply rep;
> -   xDRI2ConnectReq *req;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2Connect, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2Connect;
> -   req->window = window;
> -   req->driverType = DRI2DriverDRI;
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   *driverName = Xmalloc(rep.driverNameLength + 1);
> -   if (*driverName == NULL) {
> -      _XEatData(dpy,
> -                ((rep.driverNameLength + 3) & ~3) +
> -                ((rep.deviceNameLength + 3) & ~3));
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   _XReadPad(dpy, *driverName, rep.driverNameLength);
> -   (*driverName)[rep.driverNameLength] = '\0';
> -
> -   *deviceName = Xmalloc(rep.deviceNameLength + 1);
> -   if (*deviceName == NULL) {
> -      Xfree(*driverName);
> -      _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -   _XReadPad(dpy, *deviceName, rep.deviceNameLength);
> -   (*deviceName)[rep.deviceNameLength] = '\0';
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return True;
> -}
> +static const DRI2EventOps ops = {
> +		.WireToEvent = DRI2WireToEvent,
> +		.EventToWire = DRI2EventToWire,
> +		.Error = DRI2Error,
> +};
>  
>  Bool
> -DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2AuthenticateReq *req;
> -   xDRI2AuthenticateReply rep;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2Authenticate, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2Authenticate;
> -   req->window = window;
> -   req->magic = magic;
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return False;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return rep.authenticated;
> -}
> -
> -void
> -DRI2CreateDrawable(Display * dpy, XID drawable)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2CreateDrawableReq *req;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2CreateDrawable, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2CreateDrawable;
> -   req->drawable = drawable;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -}
> -
> -void
> -DRI2DestroyDrawable(Display * dpy, XID drawable)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2DestroyDrawableReq *req;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   XSync(dpy, False);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2DestroyDrawable, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2DestroyDrawable;
> -   req->drawable = drawable;
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -}
> -
> -DRI2Buffer *
> -DRI2GetBuffers(Display * dpy, XID drawable,
> -               int *width, int *height,
> -               unsigned int *attachments, int count, int *outCount)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2GetBuffersReply rep;
> -   xDRI2GetBuffersReq *req;
> -   DRI2Buffer *buffers;
> -   xDRI2Buffer repBuffer;
> -   CARD32 *p;
> -   int i;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReqExtra(DRI2GetBuffers, count * 4, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2GetBuffers;
> -   req->drawable = drawable;
> -   req->count = count;
> -   p = (CARD32 *) & req[1];
> -   for (i = 0; i < count; i++)
> -      p[i] = attachments[i];
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   *width = rep.width;
> -   *height = rep.height;
> -   *outCount = rep.count;
> -
> -   buffers = Xmalloc(rep.count * sizeof buffers[0]);
> -   if (buffers == NULL) {
> -      _XEatData(dpy, rep.count * sizeof repBuffer);
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   for (i = 0; i < rep.count; i++) {
> -      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
> -      buffers[i].attachment = repBuffer.attachment;
> -      buffers[i].name = repBuffer.name;
> -      buffers[i].pitch = repBuffer.pitch;
> -      buffers[i].cpp = repBuffer.cpp;
> -      buffers[i].flags = repBuffer.flags;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return buffers;
> -}
> -
> -
> -DRI2Buffer *
> -DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
> -                         int *width, int *height,
> -                         unsigned int *attachments, int count, int *outCount)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2GetBuffersReply rep;
> -   xDRI2GetBuffersReq *req;
> -   DRI2Buffer *buffers;
> -   xDRI2Buffer repBuffer;
> -   CARD32 *p;
> -   int i;
> -
> -   XextCheckExtension(dpy, info, dri2ExtensionName, False);
> -
> -   LockDisplay(dpy);
> -   GetReqExtra(DRI2GetBuffers, count * (4 * 2), req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2GetBuffersWithFormat;
> -   req->drawable = drawable;
> -   req->count = count;
> -   p = (CARD32 *) & req[1];
> -   for (i = 0; i < (count * 2); i++)
> -      p[i] = attachments[i];
> -
> -   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   *width = rep.width;
> -   *height = rep.height;
> -   *outCount = rep.count;
> -
> -   buffers = Xmalloc(rep.count * sizeof buffers[0]);
> -   if (buffers == NULL) {
> -      _XEatData(dpy, rep.count * sizeof repBuffer);
> -      UnlockDisplay(dpy);
> -      SyncHandle();
> -      return NULL;
> -   }
> -
> -   for (i = 0; i < rep.count; i++) {
> -      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
> -      buffers[i].attachment = repBuffer.attachment;
> -      buffers[i].name = repBuffer.name;
> -      buffers[i].pitch = repBuffer.pitch;
> -      buffers[i].cpp = repBuffer.cpp;
> -      buffers[i].flags = repBuffer.flags;
> -   }
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -
> -   return buffers;
> -}
> -
> -
> -void
> -DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
> -               CARD32 dest, CARD32 src)
> -{
> -   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -   xDRI2CopyRegionReq *req;
> -   xDRI2CopyRegionReply rep;
> -
> -   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
> -
> -   LockDisplay(dpy);
> -   GetReq(DRI2CopyRegion, req);
> -   req->reqType = info->codes->major_opcode;
> -   req->dri2ReqType = X_DRI2CopyRegion;
> -   req->drawable = drawable;
> -   req->region = region;
> -   req->dest = dest;
> -   req->src = src;
> -
> -   _XReply(dpy, (xReply *) & rep, 0, xFalse);
> -
> -   UnlockDisplay(dpy);
> -   SyncHandle();
> -}
> -
> -#ifdef X_DRI2SwapBuffers
> -static void
> -load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor,
> -	     CARD64 remainder)
> -{
> -    req->target_msc_hi = target >> 32;
> -    req->target_msc_lo = target & 0xffffffff;
> -    req->divisor_hi = divisor >> 32;
> -    req->divisor_lo = divisor & 0xffffffff;
> -    req->remainder_hi = remainder >> 32;
> -    req->remainder_lo = remainder & 0xffffffff;
> -}
> -
> -static CARD64
> -vals_to_card64(CARD32 lo, CARD32 hi)
> -{
> -    return (CARD64)hi << 32 | lo;
> -}
> -
> -void DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc,
> -		     CARD64 divisor, CARD64 remainder, CARD64 *count)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2SwapBuffersReq *req;
> -    xDRI2SwapBuffersReply rep;
> -
> -    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2SwapBuffers, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2SwapBuffers;
> -    req->drawable = drawable;
> -    load_swap_req(req, target_msc, divisor, remainder);
> -
> -    _XReply(dpy, (xReply *)&rep, 0, xFalse);
> -
> -    *count = vals_to_card64(rep.swap_lo, rep.swap_hi);
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -}
> -#endif
> -
> -#ifdef X_DRI2GetMSC
> -Bool DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc,
> -		CARD64 *sbc)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2GetMSCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2GetMSC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2GetMSC;
> -    req->drawable = drawable;
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = vals_to_card64(rep.ust_lo, rep.ust_hi);
> -    *msc = vals_to_card64(rep.msc_lo, rep.msc_hi);
> -    *sbc = vals_to_card64(rep.sbc_lo, rep.sbc_hi);
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> -}
> -#endif
> -
> -#ifdef X_DRI2WaitMSC
> -static void
> -load_msc_req(xDRI2WaitMSCReq *req, CARD64 target, CARD64 divisor,
> -	     CARD64 remainder)
> -{
> -    req->target_msc_hi = target >> 32;
> -    req->target_msc_lo = target & 0xffffffff;
> -    req->divisor_hi = divisor >> 32;
> -    req->divisor_lo = divisor & 0xffffffff;
> -    req->remainder_hi = remainder >> 32;
> -    req->remainder_lo = remainder & 0xffffffff;
> -}
> -
> -Bool DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -		 CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc)
> +DRI2Init(Display * dpy)
>  {
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2WaitMSCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2WaitMSC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2WaitMSC;
> -    req->drawable = drawable;
> -    load_msc_req(req, target_msc, divisor, remainder);
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = ((CARD64)rep.ust_hi << 32) | (CARD64)rep.ust_lo;
> -    *msc = ((CARD64)rep.msc_hi << 32) | (CARD64)rep.msc_lo;
> -    *sbc = ((CARD64)rep.sbc_hi << 32) | (CARD64)rep.sbc_lo;
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> +	return DRI2InitDisplay(dpy, &ops);
>  }
> -#endif
> -
> -#ifdef X_DRI2WaitSBC
> -static void
> -load_sbc_req(xDRI2WaitSBCReq *req, CARD64 target)
> -{
> -    req->target_sbc_hi = target >> 32;
> -    req->target_sbc_lo = target & 0xffffffff;
> -}
> -
> -Bool DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
> -		 CARD64 *msc, CARD64 *sbc)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2WaitSBCReq *req;
> -    xDRI2MSCReply rep;
> -
> -    XextCheckExtension (dpy, info, dri2ExtensionName, False);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2WaitSBC, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2WaitSBC;
> -    req->drawable = drawable;
> -    load_sbc_req(req, target_sbc);
> -
> -    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -	return False;
> -    }
> -
> -    *ust = ((CARD64)rep.ust_hi << 32) | rep.ust_lo;
> -    *msc = ((CARD64)rep.msc_hi << 32) | rep.msc_lo;
> -    *sbc = ((CARD64)rep.sbc_hi << 32) | rep.sbc_lo;
> -
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -
> -    return True;
> -}
> -#endif
> -
> -#ifdef X_DRI2SwapInterval
> -void DRI2SwapInterval(Display *dpy, XID drawable, int interval)
> -{
> -    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
> -    xDRI2SwapIntervalReq *req;
> -
> -    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
> -
> -    LockDisplay(dpy);
> -    GetReq(DRI2SwapInterval, req);
> -    req->reqType = info->codes->major_opcode;
> -    req->dri2ReqType = X_DRI2SwapInterval;
> -    req->drawable = drawable;
> -    req->interval = interval;
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -}
> -#endif
>  
>  #endif /* GLX_DIRECT_RENDERING */
> diff --git a/src/glx/dri2.h b/src/glx/dri2.h
> deleted file mode 100644
> index 114e9f8..0000000
> --- a/src/glx/dri2.h
> +++ /dev/null
> @@ -1,106 +0,0 @@
> -/*
> - * Copyright © 2007,2008 Red Hat, Inc.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a
> - * copy of this software and associated documentation files (the "Soft-
> - * ware"), to deal in the Software without restriction, including without
> - * limitation the rights to use, copy, modify, merge, publish, distribute,
> - * and/or sell copies of the Software, and to permit persons to whom the
> - * Software is furnished to do so, provided that the above copyright
> - * notice(s) and this permission notice appear in all copies of the Soft-
> - * ware and that both the above copyright notice(s) and this permission
> - * notice appear in supporting documentation.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
> - * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
> - * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
> - * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
> - * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
> - * MANCE OF THIS SOFTWARE.
> - *
> - * Except as contained in this notice, the name of a copyright holder shall
> - * not be used in advertising or otherwise to promote the sale, use or
> - * other dealings in this Software without prior written authorization of
> - * the copyright holder.
> - *
> - * Authors:
> - *   Kristian Høgsberg (krh at redhat.com)
> - */
> -
> -#ifndef _DRI2_H_
> -#define _DRI2_H_
> -
> -#include <X11/extensions/Xfixes.h>
> -#include <X11/extensions/dri2tokens.h>
> -
> -typedef struct
> -{
> -   unsigned int attachment;
> -   unsigned int name;
> -   unsigned int pitch;
> -   unsigned int cpp;
> -   unsigned int flags;
> -} DRI2Buffer;
> -
> -extern Bool
> -DRI2QueryExtension(Display * display, int *eventBase, int *errorBase);
> -
> -extern Bool
> -DRI2QueryVersion(Display * display, int *major, int *minor);
> -
> -extern Bool
> -DRI2Connect(Display * display, XID window,
> -            char **driverName, char **deviceName);
> -
> -extern Bool
> -DRI2Authenticate(Display * display, XID window, drm_magic_t magic);
> -
> -extern void
> -DRI2CreateDrawable(Display * display, XID drawable);
> -
> -extern void
> -DRI2DestroyDrawable(Display * display, XID handle);
> -
> -extern DRI2Buffer*
> -DRI2GetBuffers(Display * dpy, XID drawable,
> -               int *width, int *height,
> -               unsigned int *attachments, int count,
> -               int *outCount);
> -
> -/**
> - * \note
> - * This function is only supported with DRI2 version 1.1 or later.
> - */
> -extern DRI2Buffer*
> -DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
> -                         int *width, int *height,
> -                         unsigned int *attachments,
> -                         int count, int *outCount);
> -
> -extern void
> -DRI2CopyRegion(Display * dpy, XID drawable,
> -               XserverRegion region,
> -               CARD32 dest, CARD32 src);
> -
> -extern void
> -DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -		CARD64 remainder, CARD64 *count);
> -
> -extern Bool
> -DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc, CARD64 *sbc);
> -
> -extern Bool
> -DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
> -	    CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc);
> -
> -extern Bool
> -DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
> -	    CARD64 *msc, CARD64 *sbc);
> -
> -extern void
> -DRI2SwapInterval(Display *dpy, XID drawable, int interval);
> -
> -#endif
> diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
> index 940626c..6e53583 100644
> --- a/src/glx/dri2_glx.c
> +++ b/src/glx/dri2_glx.c
> @@ -37,6 +37,7 @@
>  #include "glapi.h"
>  #include "glxclient.h"
>  #include <X11/extensions/dri2proto.h>
> +#include <X11/extensions/dri2.h>
>  #include "xf86dri.h"
>  #include <dlfcn.h>
>  #include <fcntl.h>
> @@ -44,7 +45,6 @@
>  #include <sys/types.h>
>  #include <sys/mman.h>
>  #include "xf86drm.h"
> -#include "dri2.h"
>  #include "dri_common.h"
>  
>  /* From xmlpool/options.h, user exposed so should be stable */
> @@ -550,8 +550,8 @@ process_buffers(struct dri2_drawable * pdraw, DRI2Buffer * buffers,
>      * __DRIbuffer tokens. */
>     for (i = 0; i < count; i++) {
>        pdraw->buffers[i].attachment = buffers[i].attachment;
> -      pdraw->buffers[i].name = buffers[i].name;
> -      pdraw->buffers[i].pitch = buffers[i].pitch;
> +      pdraw->buffers[i].name = buffers[i].names[0];
> +      pdraw->buffers[i].pitch = buffers[i].pitch[0];
>        pdraw->buffers[i].cpp = buffers[i].cpp;
>        pdraw->buffers[i].flags = buffers[i].flags;
>        if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
> @@ -881,7 +881,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
>        return NULL;
>     }
>  
> -   if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen),
> +   if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen), DRI2DriverDRI,
>  		    &driverName, &deviceName)) {
>        glx_screen_cleanup(&psc->base);
>        XFree(psc);
> @@ -1041,6 +1041,9 @@ dri2CreateDisplay(Display * dpy)
>     struct dri2_display *pdp;
>     int eventBase, errorBase, i;
>  
> +   if (!DRI2Init(dpy))
> +	   return NULL;
> +
>     if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
>        return NULL;
>  
> diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c
> index a52159c..a6a4d62 100644
> --- a/src/glx/dri_glx.c
> +++ b/src/glx/dri_glx.c
> @@ -37,9 +37,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>  #include <X11/Xlib.h>
>  #include <X11/extensions/Xfixes.h>
>  #include <X11/extensions/Xdamage.h>
> +#include <X11/extensions/dri2.h>
>  #include "glxclient.h"
>  #include "xf86dri.h"
> -#include "dri2.h"
>  #include "sarea.h"
>  #include <dlfcn.h>
>  #include <sys/types.h>
> @@ -133,7 +133,8 @@ driGetDriverName(Display * dpy, int scrNum, char **driverName)
>     }
>     else if (DRI2QueryExtension(dpy, &event, &error)) {  /* DRI2 */
>        char *dev;
> -      Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev);
> +      Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), DRI2DriverDRI,
> +                             driverName, &dev);
>  
>        if (ret)
>           Xfree(dev);


More information about the xorg-devel mailing list