summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorJesse Barnes <jbarnes@virtuousgeek.org>2010-01-11 15:23:29 -0500
committerJesse Barnes <jbarnes@virtuousgeek.org>2010-01-11 15:23:29 -0500
commitc6ef705e414c8e93ee471f50d15ada3492a9b067 (patch)
tree5b037def16eaa6e58860f7b66d79fd75067a0cb2 /progs
parentcca66dbb59673168d57b4e3499ccc31f4ddc86ad (diff)
parent7c50d29f7ced3d60e52ee0146d982b49ea421de2 (diff)
Merge branch 'master' of ssh://people.freedesktop.org/~jbarnes/mesa
Conflicts due to DRI1 removal: src/mesa/drivers/dri/intel/intel_context.c src/mesa/drivers/dri/intel/intel_screen.c
Diffstat (limited to 'progs')
-rw-r--r--progs/xdemos/.gitignore1
-rw-r--r--progs/xdemos/Makefile1
-rw-r--r--progs/xdemos/glsync.c111
-rw-r--r--progs/xdemos/msctest.c202
4 files changed, 274 insertions, 41 deletions
diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore
index 1b9b3a87c0..5ae0f5a062 100644
--- a/progs/xdemos/.gitignore
+++ b/progs/xdemos/.gitignore
@@ -26,3 +26,4 @@ xdemo
xfont
xrotfontdemo
yuvrect_client
+msctest
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index 77f667978c..f866a32865 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -29,6 +29,7 @@ PROGS = \
glxsnoop \
glxswapcontrol \
manywin \
+ msctest \
multictx \
offset \
overlay \
diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c
index 9d4b0f1ce2..c00ba9e468 100644
--- a/progs/xdemos/glsync.c
+++ b/progs/xdemos/glsync.c
@@ -59,6 +59,7 @@
void (*video_sync_get)();
void (*video_sync)();
+void (*swap_interval)();
static int GLXExtensionSupported(Display *dpy, const char *extension)
{
@@ -84,7 +85,7 @@ static int GLXExtensionSupported(Display *dpy, const char *extension)
extern char *optarg;
extern int optind, opterr, optopt;
-static char optstr[] = "w:h:s:v";
+static char optstr[] = "w:h:s:vi:";
enum sync_type {
none = 0,
@@ -100,6 +101,7 @@ static void usage(char *name)
printf("\t\tn: none\n");
printf("\t\ts: SGI video sync extension\n");
printf("\t\tb: buffer swap\n");
+ printf("\t-i<swap interval>\n");
printf("\t-v: verbose (print count)\n");
exit(-1);
}
@@ -109,16 +111,28 @@ int main(int argc, char *argv[])
Display *disp;
XVisualInfo *pvi;
XSetWindowAttributes swa;
- int attrib[14];
GLint last_val = -1, count = 0;
Window winGL;
GLXContext context;
int dummy;
Atom wmDelete;
enum sync_type waitforsync = none;
- int width = 500, height = 500, verbose = 0,
- countonly = 0;
+ int width = 500, height = 500, verbose = 0, interval = 1;
int c, i = 1;
+ int ret;
+ int attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ None };
+ int db_attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ None };
+ XSizeHints sizehints;
opterr = 0;
while ((c = getopt(argc, argv, optstr)) != -1) {
@@ -148,6 +162,9 @@ int main(int argc, char *argv[])
case 'v':
verbose = 1;
break;
+ case 'i':
+ interval = atoi(optarg);
+ break;
default:
usage(argv[0]);
break;
@@ -170,34 +187,17 @@ int main(int argc, char *argv[])
return -1;
}
- attrib[0] = GLX_RGBA;
- attrib[1] = 1;
- attrib[2] = GLX_RED_SIZE;
- attrib[3] = 1;
- attrib[4] = GLX_GREEN_SIZE;
- attrib[5] = 1;
- attrib[6] = GLX_BLUE_SIZE;
- attrib[7] = 1;
- if (waitforsync != buffer_swap)
- attrib[8] = None;
- else {
- attrib[8] = GLX_DOUBLEBUFFER;
- attrib[9] = 1;
- attrib[10] = None;
+ if (waitforsync != buffer_swap) {
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), attribs);
+ } else {
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs);
}
- pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
if (!pvi) {
fprintf(stderr, "failed to choose visual, exiting\n");
return -1;
}
- context = glXCreateContext(disp, pvi, None, GL_TRUE);
- if (!context) {
- fprintf(stderr, "failed to create glx context\n");
- return -1;
- }
-
pvi->screen = DefaultScreen(disp);
swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
@@ -217,24 +217,58 @@ int main(int argc, char *argv[])
wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
XSetWMProtocols(disp, winGL, &wmDelete, 1);
+ sizehints.x = 0;
+ sizehints.y = 0;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+
+ XSetNormalHints(disp, winGL, &sizehints);
XSetStandardProperties(disp, winGL, "glsync test", "glsync text",
- None, NULL, 0, NULL);
+ None, NULL, 0, &sizehints);
- XMapRaised(disp, winGL);
+ context = glXCreateContext(disp, pvi, NULL, GL_TRUE);
+ if (!context) {
+ fprintf(stderr, "failed to create glx context\n");
+ return -1;
+ }
- glXMakeCurrent(disp, winGL, context);
+ XMapWindow(disp, winGL);
+ ret = glXMakeCurrent(disp, winGL, context);
+ if (ret) {
+ fprintf(stderr, "failed to make context current: %d\n", ret);
+ }
video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI");
video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI");
- if (!video_sync_get || !video_sync) {
+ swap_interval = glXGetProcAddress((unsigned char *)"glXSwapIntervalSGI");
+
+ if (!video_sync_get || !video_sync || !swap_interval) {
fprintf(stderr, "failed to get sync functions\n");
return -1;
}
+ if (waitforsync == buffer_swap) {
+ swap_interval(interval);
+ fprintf(stderr, "set swap interval to %d\n", interval);
+ }
video_sync_get(&count);
count++;
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
while (i++) {
+ /* Alternate colors to make tearing obvious */
+ if (i & 1) {
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ glColor3f(1.0f, 1.0f, 1.0f);
+ } else {
+ glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
+ glColor3f(1.0f, 0.0f, 0.0f);
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glRectf(0, 0, width, height);
+
/* Wait for vsync */
if (waitforsync == sgi_video_sync) {
if (verbose)
@@ -245,24 +279,19 @@ int main(int argc, char *argv[])
if (count == last_val)
fprintf(stderr, "error: count didn't change: %d\n", count);
last_val = count;
+ glFlush();
} else if (waitforsync == buffer_swap) {
glXSwapBuffers(disp, winGL);
+ } else {
+ video_sync_get(&count);
+ sleep(1);
+ glFinish();
}
- if (countonly) {
- video_sync(2, 1, &count);
+ if (verbose) {
+ video_sync_get(&count);
fprintf(stderr, "current count: %d\n", count);
- sleep(1);
- continue;
}
-
- /* Alternate colors to make tearing obvious */
- if (i & 1)
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- else
- glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glFlush();
}
XDestroyWindow(disp, winGL);
diff --git a/progs/xdemos/msctest.c b/progs/xdemos/msctest.c
new file mode 100644
index 0000000000..001ecf04d6
--- /dev/null
+++ b/progs/xdemos/msctest.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * 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.
+ *
+ * Authors:
+ * Jesse Barnes <jesse.barnes@intel.com>
+ *
+ */
+
+/** @file msctest.c
+ * Simple test for MSC functionality.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glx.h>
+#include <GL/glxext.h>
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+void (*get_sync_values)(Display *dpy, Window winGL, int64_t *ust, int64_t *msc, int64_t *sbc);
+void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc);
+
+static int GLXExtensionSupported(Display *dpy, const char *extension)
+{
+ const char *extensionsString, *client_extensions, *pos;
+
+ extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
+ client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS);
+
+ pos = strstr(extensionsString, extension);
+
+ if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
+ (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
+ return 1;
+
+ pos = strstr(client_extensions, extension);
+
+ if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
+ (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
+ return 1;
+
+ return 0;
+}
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+static char optstr[] = "v";
+
+static void usage(char *name)
+{
+ printf("usage: %s\n", name);
+ exit(-1);
+}
+
+int main(int argc, char *argv[])
+{
+ Display *disp;
+ XVisualInfo *pvi;
+ XSetWindowAttributes swa;
+ int attrib[14];
+ Window winGL;
+ GLXContext context;
+ int dummy;
+ Atom wmDelete;
+ int verbose = 0, width = 200, height = 200;
+ int c, i = 1;
+ int64_t ust, msc, sbc;
+
+ opterr = 0;
+ while ((c = getopt(argc, argv, optstr)) != -1) {
+ switch (c) {
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ disp = XOpenDisplay(NULL);
+ if (!disp) {
+ fprintf(stderr, "failed to open display\n");
+ return -1;
+ }
+
+ if (!glXQueryExtension(disp, &dummy, &dummy)) {
+ fprintf(stderr, "glXQueryExtension failed\n");
+ return -1;
+ }
+
+ if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) {
+ fprintf(stderr, "GLX_OML_sync_control not supported, exiting\n");
+ return -1;
+ }
+
+ attrib[0] = GLX_RGBA;
+ attrib[1] = 1;
+ attrib[2] = GLX_RED_SIZE;
+ attrib[3] = 1;
+ attrib[4] = GLX_GREEN_SIZE;
+ attrib[5] = 1;
+ attrib[6] = GLX_BLUE_SIZE;
+ attrib[7] = 1;
+ attrib[8] = GLX_DOUBLEBUFFER;
+ attrib[9] = 1;
+ attrib[10] = None;
+
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
+ if (!pvi) {
+ fprintf(stderr, "failed to choose visual, exiting\n");
+ return -1;
+ }
+
+ context = glXCreateContext(disp, pvi, None, GL_TRUE);
+ if (!context) {
+ fprintf(stderr, "failed to create glx context\n");
+ return -1;
+ }
+
+ pvi->screen = DefaultScreen(disp);
+
+ swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
+ pvi->visual, AllocNone);
+ swa.border_pixel = 0;
+ swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
+ StructureNotifyMask;
+ winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
+ 0, 0,
+ width, height,
+ 0, pvi->depth, InputOutput, pvi->visual,
+ CWBorderPixel | CWColormap | CWEventMask, &swa);
+ if (!winGL) {
+ fprintf(stderr, "window creation failed\n");
+ return -1;
+ }
+ wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
+ XSetWMProtocols(disp, winGL, &wmDelete, 1);
+
+ XSetStandardProperties(disp, winGL, "msc test", "msc text",
+ None, NULL, 0, NULL);
+
+ XMapRaised(disp, winGL);
+
+ glXMakeCurrent(disp, winGL, context);
+
+ get_sync_values = glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
+ wait_sync = glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
+
+ if (!get_sync_values || !wait_sync) {
+ fprintf(stderr, "failed to get sync values function\n");
+ return -1;
+ }
+
+ while (i++) {
+ get_sync_values(disp, winGL, &ust, &msc, &sbc);
+ fprintf(stderr, "ust: %llu, msc: %llu, sbc: %llu\n", ust, msc,
+ sbc);
+
+ /* Alternate colors to make tearing obvious */
+ if (i & 1)
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ else
+ glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glXSwapBuffers(disp, winGL);
+ wait_sync(disp, winGL, 0, 60, 0, &ust, &msc, &sbc);
+ fprintf(stderr,
+ "wait returned ust: %llu, msc: %llu, sbc: %llu\n",
+ ust, msc, sbc);
+ sleep(1);
+ }
+
+ XDestroyWindow(disp, winGL);
+ glXDestroyContext(disp, context);
+ XCloseDisplay(disp);
+
+ return 0;
+}