summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Versace <chad.versace@linux.intel.com>2012-08-27 18:59:09 -0700
committerChad Versace <chad.versace@linux.intel.com>2012-09-04 19:34:10 -0700
commit9eb653ee99a50bae33085d1bf235a0c7959de50b (patch)
treec1503a10ae62c39764a15bca71f5e79088c4a986 /src
parent2c5e406e345ae70d2b22edd95be072d9f9ee7ea0 (diff)
glut_waffle: Add input support for X11 [v2]
Add support for input when using glut_waffle's GLX and X11/EGL backends. Tested with fbo-clean-formats; I cycled through the tests with the keyboard and then quit with the escape key. v2: - Rewrite x11_event_loop() without continue, per brianp. - Remove spurious waffle_window_swap_buffers from x11_event_loop. Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/glut_waffle/CMakeLists.no_api.txt6
-rw-r--r--src/glut_waffle/glut_waffle.c71
-rw-r--r--src/glut_waffle/priv/common.h11
-rw-r--r--src/glut_waffle/priv/x11.c89
-rw-r--r--src/glut_waffle/priv/x11.h31
5 files changed, 199 insertions, 9 deletions
diff --git a/src/glut_waffle/CMakeLists.no_api.txt b/src/glut_waffle/CMakeLists.no_api.txt
index 63a2e19f2..780f01a3a 100644
--- a/src/glut_waffle/CMakeLists.no_api.txt
+++ b/src/glut_waffle/CMakeLists.no_api.txt
@@ -1,7 +1,11 @@
-link_libraries(${WAFFLE_LIBRARIES})
+link_libraries(
+ ${WAFFLE_LIBRARIES}
+ X11
+ )
add_library(glut_waffle SHARED
glut_waffle.c
priv/common.c
+ priv/x11.c
)
diff --git a/src/glut_waffle/glut_waffle.c b/src/glut_waffle/glut_waffle.c
index 1c3b8127a..5837b497e 100644
--- a/src/glut_waffle/glut_waffle.c
+++ b/src/glut_waffle/glut_waffle.c
@@ -21,6 +21,7 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@@ -28,8 +29,15 @@
#include <string.h>
#include <unistd.h>
+#include <waffle_glx.h>
+#include <waffle_x11_egl.h>
+
#include "priv/common.h"
+#ifdef PIGLIT_HAS_X11
+# include "priv/x11.h"
+#endif
+
void
glutInitAPIMask(int mask)
{
@@ -86,6 +94,12 @@ glutInit(int *argcp, char **argv)
"value \"%s\"", piglit_platform);
}
+#ifndef PIGLIT_HAS_X11
+ if (_glut->waffle_platform == WAFFLE_PLATFORM_GLX ||
+ _glut->waffle_platform == WAFFLE_PLATFORM_X11_EGL)
+ glutFatal("piglit was built without x11 support");
+#endif
+
waffle_init_attrib_list[1] = _glut->waffle_platform;
ok = waffle_init(waffle_init_attrib_list);
if (!ok)
@@ -181,6 +195,7 @@ glutCreateWindow(const char *title)
{
bool ok = true;
struct waffle_config *config = NULL;
+ union waffle_native_window *n_window = NULL;
if (_glut->window)
glutFatal("cannot create window; one already exists");
@@ -201,6 +216,30 @@ glutCreateWindow(const char *title)
if (!_glut->window->waffle)
glutFatal("waffle_window_create() failed");
+ n_window = waffle_window_get_native(_glut->window->waffle);
+ if (!n_window)
+ glutFatal("waffle_window_get_window() failed");
+
+ switch (_glut->waffle_platform) {
+#ifdef PIGLIT_HAS_X11
+ case WAFFLE_PLATFORM_GLX:
+ _glut->window->x11.display = n_window->glx->xlib_display;
+ _glut->window->x11.window = n_window->glx->xlib_window;
+ break;
+ case WAFFLE_PLATFORM_X11_EGL:
+ _glut->window->x11.display = n_window->x11_egl->display.xlib_display;
+ _glut->window->x11.window = n_window->x11_egl->xlib_window;
+ break;
+#endif
+ case WAFFLE_PLATFORM_WAYLAND:
+ printf("glut_waffle: warning: input is not yet "
+ "implemented for Wayland\n");
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
ok = waffle_make_current(_glut->display, _glut->window->waffle,
_glut->context);
if (!ok)
@@ -278,14 +317,30 @@ glutMainLoop(void)
if (_glut->window->display_cb)
_glut->window->display_cb();
- // FIXME: Tests run without -auto require basic input.
-
- // Workaround for input:
- // Since glut_waffle doesn't handle input yet, it sleeps in order to
- // give the user a chance to see the test output. If the user wishes
- // the test to sleep for a shorter or longer time, he can use Ctrl-C
- // or Ctrl-Z.
- sleep(20);
+ switch (_glut->waffle_platform) {
+#ifdef PIGLIT_HAS_X11
+ case WAFFLE_PLATFORM_GLX:
+ case WAFFLE_PLATFORM_X11_EGL:
+ x11_event_loop();
+ break;
+#endif
+ case WAFFLE_PLATFORM_WAYLAND:
+ /* The Wayland window fails to appear on the first call to
+ * swapBuffers (which occured in display_cb above). This is
+ * likely due to swapBuffers being called before receiving an
+ * expose event. Until piglit has proper Wayland support,
+ * call swapBuffers again as a workaround.
+ */
+ if (_glut->window->display_cb)
+ _glut->window->display_cb();
+
+ /* FINISHME: Write event loop for Wayland. */
+ sleep(20);
+ break;
+ default:
+ assert(0);
+ break;
+ }
}
void
diff --git a/src/glut_waffle/priv/common.h b/src/glut_waffle/priv/common.h
index 2b3ebca2a..1ee28a445 100644
--- a/src/glut_waffle/priv/common.h
+++ b/src/glut_waffle/priv/common.h
@@ -24,11 +24,22 @@
#include <waffle.h>
+#ifdef PIGLIT_HAS_X11
+# include <X11/Xlib.h>
+#endif
+
#include "glut_waffle.h"
struct glut_window {
struct waffle_window *waffle;
+#ifdef PIGLIT_HAS_X11
+ struct {
+ Display *display;
+ Window window;
+ } x11;
+#endif
+
int id;
GLUT_EGLreshapeCB reshape_cb;
diff --git a/src/glut_waffle/priv/x11.c b/src/glut_waffle/priv/x11.c
new file mode 100644
index 000000000..1ffe066eb
--- /dev/null
+++ b/src/glut_waffle/priv/x11.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2012 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 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 <stdbool.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+
+#include "common.h"
+
+static void
+x11_process_next_event(void)
+{
+ struct glut_window *gwin = _glut->window;
+ Display *xdpy = gwin->x11.display;
+
+ bool redraw = false;
+ XEvent event;
+
+ if (!XPending(xdpy))
+ return;
+
+ XNextEvent(xdpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = true;
+ break;
+ case ConfigureNotify:
+ if (gwin->reshape_cb)
+ gwin->reshape_cb(event.xconfigure.width,
+ event.xconfigure.height);
+ break;
+ case KeyPress: {
+ char buffer[1];
+ KeySym sym;
+ int n;
+
+ redraw = true;
+ n = XLookupString(&event.xkey,
+ buffer,
+ sizeof(buffer), &sym, NULL);
+
+ if (n > 0 && gwin->keyboard_cb)
+ gwin->keyboard_cb(buffer[0],
+ event.xkey.x, event.xkey.y);
+ break;
+ }
+ default:
+ break;
+ }
+
+ _glut->redisplay = redraw;
+}
+
+void
+x11_event_loop(void)
+{
+ while (true) {
+ x11_process_next_event();
+
+ if (_glut->redisplay) {
+ _glut->redisplay = 0;
+
+ if (_glut->window->display_cb)
+ _glut->window->display_cb();
+ }
+ }
+}
diff --git a/src/glut_waffle/priv/x11.h b/src/glut_waffle/priv/x11.h
new file mode 100644
index 000000000..9efa2b91c
--- /dev/null
+++ b/src/glut_waffle/priv/x11.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012 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 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.
+ */
+
+#pragma once
+
+#include "common.h"
+
+struct glut_window*
+x11_window_create(void);
+
+void
+x11_event_loop(void);