summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2009-02-12 20:21:01 -0500
committerKristian Høgsberg <krh@redhat.com>2009-02-12 20:21:07 -0500
commitaa867ad6edd4b6c296431911e51462c679a8ef8c (patch)
tree85b6f03fb74c92d547b4069a1aa2b69155e82a26
parent768a46b6b2eefae931b3fa9cb965800756a84402 (diff)
Move test case to test/ subdirectory.
-rw-r--r--Makefile.in7
-rw-r--r--configure.ac2
-rw-r--r--gears.h31
-rw-r--r--test/Makefile.in18
-rw-r--r--test/gears.c (renamed from gears.c)50
-rw-r--r--test/setup.c (renamed from test.c)102
-rw-r--r--test/setup.h19
7 files changed, 123 insertions, 106 deletions
diff --git a/Makefile.in b/Makefile.in
index a236e39..4333b39 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -4,7 +4,7 @@ LDLIBS = @EAGLE_LIBS@ -ldl
prefix = @prefix@
exec_prefix = @exec_prefix@
-all : libeagle.so test
+all : libeagle.so
x11_dri2_objs = x11-dri2.o libdri2.o
@@ -25,11 +25,6 @@ $(objs) : eagle.h eagle-internal.h
libeagle.so : $(objs)
gcc -o $@ $(objs) -shared $(LDLIBS)
-test_objs = test.o gears.o
-
-test : libeagle.so $(test_objs)
- gcc -o $@ -L. -leagle -lm $(test_objs)
-
import-glapi :
cp $(MESA_SRC)/src/mesa/main/glheader.h glapi
cp $(MESA_SRC)/src/glx/mini/dispatch.c glapi
diff --git a/configure.ac b/configure.ac
index 6f8ce6f..1a751c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,5 +11,5 @@ if test $CC = gcc; then
fi
AC_SUBST(GCC_CFLAGS)
-AC_CONFIG_FILES([Makefile eagle.pc])
+AC_CONFIG_FILES([Makefile eagle.pc test/Makefile])
AC_OUTPUT \ No newline at end of file
diff --git a/gears.h b/gears.h
deleted file mode 100644
index 68bdef7..0000000
--- a/gears.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- *
- * 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
- * BRIAN PAUL 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.
- */
-
-#ifndef _GEARS_H_
-#define _GEARS_H_
-
-struct gears;
-
-struct gears *gears_create(int width, int height);
-
-void gears_draw(struct gears *gears, GLfloat angle);
-
-#endif
diff --git a/test/Makefile.in b/test/Makefile.in
new file mode 100644
index 0000000..8944990
--- /dev/null
+++ b/test/Makefile.in
@@ -0,0 +1,18 @@
+CFLAGS = -fPIC -g @GCC_CFLAGS@ @EAGLE_CFLAGS@
+LDLIBS = @EAGLE_LIBS@ -ldl
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+all : gears
+
+gears_objs = gears.o setup.o
+
+gears : ../libeagle.so $(gears_objs)
+ gcc -o $@ -L.. -leagle -lm $(gears_objs)
+
+clean :
+ rm -f *.o glapi/*.o libeagle.so test
+
+Makefile : Makefile.in
+ ../config.status $@
diff --git a/gears.c b/test/gears.c
index 3dcbd67..5a2868c 100644
--- a/gears.c
+++ b/test/gears.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright © 2009 Kristian Høgsberg
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -20,9 +21,16 @@
*/
#include <stdlib.h>
+#include <stdio.h>
+#include <sys/time.h>
#include <math.h>
#include <GL/gl.h>
-#include "gears.h"
+#include <poll.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "../eagle.h"
+#include "setup.h"
struct gears {
int width, height;
@@ -146,7 +154,7 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glEnd();
}
-struct gears *
+static struct gears *
gears_create(int width, int height)
{
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0};
@@ -199,7 +207,7 @@ gears_create(int width, int height)
return gears;
}
-void
+static void
gears_draw(struct gears *gears, GLfloat angle)
{
GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
@@ -237,3 +245,39 @@ gears_draw(struct gears *gears, GLfloat angle)
glFlush();
}
+
+static void render(struct state *state)
+{
+ struct pollfd p[1];
+ GLfloat angle = 0.0;
+ struct gears *gears;
+ struct timeval before, now;
+ int count, elapsed, slice = 300;
+
+ gears = gears_create(state->width, state->height);
+ p[0].fd = STDIN_FILENO;
+ p[0].events = POLLIN;
+ count = 0;
+ gettimeofday(&before, NULL);
+ while (1) {
+ glClear(GL_COLOR_BUFFER_BIT);
+ gears_draw(gears, angle);
+ eglSwapBuffers(state->display, state->surface);
+ angle += 0.4;
+ count += 1;
+ if (count == slice) {
+ gettimeofday(&now, NULL);
+ elapsed = (now.tv_sec - before.tv_sec) * 1000 +
+ (now.tv_usec - before.tv_usec) / 1000;
+ before = now;
+ printf("%d frames in %d seconds: %f fps\n",
+ slice, elapsed, (float) 1000 * slice / elapsed);
+ count = 0;
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ return setup(argv, argv, render);
+}
diff --git a/test.c b/test/setup.c
index d4bc79a..a16c504 100644
--- a/test.c
+++ b/test/setup.c
@@ -1,66 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
-#include <poll.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include "eagle.h"
-#include "gears.h"
#include <sys/time.h>
#include <drm_mode.h>
#include <xf86drmMode.h>
#include <sys/ioctl.h>
#include <i915_drm.h>
+#include "setup.h"
+
#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0])
-static void die(const char *msg)
+void die(const char *msg)
{
fprintf(stderr, "%s", msg);
exit(EXIT_FAILURE);
}
-static void run(EGLDisplay display, EGLSurface surface, EGLConfig config,
- int width, int height)
+static void run(struct state *state, render_func_t render)
{
- EGLContext context;
- struct pollfd p[1];
- GLfloat angle = 0.0;
- struct gears *gears;
- struct timeval before, now;
- int count, elapsed, slice = 300;
-
- context = eglCreateContext(display, config, NULL, NULL);
- if (context == NULL)
+ state->context = eglCreateContext(state->display, state->config, NULL, NULL);
+ if (state->context == NULL)
die("failed to create context\n");
- if (!eglMakeCurrent(display, surface, surface, context))
+ if (!eglMakeCurrent(state->display, state->surface, state->surface, state->context))
die("failed to make context current\n");
- gears = gears_create(width, height);
- p[0].fd = STDIN_FILENO;
- p[0].events = POLLIN;
- count = 0;
- gettimeofday(&before, NULL);
- while (1) {
- glClear(GL_COLOR_BUFFER_BIT);
- gears_draw(gears, angle);
- eglSwapBuffers(display, surface);
- angle += 0.4;
- count += 1;
- if (count == slice) {
- gettimeofday(&now, NULL);
- elapsed = (now.tv_sec - before.tv_sec) * 1000 +
- (now.tv_usec - before.tv_usec) / 1000;
- before = now;
- printf("%d frames in %d seconds: %f fps\n",
- slice, elapsed, (float) 1000 * slice / elapsed);
- count = 0;
- }
- }
-
- eglTerminate(display);
+ render(state);
+ eglTerminate(state->display);
}
static const EGLint config_attribs[] = {
@@ -69,11 +40,8 @@ static const EGLint config_attribs[] = {
EGL_NONE
};
-static void run_dri2(int x, int y, int width, int height)
+static void run_dri2(int x, int y, int width, int height, render_func_t render)
{
- EGLDisplay display;
- EGLSurface surface;
- EGLConfig config;
EGLint major, minor;
Display *x11_display;
Window root, window;
@@ -81,6 +49,7 @@ static void run_dri2(int x, int y, int width, int height)
XSizeHints sizehints;
int screen;
unsigned long mask;
+ struct state state;
static const char name[] = "eglgears";
x11_display = XOpenDisplay(NULL);
@@ -89,8 +58,10 @@ static void run_dri2(int x, int y, int width, int height)
screen = DefaultScreen(x11_display);
root = RootWindow(x11_display, screen);
- display = eglCreateDisplayX11(x11_display, root);
- if (display == NULL)
+ state.width = width;
+ state.height = height;
+ state.display = eglCreateDisplayX11(x11_display, root);
+ if (state.display == NULL)
die("failed to create display\n");
attributes.event_mask =
@@ -113,17 +84,17 @@ static void run_dri2(int x, int y, int width, int height)
XMapWindow(x11_display, window);
- if (!eglInitialize(display, &major, &minor))
+ if (!eglInitialize(state.display, &major, &minor))
die("failed to initialize display\n");
- if (!eglChooseConfig(display, config_attribs, &config, 1, NULL))
+ if (!eglChooseConfig(state.display, config_attribs, &state.config, 1, NULL))
die("failed to pick a config\n");
- surface = eglCreateSurfaceX11(display, config, window, width, height);
- if (surface == NULL)
+ state.surface = eglCreateSurfaceX11(state.display, state.config, window, width, height);
+ if (state.surface == NULL)
die("failed to create surface\n");
- run(display, surface, config, width, height);
+ run(&state, render);
}
static uint32_t
@@ -211,48 +182,49 @@ create_frontbuffer(EGLDisplay display, int *width, int *height, int *stride)
return flink.name;
}
-static void run_native(int x, int y, int width, int height)
+static void run_native(int x, int y, int width, int height, render_func_t render)
{
- EGLDisplay display;
- EGLSurface surface;
- EGLConfig config;
EGLint major, minor;
uint32_t name;
int fb_width, fb_height, fb_stride;
struct udev *udev;
struct udev_device *device;
+ struct state state;
const static EGLint attribs[] =
{ EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };
udev = udev_new();
device = udev_device_new_from_syspath(udev, "/sys/class/drm/card0");
- display = eglCreateDisplayNative(device);
- if (display == NULL)
+ state.width = width;
+ state.height = height;
+ state.display = eglCreateDisplayNative(device);
+ if (state.display == NULL)
die("failed to create display\n");
- if (!eglInitialize(display, &major, &minor))
+ if (!eglInitialize(state.display, &major, &minor))
die("failed to initialize display\n");
- if (!eglChooseConfig(display, config_attribs, &config, 1, NULL))
+ if (!eglChooseConfig(state.display, config_attribs, &state.config, 1, NULL))
die("failed to pick a config\n");
- name = create_frontbuffer(display, &fb_width, &fb_height, &fb_stride);
- surface = eglCreateSurfaceForName(display, config,
- name, width, height, fb_stride, attribs);
- if (surface == NULL)
+ name = create_frontbuffer(state.display, &fb_width, &fb_height, &fb_stride);
+ state.surface = eglCreateSurfaceForName(state.display, state.config,
+ name, width, height,
+ fb_stride, attribs);
+ if (state.surface == NULL)
die("failed to create surface\n");
- run(display, surface, config, width, height);
+ run(&state, render);
}
-int main(int argc, char *argv[])
+int setup(int argc, char *argv[], render_func_t render)
{
const int x = 100, y = 100, width = 300, height = 300;
- run_dri2(x, y, width, height);
+ run_dri2(x, y, width, height, render);
fprintf(stderr, "open x11 display failed, trying drmfb\n");
- run_native(x, y, width, height);
+ run_native(x, y, width, height, render);
return 0;
}
diff --git a/test/setup.h b/test/setup.h
new file mode 100644
index 0000000..fe453ad
--- /dev/null
+++ b/test/setup.h
@@ -0,0 +1,19 @@
+#ifndef SETUP_H
+#define SETUP_H
+
+void die(const char *msg);
+
+struct state {
+ EGLDisplay display;
+ EGLSurface surface;
+ EGLConfig config;
+ EGLContext context;
+ int width;
+ int height;
+};
+
+typedef int (*render_func_t)(struct state *state);
+
+int setup(int argc, char *argv[], render_func_t render);
+
+#endif