summaryrefslogtreecommitdiff
path: root/progs/xdemos
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-01-16 23:21:06 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-01-16 23:21:06 +0000
commitba5d600c90f7075cf2c33a0c5c679ef822e8746e (patch)
treeec6794fba9f2fe563a8bbc03ca06e288b7f51c28 /progs/xdemos
parentfdfe06ad804ea13e6e436d66c1bcafe0bde2f545 (diff)
parent164fd16cfbc09970676c2e6866e062a5c9b410db (diff)
Merge remote branch 'origin/master' into lp-binning
Conflicts: src/gallium/drivers/llvmpipe/lp_quad.h src/gallium/drivers/llvmpipe/lp_setup.c
Diffstat (limited to 'progs/xdemos')
-rw-r--r--progs/xdemos/.gitignore1
-rw-r--r--progs/xdemos/Makefile1
-rw-r--r--progs/xdemos/corender.c1
-rw-r--r--progs/xdemos/glsync.c113
-rw-r--r--progs/xdemos/glxheads.c32
-rw-r--r--progs/xdemos/manywin.c34
-rw-r--r--progs/xdemos/msctest.c202
-rw-r--r--progs/xdemos/sharedtex_mt.c4
8 files changed, 339 insertions, 49 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/corender.c b/progs/xdemos/corender.c
index 640c902c13..e706f4b3da 100644
--- a/progs/xdemos/corender.c
+++ b/progs/xdemos/corender.c
@@ -20,7 +20,6 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <X11/keysym.h>
#include <unistd.h>
#include "ipc.h"
diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c
index da87306cf2..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,12 +85,12 @@ 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,
sgi_video_sync,
- buffer_swap,
+ buffer_swap
};
static void usage(char *name)
@@ -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/glxheads.c b/progs/xdemos/glxheads.c
index b1a63d3d50..edae0a3ef7 100644
--- a/progs/xdemos/glxheads.c
+++ b/progs/xdemos/glxheads.c
@@ -145,14 +145,40 @@ AddHead(const char *displayName)
/* save the info for this head */
{
struct head *h = &Heads[NumHeads];
+ const char * tmp;
+
+ if (strlen(displayName) + 1 > sizeof(h->DisplayName)) {
+ Error(displayName, "displayName string length overflow");
+ return NULL;
+ }
strcpy(h->DisplayName, displayName);
+
h->Dpy = dpy;
h->Win = win;
h->Context = ctx;
h->Angle = 0.0;
- strcpy(h->Version, (char *) glGetString(GL_VERSION));
- strcpy(h->Vendor, (char *) glGetString(GL_VENDOR));
- strcpy(h->Renderer, (char *) glGetString(GL_RENDERER));
+
+ tmp = (char *) glGetString(GL_VERSION);
+ if (strlen(tmp) + 1 > sizeof(h->Version)) {
+ Error(displayName, "GL_VERSION string length overflow");
+ return NULL;
+ }
+ strcpy(h->Version, tmp);
+
+ tmp = (char *) glGetString(GL_VENDOR);
+ if (strlen(tmp) + 1 > sizeof(h->Vendor)) {
+ Error(displayName, "GL_VENDOR string length overflow");
+ return NULL;
+ }
+ strcpy(h->Vendor, tmp);
+
+ tmp = (char *) glGetString(GL_RENDERER);
+ if (strlen(tmp) + 1 > sizeof(h->Renderer)) {
+ Error(displayName, "GL_RENDERER string length overflow");
+ return NULL;
+ }
+ strcpy(h->Renderer, tmp);
+
NumHeads++;
return &Heads[NumHeads-1];
}
diff --git a/progs/xdemos/manywin.c b/progs/xdemos/manywin.c
index ee357f32a4..8ad5c4fe49 100644
--- a/progs/xdemos/manywin.c
+++ b/progs/xdemos/manywin.c
@@ -177,14 +177,40 @@ AddHead(const char *displayName, const char *name)
/* save the info for this head */
{
struct head *h = &Heads[NumHeads];
+ const char * tmp;
+
+ if (strlen(name) + 1 > sizeof(h->DisplayName)) {
+ Error(displayName, "name string overflow");
+ return NULL;
+ }
strcpy(h->DisplayName, name);
+
h->Dpy = dpy;
h->Win = win;
h->Context = ctx;
h->Angle = 0.0;
- strcpy(h->Version, (char *) glGetString(GL_VERSION));
- strcpy(h->Vendor, (char *) glGetString(GL_VENDOR));
- strcpy(h->Renderer, (char *) glGetString(GL_RENDERER));
+
+ tmp = (char *) glGetString(GL_VERSION);
+ if (strlen(tmp) + 1 > sizeof(h->Version)) {
+ Error(displayName, "GL_VERSION string overflow");
+ return NULL;
+ }
+ strcpy(h->Version, tmp);
+
+ tmp = (char *) glGetString(GL_VENDOR);
+ if (strlen(tmp) + 1 > sizeof(h->Vendor)) {
+ Error(displayName, "GL_VENDOR string overflow");
+ return NULL;
+ }
+ strcpy(h->Vendor, tmp);
+
+ tmp = (char *) glGetString(GL_RENDERER);
+ if (strlen(tmp) + 1 > sizeof(h->Renderer)) {
+ Error(displayName, "GL_RENDERER string overflow");
+ return NULL;
+ }
+ strcpy(h->Renderer, tmp);
+
NumHeads++;
return &Heads[NumHeads-1];
}
@@ -374,6 +400,8 @@ main(int argc, char *argv[])
}
if (n < 1)
n = 1;
+ if (n > MAX_HEADS)
+ n = MAX_HEADS;
printf("%d windows\n", n);
for (i = 0; i < n; i++) {
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;
+}
diff --git a/progs/xdemos/sharedtex_mt.c b/progs/xdemos/sharedtex_mt.c
index f924448cc4..a90903adec 100644
--- a/progs/xdemos/sharedtex_mt.c
+++ b/progs/xdemos/sharedtex_mt.c
@@ -174,6 +174,10 @@ AddWindow(Display *dpy, const char *displayName, int xpos, int ypos,
{
static int id = 0;
struct window *h = &Windows[NumWindows];
+ if (strlen(displayName) + 1 > sizeof(h->DisplayName)) {
+ Error(displayName, "string overflow");
+ return NULL;
+ }
strcpy(h->DisplayName, displayName);
h->Dpy = dpy;
h->Win = win;