pax_global_header00006660000000000000000000000064117530664070014523gustar00rootroot0000000000000052 comment=26fee2e487d59eefa475806f7fb5a76a139398c6 libdri2-1.0.0~git20120510+26fee2e/000077500000000000000000000000001175306640700157175ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/.gitignore000066400000000000000000000004171175306640700177110ustar00rootroot00000000000000aclocal.m4 autom4te.cache Makefile.in Makefile .deps .libs *.o *.lo *.la libtool *.pc config.log config.status config.guess config.h config.h.in config.sub config configure install-sh ltmain.sh missing stamp-h1 depcomp .cproject .project .settings dri2test dri2videotest libdri2-1.0.0~git20120510+26fee2e/COPYING000066400000000000000000000043001175306640700167470ustar00rootroot00000000000000Copyright 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. libdri2-1.0.0~git20120510+26fee2e/Makefile.am000066400000000000000000000031371175306640700177570ustar00rootroot00000000000000# # 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 libdri2-1.0.0~git20120510+26fee2e/README000066400000000000000000000012671175306640700166050ustar00rootroot00000000000000libdri2 - 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 libdri2-1.0.0~git20120510+26fee2e/autogen.sh000077500000000000000000000004651175306640700177250ustar00rootroot00000000000000#! /bin/sh srcdir=`dirname $0` test -z "$srcdir" && srcdir=. ORIGDIR=`pwd` cd $srcdir autoreconf -v --install || exit 1 cd $ORIGDIR || exit $? test -n "$NOCONFIGURE" && { echo "skipping configure stage as requested." echo "autogen.sh done." exit 0 } $srcdir/configure --enable-maintainer-mode "$@" libdri2-1.0.0~git20120510+26fee2e/configure.ac000066400000000000000000000063431175306640700202130ustar00rootroot00000000000000# # 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]) 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]) 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_OMAP, [test "x$HAVE_OMAP" = xyes]) AM_CONDITIONAL(ENABLE_NOUVEAU, [test "x$HAVE_NOUVEAU" = xyes]) 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 libdri2-1.0.0~git20120510+26fee2e/dri2.pc.in000066400000000000000000000003641175306640700175130ustar00rootroot00000000000000prefix=@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 libdri2-1.0.0~git20120510+26fee2e/include/000077500000000000000000000000001175306640700173425ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/include/Makefile.am000066400000000000000000000000161175306640700213730ustar00rootroot00000000000000SUBDIRS = X11 libdri2-1.0.0~git20120510+26fee2e/include/X11/000077500000000000000000000000001175306640700177135ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/include/X11/Makefile.am000066400000000000000000000000251175306640700217440ustar00rootroot00000000000000SUBDIRS = extensions libdri2-1.0.0~git20120510+26fee2e/include/X11/extensions/000077500000000000000000000000001175306640700221125ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/include/X11/extensions/Makefile.am000066400000000000000000000000731175306640700241460ustar00rootroot00000000000000extdir = $(includedir)/X11/extensions ext_HEADERS = dri2.h libdri2-1.0.0~git20120510+26fee2e/include/X11/extensions/dri2.h000066400000000000000000000077751175306640700231430ustar00rootroot00000000000000/* * 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 #include #include #include #include #include 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 * dpy, XID window, int driverType, 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 libdri2-1.0.0~git20120510+26fee2e/src/000077500000000000000000000000001175306640700165065ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/src/Makefile.am000066400000000000000000000012031175306640700205360ustar00rootroot00000000000000lib_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 libdri2-1.0.0~git20120510+26fee2e/src/dri2.c000066400000000000000000000430521175306640700175160ustar00rootroot00000000000000/* * 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 #include #include #include #include #include #include #include #include "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) 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, int driverType, 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 = driverType; 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 libdri2-1.0.0~git20120510+26fee2e/src/list.h000066400000000000000000000056511175306640700176410ustar00rootroot00000000000000/* * Copyright © 2010 Intel Corporation * Copyright © 2010 Francisco Jerez * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * */ #ifndef _LIST_H_ #define _LIST_H_ /* classic doubly-link circular list */ struct list { struct list *next, *prev; }; static void list_init(struct list *list) { list->next = list->prev = list; } static inline void __list_add(struct list *entry, struct list *prev, struct list *next) { next->prev = entry; entry->next = next; entry->prev = prev; prev->next = entry; } static inline void list_add(struct list *entry, struct list *head) { __list_add(entry, head, head->next); } static inline void __list_del(struct list *prev, struct list *next) { next->prev = prev; prev->next = next; } static inline void list_del(struct list *entry) { __list_del(entry->prev, entry->next); list_init(entry); } static inline Bool list_is_empty(struct list *head) { return head->next == head; } #ifndef container_of #define container_of(ptr, type, member) \ (type *)((char *)(ptr) - (char *) &((type *)0)->member) #endif #define list_entry(ptr, type, member) \ container_of(ptr, type, member) #define list_first_entry(ptr, type, member) \ list_entry((ptr)->next, type, member) #define __container_of(ptr, sample, member) \ (void *)((char *)(ptr) \ - ((char *)&(sample)->member - (char *)(sample))) #define list_for_each_entry(pos, head, member) \ for (pos = __container_of((head)->next, pos, member); \ &pos->member != (head); \ pos = __container_of(pos->member.next, pos, member)) #define list_for_each_entry_safe(pos, tmp, head, member) \ for (pos = __container_of((head)->next, pos, member), \ tmp = __container_of(pos->member.next, pos, member); \ &pos->member != (head); \ pos = tmp, tmp = __container_of(pos->member.next, tmp, member)) #endif libdri2-1.0.0~git20120510+26fee2e/test/000077500000000000000000000000001175306640700166765ustar00rootroot00000000000000libdri2-1.0.0~git20120510+26fee2e/test/Makefile.am000066400000000000000000000010411175306640700207260ustar00rootroot00000000000000lib_LTLIBRARIES = libdri2test.la COMMON_SOURCES = dri2util.c COMMON_LIBADD = @DRI2_LIBS@ COMMON_CFLAGS = -g -O0 $(CWARNFLAGS) -I$(top_srcdir)/include @DRI2_CFLAGS@ if ENABLE_NOUVEAU COMMON_SOURCES += dri2-nouveau.c COMMON_LIBADD += @NOUVEAU_LIBS@ COMMON_CFLAGS += @NOUVEAU_CFLAGS@ endif if ENABLE_OMAP COMMON_SOURCES += dri2-omap.c COMMON_LIBADD += @OMAP_LIBS@ COMMON_CFLAGS += @OMAP_CFLAGS@ endif libdri2test_la_SOURCES = dri2test.c $(COMMON_SOURCES) libdri2test_la_LIBADD = $(COMMON_LIBADD) libdri2test_la_CFLAGS = $(COMMON_CFLAGS) libdri2-1.0.0~git20120510+26fee2e/test/dri2-nouveau.c000066400000000000000000000047631175306640700213740ustar00rootroot00000000000000/* * 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 "dri2util.h" #include #include 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, }; libdri2-1.0.0~git20120510+26fee2e/test/dri2-omap.c000066400000000000000000000042041175306640700206340ustar00rootroot00000000000000/* * 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 "dri2util.h" #include #include 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, }; libdri2-1.0.0~git20120510+26fee2e/test/dri2test.c000066400000000000000000000070221175306640700206030ustar00rootroot00000000000000/* * 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 "dri2util.h" #define WIDTH 500 #define HEIGHT 500 #define NFRAMES 300 /* 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, DRI2DriverDRI, &driver)) < 0) { return -1; } backend = get_backend(driver); if (!backend) { 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; } libdri2-1.0.0~git20120510+26fee2e/test/dri2util.c000066400000000000000000000100311175306640700205730ustar00rootroot00000000000000/* * 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 "dri2util.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, }; int dri2_connect(Display *dpy, int driverType, 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, driverType, 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 Backend * get_backend(const char *driver) { #ifdef HAVE_NOUVEAU if (!strcmp(driver, "nouveau")) { return &nouveau_backend; } #endif #ifdef HAVE_OMAP if (!strcmp(driver, "omap")) { return &omap_backend; } #endif ERROR_MSG("no suitable backend DRM driver found"); return NULL; } libdri2-1.0.0~git20120510+26fee2e/test/dri2util.h000066400000000000000000000052121175306640700206050ustar00rootroot00000000000000/* * 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 #include #include #include #include #include #include #include #include #include #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) static inline void print_hex(int len, const unsigned char *val) { char buf[33]; int i, j; for (i = 0; i < len; i += j) { for (j = 0; (j < 16) && ((i + j) < len); ++j) sprintf(&buf[j * 2], "%02x", val[i + j]); fprintf(stderr, "\t%s\n", buf); } } 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; int dri2_connect(Display *dpy, int driverType, char **driver); Backend * get_backend(const char *driver); #endif /* _DRI2TEST_H_ */