summaryrefslogtreecommitdiff
path: root/eagle.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-09-30 16:30:23 -0400
committerKristian Høgsberg <krh@redhat.com>2008-09-30 16:30:23 -0400
commit92525432151e6db4a6d258b9b16fce88a08ae53c (patch)
treefeb56240b9bc173c0836c12af61f9793eb095315 /eagle.c
parent5c95fb5ecd895ff3aae68e9d8e3c054613bbd250 (diff)
Update to new DRI2 design, make test case link.
Diffstat (limited to 'eagle.c')
-rw-r--r--eagle.c153
1 files changed, 16 insertions, 137 deletions
diff --git a/eagle.c b/eagle.c
index cf24099..e1504df 100644
--- a/eagle.c
+++ b/eagle.c
@@ -3,11 +3,11 @@
#include <stdio.h>
#include <string.h>
#include <limits.h>
+#include <fcntl.h>
#include <dlfcn.h>
#include <GL/gl.h>
#include "eagle.h"
#include <GL/internal/dri_interface.h>
-#include <GL/internal/dri_sarea.h>
#include <xf86drm.h>
#include <xf86mm.h>
@@ -16,20 +16,16 @@ struct EGLDisplay {
EGLBoolean initialized;
int fd;
- drmBO sareaBO;
- void *sarea;
- unsigned int sareaSize;
const char *driverName;
- __DRIEventBuffer *buffer;
- int locked;
-
EGLConfig configs;
int numConfigs;
__DRIscreen *driScreen;
void *driver;
__DRIcoreExtension *core;
+ __DRIdri2Extension *dri2;
+
__DRIswapControlExtension *swapControl;
};
@@ -40,7 +36,7 @@ struct EGLSurface {
__DRIdrawable *driDrawable;
- __DRIDrawableBuffer buffers[10];
+ __DRIbuffer buffers[10];
};
struct EGLContext {
@@ -73,120 +69,11 @@ eglGetError()
return lastError;
}
-static void *
-eglDisplayAllocEvent(EGLDisplay display, size_t size)
-{
- __DRIEventBuffer *buffer = display->buffer;
- unsigned int *pad, mask = buffer->size - 1;
- size_t pad_size;
- void *p;
-
- if ((buffer->head & mask) + size > buffer->size) {
- /* The requested event size would wrap the buffer, so pad to
- * the end and allocate the event from the start. */
- pad_size = buffer->size - (buffer->head & mask);
- pad = (unsigned int *)
- (buffer->data + (buffer->prealloc & mask));
- *pad = DRI2_EVENT_HEADER(DRI2_EVENT_PAD, pad_size);
- buffer->prealloc += pad_size;
- }
-
- p = buffer->data + (buffer->prealloc & mask);
- buffer->prealloc += size;
-
- return p;
-}
-
-static void
-eglDisplayCommitEvents(EGLDisplay display)
-{
- display->buffer->head = display->buffer->prealloc;
-}
-
-static void
-eglPostSurfaceConfig(EGLSurface surface)
-{
- EGLDisplay display = surface->display;
- __DRIDrawableConfigEvent *e;
- size_t size;
-
- size = sizeof *e + sizeof e->rects[0];
-
- e = eglDisplayAllocEvent(display, size);
- e->event_header = DRI2_EVENT_HEADER(DRI2_EVENT_DRAWABLE_CONFIG, size);
- e->drawable = surface->id;
- e->x = surface->x;
- e->y = surface->y;
- e->width = surface->width;
- e->height = surface->height;
-
- e->num_rects = 1;
- e->rects[0].x1 = surface->x;
- e->rects[0].y1 = surface->y;
- e->rects[0].x2 = surface->x + surface->width;
- e->rects[0].y2 = surface->y + surface->height;
-}
-
-static void
-eglPostBufferAttach(EGLSurface surface, __DRIDrawableBuffer *buffer)
-{
- EGLDisplay display = surface->display;
- __DRIBufferAttachEvent *e;
- size_t size;
-
- size = sizeof *e;
-
- e = eglDisplayAllocEvent(display, size);
- e->event_header = DRI2_EVENT_HEADER(DRI2_EVENT_BUFFER_ATTACH, size);
- e->drawable = surface->id;
- e->buffer.attachment = buffer->attachment;
- e->buffer.handle = buffer->handle;
- e->buffer.pitch = buffer->pitch;
- e->buffer.cpp = buffer->cpp;
- e->buffer.flags = buffer->flags;
-}
-
static const __DRIextension *eglLoaderExtensions[] = {
NULL
};
-static void *
-eglSetupSAREA(EGLDisplay display, size_t driverSareaSize)
-{
- const size_t eventBufferSize = 32 * 1024;
- unsigned long mask;
-
- display->sareaSize =
- sizeof(*display->buffer) + eventBufferSize +
- driverSareaSize +
- sizeof (unsigned int);
-
- mask = DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MAPPABLE |
- DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_SHAREABLE;
-
- if (drmBOCreate(display->fd, display->sareaSize, 1,
- NULL, mask, 0, &display->sareaBO))
- return NULL;
-
- if (drmBOMap(display->fd, &display->sareaBO,
- DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE,
- 0, &display->sarea)) {
- drmBOUnreference(display->fd, &display->sareaBO);
- return NULL;
- }
-
- memset(display->sarea, 0, display->sareaSize);
-
- display->buffer = display->sarea;
- display->buffer->block_header =
- DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_EVENT_BUFFER,
- sizeof *display->buffer + eventBufferSize);
- display->buffer->size = eventBufferSize;
-
- return DRI2_SAREA_BLOCK_NEXT(display->buffer);
-}
-
-static const char driDriverPath[] = "/usr/lib/dri";
+static const char driDriverPath[] = "/home/krh/install/lib/dri";
static int
eglLoadDriver(EGLDisplay display, const char *driverName)
@@ -213,9 +100,14 @@ eglLoadDriver(EGLDisplay display, const char *driverName)
extensions[i]->version >= __DRI_CORE_VERSION) {
display->core = (__DRIcoreExtension *) extensions[i];
}
+
+ if (strcmp(extensions[i]->name, __DRI_DRI2) == 0 &&
+ extensions[i]->version >= __DRI_DRI2_VERSION) {
+ display->dri2 = (__DRIdri2Extension *) extensions[i];
+ }
}
- if (display->core == NULL) {
+ if (display->core == NULL || display->dri2 == NULL) {
dlclose(display->driver);
return -1;
}
@@ -229,29 +121,20 @@ EGLDisplay
eglCreateDisplay(const char *device)
{
EGLDisplay display;
- void *p;
int i;
const __DRIconfig **configs;
- const char *busId = "FIXME";
display = malloc(sizeof *display);
display->initialized = EGL_FALSE;
display->next_surface_id = 1;
- display->fd = drmOpen("i915", busId);
-
- /* FIXME: Chipset specific setup... */
-
- p = eglSetupSAREA(display, 0);
- if (p == NULL)
- goto fail;
+ display->fd = open(device, O_RDWR);
if (eglLoadDriver(display, "i915") < 0)
goto fail;
-
+
display->driScreen =
- display->core->createNewScreen(0, display->fd,
- display->sareaBO.handle,
+ display->dri2->createNewScreen(0, display->fd,
eglLoaderExtensions,
&configs,
display);
@@ -443,8 +326,6 @@ EGLSurface
eglCreateSurface(EGLDisplay display, EGLConfig fbconfig,
int x, int y, int width, int height)
{
- /* If parent is NULL, x and y must be 0 and a buffer is created. */
-
EGLSurface surface;
surface = malloc(sizeof *surface);
@@ -457,10 +338,8 @@ eglCreateSurface(EGLDisplay display, EGLConfig fbconfig,
surface->id = display->next_surface_id++;
surface->driDrawable =
- display->core->createNewDrawable(display->driScreen,
+ display->dri2->createNewDrawable(display->driScreen,
fbconfig->driConfig,
- surface->id,
- display->buffer->head,
surface);
return surface;
@@ -493,7 +372,7 @@ eglCreatePbufferSurface(EGLDisplay display,
case EGL_MIPMAP_TEXTURE:
case EGL_COLORSPACE:
case EGL_ALPHA_FORMAT:
- break;
+ break;
}
}