summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-01-21 21:47:42 -0500
committerKristian Høgsberg <krh@bitplanet.net>2010-01-21 21:47:42 -0500
commit0bdc1f71b7706f0139e835e205551f6e31beb9b3 (patch)
tree546f93b312a648fc70478ca911ad71b4a6e75476
parent7b9db343f8e90bebcddcb9d7176d00b136c6acc4 (diff)
Use INTEL_object_external and INTEL_context_none
-rw-r--r--eagle.c80
-rw-r--r--eagle.h3
-rw-r--r--native.c94
-rw-r--r--test/setup.c62
4 files changed, 63 insertions, 176 deletions
diff --git a/eagle.c b/eagle.c
index 38b6116..3ab498f 100644
--- a/eagle.c
+++ b/eagle.c
@@ -41,41 +41,6 @@ static EGLint lastError;
static EGLContext currentContext;
static void
-(*_mesa_TextureExternalMESA)(GLint target,
- GLint glx_texture_format,
- GLuint cpp,
- GLuint width, GLuint height,
- GLuint pitch, GLuint handle);
-static void
-(*_mesa_RenderbufferExternalMESA)(GLint target,
- GLint internalFormat,
- GLuint width, GLuint height,
- GLuint pitch, GLuint handle);
-
-EAGLE_EXPORT void
-glTextureExternalMESA(GLint target,
- GLint glx_texture_format,
- GLuint cpp,
- GLuint width, GLuint height,
- GLuint pitch, GLuint handle)
-{
- _mesa_TextureExternalMESA(target, glx_texture_format, cpp,
- width, height, pitch, handle);
-}
-
-EAGLE_EXPORT void
-glRenderbufferExternalMESA(GLint target,
- GLint internalFormat,
- GLuint width, GLuint height,
- GLuint pitch, GLuint handle)
-{
- _mesa_RenderbufferExternalMESA(target, internalFormat,
- width, height, pitch, handle);
-}
-
-
-
-static void
eglSetError(EGLint error)
{
lastError = error;
@@ -140,25 +105,6 @@ static const __DRIextension *eglLoaderExtensions[] = {
static const char driDriverPath[] = EAGLE_DRIVER_PATH;
-static void
-lookup_hacks(EGLDisplay display)
-{
- _mesa_TextureExternalMESA =
- dlsym(display->driver, "_mesa_TextureExternalMESA");
- if (_mesa_TextureExternalMESA == NULL) {
- fprintf(stderr, "_mesa_TextureExternalMESA not found\n");
- exit(1);
- }
-
- _mesa_RenderbufferExternalMESA =
- dlsym(display->driver, "_mesa_RenderbufferExternalMESA");
- if (_mesa_RenderbufferExternalMESA == NULL) {
- fprintf(stderr, "_mesa_RenderbufferExternalMESA not found\n");
- exit(1);
- }
-
-}
-
static int
eglLoadDriver(EGLDisplay display, const char *driverName)
{
@@ -185,8 +131,6 @@ eglLoadDriver(EGLDisplay display, const char *driverName)
return -1;
}
- lookup_hacks(display);
-
extensions = dlsym(display->driver, __DRI_DRIVER_EXTENSIONS);
if (extensions == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
@@ -222,7 +166,7 @@ eglInitDisplay(EGLDisplay display,
{
const __DRIconfig **configs;
const __DRIextension **extensions;
- int i;
+ int i, context_none = 0;
memset(display, 0, sizeof *display);
display->initialized = EGL_FALSE;
@@ -263,6 +207,11 @@ eglInitDisplay(EGLDisplay display,
display->flush =
(__DRI2flushExtension *) extensions[i];
}
+
+ if (strcmp(extensions[i]->name, __DRI_CONTEXT_NONE) == 0 &&
+ extensions[i]->version >= __DRI_CONTEXT_NONE_VERSION) {
+ context_none = 1;
+ }
}
if (display->texBuffer == NULL) {
@@ -275,6 +224,11 @@ eglInitDisplay(EGLDisplay display,
goto fail;
}
+ if (context_none == 0) {
+ fprintf(stderr, "dri driver has no context none extension\n");
+ goto fail;
+ }
+
for (i = 0; configs[i]; i++)
;
display->numConfigs = i;
@@ -670,6 +624,7 @@ eglCreateContext(EGLDisplay display, EGLConfig config,
{
EGLContext context;
__DRIcontext *driShared;
+ const __DRIconfig *driConfig;
context = malloc(sizeof *context);
@@ -678,9 +633,14 @@ eglCreateContext(EGLDisplay display, EGLConfig config,
else
driShared = NULL;
+ if (config)
+ driConfig = config->driConfig;
+ else
+ driConfig = NULL;
+
context->driContext =
display->dri2->createNewContext(display->driScreen,
- config->driConfig,
+ driConfig,
driShared,
context);
if (context->driContext == NULL) {
@@ -713,8 +673,12 @@ eglMakeCurrent(EGLDisplay display,
if (draw != NULL)
driDraw = draw->driDrawable;
+ else
+ driDraw = NULL;
if (read != NULL)
driRead = read->driDrawable;
+ else
+ driRead = NULL;
status = display->core->bindContext(context->driContext,
driDraw, driRead);
diff --git a/eagle.h b/eagle.h
index 73a2651..240c137 100644
--- a/eagle.h
+++ b/eagle.h
@@ -195,9 +195,6 @@ typedef int EGLenum; /* FIXME: is this part of EGL? */
extern EGLint eglGetError(void);
extern EGLDisplay eglCreateDisplayNative(struct udev_device *device);
-extern EGLSurface eglCreateSurfaceNative(EGLDisplay display,
- EGLConfig config,
- int x, int y, int width, int height);
extern int eglGetDisplayFD(EGLDisplay display);
diff --git a/native.c b/native.c
index da1be59..40b3dfc 100644
--- a/native.c
+++ b/native.c
@@ -346,97 +346,3 @@ r300CreateDisplay(struct udev_device *device)
{
return nativeCreateDisplay(device, "r300", &radeonBackend.base);
}
-
-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->current = &nativeSurface->colorBuffers[0];
- nativeSurface->colorBufferCount = colorBufferCount;
- for (i = 0; i < colorBufferCount; i++) {
- nativeSurface->colorBufferHandles[i] =
- intelCreateBuffer(display->fd,
- width,
- height,
- &nativeSurface->colorBuffers[i]);
- }
-
- eglInitSurface(&nativeSurface->base, display, config, width, height);
-
- return &nativeSurface->base;
-}
-
-EAGLE_EXPORT EGLSurface
-eglCreateSurfaceForName(EGLDisplay display, EGLConfig config,
- uint32_t name, uint32_t width,
- uint32_t height, uint32_t stride, const EGLint *attribList)
-{
- EGLSurfaceNative nativeSurface;
- struct drm_gem_open open_arg;
- int ret;
-
- nativeSurface = malloc(sizeof *nativeSurface);
- if (nativeSurface == NULL)
- return NULL;
-
- 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;
-
- eglInitSurface(&nativeSurface->base, display, config, width, height);
-
- return &nativeSurface->base;
-}
-
-EAGLE_EXPORT EGLBoolean
-eglGetColorBuffer(EGLSurface surface, uint32_t index,
- uint32_t *name, uint32_t *handle, uint32_t *stride)
-{
- EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface;
-
- if (index >= nativeSurface->colorBufferCount)
- return EGL_FALSE;
-
- *name = nativeSurface->colorBuffers[index].name;
- *handle = nativeSurface->colorBufferHandles[index];
- *stride = nativeSurface->colorBuffers[index].pitch;
-
- return EGL_TRUE;
-}
-
-EAGLE_EXPORT EGLBoolean
-eglBindColorBuffer(EGLDisplay display, EGLSurface surface, uint32_t index)
-{
- EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface;
-
- if (index >= nativeSurface->colorBufferCount)
- return EGL_FALSE;
-
- display->flush->flushInvalidate(surface->driDrawable);
- nativeSurface->current = &nativeSurface->colorBuffers[index];
-
- return EGL_TRUE;
-}
diff --git a/test/setup.c b/test/setup.c
index 35070b5..a39868c 100644
--- a/test/setup.c
+++ b/test/setup.c
@@ -1,3 +1,5 @@
+#define GL_GLEXT_PROTOTYPES
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -6,8 +8,8 @@
#include <GL/gl.h>
#include "../eagle.h"
#include <sys/time.h>
-#include <drm_mode.h>
#include <xf86drm.h>
+#include <drm_mode.h>
#include <xf86drmMode.h>
#include <sys/ioctl.h>
#include <i915_drm.h>
@@ -122,9 +124,11 @@ static void run_native(int x, int y, int width, int height, init_func_t init, re
drmModeModeInfo *mode;
int i, ret, fd, done;
drmEventContext evctx;
+ GLuint fbo;
struct buffer {
unsigned int fb_id;
- uint32_t name, handle, stride;
+ GLint name, handle, stride;
+ GLuint rb;
} b[2];
udev = udev_new();
@@ -138,9 +142,6 @@ static void run_native(int x, int y, int width, int height, init_func_t init, re
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);
@@ -180,14 +181,34 @@ static void run_native(int x, int y, int width, int height, init_func_t init, re
drmModeFreeEncoder(encoder);
}
- state.surface = eglCreateSurface(state.display, state.config,
- mode->hdisplay, mode->vdisplay, 2, NULL);
- for (i = 0; i < 2; i++) {
- eglGetColorBuffer(state.surface,
- i, &b[i].name, &b[i].handle, &b[i].stride);
+ state.context = eglCreateContext(state.display, NULL, NULL, NULL);
+ if (state.context == NULL)
+ die("failed to create context\n");
+
+ if (!eglMakeCurrent(state.display, NULL, NULL, state.context))
+ die("failed to make context current\n");
- ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay,
- 32, 32, b[i].stride, b[i].handle, &b[i].fb_id);
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo);
+
+ for (i = 0; i < 2; i++) {
+ glGenRenderbuffers(1, &b[i].rb);
+ glBindRenderbuffer(GL_RENDERBUFFER_EXT, b[i].rb);
+ glRenderbufferStorage(GL_RENDERBUFFER_EXT,
+ GL_RGBA,
+ mode->hdisplay,
+ mode->vdisplay);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
+ GL_RENDERBUFFER_STRIDE_INTEL,
+ &b[i].stride);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
+ GL_RENDERBUFFER_HANDLE_INTEL,
+ &b[i].handle);
+
+ ret = drmModeAddFB(fd,
+ mode->hdisplay, mode->vdisplay,
+ 32, 32,
+ b[i].stride, b[i].handle, &b[i].fb_id);
if (ret) {
fprintf(stderr, "failed to add fb %d: %m\n", i);
return;
@@ -201,13 +222,6 @@ static void run_native(int x, int y, int width, int height, init_func_t init, re
return;
}
- state.context = eglCreateContext(state.display, state.config, NULL, NULL);
- if (state.context == NULL)
- die("failed to create context\n");
-
- if (!eglMakeCurrent(state.display, state.surface, state.surface, state.context))
- die("failed to make context current\n");
-
init(&state);
memset(&evctx, 0, sizeof evctx);
@@ -216,8 +230,14 @@ static void run_native(int x, int y, int width, int height, init_func_t init, re
i = 0;
while (1) {
render(&state);
- eglBindColorBuffer(state.display, state.surface, i ^ 1);
- drmModePageFlip(fd, encoder->crtc_id, b[i].fb_id, &done);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT,
+ b[i ^ 1].rb);
+
+ drmModePageFlip(fd, encoder->crtc_id, b[i].fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, &done);
i ^= 1;
done = 0;
while (!done)