summaryrefslogtreecommitdiff
path: root/test/glx_common.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2013-11-11 09:59:25 -0800
committerEric Anholt <eric@anholt.net>2013-11-14 11:18:15 -0800
commit04cf940e1b6406e3bda59b857fe410073332b032 (patch)
treef5cc9cb4f99609488df9a462b3c334779761ff53 /test/glx_common.c
parented938dc4c592f0e3420a2b0ab6e3b5f9cec0c1f7 (diff)
downloadlibepoxy-04cf940e1b6406e3bda59b857fe410073332b032.tar.gz
Add an initial testsuite for GLX API.
Diffstat (limited to 'test/glx_common.c')
-rw-r--r--test/glx_common.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/glx_common.c b/test/glx_common.c
new file mode 100644
index 0000000..1c1b3f5
--- /dev/null
+++ b/test/glx_common.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "epoxy/glx.h"
+
+Display *
+get_display_or_skip(void)
+{
+ Display *dpy = XOpenDisplay(NULL);
+
+ if (!dpy) {
+ fprintf(stderr, "couldn't open display\n");
+ exit(77);
+ }
+
+ return dpy;
+}
+
+static XVisualInfo *
+get_glx_visual(Display *dpy)
+{
+ XVisualInfo *visinfo;
+ int attrib[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None
+ };
+ int screen = DefaultScreen(dpy);
+
+ visinfo = glXChooseVisual(dpy, screen, attrib);
+ if (visinfo == NULL) {
+ fprintf(stderr,
+ "Couldn't get an RGBA, double-buffered visual\n");
+ exit(1);
+ }
+
+ return visinfo;
+}
+
+static Window
+get_glx_window(Display *dpy, XVisualInfo *visinfo, bool map)
+{
+ XSetWindowAttributes window_attr;
+ unsigned long mask;
+ int screen = DefaultScreen(dpy);
+ Window root_win = RootWindow(dpy, screen);
+ Window win;
+
+ window_attr.background_pixel = 0;
+ window_attr.border_pixel = 0;
+ window_attr.colormap = XCreateColormap(dpy, root_win,
+ visinfo->visual, AllocNone);
+ window_attr.event_mask = StructureNotifyMask | ExposureMask |
+ KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+ win = XCreateWindow(dpy, root_win, 0, 0,
+ 10, 10, /* width, height */
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &window_attr);
+
+ return win;
+}
+
+void
+make_glx_context_current_or_skip(Display *dpy)
+{
+ GLXContext ctx;
+ XVisualInfo *visinfo = get_glx_visual(dpy);
+ Window win = get_glx_window(dpy, visinfo, false);
+
+ ctx = glXCreateContext(dpy, visinfo, False, True);
+ if (ctx == None) {
+ fprintf(stderr, "glXCreateContext failed\n");
+ exit(1);
+ }
+
+ glXMakeCurrent(dpy, win, ctx);
+}