summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING42
-rw-r--r--Makefile.am50
-rw-r--r--README25
-rwxr-xr-xautogen.sh12
-rw-r--r--configure.ac91
-rw-r--r--dri2.pc.in12
-rw-r--r--include/Makefile.am1
-rw-r--r--include/X11/Makefile.am1
-rw-r--r--include/X11/extensions/Makefile.am2
-rw-r--r--include/X11/extensions/dri2.h121
-rw-r--r--src/Makefile.am28
-rw-r--r--src/dri2.c693
-rw-r--r--test/Makefile.am18
-rw-r--r--test/dri2test-nouveau.c85
-rw-r--r--test/dri2test-omap.c70
-rw-r--r--test/dri2test.c236
-rw-r--r--test/dri2test.h70
17 files changed, 1557 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..83b3df2
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,42 @@
+Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
+and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital or MIT not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 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 PERFORMANCE OF THIS
+SOFTWARE.
+
+______________________________________________________________________________
+
+Copyright 2005 Red Hat, Inc.
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of Red Hat not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission. Red Hat makes no
+representations about the suitability of this software for any purpose. It
+is provided "as is" without express or implied warranty.
+
+RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL 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
+PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..4a7b6a1
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,50 @@
+#
+# Copyright 2005 Red Hat, Inc.
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of Red Hat not be used in
+# advertising or publicity pertaining to distribution of the software without
+# specific, written prior permission. Red Hat makes no
+# representations about the suitability of this software for any purpose. It
+# is provided "as is" without express or implied warranty.
+#
+# RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL 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
+# PERFORMANCE OF THIS SOFTWARE.
+
+SUBDIRS = src include
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = dri2.pc
+
+MAINTAINERCLEANFILES = ChangeLog INSTALL
+
+.PHONY: ChangeLog INSTALL
+
+INSTALL:
+ $(INSTALL_CMD)
+
+ChangeLog:
+ $(CHANGELOG_CMD)
+
+dist-hook: ChangeLog INSTALL
+
+if LINT
+lint:
+ (cd src && $(MAKE) $(MFLAGS) lint)
+endif
+
+if ENABLE_TEST
+SUBDIRS += test
+bin_PROGRAMS = dri2test
+dri2test_SOURCES =
+dri2test_LDFLAGS = -no-undefined
+dri2test_LDADD = test/libdri2test.la src/libdri2.la @DRI2_LIBS@
+endif
diff --git a/README b/README
new file mode 100644
index 0000000..ad203b1
--- /dev/null
+++ b/README
@@ -0,0 +1,25 @@
+libdri2 - library for the DRI2 extension to the X Window System
+
+All questions regarding this software should be directed at the
+Xorg mailing list:
+
+ http://lists.freedesktop.org/mailman/listinfo/xorg
+
+Please submit bug reports to the Xorg bugzilla:
+
+ https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
+
+The master development code repository can be found at:
+
+ git://anongit.freedesktop.org/git/xorg/lib/libdri2
+
+ http://cgit.freedesktop.org/xorg/lib/libdri2
+
+For patch submission instructions, see:
+
+ http://www.x.org/wiki/Development/Documentation/SubmittingPatches
+
+For more information on the git code manager, see:
+
+ http://wiki.x.org/wiki/GitPage
+
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..904cd67
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+
+autoreconf -v --install || exit 1
+cd $ORIGDIR || exit $?
+
+$srcdir/configure --enable-maintainer-mode "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..f07ff96
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,91 @@
+#
+# Copyright 2005 Red Hat, Inc.
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of Red Hat not be used in
+# advertising or publicity pertaining to distribution of the software without
+# specific, written prior permission. Red Hat makes no
+# representations about the suitability of this software for any purpose. It
+# is provided "as is" without express or implied warranty.
+#
+# RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL 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
+# PERFORMANCE OF THIS SOFTWARE.
+#
+
+# Initialize Autoconf
+AC_PREREQ([2.60])
+AC_INIT([libdri2], [1.0.0],
+ [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libdri2])
+AC_CONFIG_SRCDIR([Makefile.am])
+AC_CONFIG_HEADERS([config.h])
+
+# Initialize Automake
+AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AM_MAINTAINER_MODE
+
+# Initialize libtool
+AC_PROG_LIBTOOL
+
+# Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
+m4_ifndef([XORG_MACROS_VERSION],
+ [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
+XORG_MACROS_VERSION(1.8)
+XORG_DEFAULT_OPTIONS
+XORG_CHECK_MALLOC_ZERO
+
+# Obtain compiler/linker options for depedencies
+PKG_CHECK_MODULES(DRI2, x11 xext xextproto libdrm)
+
+# Optionally enable simple test app...
+AC_ARG_ENABLE(test,
+ AS_HELP_STRING([--enable-test],
+ [build simple test app (default: disabled)]),
+ [TEST=$enableval], [TEST=no])
+
+if test "x$TEST" = xyes; then
+ have_drm_driver=no
+
+ # Check for individual driver implementations... not required for
+ # libdri2, but is required for the test app to map the buffer..
+ PKG_CHECK_MODULES(NOUVEAU, libdrm_nouveau, [HAVE_NOUVEAU=yes], [HAVE_NOUVEAU=no])
+ AM_CONDITIONAL(ENABLE_NOUVEAU, [test "x$HAVE_NOUVEAU" = xyes])
+ if test "x$HAVE_NOUVEAU" = "xyes"; then
+ have_drm_driver=yes
+ AC_DEFINE(HAVE_NOUVEAU, 1, [Have nouveau support])
+ fi
+ PKG_CHECK_MODULES(OMAP, libdrm_omap, [HAVE_OMAP=yes], [HAVE_OMAP=no])
+ AM_CONDITIONAL(ENABLE_OMAP, [test "x$HAVE_OMAP" = xyes])
+ if test "x$HAVE_OMAP" = "xyes"; then
+ have_drm_driver=yes
+ AC_DEFINE(HAVE_OMAP, 1, [Have omap support])
+ fi
+
+ if test "x$have_drm_driver" = "xyes"; then
+ AC_DEFINE(ENABLE_TEST, 1, [build simple test app])
+ else
+ AC_MSG_WARN([No known DRM driver, disable test app])
+ TEST=no
+ fi
+fi
+AM_CONDITIONAL(ENABLE_TEST, [test "x$TEST" = xyes])
+
+# Allow checking code with lint, sparse, etc.
+XORG_WITH_LINT
+XORG_LINT_LIBRARY([dri2])
+
+AC_CONFIG_FILES([Makefile
+ include/Makefile
+ include/X11/Makefile
+ include/X11/extensions/Makefile
+ src/Makefile
+ test/Makefile
+ dri2.pc])
+AC_OUTPUT
diff --git a/dri2.pc.in b/dri2.pc.in
new file mode 100644
index 0000000..e29251b
--- /dev/null
+++ b/dri2.pc.in
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: dri2
+Description: The dri2 Library
+Version: @PACKAGE_VERSION@
+Requires: xproto
+Requires.private: x11 xext
+Cflags: -I${includedir}
+Libs: -L${libdir} -ldri2
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..a48f256
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = X11
diff --git a/include/X11/Makefile.am b/include/X11/Makefile.am
new file mode 100644
index 0000000..1b5c62d
--- /dev/null
+++ b/include/X11/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = extensions
diff --git a/include/X11/extensions/Makefile.am b/include/X11/extensions/Makefile.am
new file mode 100644
index 0000000..21125eb
--- /dev/null
+++ b/include/X11/extensions/Makefile.am
@@ -0,0 +1,2 @@
+extdir = $(includedir)/X11/extensions
+ext_HEADERS = dri2.h
diff --git a/include/X11/extensions/dri2.h b/include/X11/extensions/dri2.h
new file mode 100644
index 0000000..2913db1
--- /dev/null
+++ b/include/X11/extensions/dri2.h
@@ -0,0 +1,121 @@
+/*
+ * 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@redhat.com)
+ */
+
+#ifndef _DRI2_H_
+#define _DRI2_H_
+
+#include <X11/Xmd.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/dri2tokens.h>
+#include <drm.h>
+
+typedef struct
+{
+ unsigned int attachment;
+ unsigned int name;
+ unsigned int pitch;
+ unsigned int cpp;
+ unsigned int flags;
+} DRI2Buffer;
+
+typedef struct
+{
+ Bool (*WireToEvent)(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire);
+ Status (*EventToWire)(Display *dpy, XExtDisplayInfo *info, XEvent *event, xEvent *wire);
+ int (*Error)(Display *dpy, xError *err, XExtCodes *codes, int *ret_code);
+} DRI2EventOps;
+
+/* Call this once per display to register event handling code.. if needed */
+extern Bool
+DRI2InitDisplay(Display * display, const DRI2EventOps * ops);
+
+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/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..07f2492
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,28 @@
+lib_LTLIBRARIES = libdri2.la
+
+libdri2_la_SOURCES = \
+ dri2.c
+
+libdri2_la_LIBADD = @DRI2_LIBS@
+AM_CFLAGS = $(CWARNFLAGS) @DRI2_CFLAGS@ -I$(top_srcdir)/include @MALLOC_ZERO_CFLAGS@
+
+libdri2_la_LDFLAGS = -version-number 1:0:0 -no-undefined
+
+if LINT
+ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS)
+
+lint:
+ $(LINT) $(ALL_LINT_FLAGS) $(libdri2_la_SOURCES) $(DRI2_LIBS)
+endif LINT
+
+if MAKE_LINT_LIB
+lintlibdir = $(libdir)
+
+lintlib_DATA = $(LINTLIB)
+
+$(LINTLIB): $(libXau_la_SOURCES)
+ $(LINT) -y -oDRI2 -x $(ALL_LINT_FLAGS) $(libdri2_la_SOURCES)
+
+CLEANFILES = $(LINTLIB)
+endif MAKE_LINT_LIB
diff --git a/src/dri2.c b/src/dri2.c
new file mode 100644
index 0000000..7b106c9
--- /dev/null
+++ b/src/dri2.c
@@ -0,0 +1,693 @@
+/*
+ * Copyright © 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@redhat.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#define NEED_REPLIES
+#include <stdio.h>
+#include <stdint.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/dri2proto.h>
+#include <drm.h>
+#include <xf86drm.h>
+#include <GL/glx.h>
+#include <GL/glxext.h>
+#include <xorg/list.h>
+#include "X11/extensions/dri2.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 (DRI2CloseDisplay2, dri2Info)
+
+/**
+ * List of per-Display privates..
+ */
+static struct list dpy_list = { &dpy_list, &dpy_list };
+
+typedef struct {
+ struct list list;
+ Display *dpy;
+ const DRI2EventOps *ops;
+} DRI2Display;
+
+static DRI2Display * dpy2dri(Display *dpy)
+{
+ DRI2Display *dri2dpy;
+ list_for_each_entry(dri2dpy, &dpy_list, list) {
+ if (dri2dpy->dpy == dpy) {
+ return dri2dpy;
+ }
+ }
+ return NULL;
+}
+
+static int
+DRI2CloseDisplay(Display *dpy, XExtCodes *codes)
+{
+ DRI2Display *dri2dpy = dpy2dri(dpy);
+ if (dri2dpy) {
+ list_del(&dri2dpy->list);
+ free(dri2dpy);
+ }
+ return DRI2CloseDisplay2(dpy, codes);
+}
+
+Bool
+DRI2InitDisplay(Display *dpy, const DRI2EventOps *ops)
+{
+ DRI2Display *dri2dpy = dpy2dri(dpy);
+ if (!dri2dpy) {
+ dri2dpy = malloc(sizeof(*dri2dpy));
+ if (!dri2dpy) {
+ return False;
+ }
+ dri2dpy->dpy = dpy;
+ dri2dpy->ops = ops;
+ list_add(&dri2dpy->list, &dpy_list);
+ }
+ return True;
+}
+
+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)
+
+#include <GL/glx.h>
+
+static Bool
+DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+ DRI2Display *dri2dpy = dpy2dri(dpy);
+
+ XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+ if (dri2dpy && dri2dpy->ops && dri2dpy->ops->WireToEvent) {
+ return dri2dpy->ops->WireToEvent(dpy, info, event, wire);
+ }
+
+ return False;
+}
+
+/* We don't actually support this. It doesn't make sense for clients to
+ * send each other DRI2 events.
+ */
+static Status
+DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+ DRI2Display *dri2dpy = dpy2dri(dpy);
+
+ XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+ if (dri2dpy && dri2dpy->ops && dri2dpy->ops->EventToWire) {
+ return dri2dpy->ops->EventToWire(dpy, info, event, wire);
+ }
+
+ return Success;
+}
+
+static int
+DRI2Error(Display *dpy, xError *err, XExtCodes *codes, int *ret_code)
+{
+ DRI2Display *dri2dpy = dpy2dri(dpy);
+
+ if (dri2dpy && dri2dpy->ops && dri2dpy->ops->Error) {
+ return dri2dpy->ops->Error(dpy, err, codes, 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;
+}
+
+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)
+{
+ 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/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..acd559c
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,18 @@
+lib_LTLIBRARIES = libdri2test.la
+
+libdri2test_la_SOURCES = dri2test.c
+libdri2test_la_LIBADD = @DRI2_LIBS@
+libdri2test_la_CFLAGS = $(CWARNFLAGS) -I$(top_srcdir)/include @DRI2_CFLAGS@
+
+
+if ENABLE_NOUVEAU
+libdri2test_la_SOURCES += dri2test-nouveau.c
+libdri2test_la_LIBADD += @NOUVEAU_LIBS@
+libdri2test_la_CFLAGS += @NOUVEAU_CFLAGS@
+endif
+
+if ENABLE_OMAP
+libdri2test_la_SOURCES += dri2test-omap.c
+libdri2test_la_LIBADD += @OMAP_LIBS@
+libdri2test_la_CFLAGS += @OMAP_CFLAGS@
+endif
diff --git a/test/dri2test-nouveau.c b/test/dri2test-nouveau.c
new file mode 100644
index 0000000..561e5e1
--- /dev/null
+++ b/test/dri2test-nouveau.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2011 Texas Instruments, 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:
+ * Rob Clark (rob@ti.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "dri2test.h"
+
+#include <nouveau_bo.h>
+#include <nouveau_drmif.h>
+
+struct nouveau_device *dev;
+
+static void setup(int fd)
+{
+ int ret = nouveau_device_open_existing(&dev, 0, fd, 0);
+ if (ret) {
+ ERROR_MSG("nouveau_device_open_existing failed: %d", ret);
+ }
+}
+
+static void * init(DRI2Buffer *dri2buf)
+{
+ struct nouveau_bo *bo = NULL;
+ int ret = nouveau_bo_handle_ref(dev, dri2buf->name, &bo);
+ if (ret) {
+ ERROR_MSG("nouveau_bo_handle_ref failed: %d", ret);
+ return NULL;
+ }
+ return bo;
+}
+
+static char * prep(void *hdl)
+{
+ struct nouveau_bo *bo = hdl;
+ int ret = nouveau_bo_map(bo, NOUVEAU_BO_RDWR);
+ if (ret) {
+ ERROR_MSG("nouveau_bo_map failed: %d", ret);
+ return NULL;
+ }
+ return bo->map;
+}
+
+static void fini(void *hdl)
+{
+ struct nouveau_bo *bo = hdl;
+ nouveau_bo_unmap(bo);
+}
+
+Backend nouveau_backend = {
+ .setup = setup,
+ .init = init,
+ .prep = prep,
+ .fini = fini,
+};
diff --git a/test/dri2test-omap.c b/test/dri2test-omap.c
new file mode 100644
index 0000000..10858af
--- /dev/null
+++ b/test/dri2test-omap.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2011 Texas Instruments, 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:
+ * Rob Clark (rob@ti.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "dri2test.h"
+
+#include <omap_drm.h>
+#include <omap_drmif.h>
+
+static struct omap_device *dev;
+
+static void setup(int fd)
+{
+ dev = omap_device_new(fd);
+}
+
+static void * init(DRI2Buffer *dri2buf)
+{
+ return omap_bo_from_name(dev, dri2buf->name);
+}
+
+static char * prep(void *hdl)
+{
+ omap_bo_cpu_prep(hdl, OMAP_GEM_WRITE);
+ return omap_bo_map(hdl);
+}
+
+static void fini(void *hdl)
+{
+ omap_bo_cpu_fini(hdl, OMAP_GEM_WRITE);
+}
+
+Backend omap_backend = {
+ .setup = setup,
+ .init = init,
+ .prep = prep,
+ .fini = fini,
+};
diff --git a/test/dri2test.c b/test/dri2test.c
new file mode 100644
index 0000000..e7b3b83
--- /dev/null
+++ b/test/dri2test.c
@@ -0,0 +1,236 @@
+/*
+ * Copyright © 2011 Texas Instruments, 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:
+ * Rob Clark (rob@ti.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "dri2test.h"
+
+static Bool WireToEvent(Display *dpy, XExtDisplayInfo *info,
+ XEvent *event, xEvent *wire)
+{
+ switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
+
+ case DRI2_BufferSwapComplete:
+ {
+// xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
+ MSG("BufferSwapComplete");
+ return True;
+ }
+ case DRI2_InvalidateBuffers:
+ {
+// xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
+ MSG("InvalidateBuffers");
+// dri2InvalidateBuffers(dpy, awire->drawable);
+ return False;
+ }
+ default:
+ /* client doesn't support server event */
+ break;
+ }
+
+ return False;
+}
+
+static Status EventToWire(Display *dpy, XExtDisplayInfo *info,
+ XEvent *event, xEvent *wire)
+{
+ switch (event->type) {
+ default:
+ /* client doesn't support server event */
+ break;
+ }
+
+ return Success;
+}
+
+static const DRI2EventOps ops = {
+ .WireToEvent = WireToEvent,
+ .EventToWire = EventToWire,
+};
+
+static int dri2_connect(Display *dpy, char **driver)
+{
+ int eventBase, errorBase, major, minor;
+ char *device;
+ drm_magic_t magic;
+ Window root;
+ int fd;
+
+ if (!DRI2InitDisplay(dpy, &ops)) {
+ ERROR_MSG("DRI2InitDisplay failed");
+ return -1;
+ }
+
+ if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) {
+ ERROR_MSG("DRI2QueryExtension failed");
+ return -1;
+ }
+
+ MSG("DRI2QueryExtension: eventBase=%d, errorBase=%d", eventBase, errorBase);
+
+ if (!DRI2QueryVersion(dpy, &major, &minor)) {
+ ERROR_MSG("DRI2QueryVersion failed");
+ return -1;
+ }
+
+ MSG("DRI2QueryVersion: major=%d, minor=%d", major, minor);
+
+ root = RootWindow(dpy, DefaultScreen(dpy));
+
+ if (!DRI2Connect(dpy, root, driver, &device)) {
+ ERROR_MSG("DRI2Connect failed");
+ return -1;
+ }
+
+ MSG("DRI2Connect: driver=%s, device=%s", *driver, device);
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ ERROR_MSG("open failed");
+ return fd;
+ }
+
+ if (drmGetMagic(fd, &magic)) {
+ ERROR_MSG("drmGetMagic failed");
+ return -1;
+ }
+
+ if (!DRI2Authenticate(dpy, root, magic)) {
+ ERROR_MSG("DRI2Authenticate failed");
+ return -1;
+ }
+
+ return fd;
+}
+
+#ifdef HAVE_NOUVEAU
+extern Backend nouveau_backend;
+#endif
+
+#ifdef HAVE_OMAP
+extern Backend omap_backend;
+#endif
+
+/* stolen from modetest.c */
+static void fill(char *virtual, int n, int width, int height, int stride)
+{
+ int i, j;
+ /* paint the buffer with colored tiles */
+ for (j = 0; j < height; j++) {
+ uint32_t *fb_ptr = (uint32_t*)((char*)virtual + j * stride);
+ for (i = 0; i < width; i++) {
+ div_t d = div(n+i, width);
+ fb_ptr[i] =
+ 0x00130502 * (d.quot >> 6) +
+ 0x000a1120 * (d.rem >> 6);
+ }
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ static unsigned attachments[] = {
+ DRI2BufferFrontLeft,
+ DRI2BufferBackLeft,
+ };
+ Display *dpy;
+ Window win;
+ Backend *backend = NULL;
+ DRI2Buffer *dri2bufs;
+ Buffer *bufs;
+ char *driver;
+ int fd, nbufs, i, w, h;
+
+ dpy = XOpenDisplay(NULL);
+ win = XCreateSimpleWindow(dpy, RootWindow(dpy, 0),
+ 1, 1, WIDTH, HEIGHT, 0, BlackPixel (dpy, 0), BlackPixel(dpy, 0));
+ XMapWindow(dpy, win);
+ XFlush(dpy);
+
+ if ((fd = dri2_connect(dpy, &driver)) < 0) {
+ return -1;
+ }
+
+#ifdef HAVE_NOUVEAU
+ if (!strcmp(driver, "nouveau")) {
+ backend = &nouveau_backend;
+ }
+#endif
+
+#ifdef HAVE_OMAP
+ if (!strcmp(driver, "omap")) {
+ backend = &omap_backend;
+ }
+#endif
+
+ if (!backend) {
+ ERROR_MSG("no suitable backend DRM driver found");
+ return -1;
+ }
+
+ backend->setup(fd);
+
+ DRI2CreateDrawable(dpy, win);
+
+ dri2bufs = DRI2GetBuffers(dpy, win, &w, &h, attachments, 2, &nbufs);
+ if (!dri2bufs) {
+ ERROR_MSG("DRI2GetBuffers failed");
+ return -1;
+ }
+
+ MSG("DRI2GetBuffers: w=%d, h=%d, nbufs=%d", w, h, nbufs);
+
+ bufs = calloc(nbufs, sizeof(Buffer));
+
+ for (i = 0; i < nbufs; i++) {
+ bufs[i].dri2buf = &dri2bufs[i];
+ bufs[i].hdl = backend->init(bufs[i].dri2buf);
+ }
+
+ for (i = 0; i < NFRAMES; i++) {
+ CARD64 count;
+
+ char *buf = backend->prep(bufs[i % nbufs].hdl);
+ fill(buf, i, w, h, bufs[i % nbufs].dri2buf->pitch);
+ backend->fini(bufs[i % nbufs].hdl);
+ DRI2SwapBuffers(dpy, win, 0, 0, 0, &count);
+ MSG("DRI2SwapBuffers: count=%lu", count);
+ if (i > 0) {
+ /* XXX wait.. */
+ }
+ }
+
+ return 0;
+}
diff --git a/test/dri2test.h b/test/dri2test.h
new file mode 100644
index 0000000..b4bac99
--- /dev/null
+++ b/test/dri2test.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2011 Texas Instruments, 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:
+ * Rob Clark (rob@ti.com)
+ */
+
+#ifndef _DRI2TEST_H_
+#define _DRI2TEST_H_
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <xf86drm.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include <X11/extensions/dri2proto.h>
+#include "X11/extensions/dri2.h"
+
+#define MSG(fmt, ...) \
+ do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); } while (0)
+#define ERROR_MSG(fmt, ...) \
+ do { fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__); } while (0)
+
+
+#define WIDTH 500
+#define HEIGHT 500
+#define NFRAMES 300
+
+typedef struct {
+ DRI2Buffer *dri2buf;
+ void *hdl;
+} Buffer;
+
+typedef struct {
+ void (*setup)(int fd);
+ void * (*init)(DRI2Buffer *dri2buf);
+ char * (*prep)(void *hdl);
+ void (*fini)(void *hdl);
+} Backend;
+
+#endif /* _DRI2TEST_H_ */