diff options
author | Kristian Høgsberg <krh@redhat.com> | 2008-03-26 14:49:46 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2008-03-26 14:49:46 -0400 |
commit | bade6229befc1def14a201acaec5b68d37224fa4 (patch) | |
tree | 56e9772334869c8d152c49cad0e5a9d00cb8b043 /eagle.c | |
parent | 0c128e21c77e482d7ace291ac9de17e69cfe556f (diff) |
Start making it compile.
Diffstat (limited to 'eagle.c')
-rw-r--r-- | eagle.c | 284 |
1 files changed, 150 insertions, 134 deletions
@@ -1,48 +1,51 @@ -typedef int EGLBoolean; -typedef int EGLint; -typedef struct EGLDisplay *EGLDisplay; -typedef struct EGLSurface *EGLSurface; -typedef struct EGLContext *EGLContext; -typedef struct EGLConfig *EGLConfig; - -#define EGL_NO_DISPLAY ((EGLDisplay) 0) -#define EGL_NO_SURFACE ((EGLSurface) 0) -#define EGL_NO_CONTEXT ((EGLContext) 0) -#define EGL_NO_CONFIG ((EGLConfig) 0) +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <limits.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> struct EGLDisplay { - int next_surface_id; + int next_surface_id; + EGLBoolean initialized; - int fd; - drmBO sareaBO; - void *sarea; - unsigned int sareaSize; - const char *driverName; + int fd; + drmBO sareaBO; + void *sarea; + unsigned int sareaSize; + const char *driverName; - __DRIEventBuffer *buffer; - int locked; + __DRIEventBuffer *buffer; + int locked; - EGLConfig *configs; - int numConfigs; + EGLConfig configs; + int numConfigs; - __DRI2screen *driScreen; - void *driver; - __DRI2interface *interface; + __DRIscreen *driScreen; + void *driver; + __DRIcoreExtension *core; + __DRIswapControlExtension *swapControl; }; struct EGLSurface { EGLDisplay display; - RegionRec clipList; + uint32_t x, y, width, height; uint32_t id; - BoxRec box; - __DRI2drawable *driDrawable; + __DRIdrawable *driDrawable; __DRIDrawableBuffer buffers[10]; }; struct EGLContext { - __DRI2context *driContext; + EGLDisplay display; + __DRIcontext *driContext; EGLConfig config; EGLSurface drawSurface; EGLSurface readSurface; @@ -50,12 +53,10 @@ struct EGLContext { }; struct EGLConfig { - __GLcontextModes *modes; + const __DRIconfig *driConfig; + unsigned int id; }; -#define EGL_FALSE 0 -#define EGL_TRUE 1 - /* FIXME: Use TLS. */ static EGLint lastError; static EGLContext currentContext; @@ -105,24 +106,13 @@ eglDisplayCommitEvents(EGLDisplay display) static void eglPostSurfaceConfig(EGLSurface surface) { - EGLDisplay *display = surface->display; - WindowPtr pWin; - PixmapPtr pPixmap; - BoxPtr pBox; - BoxRec pixmapBox; - int nBox; - int i; + EGLDisplay display = surface->display; __DRIDrawableConfigEvent *e; size_t size; - nBox = REGION_NUM_RECTS(&surface->clipList); - pBox = REGION_RECTS(&surface->clipList); - - pPixmap = pDisplay->GetWindowPixmap(pWin); - - size = sizeof *e + nBox * sizeof e->rects[0]; + size = sizeof *e + sizeof e->rects[0]; - e = EGLDisplayAllocEvent(display, size); + e = eglDisplayAllocEvent(display, size); e->event_header = DRI2_EVENT_HEADER(DRI2_EVENT_DRAWABLE_CONFIG, size); e->drawable = surface->id; e->x = surface->x; @@ -130,45 +120,36 @@ eglPostSurfaceConfig(EGLSurface surface) e->width = surface->width; e->height = surface->height; - e->num_rects = nBox; - for (i = 0; i < nBox; i++) { - e->rects[i].x1 = pBox->x1 - pPixmap->screen_x; - e->rects[i].y1 = pBox->y1 - pPixmap->screen_y; - e->rects[i].x2 = pBox->x2 - pPixmap->screen_x; - e->rects[i].y2 = pBox->y2 - pPixmap->screen_y; - pBox++; - } + 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; + EGLDisplay display = surface->display; __DRIBufferAttachEvent *e; size_t size; size = sizeof *e; - e = EGLDisplayAllocEvent(display, size); + e = eglDisplayAllocEvent(display, size); e->event_header = DRI2_EVENT_HEADER(DRI2_EVENT_BUFFER_ATTACH, size); - e->drawable = ed->id; + 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; - - pPriv->handle = handle; } static const __DRIextension *eglLoaderExtensions[] = { - &contextModesExtension.base, - &systemTimeExtension.base, - &damageExtension.base, NULL }; - static void * eglSetupSAREA(EGLDisplay display, size_t driverSareaSize) { @@ -176,7 +157,7 @@ eglSetupSAREA(EGLDisplay display, size_t driverSareaSize) unsigned long mask; display->sareaSize = - sizeof(*display->buffer) + event_buffer_size + + sizeof(*display->buffer) + eventBufferSize + driverSareaSize + sizeof (unsigned int); @@ -200,7 +181,7 @@ eglSetupSAREA(EGLDisplay display, size_t driverSareaSize) display->buffer->block_header = DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_EVENT_BUFFER, sizeof *display->buffer + eventBufferSize); - display->buffer->size = event_buffer_size; + display->buffer->size = eventBufferSize; return DRI2_SAREA_BLOCK_NEXT(display->buffer); } @@ -222,22 +203,24 @@ eglLoadDriver(EGLDisplay display, const char *driverName) return -1; extensions = dlsym(display->driver, __DRI_DRIVER_EXTENSIONS); - if (extension == NULL) { + if (extensions == NULL) { dlclose(display->driver); return -1; } for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_DRI2_INTERFACE) == 0 && - extensions[i]->version >= __DRI_DRI2_INTERFACE_VERSION) { - display->interface = (__DRI2interface *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_CORE) == 0 && + extensions[i]->version >= __DRI_CORE_VERSION) { + display->core = (__DRIcoreExtension *) extensions[i]; } } - if (display->interface == NULL) { + if (display->core == NULL) { dlclose(display->driver); return -1; } + + return 0; } /* Should be eagleCreateDisplay to avoid invading egl namespace?/ */ @@ -248,39 +231,48 @@ 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); + p = eglSetupSAREA(display, 0); if (p == NULL) goto fail; - if (EglLoadDriver(display) < 0) + if (eglLoadDriver(display, "i915") < 0) goto fail; display->driScreen = - display->interface->createNewScreen(0, scree->fd, - display->sareaBO.handle, - eglLoaderExtensions, - &display->configs, - display); + display->core->createNewScreen(0, display->fd, + display->sareaBO.handle, + eglLoaderExtensions, + &configs, + display); if (display->driScreen == NULL) goto fail; - for (i = 0; display->configs[i]; i++) + for (i = 0; configs[i]; i++) ; display->numConfigs = i; + display->configs = + malloc(display->numConfigs * sizeof *display->configs); + for (i = 0; configs[i]; i++) { + display->configs[i].driConfig = configs[i]; + display->configs[i].id = i; + } return display; fail: - drmClose(fd); + drmClose(display->fd); free(display); return NULL; @@ -294,7 +286,9 @@ eglInitialize(EGLDisplay display, EGLint *major, EGLint *minor) if (minor != NULL) *minor = 1; - return EGL_TRUE + display->initialized = EGL_TRUE; + + return EGL_TRUE; } EGLBoolean @@ -338,7 +332,7 @@ eglGetConfigs(EGLDisplay display, EGLConfig *configs, if (configs != NULL) for (i = 0; i < num; i++) - configs[i] = display->configs[i]; + configs[i] = &display->configs[i]; return EGL_TRUE; } @@ -355,12 +349,11 @@ static struct { int egl_attrib, dri_attrib; } attrib_map[] = { { EGL_RED_SIZE, __DRI_ATTRIB_RED_SIZE }, { EGL_GREEN_SIZE, __DRI_ATTRIB_GREEN_SIZE }, { EGL_BLUE_SIZE, __DRI_ATTRIB_BLUE_SIZE }, - { EGL_LUMINANCE_SIZE, __DRI_ATTRIB_LUMINANCE }, - { EGL_ALPHA_SIZE, __DRI_ATTRIB_ALPHA }, + { EGL_LUMINANCE_SIZE, __DRI_ATTRIB_LUMINANCE_SIZE }, + { EGL_ALPHA_SIZE, __DRI_ATTRIB_ALPHA_SIZE }, { EGL_ALPHA_MASK_SIZE, __DRI_ATTRIB_ALPHA_MASK_SIZE }, { EGL_BIND_TO_TEXTURE_RGB, __DRI_ATTRIB_BIND_TO_TEXTURE_RGB }, { EGL_BIND_TO_TEXTURE_RGBA, __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA }, - { EGL_COLOR_BUFFER_TYPE, __DRI_ATTRIB_COLOR_BUFFER_TYPE }, { EGL_CONFIG_CAVEAT, __DRI_ATTRIB_CONFIG_CAVEAT }, { EGL_DEPTH_SIZE, __DRI_ATTRIB_DEPTH_SIZE }, { EGL_LEVEL, __DRI_ATTRIB_LEVEL }, @@ -369,7 +362,6 @@ static struct { int egl_attrib, dri_attrib; } attrib_map[] = { { EGL_MAX_PBUFFER_PIXELS, __DRI_ATTRIB_MAX_PBUFFER_PIXELS }, { EGL_MAX_SWAP_INTERVAL, __DRI_ATTRIB_MAX_SWAP_INTERVAL }, { EGL_MIN_SWAP_INTERVAL, __DRI_ATTRIB_MIN_SWAP_INTERVAL }, - { EGL_NATIVE_RENDERABLE, __DRI_ATTRIB_NATIVE_RENDERABLE }, { EGL_SAMPLE_BUFFERS, __DRI_ATTRIB_SAMPLE_BUFFERS }, { EGL_SAMPLES, __DRI_ATTRIB_SAMPLES }, { EGL_STENCIL_SIZE, __DRI_ATTRIB_STENCIL_SIZE }, @@ -385,7 +377,7 @@ EGLBoolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, EGLint attribute, EGLint *value) { - int dri_attrib, dri_value, i; + unsigned int dri_attrib, dri_value, i; switch (attribute) { case EGL_CONFIG_ID: @@ -407,17 +399,20 @@ eglGetConfigAttrib(EGLDisplay display, EGLConfig config, /* FIXME: Look up __DRI_ATTRIB_CONFIG_CAVEAT instead. */ eglSetError(EGL_BAD_ATTRIBUTE); return EGL_FALSE; + case EGL_COLOR_BUFFER_TYPE: + return EGL_FALSE; } for (i = 0; i < ARRAY_SIZE(attrib_map); i++) - if (attrib_map[i].egl_attrib == attrib_map) + if (attrib_map[i].egl_attrib == attribute) dri_attrib = attrib_map[i].dri_attrib; if (i == ARRAY_SIZE(attrib_map)) return EGL_FALSE; - if (!display->interface->getConfigAttrib(config->driConfig, - dri_attribute, &dri_value)) { + /* FIXME: Signedness of attribs and tokens? */ + if (!display->core->getConfigAttrib(config->driConfig, + dri_attrib, &dri_value)) { eglSetError(EGL_BAD_ATTRIBUTE); return EGL_FALSE; } @@ -429,7 +424,7 @@ eglGetConfigAttrib(EGLDisplay display, EGLConfig config, break; case EGL_CONFIG_CAVEAT: *value = EGL_NONE; - *value = EGL_SLOW; + *value = EGL_SLOW_CONFIG; *value = EGL_NON_CONFORMANT_CONFIG; break; case EGL_TRANSPARENT_TYPE: @@ -445,7 +440,7 @@ eglGetConfigAttrib(EGLDisplay display, EGLConfig config, } EGLSurface -eglCreateSurface(EGLSurface parent, EglFBConfig fbconfig, +eglCreateSurface(EGLSurface parent, 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. */ @@ -455,12 +450,11 @@ eglCreateSurface(EGLSurface parent, EglFBConfig fbconfig, surface = malloc(sizeof *surface); surface->display = display; - surface->box.x0 = x; - surface->box.y0 = y; - surface->box.x1 = x + width; - surface->box.y1 = y + height; + surface->x = x; + surface->y = y; + surface->width = width; + surface->height = height; surface->id = display->next_surface_id++; - REGION_INIT(surface->clipList, &ed->box); surface->driDrawable = display->interface->createNewDrawable(display->driScreen, @@ -472,45 +466,34 @@ eglCreateSurface(EGLSurface parent, EglFBConfig fbconfig, return surface; } -/* Crazy idea: */ -typedef void *EGLNativeWindowType -struct EGLXWindow { - EGLint type; /* Always EAGLE_X_WINDOW */ - XID window /* XID of X window */ -}; - -struct EGLDRIWindow { - EGLint type; /* Always EAGLE_DRI_WINDOW */ - /* ... */ /* Dunno */ -}; - EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attribList) { + return EGL_NO_SURFACE; } EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, const EGLint *attribList) { - int i, x, y, width, height; + int i, width, height; for (i = 0; attribList[i]; i += 2) { - switch {attribList[i]) { + switch (attribList[i]) { case EGL_WIDTH: - width = attribList[i + 1]: + width = attribList[i + 1]; break; case EGL_HEIGHT: - height = attribList[i + 1]: + height = attribList[i + 1]; break; case EGL_LARGEST_PBUFFER: case EGL_TEXTURE_FORMAT: case EGL_TEXTURE_TARGET: case EGL_MIPMAP_TEXTURE: - case EGL_VG_COLORSPACE: - case EGL_VG_ALPHA_FORMAT: - break; + case EGL_COLORSPACE: + case EGL_ALPHA_FORMAT: + break; } } @@ -521,13 +504,14 @@ EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attribList) { + return EGL_NO_SURFACE; } EGLBoolean eglDestroySurface(EGLDisplay display, EGLSurface surface) { - display->interface->destroyDrawable(surface->driDrawable); + display->core->destroyDrawable(surface->driDrawable); free(surface); return EGL_TRUE; @@ -559,9 +543,9 @@ EGLBoolean eglReleaseTexImage(EGLDisplay dpy, return EGL_TRUE; } -EGLContext * -eglCreateContext(EGLDisplay display, EglConfig config, - EGLContext shareContext, const EGLint *attribList) +EGLContext +eglCreateContext(EGLDisplay display, EGLConfig config, + EGLContext shared, const EGLint *attribList) { EGLContext context; __DRIcontext *driShared; @@ -572,21 +556,22 @@ eglCreateContext(EGLDisplay display, EglConfig config, driShared = shared->driContext; context->driContext = - display->interface->createNewContext(display->driScreen, - Config, - driShared, - context); - + display->core->createNewContext(display->driScreen, + config->driConfig, + driShared, + context); + if (context->driContext == NULL) { + free(context); + return EGL_NO_CONTEXT; + } - return surface; + return context; } void eglDestroyContext(EGLDisplay display, EGLContext context) { - EGLDisplay display = context->display; - - display->interface->destroyContext(context->driContext); + display->core->destroyContext(context->driContext); free(context); } @@ -604,27 +589,38 @@ eglMakeCurrent(EGLDisplay display, if (read != NULL) driRead = read->driDrawable; - display->interface->bindContext(ctx->driContext, driDraw, driRead); + return display->core->bindContext(context->driContext, + driDraw, driRead); } EGLContext eglGetCurrentContext() { + return currentContext; } EGLSurface eglGetCurrentSurface(EGLint readdraw) { + switch (readdraw) { + case EGL_READ: + return currentContext->readSurface; + case EGL_DRAW: + return currentContext->drawSurface; + default: + eglSetError(EGL_BAD_SURFACE); /* FIXME: what's this error */ + return EGL_NO_SURFACE; + } } EGLDisplay eglGetCurrentDisplay(void) { - return eglGetCurrentContext()->display; + return currentContext->display; } EGLBoolean -eglQueryContext(EGLDisplay display, EGLContext contex, +eglQueryContext(EGLDisplay display, EGLContext context, EGLint attribute, EGLint *value) { switch (attribute) { @@ -635,6 +631,8 @@ eglQueryContext(EGLDisplay display, EGLContext contex, *value = EGL_OPENGL_ES_BIT; return EGL_TRUE; case EGL_CONTEXT_CLIENT_VERSION: + /* FIXME: What? */ + return EGL_FALSE; case EGL_RENDER_BUFFER: if (context->drawSurface == NULL) return EGL_NONE; @@ -651,33 +649,40 @@ eglQueryContext(EGLDisplay display, EGLContext contex, EGLBoolean eglBindAPI(EGLenum api) { + return EGL_TRUE; } EGLenum eglQueryAPI(void) { + return EGL_TRUE; } EGLBoolean eglWaitClient(void) { + return EGL_TRUE; } EGLBoolean eglWaitGL(void) { + return EGL_TRUE; } EGLBoolean eglWaitNative(EGLint engine) { + return EGL_TRUE; } EGLBoolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) { - display->interface->swapBuffers(surface->driDrawable); + display->core->swapBuffers(surface->driDrawable); + + return EGL_TRUE; } @@ -685,13 +690,24 @@ EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) { + return EGL_TRUE; } EGLBoolean -eglSwapInterval(EGLDisplay dpy, EGLint interval) +eglSwapInterval(EGLDisplay display, EGLint interval) { + __DRIdrawable *drawable; + + if (display->swapControl) { + drawable = currentContext->readSurface->driDrawable; + display->swapControl->setSwapInterval(drawable, interval); + return EGL_TRUE; + } else { + return EGL_FALSE; + } } -void (*eglGetProcAddress(const char *procname))() +void (*eglGetProcAddress(const char *procname))(void) { + return NULL; } |