diff options
author | Kristian Høgsberg <krh@redhat.com> | 2009-05-10 23:43:02 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2009-05-10 23:43:02 -0400 |
commit | ab2fd1164cd22698247f46fdf8656c219185b635 (patch) | |
tree | b7b8f569b9940432ab8b360bd044ba4630b57bac | |
parent | 113248631063bd490bcf5e27b07a53bd145efe38 (diff) |
Create test case surfaces using eglCreateSurfaceForName()
-rw-r--r-- | test/setup.c | 96 |
1 files changed, 34 insertions, 62 deletions
diff --git a/test/setup.c b/test/setup.c index 7c64fcd..3fa0753 100644 --- a/test/setup.c +++ b/test/setup.c @@ -4,7 +4,7 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <GL/gl.h> -#include "eagle.h" +#include "../eagle.h" #include <sys/time.h> #include <drm_mode.h> #include <xf86drmMode.h> @@ -101,24 +101,42 @@ static void run_dri2(int x, int y, int width, int height, render_func_t render) run(&state, render); } -static uint32_t -create_frontbuffer(EGLDisplay display, int *width, int *height, int *stride) +static void run_native(int x, int y, int width, int height, render_func_t render) { + EGLint major, minor; + struct udev *udev; + struct udev_device *device; + struct state state; drmModeConnector *connector; drmModeRes *resources; drmModeEncoder *encoder; drmModeModeInfo *mode; - struct drm_i915_gem_create create; - struct drm_gem_flink flink; unsigned int fb_id; + uint32_t name, handle, stride; int i, ret, fd; + 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"); + state.width = width; + state.height = height; + state.display = eglCreateDisplayNative(device); + if (state.display == NULL) + die("failed to create display\n"); - fd = eglGetDisplayFD(display); + if (!eglInitialize(state.display, &major, &minor)) + die("failed to initialize display\n"); + + if (!eglChooseConfig(state.display, config_attribs, &state.config, 1, NULL)) + die("failed to pick a config\n"); + + fd = eglGetDisplayFD(state.display); resources = drmModeGetResources(fd); if (!resources) { fprintf(stderr, "drmModeGetResources failed\n"); - return 0; + return; } for (i = 0; i < resources->count_connectors; i++) { @@ -135,7 +153,7 @@ create_frontbuffer(EGLDisplay display, int *width, int *height, int *stride) if (i == resources->count_connectors) { fprintf(stderr, "No currently active connector found.\n"); - return -1; + return; } mode = &connector->modes[0]; @@ -152,72 +170,26 @@ create_frontbuffer(EGLDisplay display, int *width, int *height, int *stride) drmModeFreeEncoder(encoder); } - /* Mode size at 32 bpp */ - create.size = mode->hdisplay * mode->vdisplay * 4; - if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { - fprintf(stderr, "gem create failed: %m\n"); - return 0; - } + state.surface = eglCreateSurfaceForName(state.display, state.config, + 0, mode->hdisplay, mode->vdisplay, + 0, attribs); + eglGetNativeBuffer(state.surface, + GL_FRONT_LEFT, &name, &handle, &stride); ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay, - 32, 32, mode->hdisplay * 4, create.handle, &fb_id); + 32, 32, stride, handle, &fb_id); if (ret) { fprintf(stderr, "failed to add fb: %m\n"); - return 0; + return; } ret = drmModeSetCrtc(fd, encoder->crtc_id, fb_id, 0, 0, &connector->connector_id, 1, mode); if (ret) { fprintf(stderr, "failed to set mode: %m\n"); - return 0; - } - - flink.handle = create.handle; - if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) != 0) { - fprintf(stderr, "gem flink failed: %m\n"); - return 0; + return; } - *width = mode->hdisplay; - *height = mode->vdisplay; - *stride = mode->hdisplay * 4; - - return flink.name; -} - -static void run_native(int x, int y, int width, int height, render_func_t render) -{ - 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"); - state.width = width; - state.height = height; - state.display = eglCreateDisplayNative(device); - if (state.display == NULL) - die("failed to create display\n"); - - if (!eglInitialize(state.display, &major, &minor)) - die("failed to initialize display\n"); - - if (!eglChooseConfig(state.display, config_attribs, &state.config, 1, NULL)) - die("failed to pick a config\n"); - - 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(&state, render); } |