summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <rob.clark@linaro.org>2011-11-11 17:13:08 -0600
committerRob Clark <rob.clark@linaro.org>2011-12-02 09:02:09 -0600
commit36f0a849668e836f2578a39ccd5e73fd1c5cad1c (patch)
tree60c99bb1cf8b6eefd0593fae9bcaeba9254c9a69
parent56adbae491360976c85629db46befd11cd4c8ef5 (diff)
a bit of rearranging before adding more tests
-rw-r--r--test/Makefile.am23
-rw-r--r--test/dri2-nouveau.c (renamed from test/dri2test-nouveau.c)2
-rw-r--r--test/dri2-omap.c (renamed from test/dri2test-omap.c)2
-rw-r--r--test/dri2test.c124
-rw-r--r--test/dri2util.c162
-rw-r--r--test/dri2util.h (renamed from test/dri2test.h)16
6 files changed, 195 insertions, 134 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index acd559c..8515c6b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,18 +1,21 @@
lib_LTLIBRARIES = libdri2test.la
-libdri2test_la_SOURCES = dri2test.c
-libdri2test_la_LIBADD = @DRI2_LIBS@
-libdri2test_la_CFLAGS = $(CWARNFLAGS) -I$(top_srcdir)/include @DRI2_CFLAGS@
-
+COMMON_SOURCES = dri2util.c
+COMMON_LIBADD = @DRI2_LIBS@
+COMMON_CFLAGS = -g -O0 $(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@
+COMMON_SOURCES += dri2-nouveau.c
+COMMON_LIBADD += @NOUVEAU_LIBS@
+COMMON_CFLAGS += @NOUVEAU_CFLAGS@
endif
if ENABLE_OMAP
-libdri2test_la_SOURCES += dri2test-omap.c
-libdri2test_la_LIBADD += @OMAP_LIBS@
-libdri2test_la_CFLAGS += @OMAP_CFLAGS@
+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)
diff --git a/test/dri2test-nouveau.c b/test/dri2-nouveau.c
index 561e5e1..f91cc48 100644
--- a/test/dri2test-nouveau.c
+++ b/test/dri2-nouveau.c
@@ -34,7 +34,7 @@
# include "config.h"
#endif
-#include "dri2test.h"
+#include "dri2util.h"
#include <nouveau_bo.h>
#include <nouveau_drmif.h>
diff --git a/test/dri2test-omap.c b/test/dri2-omap.c
index 10858af..181599d 100644
--- a/test/dri2test-omap.c
+++ b/test/dri2-omap.c
@@ -34,7 +34,7 @@
# include "config.h"
#endif
-#include "dri2test.h"
+#include "dri2util.h"
#include <omap_drm.h>
#include <omap_drmif.h>
diff --git a/test/dri2test.c b/test/dri2test.c
index e7b3b83..1615add 100644
--- a/test/dri2test.c
+++ b/test/dri2test.c
@@ -34,113 +34,11 @@
# include "config.h"
#endif
-#include "dri2test.h"
+#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,
-};
-
-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
+#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)
@@ -183,20 +81,8 @@ int main(int argc, char **argv)
return -1;
}
-#ifdef HAVE_NOUVEAU
- if (!strcmp(driver, "nouveau")) {
- backend = &nouveau_backend;
- }
-#endif
-
-#ifdef HAVE_OMAP
- if (!strcmp(driver, "omap")) {
- backend = &omap_backend;
- }
-#endif
-
+ backend = get_backend(driver);
if (!backend) {
- ERROR_MSG("no suitable backend DRM driver found");
return -1;
}
diff --git a/test/dri2util.c b/test/dri2util.c
new file mode 100644
index 0000000..4c41f5b
--- /dev/null
+++ b/test/dri2util.c
@@ -0,0 +1,162 @@
+/*
+ * 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, 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
+
+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;
+}
diff --git a/test/dri2test.h b/test/dri2util.h
index b4bac99..d30460d 100644
--- a/test/dri2test.h
+++ b/test/dri2util.h
@@ -50,10 +50,17 @@
#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);
+ }
+}
-#define WIDTH 500
-#define HEIGHT 500
-#define NFRAMES 300
typedef struct {
DRI2Buffer *dri2buf;
@@ -67,4 +74,7 @@ typedef struct {
void (*fini)(void *hdl);
} Backend;
+int dri2_connect(Display *dpy, char **driver);
+Backend * get_backend(const char *driver);
+
#endif /* _DRI2TEST_H_ */