diff options
Diffstat (limited to 'intel.c')
-rw-r--r-- | intel.c | 204 |
1 files changed, 108 insertions, 96 deletions
@@ -37,10 +37,11 @@ typedef struct EGLSurfaceNative *EGLSurfaceNative; struct EGLSurfaceNative { struct EGLSurface base; + __DRIbuffer *current; + __DRIbuffer colorBuffers[2]; + int colorBufferCount; + uint32_t colorBufferHandles[2]; uint32_t handles[10]; - EGLBoolean backBuffer; - __DRIbuffer front; - uint32_t frontHandle; }; static inline uint32_t @@ -179,8 +180,12 @@ intelGetBuffers(EGLSurface surface, unsigned int *attachments, int count) { EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; __DRIbuffer *buffer; - struct drm_gem_open open_arg; - int i, ret; + int i; + + buffer = &surface->buffers[0]; + buffer->pitch = nativeSurface->current->pitch; + buffer->name = nativeSurface->current->name; + buffer->cpp = nativeSurface->current->cpp; if (count == surface->count) return; @@ -192,16 +197,10 @@ intelGetBuffers(EGLSurface surface, unsigned int *attachments, int count) buffer = &surface->buffers[i]; buffer->attachment = attachments[i]; - if (buffer->attachment == __DRI_BUFFER_FRONT_LEFT && - nativeSurface->front.name != ~0 && - !nativeSurface->backBuffer) { - buffer->name = nativeSurface->front.name; - buffer->pitch = nativeSurface->front.pitch; - buffer->cpp = 4; - open_arg.name = buffer->name; - ret = ioctl(surface->display->fd, - DRM_IOCTL_GEM_OPEN, &open_arg); - nativeSurface->handles[i] = open_arg.handle; + if (buffer->attachment == __DRI_BUFFER_FRONT_LEFT) { + buffer->pitch = nativeSurface->current->pitch; + buffer->name = nativeSurface->current->name; + buffer->cpp = nativeSurface->current->cpp; continue; } @@ -229,6 +228,12 @@ intelDestroySurface(EGLDisplay display, EGLSurface surface) struct drm_gem_close close; int i; + for (i = 0; i < nativeSurface->colorBufferCount; i++) { + close.handle = nativeSurface->colorBufferHandles[i]; + if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) + fprintf(stderr, "close of bo %d failed\n", close.handle); + } + for (i = 0; i < surface->count; i++) { close.handle = nativeSurface->handles[i]; if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) @@ -240,127 +245,134 @@ intelDestroySurface(EGLDisplay display, EGLSurface surface) return EGL_TRUE; } -static EGLBoolean -intelSwapBuffers(EGLDisplay display, EGLSurface surface) +static const struct EagleBackend intelBackend = { + intelGetBuffers, + intelDestroySurface, +}; + +static EGLDisplay +intelCreateDisplay(struct udev_device *device, const char *driver) { - EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - EGLContext context; + EGLDisplay display; + const char *path; - if (!nativeSurface->backBuffer) - return EGL_TRUE; + display = malloc(sizeof *display); + if (display == NULL) + return NULL; + + path = udev_device_get_devnode(device); + if (eglInitDisplay(display, path, driver) < 0) { + free(display); + return NULL; + } - context = eglGetCurrentContext(); + display->backend = &intelBackend; - display->copyBuffer->copyBuffer(context->driContext, - &nativeSurface->front, - 0, 0, - surface->driDrawable, __DRI_BUFFER_FRONT_LEFT, - 0, 0, - surface->width, - surface->height); + return display; +} - glFlush(); +EGLDisplay +i915CreateDisplay(struct udev_device *device) +{ + return intelCreateDisplay(device, "i915"); +} - return EGL_TRUE; +EGLDisplay +i965CreateDisplay(struct udev_device *device) +{ + return intelCreateDisplay(device, "i965"); } -static EGLSurface -intelCreateSurfaceForName(EGLDisplay display, EGLConfig config, - uint32_t name, uint32_t width, - uint32_t height, uint32_t stride, const EGLint *attribList) +EAGLE_EXPORT EGLSurface +eglCreateSurface(EGLDisplay display, EGLConfig config, + uint32_t width, uint32_t height, + uint32_t colorBufferCount, const EGLint *attribList) { EGLSurfaceNative nativeSurface; int i; + if (colorBufferCount < 1 || colorBufferCount > 2) + return NULL; + nativeSurface = malloc(sizeof *nativeSurface); if (nativeSurface == NULL) return NULL; - nativeSurface->backBuffer = EGL_FALSE; - - nativeSurface->front.attachment = __DRI_BUFFER_FRONT_LEFT; - if (name == 0) { - nativeSurface->frontHandle = + nativeSurface->current = &nativeSurface->colorBuffers[0]; + nativeSurface->colorBufferCount = colorBufferCount; + for (i = 0; i < colorBufferCount; i++) { + nativeSurface->colorBufferHandles[i] = intelCreateBuffer(display->fd, - width, height, - &nativeSurface->front); - } else { - nativeSurface->front.name = name; - nativeSurface->front.pitch = stride; - nativeSurface->front.cpp = 4; - nativeSurface->front.flags = 0; - nativeSurface->frontHandle = 0; + width, + height, + &nativeSurface->colorBuffers[i]); } eglInitSurface(&nativeSurface->base, display, config, width, height); - for (i = 0; attribList && attribList[i] != EGL_NONE; i += 2) { - if (attribList[i] == EGL_RENDER_BUFFER && - attribList[i + 1] == EGL_BACK_BUFFER) - nativeSurface->backBuffer = EGL_TRUE; - } - return &nativeSurface->base; } -static const struct EagleBackend intelBackend = { - intelGetBuffers, - intelSwapBuffers, - intelDestroySurface, - intelCreateSurfaceForName -}; - -static EGLDisplay -intelCreateDisplay(struct udev_device *device, const char *driver) +EAGLE_EXPORT EGLSurface +eglCreateSurfaceForName(EGLDisplay display, EGLConfig config, + uint32_t name, uint32_t width, + uint32_t height, uint32_t stride, const EGLint *attribList) { - EGLDisplay display; - const char *path; + EGLSurfaceNative nativeSurface; + struct drm_gem_open open_arg; + int ret; - display = malloc(sizeof *display); - if (display == NULL) + nativeSurface = malloc(sizeof *nativeSurface); + if (nativeSurface == NULL) return NULL; - - path = udev_device_get_devnode(device); - if (eglInitDisplay(display, path, driver) < 0) { - free(display); + + nativeSurface->current = &nativeSurface->colorBuffers[0]; + nativeSurface->colorBufferCount = 1; + nativeSurface->colorBuffers[0].attachment = __DRI_BUFFER_FRONT_LEFT; + nativeSurface->colorBuffers[0].name = name; + nativeSurface->colorBuffers[0].pitch = stride; + nativeSurface->colorBuffers[0].cpp = 4; + nativeSurface->colorBuffers[0].flags = 0; + + open_arg.name = name; + ret = ioctl(display->fd, DRM_IOCTL_GEM_OPEN, &open_arg); + if (ret < 0) { + free(nativeSurface); return NULL; } + nativeSurface->colorBufferHandles[0] = open_arg.handle; - display->backend = &intelBackend; + eglInitSurface(&nativeSurface->base, display, config, width, height); - return display; + return &nativeSurface->base; } EAGLE_EXPORT EGLBoolean -eglGetNativeBuffer(EGLSurface surface, GLenum buffer, - uint32_t *name, uint32_t *handle, uint32_t *stride) +eglGetColorBuffer(EGLSurface surface, uint32_t index, + uint32_t *name, uint32_t *handle, uint32_t *stride) { EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - switch (buffer) { - case GL_FRONT_LEFT: - *name = nativeSurface->front.name; - *handle = nativeSurface->frontHandle; - *stride = nativeSurface->front.pitch; - return EGL_TRUE; - case GL_BACK_LEFT: - *name = surface->buffers[0].name; - *handle = nativeSurface->handles[0]; - *stride = surface->buffers[0].pitch; - return EGL_TRUE; - default: + if (index >= nativeSurface->colorBufferCount) return EGL_FALSE; - } -} -EGLDisplay -i915CreateDisplay(struct udev_device *device) -{ - return intelCreateDisplay(device, "i915"); + *name = nativeSurface->colorBuffers[index].name; + *handle = nativeSurface->colorBufferHandles[index]; + *stride = nativeSurface->colorBuffers[index].pitch; + + return EGL_TRUE; } -EGLDisplay -i965CreateDisplay(struct udev_device *device) +EAGLE_EXPORT EGLBoolean +eglBindColorBuffer(EGLDisplay display, EGLSurface surface, uint32_t index) { - return intelCreateDisplay(device, "i965"); + EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; + + if (index >= nativeSurface->colorBufferCount) + return EGL_FALSE; + + display->flush->flushInvalidate(surface->driDrawable); + nativeSurface->current = &nativeSurface->colorBuffers[index]; + + return EGL_TRUE; } |