diff options
author | Kristian Høgsberg <krh@redhat.com> | 2008-11-17 13:54:32 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2008-11-17 13:54:32 -0500 |
commit | 5b4100ff307ce3d1fd82930b1dec12437f82e35f (patch) | |
tree | f4743f91ed4a0db659d5470891ad33555bfe33fa | |
parent | 596f32d111c7fe087dfe4dde035ee5b5b352f895 (diff) |
Make test case use either dri2 or drmfb.
This crashes my X server right now...
-rw-r--r-- | test.c | 141 | ||||
-rw-r--r-- | x11-dri2.c | 6 |
2 files changed, 99 insertions, 48 deletions
@@ -2,47 +2,111 @@ #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" #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0]) -static int option_verbose; - static void die(const char *msg) { fprintf(stderr, "%s", msg); exit(EXIT_FAILURE); } -static void print_config(EGLDisplay display, EGLConfig config) +static void run(EGLDisplay display, EGLSurface surface, EGLConfig config, + int width, int height) { - EGLint id, size, red, green, blue, stencil, depth; - - eglGetConfigAttrib(display, config, EGL_CONFIG_ID, &id); - eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &size); - eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red); - eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencil); - eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depth); - - printf("%2d %2d %d %d %d %d %d\n", - id, size, red, green, blue, stencil, depth); + EGLContext context; + struct pollfd p[1]; + GLfloat angle = 0.0; + struct gears *gears; + + context = eglCreateContext(display, config, NULL, NULL); + if (context == NULL) + die("failed to create context\n"); + + if (!eglMakeCurrent(display, surface, surface, context)) + die("failed to make context current\n"); + + gears = gears_create(width, height); + p[0].fd = STDIN_FILENO; + p[0].events = POLLIN; + while (poll(p, 1, 20) == 0) { + gears_draw(gears, angle); + eglSwapBuffers(display, surface); + angle += 1; + } + + eglTerminate(display); } -int main(int argc, char *argv[]) +static void run_dri2(int x, int y, int width, int height) { EGLDisplay display; - EGLint major, minor, count, i; + EGLSurface surface; EGLConfig configs[64]; + EGLint major, minor, count; + Display *x11_display; + Window root, window; + XSetWindowAttributes attributes; + XSizeHints sizehints; + int screen; + unsigned long mask; + static const char name[] = "eglgears"; + + x11_display = XOpenDisplay(NULL); + if (x11_display == NULL) + return; + + screen = DefaultScreen(x11_display); + root = RootWindow(x11_display, screen); + display = eglCreateDisplayX11(x11_display, root); + if (display == NULL) + die("failed to create display\n"); + + attributes.event_mask = + StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWEventMask; + window = XCreateWindow(x11_display, root, x, y, width, height, + 0, DefaultDepth(x11_display, screen), + InputOutput, + DefaultVisual(x11_display, screen), + mask, &attributes); + + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(x11_display, window, &sizehints); + XSetStandardProperties(x11_display, window, name, name, + None, (char **)NULL, 0, &sizehints); + + XMapWindow(x11_display, window); + + if (!eglInitialize(display, &major, &minor)) + die("failed to initialize display\n"); + + if (!eglGetConfigs(display, configs, ARRAY_SIZE(configs), &count)) + die("failed to get configs\n"); + + surface = eglCreateSurfaceX11(display, configs[24], + window, width, height); + if (surface == NULL) + die("failed to create surface\n"); + + run(display, surface, configs[24], width, height); +} + +static void run_native(int x, int y, int width, int height) +{ + EGLDisplay display; EGLSurface surface; - EGLContext context; - const int width = 300, height = 300; - struct pollfd p[1]; - GLfloat angle = 0.0; - struct gears *gears; + EGLConfig configs[64]; + EGLint major, minor, count; display = eglCreateDisplayNative("/dev/dri/card0", "i965"); if (display == NULL) @@ -54,35 +118,22 @@ int main(int argc, char *argv[]) if (!eglGetConfigs(display, configs, ARRAY_SIZE(configs), &count)) die("failed to get configs\n"); - if (option_verbose) { - printf("got %d configs\n", count); - printf("id size r g b stencil depth\n" - "----------------------------------\n"); - for (i = 0; i < count; i++) - print_config(display, configs[i]); - } - - surface = eglCreateSurfaceNative(display, configs[24], 0, 0, width, height); + surface = eglCreateSurfaceNative(display, configs[24], + x, y, width, height); if (surface == NULL) die("failed to create surface\n"); - context = eglCreateContext(display, configs[24], NULL, NULL); - if (context == NULL) - die("failed to create context\n"); + run(display, surface, configs[24], width, height); +} - if (!eglMakeCurrent(display, surface, surface, context)) - die("failed to make context current\n"); +int main(int argc, char *argv[]) +{ + const int x = 100, y = 100, width = 300, height = 300; - gears = gears_create(width, height); - p[0].fd = STDIN_FILENO; - p[0].events = POLLIN; - while (poll(p, 1, 20) == 0) { - gears_draw(gears, angle); - eglSwapBuffers(display, surface); - angle += 1; - } + run_dri2(x, y, width, height); - eglTerminate(display); + fprintf(stderr, "open x11 display failed, trying drmfb\n"); + run_native(x, y, width, height); return 0; } @@ -93,7 +93,7 @@ eglCreateDisplayX11(Display *display, Window root) int eventBase, errorBase; int major, minor; drm_magic_t magic; - char *driverName, *busId; + char *driverName, *deviceName; if (!DRI2QueryExtension(display, &eventBase, &errorBase)) return NULL; @@ -101,7 +101,7 @@ eglCreateDisplayX11(Display *display, Window root) if (!DRI2QueryVersion(display, &major, &minor) || major < 1) return NULL; - if (!DRI2Connect(display, root, &driverName, &busId)) + if (!DRI2Connect(display, root, &driverName, &deviceName)) return NULL; x11Display = malloc(sizeof *x11Display); @@ -112,7 +112,7 @@ eglCreateDisplayX11(Display *display, Window root) x11Display->errorBase = errorBase; x11Display->display = display; - if (eglInitDisplay(&x11Display->base, "/dev/dri/card0", driverName) < 0) { + if (eglInitDisplay(&x11Display->base, deviceName, driverName) < 0) { free(x11Display); return NULL; } |