diff options
Diffstat (limited to 'src/egl')
42 files changed, 2804 insertions, 3139 deletions
diff --git a/src/egl/drivers/Makefile.template b/src/egl/drivers/Makefile.template new file mode 100644 index 0000000000..e9a614ce62 --- /dev/null +++ b/src/egl/drivers/Makefile.template @@ -0,0 +1,51 @@ +# src/egl/drivers/Makefile.template +# +# Drivers should define +# +# EGL_DRIVER, the driver name +# EGL_SOURCES, the driver sources +# EGL_INCLUDES, the include pathes +# EGL_CFLAGS, additional CFLAGS +# EGL_LIBS, additional LIBS +# +# before including this template. +# + + +EGL_DRIVER_PATH = $(TOP)/$(LIB_DIR)/$(EGL_DRIVER) +EGL_OBJECTS = $(EGL_SOURCES:.c=.o) + + +default: depend $(EGL_DRIVER_PATH) + +$(EGL_DRIVER_PATH): $(EGL_DRIVER) + $(INSTALL) $< $(TOP)/$(LIB_DIR) + +$(EGL_DRIVER): $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template + @$(MKLIB) -o $(EGL_DRIVER) -noprefix \ + -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -L$(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ + $(EGL_OBJECTS) $(EGL_LIBS) + +.c.o: + $(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@ + + +install: $(EGL_DRIVER_PATH) + $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + $(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + +clean: + rm -f $(EGL_DRIVER) + rm -f $(EGL_OBJECTS) + rm -f depend depend.bak + +depend: $(EGL_SOURCES) + @ echo "running $(MKDEP)" + @ rm -f depend + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(EGL_INCLUDES) $(EGL_SOURCES) \ + >/dev/null 2>/dev/null + +sinclude depend +# DO NOT DELETE diff --git a/src/egl/drivers/demo/Makefile b/src/egl/drivers/demo/Makefile deleted file mode 100644 index 444dfb35bd..0000000000 --- a/src/egl/drivers/demo/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# src/egl/drivers/demo/Makefile - -TOP = ../../../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = -I$(TOP)/include -I$(TOP)/src/egl/main $(X11_INCLUDES) - - -SOURCES = demo.c - -OBJECTS = $(SOURCES:.c=.o) - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - - -default: $(TOP)/$(LIB_DIR)/demodriver.so - - -$(TOP)/$(LIB_DIR)/demodriver.so: $(OBJECTS) - $(MKLIB) -o demodriver.so -noprefix -linker '$(CC)' \ - -ldflags '$(LDFLAGS)' -install $(TOP)/$(LIB_DIR) \ - $(OBJECTS) - -install: - -clean: - -rm -f *.o - -rm -f *.so diff --git a/src/egl/drivers/demo/demo.c b/src/egl/drivers/demo/demo.c deleted file mode 100644 index 0933c0bdaa..0000000000 --- a/src/egl/drivers/demo/demo.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Sample driver: Demo - */ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include "eglconfig.h" -#include "eglcontext.h" -#include "egldisplay.h" -#include "egldriver.h" -#include "eglglobals.h" -#include "eglmode.h" -#include "eglscreen.h" -#include "eglsurface.h" - - -/** - * Demo driver-specific driver class derived from _EGLDriver - */ -typedef struct demo_driver -{ - _EGLDriver Base; /* base class/object */ - unsigned DemoStuff; -} DemoDriver; - -#define DEMO_DRIVER(D) ((DemoDriver *) (D)) - - -/** - * Demo driver-specific surface class derived from _EGLSurface - */ -typedef struct demo_surface -{ - _EGLSurface Base; /* base class/object */ - unsigned DemoStuff; -} DemoSurface; - - -/** - * Demo driver-specific context class derived from _EGLContext - */ -typedef struct demo_context -{ - _EGLContext Base; /* base class/object */ - unsigned DemoStuff; -} DemoContext; - - - -static EGLBoolean -demoInitialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor) -{ - _EGLScreen *scrn; - EGLint i; - - /* Create a screen */ - scrn = calloc(1, sizeof(*scrn)); - _eglAddScreen(disp, scrn); - - /* Create the screen's modes - silly example */ - _eglAddNewMode(scrn, 1600, 1200, 72 * 1000, "1600x1200-72"); - _eglAddNewMode(scrn, 1280, 1024, 72 * 1000, "1280x1024-70"); - _eglAddNewMode(scrn, 1280, 1024, 70 * 1000, "1280x1024-70"); - _eglAddNewMode(scrn, 1024, 768, 72 * 1000, "1024x768-72"); - - /* Create the display's visual configs - silly example */ - for (i = 0; i < 4; i++) { - _EGLConfig *config = calloc(1, sizeof(_EGLConfig)); - _eglInitConfig(config, i + 1); - _eglSetConfigAttrib(config, EGL_RED_SIZE, 8); - _eglSetConfigAttrib(config, EGL_GREEN_SIZE, 8); - _eglSetConfigAttrib(config, EGL_BLUE_SIZE, 8); - _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, 8); - _eglSetConfigAttrib(config, EGL_BUFFER_SIZE, 32); - if (i & 1) { - _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, 32); - } - if (i & 2) { - _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, 8); - } - _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, - (EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)); - _eglAddConfig(disp, config); - } - - /* enable supported extensions */ - disp->Extensions.MESA_screen_surface = EGL_TRUE; - disp->Extensions.MESA_copy_context = EGL_TRUE; - - *major = 1; - *minor = 0; - - return EGL_TRUE; -} - - -static EGLBoolean -demoTerminate(_EGLDriver *drv, _EGLDisplay *dpy) -{ - /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ - return EGL_TRUE; -} - - -static DemoContext * -LookupDemoContext(_EGLContext *c) -{ - return (DemoContext *) c; -} - - -static DemoSurface * -LookupDemoSurface(_EGLSurface *s) -{ - return (DemoSurface *) s; -} - - -static _EGLContext * -demoCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) -{ - DemoContext *c; - int i; - - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - /* no attribs defined for now */ - default: - _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); - return NULL; - } - } - - c = (DemoContext *) calloc(1, sizeof(DemoContext)); - if (!c) - return NULL; - - _eglInitContext(drv, &c->Base, conf, attrib_list); - c->DemoStuff = 1; - printf("demoCreateContext\n"); - - return &c->Base; -} - - -static _EGLSurface * -demoCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) -{ - int i; - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - /* no attribs at this time */ - default: - _eglError(EGL_BAD_ATTRIBUTE, "eglCreateWindowSurface"); - return NULL; - } - } - printf("eglCreateWindowSurface()\n"); - /* XXX unfinished */ - - return NULL; -} - - -static _EGLSurface * -demoCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list) -{ - EGLint i; - - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - /* no attribs at this time */ - default: - _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface"); - return NULL; - } - } - - if (GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE) == 0) { - _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface"); - return NULL; - } - - printf("eglCreatePixmapSurface()\n"); - return NULL; -} - - -static _EGLSurface * -demoCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - const EGLint *attrib_list) -{ - DemoSurface *surf = (DemoSurface *) calloc(1, sizeof(DemoSurface)); - - if (!surf) - return NULL; - - if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT, - conf, attrib_list)) { - free(surf); - return NULL; - } - - /* a real driver would allocate the pbuffer memory here */ - - return &surf->Base; -} - - -static EGLBoolean -demoDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface) -{ - DemoSurface *fs = LookupDemoSurface(surface); - if (!_eglIsSurfaceBound(&fs->Base)) - free(fs); - return EGL_TRUE; -} - - -static EGLBoolean -demoDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context) -{ - DemoContext *fc = LookupDemoContext(context); - if (!_eglIsContextBound(&fc->Base)) - free(fc); - return EGL_TRUE; -} - - -static EGLBoolean -demoMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *drawSurf, _EGLSurface *readSurf, _EGLContext *ctx) -{ - /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ - EGLBoolean b; - - b = _eglMakeCurrent(drv, dpy, drawSurf, readSurf, ctx); - if (!b) - return EGL_FALSE; - - /* XXX this is where we'd do the hardware context switch */ - (void) drawSurf; - (void) readSurf; - (void) ctx; - - printf("eglMakeCurrent()\n"); - return EGL_TRUE; -} - - -static void -demoUnload(_EGLDriver *drv) -{ - free(drv); -} - - -/** - * The bootstrap function. Return a new DemoDriver object and - * plug in API functions. - */ -_EGLDriver * -_eglMain(const char *args) -{ - DemoDriver *demo; - - demo = (DemoDriver *) calloc(1, sizeof(DemoDriver)); - if (!demo) { - return NULL; - } - - /* First fill in the dispatch table with defaults */ - _eglInitDriverFallbacks(&demo->Base); - /* then plug in our Demo-specific functions */ - demo->Base.API.Initialize = demoInitialize; - demo->Base.API.Terminate = demoTerminate; - demo->Base.API.CreateContext = demoCreateContext; - demo->Base.API.MakeCurrent = demoMakeCurrent; - demo->Base.API.CreateWindowSurface = demoCreateWindowSurface; - demo->Base.API.CreatePixmapSurface = demoCreatePixmapSurface; - demo->Base.API.CreatePbufferSurface = demoCreatePbufferSurface; - demo->Base.API.DestroySurface = demoDestroySurface; - demo->Base.API.DestroyContext = demoDestroyContext; - - demo->Base.Name = "egl/demo"; - demo->Base.Unload = demoUnload; - - return &demo->Base; -} diff --git a/src/egl/drivers/dri2/Makefile b/src/egl/drivers/dri2/Makefile new file mode 100644 index 0000000000..129e67b8c6 --- /dev/null +++ b/src/egl/drivers/dri2/Makefile @@ -0,0 +1,18 @@ +# src/egl/drivers/dri2/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER = egl_dri2.so +EGL_SOURCES = egl_dri2.c + +EGL_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/mesa \ + -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" \ + $(EGL_DRI2_CFLAGS) + +EGL_LIBS = $(EGL_DRI2_LIBS) + +include ../Makefile.template diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c new file mode 100644 index 0000000000..92378892e5 --- /dev/null +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -0,0 +1,974 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Kristian Høgsberg <krh@bitplanet.net> + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <limits.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> +#include <xf86drm.h> +#include <GL/gl.h> +#include <GL/internal/dri_interface.h> +#include <xcb/xcb.h> +#include <xcb/dri2.h> +#include <xcb/xfixes.h> +#include <X11/Xlib-xcb.h> + +#include <glapi/glapi.h> +#include "eglconfigutil.h" +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" +#include "eglsurface.h" + +struct dri2_egl_driver +{ + _EGLDriver base; +}; + +struct dri2_egl_display +{ + xcb_connection_t *conn; + int dri2_major; + int dri2_minor; + __DRIscreen *dri_screen; + void *driver; + __DRIcoreExtension *core; + __DRIdri2Extension *dri2; + __DRI2flushExtension *flush; + int fd; + + __DRIdri2LoaderExtension loader_extension; + const __DRIextension *extensions[2]; +}; + +struct dri2_egl_context +{ + _EGLContext base; + __DRIcontext *dri_context; +}; + +struct dri2_egl_surface +{ + _EGLSurface base; + __DRIdrawable *dri_drawable; + xcb_drawable_t drawable; + __DRIbuffer buffers[5]; + int buffer_count; + xcb_xfixes_region_t region; + int have_back; + int have_fake_front; + int swap_interval; +}; + +struct dri2_egl_config +{ + _EGLConfig base; + const __DRIconfig *dri_config; +}; + +/* standard typecasts */ +_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl) + +EGLint dri2_to_egl_attribute_map[] = { + 0, + EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ + EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ + EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ + EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ + EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ + 0, /* __DRI_ATTRIB_LUMINANCE_SIZE */ + EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ + 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ + EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ + EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ + EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ + EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ + 0, /* __DRI_ATTRIB_RENDER_TYPE, */ + 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ + 0, /* __DRI_ATTRIB_CONFORMANT */ + 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ + 0, /* __DRI_ATTRIB_STEREO */ + 0, /* __DRI_ATTRIB_AUX_BUFFERS */ + 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ + 0, /* __DRI_ATTRIB_FLOAT_MODE */ + 0, /* __DRI_ATTRIB_RED_MASK */ + 0, /* __DRI_ATTRIB_GREEN_MASK */ + 0, /* __DRI_ATTRIB_BLUE_MASK */ + 0, /* __DRI_ATTRIB_ALPHA_MASK */ + EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ + EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ + EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ + 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ + 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ + 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ + 0, /* __DRI_ATTRIB_SWAP_METHOD */ + EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ + EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ + 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ + 0, /* __DRI_ATTRIB_YINVERTED */ +}; + +static void +dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id) +{ + struct dri2_egl_config *conf; + struct dri2_egl_display *dri2_dpy; + unsigned int attrib, value, double_buffer; + EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; + int i; + + dri2_dpy = disp->DriverData; + conf = malloc(sizeof *conf); + if (conf == NULL) + return; + + conf->dri_config = dri_config; + _eglInitConfig(&conf->base, disp, id); + + i = 0; + while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { + switch (attrib) { + case 0: + break; + + case __DRI_ATTRIB_RENDER_TYPE: + if (value & __DRI_ATTRIB_RGBA_BIT) + value = EGL_RGB_BUFFER; + else if (value & __DRI_ATTRIB_LUMINANCE_BIT) + value = EGL_LUMINANCE_BUFFER; + else + /* not valid */; + _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE, value); + break; + + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) + value = EGL_NON_CONFORMANT_CONFIG; + else if (value & __DRI_ATTRIB_SLOW_BIT) + value = EGL_SLOW_CONFIG; + else + value = EGL_NONE; + _eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, value); + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: + bind_to_texture_rgb = value; + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: + bind_to_texture_rgba = value; + break; + + case __DRI_ATTRIB_DOUBLE_BUFFER: + double_buffer = value; + break; + + default: + key = dri2_to_egl_attribute_map[attrib]; + if (key != 0) + _eglSetConfigKey(&conf->base, key, value); + break; + } + } + + /* EGL_SWAP_BEHAVIOR_PRESERVED_BIT */ + + if (double_buffer) { + /* FIXME: Figure out how to get the visual ID and types */ + _eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT); + _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID, 0x21); + _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE, + XCB_VISUAL_CLASS_TRUE_COLOR); + } else { + _eglSetConfigKey(&conf->base, + EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); + _eglSetConfigKey(&conf->base, + EGL_BIND_TO_TEXTURE_RGB, bind_to_texture_rgb); + _eglSetConfigKey(&conf->base, + EGL_BIND_TO_TEXTURE_RGBA, bind_to_texture_rgba); + } + + /* EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT, EGL_OPENGL_ES2_BIT */ + _eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT); + _eglSetConfigKey(&conf->base, EGL_CONFORMANT, EGL_OPENGL_BIT); + + if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { + _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); + free(conf); + return; + } + + _eglAddConfig(disp, &conf->base); +} + +/** + * Process list of buffer received from the server + * + * Processes the list of buffers received in a reply from the server to either + * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. + */ +static void +dri2_process_buffers(struct dri2_egl_surface *dri2_surf, + xcb_dri2_dri2_buffer_t *buffers, unsigned count) +{ + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_rectangle_t rectangle; + int i; + + dri2_surf->buffer_count = count; + dri2_surf->have_fake_front = 0; + dri2_surf->have_back = 0; + + /* This assumes the DRI2 buffer attachment tokens matches the + * __DRIbuffer tokens. */ + for (i = 0; i < count; i++) { + dri2_surf->buffers[i].attachment = buffers[i].attachment; + dri2_surf->buffers[i].name = buffers[i].name; + dri2_surf->buffers[i].pitch = buffers[i].pitch; + dri2_surf->buffers[i].cpp = buffers[i].cpp; + dri2_surf->buffers[i].flags = buffers[i].flags; + if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) + dri2_surf->have_fake_front = 1; + if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT) + dri2_surf->have_back = 1; + } + + if (dri2_surf->region != XCB_NONE) + xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region); + + rectangle.x = 0; + rectangle.y = 0; + rectangle.width = dri2_surf->base.Width; + rectangle.height = dri2_surf->base.Height; + dri2_surf->region = xcb_generate_id(dri2_dpy->conn); + xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle); +} + +static __DRIbuffer * +dri2_get_buffers(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_dri2_dri2_buffer_t *buffers; + xcb_dri2_get_buffers_reply_t *reply; + xcb_dri2_get_buffers_cookie_t cookie; + + cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, + dri2_surf->drawable, + count, count, attachments); + reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); + buffers = xcb_dri2_get_buffers_buffers (reply); + if (buffers == NULL) + return NULL; + + *out_count = reply->count; + dri2_surf->base.Width = *width = reply->width; + dri2_surf->base.Height = *height = reply->height; + dri2_process_buffers(dri2_surf, buffers, *out_count); + + free(reply); + + return dri2_surf->buffers; +} + +static void +dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +{ + /* FIXME: Does EGL support front buffer rendering at all? */ + +#if 0 + struct dri2_egl_surface *dri2_surf = loaderPrivate; + + dri2WaitGL(dri2_surf); +#endif +} + +static __DRIbuffer * +dri2_get_buffers_with_format(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_dri2_dri2_buffer_t *buffers; + xcb_dri2_get_buffers_with_format_reply_t *reply; + xcb_dri2_get_buffers_with_format_cookie_t cookie; + xcb_dri2_attach_format_t *format_attachments; + + format_attachments = (xcb_dri2_attach_format_t *) attachments; + cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, + dri2_surf->drawable, + count, count, + format_attachments); + + reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, + cookie, NULL); + if (reply == NULL) + return NULL; + + buffers = xcb_dri2_get_buffers_with_format_buffers (reply); + dri2_surf->base.Width = *width = reply->width; + dri2_surf->base.Height = *height = reply->height; + *out_count = reply->count; + dri2_process_buffers(dri2_surf, buffers, *out_count); + + free(reply); + + return dri2_surf->buffers; +} + +#ifdef GLX_USE_TLS +static const char dri_driver_format[] = "%.*s/tls/%.*s_dri.so"; +#else +static const char dri_driver_format[] = "%.*s/%.*s_dri.so"; +#endif + +static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; + +/** + * Called via eglInitialize(), GLX_drv->API.Initialize(). + */ +static EGLBoolean +dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, + EGLint *major, EGLint *minor) +{ + const __DRIextension **extensions; + const __DRIconfig **driver_configs; + struct dri2_egl_display *dri2_dpy; + char path[PATH_MAX], *search_paths, *p, *next, *end; + xcb_xfixes_query_version_reply_t *xfixes_query; + xcb_xfixes_query_version_cookie_t xfixes_query_cookie; + xcb_dri2_query_version_reply_t *dri2_query; + xcb_dri2_query_version_cookie_t dri2_query_cookie; + xcb_dri2_connect_reply_t *connect; + xcb_dri2_connect_cookie_t connect_cookie; + xcb_dri2_authenticate_reply_t *authenticate; + xcb_dri2_authenticate_cookie_t authenticate_cookie; + xcb_generic_error_t *error; + drm_magic_t magic; + xcb_screen_iterator_t s; + int i; + + dri2_dpy = malloc(sizeof *dri2_dpy); + if (!dri2_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + disp->DriverData = (void *) dri2_dpy; + if (disp->NativeDisplay != NULL) + dri2_dpy->conn = XGetXCBConnection(disp->NativeDisplay); + else + dri2_dpy->conn = xcb_connect(0, 0); + if (!dri2_dpy->conn) { + _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); + goto cleanup_dpy; + } + + xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); + xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); + + xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, + XCB_XFIXES_MAJOR_VERSION, + XCB_XFIXES_MINOR_VERSION); + + dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, + XCB_DRI2_MAJOR_VERSION, + XCB_DRI2_MINOR_VERSION); + + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn, + s.data->root, + XCB_DRI2_DRIVER_TYPE_DRI); + + xfixes_query = + xcb_xfixes_query_version_reply (dri2_dpy->conn, + xfixes_query_cookie, &error); + if (xfixes_query == NULL || + error != NULL || xfixes_query->major_version < 2) { + _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version"); + free(error); + goto cleanup_conn; + } + free(xfixes_query); + + dri2_query = + xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); + if (dri2_query == NULL || error != NULL) { + _eglLog(_EGL_FATAL, "DRI2: failed to query version"); + free(error); + goto cleanup_conn; + } + dri2_dpy->dri2_major = dri2_query->major_version; + dri2_dpy->dri2_minor = dri2_query->minor_version; + free(dri2_query); + + connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); + if (connect == NULL || + connect->driver_name_length + connect->device_name_length == 0) { + _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); + goto cleanup_connect; + } + + search_paths = NULL; + if (geteuid() == getuid()) { + /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ + search_paths = getenv("LIBGL_DRIVERS_PATH"); + } + if (search_paths == NULL) + search_paths = DEFAULT_DRIVER_DIR; + + dri2_dpy->driver = NULL; + end = search_paths + strlen(search_paths); + for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { + next = strchr(p, ':'); + if (next == NULL) + next = end; + + snprintf(path, sizeof path, + dri_driver_format, + (int) (next - p), p, + xcb_dri2_connect_driver_name_length (connect), + xcb_dri2_connect_driver_name (connect)); + + dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); + } + + if (dri2_dpy->driver == NULL) { + _eglLog(_EGL_FATAL, + "DRI2: failed to open any driver (search paths %s)", + search_paths); + goto cleanup_connect; + } + + _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); + extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + _eglLog(_EGL_FATAL, + "DRI2: driver exports no extensions (%s)", dlerror()); + goto cleanup_driver; + } + + for (i = 0; extensions[i]; i++) { + _eglLog(_EGL_DEBUG, "DRI2: found driver extension `%s'", + extensions[i]->name); + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + dri2_dpy->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) + dri2_dpy->dri2 = (__DRIdri2Extension *) extensions[i]; + } + + if (dri2_dpy->core == NULL) { + _eglLog(_EGL_FATAL, "DRI2: driver has no core extension"); + goto cleanup_driver; + } + + if (dri2_dpy->dri2 == NULL) { + _eglLog(_EGL_FATAL, "DRI2: driver has no dri2 extension"); + goto cleanup_driver; + } + + snprintf(path, sizeof path, "%.*s", + xcb_dri2_connect_device_name_length (connect), + xcb_dri2_connect_device_name (connect)); + dri2_dpy->fd = open (path, O_RDWR); + if (dri2_dpy->fd == -1) { + _eglLog(_EGL_FATAL, + "DRI2: could not open %s (%s)", path, strerror(errno)); + goto cleanup_driver; + } + + if (drmGetMagic(dri2_dpy->fd, &magic)) { + _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic"); + goto cleanup_fd; + } + + authenticate_cookie = xcb_dri2_authenticate_unchecked (dri2_dpy->conn, + s.data->root, magic); + authenticate = xcb_dri2_authenticate_reply (dri2_dpy->conn, + authenticate_cookie, NULL); + if (authenticate == NULL || !authenticate->authenticated) { + _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); + free(authenticate); + goto cleanup_fd; + } + + free(authenticate); + if (dri2_dpy->dri2_minor >= 1) { + dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; + dri2_dpy->loader_extension.base.version = 3; + dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; + dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; + dri2_dpy->loader_extension.getBuffersWithFormat = + dri2_get_buffers_with_format; + } else { + dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; + dri2_dpy->loader_extension.base.version = 2; + dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; + dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; + dri2_dpy->loader_extension.getBuffersWithFormat = NULL; + } + + dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base; + dri2_dpy->extensions[1] = NULL; + + dri2_dpy->dri_screen = + dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, + &driver_configs, dri2_dpy); + + if (dri2_dpy->dri_screen == NULL) { + _eglLog(_EGL_FATAL, "DRI2: failed to create dri screen"); + goto cleanup_fd; + } + + extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); + for (i = 0; extensions[i]; i++) { + _eglLog(_EGL_DEBUG, "DRI2: found core extension `%s'", + extensions[i]->name); + if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) + dri2_dpy->flush = (__DRI2flushExtension *) extensions[i]; + } + + if (dri2_dpy->flush == NULL) { + _eglLog(_EGL_FATAL, "DRI2: driver doesn't support the flush extension"); + goto cleanup_dri_screen; + } + + for (i = 0; driver_configs[i]; i++) + dri2_add_config(disp, driver_configs[i], i + 1); + if (!disp->NumConfigs) { + _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); + goto cleanup_configs; + } + + disp->ClientAPIsMask = EGL_OPENGL_BIT; + + /* we're supporting EGL 1.4 */ + *major = 1; + *minor = 4; + free (connect); + return EGL_TRUE; + + cleanup_configs: + _eglCleanupDisplay(disp); + cleanup_dri_screen: + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); + cleanup_fd: + close(dri2_dpy->fd); + cleanup_driver: + dlclose(dri2_dpy->driver); + cleanup_connect: + free(connect); + cleanup_conn: + if (disp->NativeDisplay == NULL) + xcb_disconnect(dri2_dpy->conn); + cleanup_dpy: + free(dri2_dpy); + + return EGL_FALSE; +} + +/** + * Called via eglTerminate(), drv->API.Terminate(). + */ +static EGLBoolean +dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + + _eglReleaseDisplayResources(drv, disp); + _eglCleanupDisplay(disp); + + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); + close(dri2_dpy->fd); + dlclose(dri2_dpy->driver); + if (disp->NativeDisplay == NULL) + xcb_disconnect(dri2_dpy->conn); + free(dri2_dpy); + disp->DriverData = NULL; + + return EGL_TRUE; +} + + +/** + * Called via eglCreateContext(), drv->API.CreateContext(). + */ +static _EGLContext * +dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) +{ + struct dri2_egl_context *dri2_ctx; + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); + struct dri2_egl_config *dri2_config = dri2_egl_config(conf); + + dri2_ctx = malloc(sizeof *dri2_ctx); + if (!dri2_ctx) { + _eglError(EGL_BAD_ALLOC, "eglCreateContext"); + return NULL; + } + + if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) + goto cleanup; + + dri2_ctx->dri_context = + dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, + dri2_config->dri_config, + dri2_ctx_shared ? + dri2_ctx_shared->dri_context : NULL, + dri2_ctx); + + if (!dri2_ctx->dri_context) + goto cleanup; + + return &dri2_ctx->base; + + cleanup: + free(dri2_ctx); + return NULL; +} + +static EGLBoolean +dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + + if (_eglIsSurfaceBound(surf)) + return EGL_TRUE; + + (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); + + xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); + + if (surf->Type == EGL_PBUFFER_BIT) + xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); + + free(surf); + + return EGL_TRUE; +} + +/** + * Called via eglMakeCurrent(), drv->API.MakeCurrent(). + */ +static EGLBoolean +dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, + _EGLSurface *rsurf, _EGLContext *ctx) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); + struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); + __DRIdrawable *ddraw, *rdraw; + __DRIcontext *cctx; + + /* bind the new context and return the "orphaned" one */ + if (!_eglBindContext(&ctx, &dsurf, &rsurf)) + return EGL_FALSE; + + ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; + rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; + cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; + + if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || + dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { + if (dsurf && !_eglIsSurfaceLinked(dsurf)) + dri2_destroy_surface(drv, disp, dsurf); + if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(dsurf)) + dri2_destroy_surface(drv, disp, rsurf); + if (ctx != NULL && !_eglIsContextLinked(ctx)) + dri2_dpy->core->unbindContext(dri2_egl_context(ctx)->dri_context); + + return EGL_TRUE; + } else { + _eglBindContext(&ctx, &dsurf, &rsurf); + + return EGL_FALSE; + } +} + +/** + * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + */ +static _EGLSurface * +dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); + struct dri2_egl_surface *dri2_surf; + xcb_get_geometry_cookie_t cookie; + xcb_get_geometry_reply_t *reply; + xcb_screen_iterator_t s; + xcb_generic_error_t *error; + + dri2_surf = malloc(sizeof *dri2_surf); + if (!dri2_surf) { + _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); + return NULL; + } + + if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) + goto cleanup_surf; + + dri2_surf->region = XCB_NONE; + if (type == EGL_PBUFFER_BIT) { + dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + xcb_create_pixmap(dri2_dpy->conn, + _eglGetConfigKey(conf, EGL_BUFFER_SIZE), + dri2_surf->drawable, s.data->root, + dri2_surf->base.Width, dri2_surf->base.Height); + } else { + dri2_surf->drawable = window; + } + + dri2_surf->dri_drawable = + (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, + dri2_conf->dri_config, dri2_surf); + if (dri2_surf->dri_drawable == NULL) { + _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); + goto cleanup_pixmap; + } + + xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable); + + if (type != EGL_PBUFFER_BIT) { + cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); + reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); + if (reply == NULL || error != NULL) { + _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); + free(error); + goto cleanup_dri_drawable; + } + + dri2_surf->base.Width = reply->width; + dri2_surf->base.Height = reply->height; + free(reply); + } + + return &dri2_surf->base; + + cleanup_dri_drawable: + dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); + cleanup_pixmap: + if (type == EGL_PBUFFER_BIT) + xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); + cleanup_surf: + free(dri2_surf); + + return NULL; +} + +/** + * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + */ +static _EGLSurface * +dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, + window, attrib_list); +} + +static _EGLSurface * +dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativePixmapType pixmap, + const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf, + pixmap, attrib_list); +} + +static _EGLSurface * +dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, + XCB_WINDOW_NONE, attrib_list); +} + +static EGLBoolean +dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); + xcb_dri2_copy_region_cookie_t cookie; + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + +#if 0 + /* FIXME: Add support for dri swapbuffers, that'll give us swap + * interval and page flipping (at least for fullscreen windows) as + * well as the page flip event. */ +#if __DRI2_FLUSH_VERSION >= 2 + if (pdraw->psc->f) + (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable); +#endif +#endif + + if (!dri2_surf->have_back) + return EGL_TRUE; + + cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, + dri2_surf->drawable, + dri2_surf->region, + XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, + XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT); + free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); + + return EGL_TRUE; +} + +/* + * Called from eglGetProcAddress() via drv->API.GetProcAddress(). + */ +static _EGLProc +dri2_get_proc_address(_EGLDriver *drv, const char *procname) +{ + /* FIXME: Do we need to support lookup of EGL symbols too? */ + + return (_EGLProc) _glapi_get_proc_address(procname); +} + +static EGLBoolean +dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); + + /* FIXME: If EGL allows frontbuffer rendering for window surfaces, + * we need to copy fake to real here.*/ + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) +{ + if (engine != EGL_CORE_NATIVE_ENGINE) + return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); + /* glXWaitX(); */ + + return EGL_TRUE; +} + +static void +dri2_unload(_EGLDriver *drv) +{ + struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); + free(dri2_drv); +} + +static EGLBoolean +dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, + EGLNativePixmapType target) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + xcb_gcontext_t gc; + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + + gc = xcb_generate_id(dri2_dpy->conn); + xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); + xcb_copy_area(dri2_dpy->conn, + dri2_surf->drawable, + target, + gc, + 0, 0, + 0, 0, + dri2_surf->base.Width, + dri2_surf->base.Height); + xcb_free_gc(dri2_dpy->conn, gc); + + return EGL_TRUE; +} + +/** + * This is the main entrypoint into the driver, called by libEGL. + * Create a new _EGLDriver object and init its dispatch table. + */ +_EGLDriver * +_eglMain(const char *args) +{ + struct dri2_egl_driver *dri2_drv; + + dri2_drv = malloc(sizeof *dri2_drv); + if (!dri2_drv) + return NULL; + + _eglInitDriverFallbacks(&dri2_drv->base); + dri2_drv->base.API.Initialize = dri2_initialize; + dri2_drv->base.API.Terminate = dri2_terminate; + dri2_drv->base.API.CreateContext = dri2_create_context; + dri2_drv->base.API.MakeCurrent = dri2_make_current; + dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; + dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; + dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; + dri2_drv->base.API.DestroySurface = dri2_destroy_surface; + dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; + dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; + dri2_drv->base.API.WaitClient = dri2_wait_client; + dri2_drv->base.API.WaitNative = dri2_wait_native; + dri2_drv->base.API.CopyBuffers = dri2_copy_buffers; + + dri2_drv->base.Name = "DRI2"; + dri2_drv->base.Unload = dri2_unload; + + return &dri2_drv->base; +} diff --git a/src/egl/drivers/glx/Makefile b/src/egl/drivers/glx/Makefile index 20ef0352ad..634638f538 100644 --- a/src/egl/drivers/glx/Makefile +++ b/src/egl/drivers/glx/Makefile @@ -1,77 +1,16 @@ # src/egl/drivers/glx/Makefile -# Build XEGL DRI driver loader library: egl_glx.so - - TOP = ../../../.. include $(TOP)/configs/current +EGL_DRIVER = egl_glx.so +EGL_SOURCES = egl_glx.c -EXTRA_DEFINES = -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" - -DRIVER_NAME = egl_glx.so - - -INCLUDE_DIRS = \ - -I. \ - -I/usr/include \ - $(shell pkg-config --cflags-only-I libdrm) \ +EGL_INCLUDES = \ -I$(TOP)/include \ - -I$(TOP)/include/GL/internal \ - -I$(TOP)/src/mesa/glapi \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/egl/main \ - -I$(TOP)/src/glx/x11 - -SOURCES = egl_glx.c - -OBJECTS = $(SOURCES:.c=.o) - -DRM_LIB = `pkg-config --libs libdrm` - -MISC_LIBS = -ldl -lXext -lGL - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(EXTRA_DEFINES) $< -o $@ - - -.PHONY: library - - -default: depend library Makefile - - -library: $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) - - -# Make the egl_glx.so library -$(TOP)/$(LIB_DIR)/$(DRIVER_NAME): $(OBJECTS) - $(TOP)/bin/mklib -o $(DRIVER_NAME) \ - -noprefix \ - -major 1 -minor 0 \ - -L$(TOP)/$(LIB_DIR) \ - -install $(TOP)/$(LIB_DIR) \ - $(OBJECTS) $(DRM_LIB) $(MISC_LIBS) - -install: - $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) - $(MINSTALL) $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) $(DESTDIR)$(INSTALL_LIB_DIR) - -clean: - rm -f *.o - rm -f *.so - rm -f depend depend.bak - + -I$(TOP)/src/egl/main -depend: $(SOURCES) $(HEADERS) - @ echo "running $(MKDEP)" - @ rm -f depend - @ touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ - $(SOURCES) $(HEADERS) >/dev/null 2>/dev/null +EGL_CFLAGS = +EGL_LIBS = -lX11 -lGL -include depend -# DO NOT DELETE +include ../Makefile.template diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 96292b0e9e..3cbfebe488 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -43,7 +43,7 @@ #include "eglcontext.h" #include "egldisplay.h" #include "egldriver.h" -#include "eglglobals.h" +#include "eglcurrent.h" #include "egllog.h" #include "eglsurface.h" @@ -54,13 +54,6 @@ #error "GL/glx.h must be equal to or greater than GLX 1.4" #endif -/* - * report OpenGL ES bits because apps usually forget to specify - * EGL_RENDERABLE_TYPE when choosing configs - */ -#define GLX_EGL_APIS (EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT) - - /** subclass of _EGLDriver */ struct GLX_egl_driver { @@ -110,6 +103,8 @@ struct GLX_egl_surface Drawable drawable; GLXDrawable glx_drawable; + + void (*destroy)(Display *, GLXDrawable); }; @@ -121,35 +116,14 @@ struct GLX_egl_config int index; }; -/** cast wrapper */ -static struct GLX_egl_driver * -GLX_egl_driver(_EGLDriver *drv) -{ - return (struct GLX_egl_driver *) drv; -} - -static struct GLX_egl_display * -GLX_egl_display(_EGLDisplay *dpy) -{ - return (struct GLX_egl_display *) dpy->DriverData; -} - -static struct GLX_egl_context * -GLX_egl_context(_EGLContext *ctx) -{ - return (struct GLX_egl_context *) ctx; -} - -static struct GLX_egl_surface * -GLX_egl_surface(_EGLSurface *surf) -{ - return (struct GLX_egl_surface *) surf; -} +/* standard typecasts */ +_EGL_DRIVER_STANDARD_TYPECASTS(GLX_egl) static int GLX_egl_config_index(_EGLConfig *conf) { - return ((struct GLX_egl_config *) conf)->index; + struct GLX_egl_config *GLX_conf = GLX_egl_config(conf); + return GLX_conf->index; } @@ -244,7 +218,7 @@ convert_fbconfig(Display *dpy, GLXFBConfig fbconfig, GLX_conf->double_buffered = (mode.doubleBufferMode != 0); return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode, - GLX_EGL_APIS, GLX_EGL_APIS); + EGL_OPENGL_BIT, EGL_OPENGL_BIT); } @@ -364,7 +338,7 @@ convert_visual(Display *dpy, XVisualInfo *vinfo, GLX_conf->double_buffered = (mode.doubleBufferMode != 0); return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode, - GLX_EGL_APIS, GLX_EGL_APIS); + EGL_OPENGL_BIT, EGL_OPENGL_BIT); } @@ -427,7 +401,7 @@ create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy, EGLBoolean ok; memset(&template, 0, sizeof(template)); - _eglInitConfig(&template.Base, id); + _eglInitConfig(&template.Base, dpy, id); if (GLX_dpy->have_fbconfig) ok = convert_fbconfig(GLX_dpy->dpy, GLX_dpy->fbconfigs[i], &template); else @@ -559,7 +533,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, } disp->DriverData = (void *) GLX_dpy; - disp->ClientAPIsMask = GLX_EGL_APIS; + disp->ClientAPIsMask = EGL_OPENGL_BIT; /* we're supporting EGL 1.4 */ *major = 1; @@ -610,7 +584,7 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, return NULL; } - if (!_eglInitContext(drv, &GLX_ctx->Base, conf, attrib_list)) { + if (!_eglInitContext(&GLX_ctx->Base, disp, conf, attrib_list)) { free(GLX_ctx); return NULL; } @@ -638,6 +612,21 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, /** + * Destroy a surface. The display is allowed to be uninitialized. + */ +static void +destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) +{ + struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); + + if (GLX_surf->destroy) + GLX_surf->destroy(disp->NativeDisplay, GLX_surf->glx_drawable); + + free(GLX_surf); +} + + +/** * Called via eglMakeCurrent(), drv->API.MakeCurrent(). */ static EGLBoolean @@ -650,8 +639,10 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx); GLXDrawable ddraw, rdraw; GLXContext cctx; + EGLBoolean ret = EGL_FALSE; - if (!_eglMakeCurrent(drv, disp, dsurf, rsurf, ctx)) + /* bind the new context and return the "orphaned" one */ + if (!_eglBindContext(&ctx, &dsurf, &rsurf)) return EGL_FALSE; ddraw = (GLX_dsurf) ? GLX_dsurf->glx_drawable : None; @@ -659,11 +650,21 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, cctx = (GLX_ctx) ? GLX_ctx->context : NULL; if (GLX_dpy->have_make_current_read) - return glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx); + ret = glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx); else if (ddraw == rdraw) - return glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx); + ret = glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx); - return EGL_FALSE; + if (ret) { + if (dsurf && !_eglIsSurfaceLinked(dsurf)) + destroy_surface(disp, dsurf); + if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(rsurf)) + destroy_surface(disp, rsurf); + } + else { + _eglBindContext(&ctx, &dsurf, &rsurf); + } + + return ret; } /** Get size of given window */ @@ -684,8 +685,9 @@ get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height) * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). */ static _EGLSurface * -GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, - NativeWindowType window, const EGLint *attrib_list) +GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) { struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); struct GLX_egl_surface *GLX_surf; @@ -697,7 +699,7 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, return NULL; } - if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_WINDOW_BIT, + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_WINDOW_BIT, conf, attrib_list)) { free(GLX_surf); return NULL; @@ -718,6 +720,9 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, return NULL; } + if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk) + GLX_surf->destroy = glXDestroyWindow; + get_drawable_size(GLX_dpy->dpy, window, &width, &height); GLX_surf->Base.Width = width; GLX_surf->Base.Height = height; @@ -726,8 +731,9 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, } static _EGLSurface * -GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, - NativePixmapType pixmap, const EGLint *attrib_list) +GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativePixmapType pixmap, + const EGLint *attrib_list) { struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); struct GLX_egl_surface *GLX_surf; @@ -739,7 +745,7 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, return NULL; } - if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PIXMAP_BIT, + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PIXMAP_BIT, conf, attrib_list)) { free(GLX_surf); return NULL; @@ -774,6 +780,9 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, return NULL; } + GLX_surf->destroy = (GLX_dpy->have_1_3) ? + glXDestroyPixmap : glXDestroyGLXPixmap; + get_drawable_size(GLX_dpy->dpy, pixmap, &width, &height); GLX_surf->Base.Width = width; GLX_surf->Base.Height = height; @@ -796,7 +805,7 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, return NULL; } - if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PBUFFER_BIT, + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PBUFFER_BIT, conf, attrib_list)) { free(GLX_surf); return NULL; @@ -838,47 +847,18 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, return NULL; } + GLX_surf->destroy = (GLX_dpy->have_1_3) ? + glXDestroyPbuffer : GLX_dpy->glXDestroyGLXPbufferSGIX; + return &GLX_surf->Base; } + static EGLBoolean GLX_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { - struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); - if (!_eglIsSurfaceBound(surf)) { - struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); - - if (GLX_dpy->have_1_3) { - switch (surf->Type) { - case EGL_WINDOW_BIT: - if (!GLX_dpy->glx_window_quirk) - glXDestroyWindow(GLX_dpy->dpy, GLX_surf->glx_drawable); - break; - case EGL_PBUFFER_BIT: - glXDestroyPbuffer(GLX_dpy->dpy, GLX_surf->glx_drawable); - break; - case EGL_PIXMAP_BIT: - glXDestroyPixmap(GLX_dpy->dpy, GLX_surf->glx_drawable); - break; - default: - break; - } - } - else { - switch (surf->Type) { - case EGL_PBUFFER_BIT: - GLX_dpy->glXDestroyGLXPbufferSGIX(GLX_dpy->dpy, - GLX_surf->glx_drawable); - break; - case EGL_PIXMAP_BIT: - glXDestroyGLXPixmap(GLX_dpy->dpy, GLX_surf->glx_drawable); - break; - default: - break; - } - } - free(surf); - } + if (!_eglIsSurfaceBound(surf)) + destroy_surface(disp, surf); return EGL_TRUE; } @@ -899,7 +879,7 @@ GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) * Called from eglGetProcAddress() via drv->API.GetProcAddress(). */ static _EGLProc -GLX_eglGetProcAddress(const char *procname) +GLX_eglGetProcAddress(_EGLDriver *drv, const char *procname) { return (_EGLProc) glXGetProcAddress((const GLubyte *) procname); } diff --git a/src/egl/drivers/xdri/Makefile b/src/egl/drivers/xdri/Makefile deleted file mode 100644 index 4c1fc9071c..0000000000 --- a/src/egl/drivers/xdri/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -# src/egl/drivers/xdri/Makefile - -# Build XEGL DRI driver loader library: egl_xdri.so - - -TOP = ../../../.. -include $(TOP)/configs/current - - -DRIVER_NAME = egl_xdri.so - - -INCLUDE_DIRS = \ - -I. \ - -I/usr/include \ - $(shell pkg-config --cflags-only-I libdrm) \ - -I$(TOP)/include \ - -I$(TOP)/include/GL/internal \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/glapi \ - -I$(TOP)/src/egl/main \ - -I$(TOP)/src/glx/x11 - -HEADERS = glxinit.h driinit.h -SOURCES = egl_xdri.c glxinit.c driinit.c - -DRI_SOURCES = dri_common.c XF86dri.c dri2.c dri2_glx.c dri_glx.c -DRI_SOURCES := $(addprefix ../../../glx/x11/,$(DRI_SOURCES)) - -SOURCES += $(DRI_SOURCES) - -OBJECTS = $(SOURCES:.c=.o) - -DRM_LIB = `pkg-config --libs libdrm` - -CFLAGS += -DGLX_DIRECT_RENDERING - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - -.PHONY: library - - -default: depend library Makefile - - -library: $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) - - -# Make the egl_xdri.so library -$(TOP)/$(LIB_DIR)/$(DRIVER_NAME): $(OBJECTS) - $(TOP)/bin/mklib -o $(DRIVER_NAME) \ - -noprefix \ - -major 1 -minor 0 \ - -L$(TOP)/$(LIB_DIR) \ - -install $(TOP)/$(LIB_DIR) \ - $(OBJECTS) $(DRM_LIB) $(GL_LIB_DEPS) - -install: - $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) - $(MINSTALL) $(TOP)/$(LIB_DIR)/$(DRIVER_NAME) $(DESTDIR)$(INSTALL_LIB_DIR) - -clean: - rm -f *.o - rm -f *.so - rm -f depend depend.bak - - -depend: $(SOURCES) $(HEADERS) - @ echo "running $(MKDEP)" - @ rm -f depend - @ touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ - $(SOURCES) $(HEADERS) >/dev/null 2>/dev/null - -include depend -# DO NOT DELETE diff --git a/src/egl/drivers/xdri/driinit.c b/src/egl/drivers/xdri/driinit.c deleted file mode 100644 index 12da1bcd24..0000000000 --- a/src/egl/drivers/xdri/driinit.c +++ /dev/null @@ -1,67 +0,0 @@ -/** - * DRI initialization. The DRI loaders are defined in src/glx/x11/. - */ - -#include <sys/time.h> - -#include "glxclient.h" -#include "driinit.h" - -/* for __DRI_SYSTEM_TIME extension */ -_X_HIDDEN int -__glXGetUST(int64_t * ust) -{ - struct timeval tv; - - if (ust == NULL) { - return -EFAULT; - } - - if (gettimeofday(&tv, NULL) == 0) { - ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; - return 0; - } - else { - return -errno; - } -} - -_X_HIDDEN GLboolean -__driGetMscRateOML(__DRIdrawable * draw, - int32_t * numerator, int32_t * denominator, void *private) -{ - return GL_FALSE; -} - -/* ignore glx extensions */ -_X_HIDDEN void -__glXEnableDirectExtension(__GLXscreenConfigs * psc, const char *name) -{ -} - -_X_HIDDEN __GLXDRIdisplay * -__driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version) -{ - __GLXDRIdisplay *driDisplay; - int ver = 0; - - /* try DRI2 first */ - driDisplay = dri2CreateDisplay(dpyPriv->dpy); - if (driDisplay) { - /* fill in the required field */ - dpyPriv->dri2Display = driDisplay; - ver = 2; - } - else { - /* try DRI */ - driDisplay = driCreateDisplay(dpyPriv->dpy); - if (driDisplay) { - dpyPriv->driDisplay = driDisplay; - ver = 1; - } - } - - if (version) - *version = ver; - return driDisplay; -} diff --git a/src/egl/drivers/xdri/driinit.h b/src/egl/drivers/xdri/driinit.h deleted file mode 100644 index 6ea05cebef..0000000000 --- a/src/egl/drivers/xdri/driinit.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef DRIINIT_INCLUDED -#define DRIINIT_INCLUDED - -#include "glxclient.h" - -extern __GLXDRIdisplay * -__driCreateDisplay(__GLXdisplayPrivate *dpyPriv, int *version); - -#endif /* DRIINIT_INCLUDED */ diff --git a/src/egl/drivers/xdri/egl_xdri.c b/src/egl/drivers/xdri/egl_xdri.c deleted file mode 100644 index d2affc66dd..0000000000 --- a/src/egl/drivers/xdri/egl_xdri.c +++ /dev/null @@ -1,610 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -/** - * Code to interface a DRI driver to libEGL. - * Note that unlike previous DRI/EGL interfaces, this one is meant to - * be used _with_ X. Applications will use eglCreateWindowSurface() - * to render into X-created windows. - * - * This is an EGL driver that, in turn, loads a regular DRI driver. - * There are some dependencies on code in libGL, but those could be - * removed with some effort. - * - * Authors: Brian Paul - */ - -#include <assert.h> -#include <stdlib.h> -#include <X11/Xlib.h> - -#include "glxinit.h" -#include "driinit.h" -#include "glapi/glapi.h" /* for glapi functions */ - -#include "eglconfig.h" -#include "eglconfigutil.h" -#include "eglcontext.h" -#include "egldisplay.h" -#include "egldriver.h" -#include "eglglobals.h" -#include "egllog.h" -#include "eglsurface.h" - -#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) - -/** subclass of _EGLDriver */ -struct xdri_egl_driver -{ - _EGLDriver Base; /**< base class */ -}; - - -/** driver data of _EGLDisplay */ -struct xdri_egl_display -{ - Display *dpy; - __GLXdisplayPrivate *dpyPriv; - __GLXDRIdisplay *driDisplay; - - __GLXscreenConfigs *psc; - EGLint scr; -}; - - -/** subclass of _EGLContext */ -struct xdri_egl_context -{ - _EGLContext Base; /**< base class */ - - /* just enough info to create dri contexts */ - GLXContext dummy_gc; - - __GLXDRIcontext *driContext; -}; - - -/** subclass of _EGLSurface */ -struct xdri_egl_surface -{ - _EGLSurface Base; /**< base class */ - - Drawable drawable; - __GLXDRIdrawable *driDrawable; -}; - - -/** subclass of _EGLConfig */ -struct xdri_egl_config -{ - _EGLConfig Base; /**< base class */ - - const __GLcontextModes *mode; /**< corresponding GLX mode */ - EGLint window_render_buffer; -}; - - - -/** cast wrapper */ -static INLINE struct xdri_egl_driver * -xdri_egl_driver(_EGLDriver *drv) -{ - return (struct xdri_egl_driver *) drv; -} - - -static INLINE struct xdri_egl_display * -lookup_display(_EGLDisplay *dpy) -{ - return (struct xdri_egl_display *) dpy->DriverData; -} - - -/** Map EGLSurface handle to xdri_egl_surface object */ -static INLINE struct xdri_egl_surface * -lookup_surface(_EGLSurface *surface) -{ - return (struct xdri_egl_surface *) surface; -} - - -/** Map EGLContext handle to xdri_egl_context object */ -static INLINE struct xdri_egl_context * -lookup_context(_EGLContext *context) -{ - return (struct xdri_egl_context *) context; -} - - -/** Map EGLConfig handle to xdri_egl_config object */ -static INLINE struct xdri_egl_config * -lookup_config(_EGLConfig *conf) -{ - return (struct xdri_egl_config *) conf; -} - - -/** Get size of given window */ -static Status -get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height) -{ - Window root; - Status stat; - int xpos, ypos; - unsigned int w, h, bw, depth; - stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); - *width = w; - *height = h; - return stat; -} - - -static EGLBoolean -convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m) -{ - static const EGLint all_apis = (EGL_OPENGL_ES_BIT | - EGL_OPENGL_ES2_BIT | - EGL_OPENVG_BIT | - EGL_OPENGL_BIT); - EGLint val; - - _eglInitConfig(conf, id); - if (!_eglConfigFromContextModesRec(conf, m, all_apis, all_apis)) - return EGL_FALSE; - - if (m->doubleBufferMode) { - /* pixmap and pbuffer surfaces are always single-buffered */ - val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); - val &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); - SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, val); - } - else { - /* EGL requires OpenGL ES context to be double-buffered */ - val = GET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE); - val &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT); - SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, val); - } - /* skip "empty" config */ - if (!val) - return EGL_FALSE; - - val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); - if (!(val & EGL_PBUFFER_BIT)) { - /* bind-to-texture cannot be EGL_TRUE without pbuffer bit */ - SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE); - SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE); - } - - /* EGL_NATIVE_RENDERABLE is a boolean */ - val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE); - if (val != EGL_TRUE) - SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, EGL_FALSE); - - return _eglValidateConfig(conf, EGL_FALSE); -} - - -/** - * Produce a set of EGL configs. - */ -static EGLint -create_configs(_EGLDisplay *disp, const __GLcontextModes *m, EGLint first_id) -{ - int id = first_id; - - for (; m; m = m->next) { - struct xdri_egl_config *xdri_conf; - _EGLConfig conf; - EGLint rb; - - if (!convert_config(&conf, id, m)) - continue; - - rb = (m->doubleBufferMode) ? EGL_BACK_BUFFER : EGL_SINGLE_BUFFER; - - xdri_conf = CALLOC_STRUCT(xdri_egl_config); - if (xdri_conf) { - memcpy(&xdri_conf->Base, &conf, sizeof(conf)); - xdri_conf->mode = m; - xdri_conf->window_render_buffer = rb; - _eglAddConfig(disp, &xdri_conf->Base); - id++; - } - } - - return id; -} - - -/** - * Called via eglInitialize(), xdri_dpy->API.Initialize(). - */ -static EGLBoolean -xdri_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy, - EGLint *minor, EGLint *major) -{ - struct xdri_egl_display *xdri_dpy; - __GLXdisplayPrivate *dpyPriv; - __GLXDRIdisplay *driDisplay; - __GLXscreenConfigs *psc; - EGLint first_id = 1; - int scr; - - xdri_dpy = CALLOC_STRUCT(xdri_egl_display); - if (!xdri_dpy) - return _eglError(EGL_BAD_ALLOC, "eglInitialize"); - - xdri_dpy->dpy = (Display *) dpy->NativeDisplay; - if (!xdri_dpy->dpy) { - xdri_dpy->dpy = XOpenDisplay(NULL); - if (!xdri_dpy->dpy) { - free(xdri_dpy); - return _eglError(EGL_NOT_INITIALIZED, "eglInitialize"); - } - } - - dpyPriv = __glXInitialize(xdri_dpy->dpy); - if (!dpyPriv) { - _eglLog(_EGL_WARNING, "failed to create GLX display"); - free(xdri_dpy); - return _eglError(EGL_NOT_INITIALIZED, "eglInitialize"); - } - - driDisplay = __driCreateDisplay(dpyPriv, NULL); - if (!driDisplay) { - _eglLog(_EGL_WARNING, "failed to create DRI display"); - free(xdri_dpy); - return _eglError(EGL_NOT_INITIALIZED, "eglInitialize"); - } - - scr = DefaultScreen(xdri_dpy->dpy); - psc = &dpyPriv->screenConfigs[scr]; - - xdri_dpy->dpyPriv = dpyPriv; - xdri_dpy->driDisplay = driDisplay; - xdri_dpy->psc = psc; - xdri_dpy->scr = scr; - - psc->driScreen = driDisplay->createScreen(psc, scr, dpyPriv); - if (!psc->driScreen) { - _eglLog(_EGL_WARNING, "failed to create DRI screen #%d", scr); - free(xdri_dpy); - return _eglError(EGL_NOT_INITIALIZED, "eglInitialize"); - } - - /* add visuals and fbconfigs */ - first_id = create_configs(dpy, psc->visuals, first_id); - create_configs(dpy, psc->configs, first_id); - - dpy->DriverData = xdri_dpy; - dpy->ClientAPIsMask = (EGL_OPENGL_BIT | - EGL_OPENGL_ES_BIT | - EGL_OPENGL_ES2_BIT | - EGL_OPENVG_BIT); - - /* we're supporting EGL 1.4 */ - *minor = 1; - *major = 4; - - return EGL_TRUE; -} - - -/** - * Called via eglTerminate(), drv->API.Terminate(). - */ -static EGLBoolean -xdri_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy) -{ - struct xdri_egl_display *xdri_dpy = lookup_display(dpy); - __GLXscreenConfigs *psc; - - _eglReleaseDisplayResources(drv, dpy); - _eglCleanupDisplay(dpy); - - psc = xdri_dpy->psc; - if (psc->driver_configs) { - unsigned int i; - for (i = 0; psc->driver_configs[i]; i++) - free((__DRIconfig *) psc->driver_configs[i]); - free(psc->driver_configs); - psc->driver_configs = NULL; - } - if (psc->driScreen) { - psc->driScreen->destroyScreen(psc); - free(psc->driScreen); - psc->driScreen = NULL; - } - - xdri_dpy->driDisplay->destroyDisplay(xdri_dpy->driDisplay); - __glXRelease(xdri_dpy->dpyPriv); - - free(xdri_dpy); - dpy->DriverData = NULL; - - return EGL_TRUE; -} - - -/* - * Called from eglGetProcAddress() via drv->API.GetProcAddress(). - */ -static _EGLProc -xdri_eglGetProcAddress(const char *procname) -{ - /* the symbol is defined in libGL.so */ - return (_EGLProc) _glapi_get_proc_address(procname); -} - - -/** - * Called via eglCreateContext(), drv->API.CreateContext(). - */ -static _EGLContext * -xdri_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - _EGLContext *share_list, const EGLint *attrib_list) -{ - struct xdri_egl_display *xdri_dpy = lookup_display(dpy); - struct xdri_egl_config *xdri_config = lookup_config(conf); - struct xdri_egl_context *shared = lookup_context(share_list); - __GLXscreenConfigs *psc = xdri_dpy->psc; - int renderType = GLX_RGBA_BIT; - struct xdri_egl_context *xdri_ctx; - - xdri_ctx = CALLOC_STRUCT(xdri_egl_context); - if (!xdri_ctx) { - _eglError(EGL_BAD_ALLOC, "eglCreateContext"); - return NULL; - } - - xdri_ctx->dummy_gc = CALLOC_STRUCT(__GLXcontextRec); - if (!xdri_ctx->dummy_gc) { - _eglError(EGL_BAD_ALLOC, "eglCreateContext"); - free(xdri_ctx); - return NULL; - } - - if (!_eglInitContext(drv, &xdri_ctx->Base, &xdri_config->Base, attrib_list)) { - free(xdri_ctx->dummy_gc); - free(xdri_ctx); - return NULL; - } - - /* the config decides the render buffer for the context */ - xdri_ctx->Base.WindowRenderBuffer = xdri_config->window_render_buffer; - - xdri_ctx->driContext = - psc->driScreen->createContext(psc, - xdri_config->mode, - xdri_ctx->dummy_gc, - (shared) ? shared->dummy_gc : NULL, - renderType); - if (!xdri_ctx->driContext) { - free(xdri_ctx->dummy_gc); - free(xdri_ctx); - return NULL; - } - - /* fill in the required field */ - xdri_ctx->dummy_gc->driContext = xdri_ctx->driContext; - - return &xdri_ctx->Base; -} - - -static EGLBoolean -xdri_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) -{ - struct xdri_egl_display *xdri_dpy = lookup_display(dpy); - struct xdri_egl_context *xdri_ctx = lookup_context(ctx); - - if (!_eglIsContextBound(ctx)) { - xdri_ctx->driContext->destroyContext(xdri_ctx->driContext, - xdri_dpy->psc, xdri_dpy->dpy); - free(xdri_ctx->dummy_gc); - free(xdri_ctx); - } - - return EGL_TRUE; -} - - -/** - * Called via eglMakeCurrent(), drv->API.MakeCurrent(). - */ -static EGLBoolean -xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d, - _EGLSurface *r, _EGLContext *context) -{ - struct xdri_egl_context *xdri_ctx = lookup_context(context); - struct xdri_egl_surface *draw = lookup_surface(d); - struct xdri_egl_surface *read = lookup_surface(r); - - if (!_eglMakeCurrent(drv, dpy, d, r, context)) - return EGL_FALSE; - - /* the symbol is defined in libGL.so */ - _glapi_check_multithread(); - - if (xdri_ctx) { - if (!xdri_ctx->driContext->bindContext(xdri_ctx->driContext, - draw->driDrawable, - read->driDrawable)) { - return EGL_FALSE; - } - } - else { - _EGLContext *old = _eglGetCurrentContext(); - if (old) { - xdri_ctx = lookup_context(old); - xdri_ctx->driContext->unbindContext(xdri_ctx->driContext); - } - } - - return EGL_TRUE; -} - - -/** - * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). - */ -static _EGLSurface * -xdri_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - NativeWindowType window, const EGLint *attrib_list) -{ - struct xdri_egl_display *xdri_dpy = lookup_display(dpy); - struct xdri_egl_config *xdri_config = lookup_config(conf); - struct xdri_egl_surface *xdri_surf; - uint width, height; - - xdri_surf = CALLOC_STRUCT(xdri_egl_surface); - if (!xdri_surf) { - _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface"); - return NULL; - } - - if (!_eglInitSurface(drv, &xdri_surf->Base, EGL_WINDOW_BIT, - &xdri_config->Base, attrib_list)) { - free(xdri_surf); - return NULL; - } - - xdri_surf->driDrawable = - xdri_dpy->psc->driScreen->createDrawable(xdri_dpy->psc, - (XID) window, - (GLXDrawable) window, - xdri_config->mode); - if (!xdri_surf->driDrawable) { - free(xdri_surf); - return NULL; - } - - xdri_surf->drawable = (Drawable) window; - - get_drawable_size(xdri_dpy->dpy, window, &width, &height); - xdri_surf->Base.Width = width; - xdri_surf->Base.Height = height; - - return &xdri_surf->Base; -} - - -/** - * Called via eglCreatePbufferSurface(), drv->API.CreatePbufferSurface(). - */ -static _EGLSurface * -xdri_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - const EGLint *attrib_list) -{ - return NULL; -} - - - -static EGLBoolean -xdri_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface) -{ - struct xdri_egl_surface *xdri_surf = lookup_surface(surface); - - if (!_eglIsSurfaceBound(&xdri_surf->Base)) { - xdri_surf->driDrawable->destroyDrawable(xdri_surf->driDrawable); - free(xdri_surf); - } - - return EGL_TRUE; -} - - -static EGLBoolean -xdri_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, - EGLint buffer) -{ - return EGL_FALSE; -} - - -static EGLBoolean -xdri_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, - EGLint buffer) -{ - return EGL_FALSE; -} - - -static EGLBoolean -xdri_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw) -{ - struct xdri_egl_display *xdri_dpy = lookup_display(dpy); - struct xdri_egl_surface *xdri_surf = lookup_surface(draw); - - xdri_dpy->psc->driScreen->swapBuffers(xdri_surf->driDrawable); - - return EGL_TRUE; -} - - -static void -xdri_Unload(_EGLDriver *drv) -{ - struct xdri_egl_driver *xdri_drv = xdri_egl_driver(drv); - free(xdri_drv); -} - - -/** - * This is the main entrypoint into the driver, called by libEGL. - * Create a new _EGLDriver object and init its dispatch table. - */ -_EGLDriver * -_eglMain(const char *args) -{ - struct xdri_egl_driver *xdri_drv = CALLOC_STRUCT(xdri_egl_driver); - if (!xdri_drv) - return NULL; - - _eglInitDriverFallbacks(&xdri_drv->Base); - xdri_drv->Base.API.Initialize = xdri_eglInitialize; - xdri_drv->Base.API.Terminate = xdri_eglTerminate; - - xdri_drv->Base.API.GetProcAddress = xdri_eglGetProcAddress; - - xdri_drv->Base.API.CreateContext = xdri_eglCreateContext; - xdri_drv->Base.API.DestroyContext = xdri_eglDestroyContext; - xdri_drv->Base.API.MakeCurrent = xdri_eglMakeCurrent; - xdri_drv->Base.API.CreateWindowSurface = xdri_eglCreateWindowSurface; - xdri_drv->Base.API.CreatePbufferSurface = xdri_eglCreatePbufferSurface; - xdri_drv->Base.API.DestroySurface = xdri_eglDestroySurface; - xdri_drv->Base.API.BindTexImage = xdri_eglBindTexImage; - xdri_drv->Base.API.ReleaseTexImage = xdri_eglReleaseTexImage; - xdri_drv->Base.API.SwapBuffers = xdri_eglSwapBuffers; - - xdri_drv->Base.Name = "X/DRI"; - xdri_drv->Base.Unload = xdri_Unload; - - return &xdri_drv->Base; -} diff --git a/src/egl/drivers/xdri/glxinit.c b/src/egl/drivers/xdri/glxinit.c deleted file mode 100644 index 7775009394..0000000000 --- a/src/egl/drivers/xdri/glxinit.c +++ /dev/null @@ -1,626 +0,0 @@ -/** - * GLX initialization. Code based on glxext.c, glx_query.c, and - * glcontextmodes.c under src/glx/x11/. The major difference is that no DRI - * related code here. - * - */ - -#include <assert.h> -#include <X11/Xlib.h> -#include <X11/Xproto.h> -#include <X11/extensions/Xext.h> -#include <X11/extensions/extutil.h> -#include <sys/time.h> - -#include "glxinit.h" - -typedef struct GLXGenericGetString -{ - CARD8 reqType; - CARD8 glxCode; - CARD16 length B16; - CARD32 for_whom B32; - CARD32 name B32; -} xGLXGenericGetStringReq; - -#define sz_xGLXGenericGetStringReq 12 -#define X_GLXGenericGetString 0 - -/* Extension required boiler plate */ - -static char *__glXExtensionName = GLX_EXTENSION_NAME; -static XExtensionInfo *__glXExtensionInfo = NULL; - -static /* const */ XExtensionHooks __glXExtensionHooks = { NULL }; -static -XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo, - __glXExtensionName, &__glXExtensionHooks, - __GLX_NUMBER_EVENTS, NULL) - -static GLint -_gl_convert_from_x_visual_type(int visualType) -{ -#define NUM_VISUAL_TYPES 6 - static const int glx_visual_types[NUM_VISUAL_TYPES] = { - GLX_STATIC_GRAY, GLX_GRAY_SCALE, - GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, - GLX_TRUE_COLOR, GLX_DIRECT_COLOR - }; - - return ((unsigned) visualType < NUM_VISUAL_TYPES) - ? glx_visual_types[visualType] : GLX_NONE; -} - -static __GLcontextModes * -_gl_context_modes_create(unsigned count, size_t minimum_size) -{ - const size_t size = (minimum_size > sizeof(__GLcontextModes)) - ? minimum_size : sizeof(__GLcontextModes); - __GLcontextModes *base = NULL; - __GLcontextModes **next; - unsigned i; - - next = &base; - for (i = 0; i < count; i++) { - *next = (__GLcontextModes *) Xmalloc(size); - if (*next == NULL) { - _gl_context_modes_destroy(base); - base = NULL; - break; - } - - memset(*next, 0, size); - (*next)->visualID = GLX_DONT_CARE; - (*next)->visualType = GLX_DONT_CARE; - (*next)->visualRating = GLX_NONE; - (*next)->transparentPixel = GLX_NONE; - (*next)->transparentRed = GLX_DONT_CARE; - (*next)->transparentGreen = GLX_DONT_CARE; - (*next)->transparentBlue = GLX_DONT_CARE; - (*next)->transparentAlpha = GLX_DONT_CARE; - (*next)->transparentIndex = GLX_DONT_CARE; - (*next)->xRenderable = GLX_DONT_CARE; - (*next)->fbconfigID = GLX_DONT_CARE; - (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML; - (*next)->bindToTextureRgb = GLX_DONT_CARE; - (*next)->bindToTextureRgba = GLX_DONT_CARE; - (*next)->bindToMipmapTexture = GLX_DONT_CARE; - (*next)->bindToTextureTargets = GLX_DONT_CARE; - (*next)->yInverted = GLX_DONT_CARE; - - next = &((*next)->next); - } - - return base; -} - -_X_HIDDEN void -_gl_context_modes_destroy(__GLcontextModes * modes) -{ - while (modes != NULL) { - __GLcontextModes *const next = modes->next; - - Xfree(modes); - modes = next; - } -} - -_X_HIDDEN char * -__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) -{ - xGLXGenericGetStringReq *req; - xGLXSingleReply reply; - int length; - int numbytes; - char *buf; - CARD32 for_whom = screen; - CARD32 glxCode = X_GLXQueryServerString; - - - LockDisplay(dpy); - - - /* All of the GLX protocol requests for getting a string from the server - * look the same. The exact meaning of the for_whom field is usually - * either the screen number (for glXQueryServerString) or the context tag - * (for GLXSingle). - */ - - GetReq(GLXGenericGetString, req); - req->reqType = opcode; - req->glxCode = glxCode; - req->for_whom = for_whom; - req->name = name; - - _XReply(dpy, (xReply *) & reply, 0, False); - - length = reply.length * 4; - numbytes = reply.size; - - buf = (char *) Xmalloc(numbytes); - if (buf != NULL) { - _XRead(dpy, buf, numbytes); - length -= numbytes; - } - - _XEatData(dpy, length); - - UnlockDisplay(dpy); - SyncHandle(); - - return buf; -} - -/************************************************************************/ -/* -** Free the per screen configs data as well as the array of -** __glXScreenConfigs. -*/ -static void -FreeScreenConfigs(__GLXdisplayPrivate * priv) -{ - __GLXscreenConfigs *psc; - GLint i, screens; - - /* Free screen configuration information */ - psc = priv->screenConfigs; - screens = ScreenCount(priv->dpy); - for (i = 0; i < screens; i++, psc++) { - if (psc->configs) { - _gl_context_modes_destroy(psc->configs); - psc->configs = NULL; /* NOTE: just for paranoia */ - } - if (psc->visuals) { - _gl_context_modes_destroy(psc->visuals); - psc->visuals = NULL; /* NOTE: just for paranoia */ - } - Xfree((char *) psc->serverGLXexts); - } - XFree((char *) priv->screenConfigs); - priv->screenConfigs = NULL; -} - -/************************************************************************/ - -/* -** Query the version of the GLX extension. This procedure works even if -** the client extension is not completely set up. -*/ -static Bool -QueryVersion(Display * dpy, int opcode, int *major, int *minor) -{ - xGLXQueryVersionReq *req; - xGLXQueryVersionReply reply; - - /* Send the glXQueryVersion request */ - LockDisplay(dpy); - GetReq(GLXQueryVersion, req); - req->reqType = opcode; - req->glxCode = X_GLXQueryVersion; - req->majorVersion = GLX_MAJOR_VERSION; - req->minorVersion = GLX_MINOR_VERSION; - _XReply(dpy, (xReply *) & reply, 0, False); - UnlockDisplay(dpy); - SyncHandle(); - - if (reply.majorVersion != GLX_MAJOR_VERSION) { - /* - ** The server does not support the same major release as this - ** client. - */ - return GL_FALSE; - } - *major = reply.majorVersion; - *minor = min(reply.minorVersion, GLX_MINOR_VERSION); - return GL_TRUE; -} - -_X_HIDDEN void -__glXInitializeVisualConfigFromTags(__GLcontextModes * config, int count, - const INT32 * bp, Bool tagged_only, - Bool fbconfig_style_tags) -{ - int i; - - if (!tagged_only) { - /* Copy in the first set of properties */ - config->visualID = *bp++; - - config->visualType = _gl_convert_from_x_visual_type(*bp++); - - config->rgbMode = *bp++; - - config->redBits = *bp++; - config->greenBits = *bp++; - config->blueBits = *bp++; - config->alphaBits = *bp++; - config->accumRedBits = *bp++; - config->accumGreenBits = *bp++; - config->accumBlueBits = *bp++; - config->accumAlphaBits = *bp++; - - config->doubleBufferMode = *bp++; - config->stereoMode = *bp++; - - config->rgbBits = *bp++; - config->depthBits = *bp++; - config->stencilBits = *bp++; - config->numAuxBuffers = *bp++; - config->level = *bp++; - - count -= __GLX_MIN_CONFIG_PROPS; - } - - /* - ** Additional properties may be in a list at the end - ** of the reply. They are in pairs of property type - ** and property value. - */ - -#define FETCH_OR_SET(tag) \ - config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1 - - for (i = 0; i < count; i += 2) { - switch (*bp++) { - case GLX_RGBA: - FETCH_OR_SET(rgbMode); - break; - case GLX_BUFFER_SIZE: - config->rgbBits = *bp++; - break; - case GLX_LEVEL: - config->level = *bp++; - break; - case GLX_DOUBLEBUFFER: - FETCH_OR_SET(doubleBufferMode); - break; - case GLX_STEREO: - FETCH_OR_SET(stereoMode); - break; - case GLX_AUX_BUFFERS: - config->numAuxBuffers = *bp++; - break; - case GLX_RED_SIZE: - config->redBits = *bp++; - break; - case GLX_GREEN_SIZE: - config->greenBits = *bp++; - break; - case GLX_BLUE_SIZE: - config->blueBits = *bp++; - break; - case GLX_ALPHA_SIZE: - config->alphaBits = *bp++; - break; - case GLX_DEPTH_SIZE: - config->depthBits = *bp++; - break; - case GLX_STENCIL_SIZE: - config->stencilBits = *bp++; - break; - case GLX_ACCUM_RED_SIZE: - config->accumRedBits = *bp++; - break; - case GLX_ACCUM_GREEN_SIZE: - config->accumGreenBits = *bp++; - break; - case GLX_ACCUM_BLUE_SIZE: - config->accumBlueBits = *bp++; - break; - case GLX_ACCUM_ALPHA_SIZE: - config->accumAlphaBits = *bp++; - break; - case GLX_VISUAL_CAVEAT_EXT: - config->visualRating = *bp++; - break; - case GLX_X_VISUAL_TYPE: - config->visualType = *bp++; - break; - case GLX_TRANSPARENT_TYPE: - config->transparentPixel = *bp++; - break; - case GLX_TRANSPARENT_INDEX_VALUE: - config->transparentIndex = *bp++; - break; - case GLX_TRANSPARENT_RED_VALUE: - config->transparentRed = *bp++; - break; - case GLX_TRANSPARENT_GREEN_VALUE: - config->transparentGreen = *bp++; - break; - case GLX_TRANSPARENT_BLUE_VALUE: - config->transparentBlue = *bp++; - break; - case GLX_TRANSPARENT_ALPHA_VALUE: - config->transparentAlpha = *bp++; - break; - case GLX_VISUAL_ID: - config->visualID = *bp++; - break; - case GLX_DRAWABLE_TYPE: - config->drawableType = *bp++; - break; - case GLX_RENDER_TYPE: - config->renderType = *bp++; - break; - case GLX_X_RENDERABLE: - config->xRenderable = *bp++; - break; - case GLX_FBCONFIG_ID: - config->fbconfigID = *bp++; - break; - case GLX_MAX_PBUFFER_WIDTH: - config->maxPbufferWidth = *bp++; - break; - case GLX_MAX_PBUFFER_HEIGHT: - config->maxPbufferHeight = *bp++; - break; - case GLX_MAX_PBUFFER_PIXELS: - config->maxPbufferPixels = *bp++; - break; - case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX: - config->optimalPbufferWidth = *bp++; - break; - case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX: - config->optimalPbufferHeight = *bp++; - break; - case GLX_VISUAL_SELECT_GROUP_SGIX: - config->visualSelectGroup = *bp++; - break; - case GLX_SWAP_METHOD_OML: - config->swapMethod = *bp++; - break; - case GLX_SAMPLE_BUFFERS_SGIS: - config->sampleBuffers = *bp++; - break; - case GLX_SAMPLES_SGIS: - config->samples = *bp++; - break; - case GLX_BIND_TO_TEXTURE_RGB_EXT: - config->bindToTextureRgb = *bp++; - break; - case GLX_BIND_TO_TEXTURE_RGBA_EXT: - config->bindToTextureRgba = *bp++; - break; - case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: - config->bindToMipmapTexture = *bp++; - break; - case GLX_BIND_TO_TEXTURE_TARGETS_EXT: - config->bindToTextureTargets = *bp++; - break; - case GLX_Y_INVERTED_EXT: - config->yInverted = *bp++; - break; - case None: - i = count; - break; - default: - break; - } - } - - config->renderType = - (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; - - config->haveAccumBuffer = ((config->accumRedBits + - config->accumGreenBits + - config->accumBlueBits + - config->accumAlphaBits) > 0); - config->haveDepthBuffer = (config->depthBits > 0); - config->haveStencilBuffer = (config->stencilBits > 0); -} - -static __GLcontextModes * -createConfigsFromProperties(Display * dpy, int nvisuals, int nprops, - int screen, GLboolean tagged_only) -{ - INT32 buf[__GLX_TOTAL_CONFIG], *props; - unsigned prop_size; - __GLcontextModes *modes, *m; - int i; - - if (nprops == 0) - return NULL; - - /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */ - - /* Check number of properties */ - if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS) - return NULL; - - /* Allocate memory for our config structure */ - modes = _gl_context_modes_create(nvisuals, sizeof(__GLcontextModes)); - if (!modes) - return NULL; - - prop_size = nprops * __GLX_SIZE_INT32; - if (prop_size <= sizeof(buf)) - props = buf; - else - props = Xmalloc(prop_size); - - /* Read each config structure and convert it into our format */ - m = modes; - for (i = 0; i < nvisuals; i++) { - _XRead(dpy, (char *) props, prop_size); - /* Older X servers don't send this so we default it here. */ - m->drawableType = GLX_WINDOW_BIT; - __glXInitializeVisualConfigFromTags(m, nprops, props, - tagged_only, GL_TRUE); - m->screen = screen; - m = m->next; - } - - if (props != buf) - Xfree(props); - - return modes; -} - -static GLboolean -getVisualConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) -{ - xGLXGetVisualConfigsReq *req; - __GLXscreenConfigs *psc; - xGLXGetVisualConfigsReply reply; - - LockDisplay(dpy); - - psc = priv->screenConfigs + screen; - psc->visuals = NULL; - GetReq(GLXGetVisualConfigs, req); - req->reqType = priv->majorOpcode; - req->glxCode = X_GLXGetVisualConfigs; - req->screen = screen; - - if (!_XReply(dpy, (xReply *) & reply, 0, False)) - goto out; - - psc->visuals = createConfigsFromProperties(dpy, - reply.numVisuals, - reply.numProps, - screen, GL_FALSE); - - out: - UnlockDisplay(dpy); - return psc->visuals != NULL; -} - -static GLboolean -getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) -{ - xGLXGetFBConfigsReq *fb_req; - xGLXGetFBConfigsSGIXReq *sgi_req; - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXGetFBConfigsReply reply; - __GLXscreenConfigs *psc; - - psc = priv->screenConfigs + screen; - psc->serverGLXexts = - __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); - - LockDisplay(dpy); - - psc->configs = NULL; - if (atof(priv->serverGLXversion) >= 1.3) { - GetReq(GLXGetFBConfigs, fb_req); - fb_req->reqType = priv->majorOpcode; - fb_req->glxCode = X_GLXGetFBConfigs; - fb_req->screen = screen; - } - else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXGetFBConfigsSGIXReq + - sz_xGLXVendorPrivateWithReplyReq, vpreq); - sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; - sgi_req->reqType = priv->majorOpcode; - sgi_req->glxCode = X_GLXVendorPrivateWithReply; - sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; - sgi_req->screen = screen; - } - else - goto out; - - if (!_XReply(dpy, (xReply *) & reply, 0, False)) - goto out; - - psc->configs = createConfigsFromProperties(dpy, - reply.numFBConfigs, - reply.numAttribs * 2, - screen, GL_TRUE); - - out: - UnlockDisplay(dpy); - return psc->configs != NULL; -} - -static GLboolean -AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) -{ - __GLXscreenConfigs *psc; - GLint i, screens; - - /* - ** First allocate memory for the array of per screen configs. - */ - screens = ScreenCount(dpy); - psc = (__GLXscreenConfigs *) Xmalloc(screens * sizeof(__GLXscreenConfigs)); - if (!psc) { - return GL_FALSE; - } - memset(psc, 0, screens * sizeof(__GLXscreenConfigs)); - priv->screenConfigs = psc; - - priv->serverGLXversion = - __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); - if (priv->serverGLXversion == NULL) { - FreeScreenConfigs(priv); - return GL_FALSE; - } - - for (i = 0; i < screens; i++, psc++) { - getFBConfigs(dpy, priv, i); - getVisualConfigs(dpy, priv, i); - psc->scr = i; - psc->dpy = dpy; - } - - SyncHandle(); - - return GL_TRUE; -} - -_X_HIDDEN void -__glXRelease(__GLXdisplayPrivate *dpyPriv) -{ - FreeScreenConfigs(dpyPriv); - - if (dpyPriv->serverGLXvendor) { - Xfree((char *) dpyPriv->serverGLXvendor); - dpyPriv->serverGLXvendor = NULL; - } - if (dpyPriv->serverGLXversion) { - Xfree((char *) dpyPriv->serverGLXversion); - dpyPriv->serverGLXversion = NULL; - } - - Xfree(dpyPriv); -} - -_X_HIDDEN __GLXdisplayPrivate * -__glXInitialize(Display * dpy) -{ - XExtDisplayInfo *info = __glXFindDisplay(dpy); - __GLXdisplayPrivate *dpyPriv; - int major, minor; - - if (!XextHasExtension(info)) - return NULL; - - /* See if the versions are compatible */ - if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor)) - return NULL; - - dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate)); - if (!dpyPriv) - return NULL; - - /* - ** Init the display private and then read in the screen config - ** structures from the server. - */ - dpyPriv->majorOpcode = info->codes->major_opcode; - dpyPriv->majorVersion = major; - dpyPriv->minorVersion = minor; - dpyPriv->dpy = dpy; - - dpyPriv->serverGLXvendor = NULL; - dpyPriv->serverGLXversion = NULL; - - if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) { - Xfree(dpyPriv); - return NULL; - } - - return dpyPriv; -} diff --git a/src/egl/drivers/xdri/glxinit.h b/src/egl/drivers/xdri/glxinit.h deleted file mode 100644 index 57206e627b..0000000000 --- a/src/egl/drivers/xdri/glxinit.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GLXINIT_INCLUDED -#define GLXINIT_INCLUDED - -#include <X11/Xlib.h> -#include "glxclient.h" - -/* this is used by DRI loaders */ -extern void -_gl_context_modes_destroy(__GLcontextModes * modes); - -extern void -__glXRelease(__GLXdisplayPrivate *dpyPriv); - -#endif /* GLXINIT_INCLUDED */ diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index ec326a845d..31f214cf6f 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -19,6 +19,7 @@ HEADERS = \ egldisplay.h \ egldriver.h \ eglglobals.h \ + eglimage.h \ egllog.h \ eglmisc.h \ eglmode.h \ @@ -36,6 +37,7 @@ SOURCES = \ egldisplay.c \ egldriver.c \ eglglobals.c \ + eglimage.c \ egllog.c \ eglmisc.c \ eglmode.c \ @@ -47,8 +49,13 @@ OBJECTS = $(SOURCES:.c=.o) # use dl*() to load drivers -LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1 +LOCAL_CFLAGS = -D_EGL_PLATFORM_POSIX=1 +EGL_DEFAULT_DISPLAY = $(word 1, $(EGL_DISPLAYS)) + +LOCAL_CFLAGS += \ + -D_EGL_DEFAULT_DISPLAY=\"$(EGL_DEFAULT_DISPLAY)\" \ + -D_EGL_DRIVER_SEARCH_DIR=\"$(EGL_DRIVER_INSTALL_DIR)\" .c.o: $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@ @@ -67,7 +74,15 @@ $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS) -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ $(EGL_LIB_DEPS) $(OBJECTS) -install: default +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR + $(INSTALL) -m 644 $(TOP)/include/KHR/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/KHR + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/EGL + $(INSTALL) -m 644 $(TOP)/include/EGL/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/EGL + +install: default install-headers $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) $(MINSTALL) $(TOP)/$(LIB_DIR)/$(EGL_LIB_GLOB) \ $(DESTDIR)$(INSTALL_LIB_DIR) diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 14cc5fa613..364ad9c458 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -60,11 +60,13 @@ #include "egldisplay.h" #include "egltypedefs.h" #include "eglglobals.h" +#include "eglcurrent.h" #include "egldriver.h" #include "eglsurface.h" #include "eglconfig.h" #include "eglscreen.h" #include "eglmode.h" +#include "eglimage.h" /** @@ -72,7 +74,7 @@ * We initialize our global vars and create a private _EGLDisplay object. */ EGLDisplay EGLAPIENTRY -eglGetDisplay(NativeDisplayType nativeDisplay) +eglGetDisplay(EGLNativeDisplayType nativeDisplay) { _EGLDisplay *dpy; dpy = _eglFindDisplay(nativeDisplay); @@ -93,23 +95,24 @@ EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLDriver *drv; EGLint major_int, minor_int; if (!disp) return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); - drv = disp->Driver; - if (!drv) { - drv = _eglOpenDriver(disp); - if (!drv) - return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); + if (!disp->Initialized) { + _EGLDriver *drv = disp->Driver; + + if (!drv) { + _eglPreloadDrivers(); + drv = _eglMatchDriver(disp); + if (!drv) + return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); + } /* Initialize the particular display now */ - if (!drv->API.Initialize(drv, disp, &major_int, &minor_int)) { - _eglCloseDriver(drv, disp); + if (!drv->API.Initialize(drv, disp, &major_int, &minor_int)) return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); - } disp->APImajor = major_int; disp->APIminor = minor_int; @@ -120,6 +123,7 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) disp->ClientAPIsMask &= _EGL_API_ALL_BITS; disp->Driver = drv; + disp->Initialized = EGL_TRUE; } else { major_int = disp->APImajor; minor_int = disp->APIminor; @@ -139,16 +143,16 @@ EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLDriver *drv; if (!disp) return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); - drv = disp->Driver; - if (drv) { + if (disp->Initialized) { + _EGLDriver *drv = disp->Driver; + drv->API.Terminate(drv, disp); - _eglCloseDriver(drv, disp); - disp->Driver = NULL; + /* do not reset disp->Driver */ + disp->Initialized = EGL_FALSE; } return EGL_TRUE; @@ -165,7 +169,7 @@ _eglCheckDisplay(_EGLDisplay *disp, const char *msg) _eglError(EGL_BAD_DISPLAY, msg); return NULL; } - if (!disp->Driver) { + if (!disp->Initialized) { _eglError(EGL_NOT_INITIALIZED, msg); return NULL; } @@ -391,9 +395,19 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, _EGLSurface *read_surf = _eglLookupSurface(read, disp); _EGLDriver *drv; - drv = _eglCheckDisplay(disp, __FUNCTION__); + if (!disp) + return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); + drv = disp->Driver; + + /* display is allowed to be uninitialized under certain condition */ + if (!disp->Initialized) { + if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE || + ctx != EGL_NO_CONTEXT) + return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); + } if (!drv) - return EGL_FALSE; + return EGL_TRUE; + if (!context && ctx != EGL_NO_CONTEXT) return _eglError(EGL_BAD_CONTEXT, __FUNCTION__); if ((!draw_surf && draw != EGL_NO_SURFACE) || @@ -415,7 +429,7 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, - NativeWindowType window, const EGLint *attrib_list) + EGLNativeWindowType window, const EGLint *attrib_list) { _EGLDisplay *disp = _eglLookupDisplay(dpy); _EGLConfig *conf = _eglLookupConfig(config, disp); @@ -436,7 +450,7 @@ eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, - NativePixmapType pixmap, const EGLint *attrib_list) + EGLNativePixmapType pixmap, const EGLint *attrib_list) { _EGLDisplay *disp = _eglLookupDisplay(dpy); _EGLConfig *conf = _eglLookupConfig(config, disp); @@ -524,7 +538,7 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval) _EGLSurface *surf; _EGL_DECLARE_DD(dpy); - if (!ctx || !_eglIsContextLinked(ctx) || ctx->Display != disp) + if (!ctx || !_eglIsContextLinked(ctx) || ctx->Resource.Display != disp) return _eglError(EGL_BAD_CONTEXT, __FUNCTION__); surf = ctx->DrawSurface; @@ -550,7 +564,7 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) EGLBoolean EGLAPIENTRY -eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, NativePixmapType target) +eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) { _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); return drv->API.CopyBuffers(drv, disp, surf, target); @@ -571,9 +585,9 @@ eglWaitClient(void) return _eglError(EGL_BAD_CURRENT_SURFACE, __FUNCTION__); /* a valid current context implies an initialized current display */ - disp = ctx->Display; + disp = ctx->Resource.Display; + assert(disp->Initialized); drv = disp->Driver; - assert(drv); return drv->API.WaitClient(drv, disp, ctx); } @@ -615,9 +629,9 @@ eglWaitNative(EGLint engine) return _eglError(EGL_BAD_CURRENT_SURFACE, __FUNCTION__); /* a valid current context implies an initialized current display */ - disp = ctx->Display; + disp = ctx->Resource.Display; + assert(disp->Initialized); drv = disp->Driver; - assert(drv); return drv->API.WaitNative(drv, disp, engine); } @@ -626,8 +640,8 @@ eglWaitNative(EGLint engine) EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void) { - _EGLDisplay *dpy = _eglGetCurrentDisplay(); - return _eglGetDisplayHandle(dpy); + _EGLContext *ctx = _eglGetCurrentContext(); + return (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY; } @@ -676,7 +690,8 @@ eglGetError(void) } -void (* EGLAPIENTRY eglGetProcAddress(const char *procname))() +__eglMustCastToProperFunctionPointerType EGLAPIENTRY +eglGetProcAddress(const char *procname) { static const struct { const char *name; @@ -697,6 +712,10 @@ void (* EGLAPIENTRY eglGetProcAddress(const char *procname))() { "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA }, { "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA }, #endif /* EGL_MESA_screen_surface */ +#ifdef EGL_KHR_image_base + { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR }, + { "eglDestroyImageKHR", (_EGLProc) eglDestroyImageKHR }, +#endif /* EGL_KHR_image_base */ { NULL, NULL } }; EGLint i; @@ -710,13 +729,12 @@ void (* EGLAPIENTRY eglGetProcAddress(const char *procname))() } } - /* preload a driver if there isn't one */ - if (!_eglGlobal.NumDrivers) - _eglPreloadDriver(NULL); + _eglPreloadDrivers(); /* now loop over drivers to query their procs */ for (i = 0; i < _eglGlobal.NumDrivers; i++) { - _EGLProc p = _eglGlobal.Drivers[i]->API.GetProcAddress(procname); + _EGLDriver *drv = _eglGlobal.Drivers[i]; + _EGLProc p = drv->API.GetProcAddress(drv, procname); if (p) return p; } @@ -977,14 +995,23 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLBoolean eglReleaseThread(void) { - /* unbind current context */ + /* unbind current contexts */ if (!_eglIsCurrentThreadDummy()) { - _EGLDisplay *disp = _eglGetCurrentDisplay(); - _EGLDriver *drv; - if (disp) { - drv = disp->Driver; - (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL); + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint api_index = t->CurrentAPIIndex; + EGLint i; + + for (i = 0; i < _EGL_API_NUM_APIS; i++) { + _EGLContext *ctx = t->CurrentContexts[i]; + if (ctx) { + _EGLDisplay *disp = ctx->Resource.Display; + _EGLDriver *drv = disp->Driver; + t->CurrentAPIIndex = i; + (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL); + } } + + t->CurrentAPIIndex = api_index; } _eglDestroyCurrentThread(); @@ -993,3 +1020,52 @@ eglReleaseThread(void) #endif /* EGL_VERSION_1_2 */ + + +#ifdef EGL_KHR_image_base + + +EGLImageKHR +eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLDriver *drv; + _EGLImage *img; + + drv = _eglCheckDisplay(disp, __FUNCTION__); + if (!drv) + return EGL_NO_IMAGE_KHR; + if (!context && ctx != EGL_NO_CONTEXT) { + _eglError(EGL_BAD_CONTEXT, __FUNCTION__); + return EGL_NO_IMAGE_KHR; + } + + img = drv->API.CreateImageKHR(drv, + disp, context, target, buffer, attr_list); + if (img) + return _eglLinkImage(img, disp); + else + return EGL_NO_IMAGE_KHR; +} + + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLImage *img = _eglLookupImage(image, disp); + _EGLDriver *drv; + + drv = _eglCheckDisplay(disp, __FUNCTION__); + if (!drv) + return EGL_FALSE; + if (!img) + return _eglError(EGL_BAD_PARAMETER, __FUNCTION__); + + _eglUnlinkImage(img); + return drv->API.DestroyImageKHR(drv, disp, img); +} + + +#endif /* EGL_KHR_image_base */ diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h index aa0abe3eb6..c3676ec56a 100644 --- a/src/egl/main/eglapi.h +++ b/src/egl/main/eglapi.h @@ -4,7 +4,7 @@ /** * A generic function ptr type */ -typedef void (*_EGLProc)(); +typedef void (*_EGLProc)(void); /** @@ -23,12 +23,13 @@ typedef EGLBoolean (*GetConfigAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLC /* context funcs */ typedef _EGLContext *(*CreateContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, _EGLContext *share_list, const EGLint *attrib_list); typedef EGLBoolean (*DestroyContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); +/* this is the only function (other than Initialize) that may be called with an uninitialized display */ typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); /* surface funcs */ -typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativeWindowType window, const EGLint *attrib_list); -typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativePixmapType pixmap, const EGLint *attrib_list); +typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativeWindowType window, const EGLint *attrib_list); +typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativePixmapType pixmap, const EGLint *attrib_list); typedef _EGLSurface *(*CreatePbufferSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface); typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint *value); @@ -37,14 +38,14 @@ typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurf typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer); typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval); typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw); -typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, NativePixmapType target); +typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLNativePixmapType target); /* misc funcs */ typedef const char *(*QueryString_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name); typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine); -typedef _EGLProc (*GetProcAddress_t)(const char *procname); +typedef _EGLProc (*GetProcAddress_t)(_EGLDriver *drv, const char *procname); @@ -69,6 +70,11 @@ typedef _EGLSurface *(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDis #endif /* EGL_VERSION_1_2 */ +#ifdef EGL_KHR_image_base +typedef _EGLImage *(*CreateImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list); +typedef EGLBoolean (*DestroyImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image); +#endif /* EGL_KHR_image_base */ + /** * The API dispatcher jumps through these functions @@ -104,7 +110,7 @@ struct _egl_api WaitNative_t WaitNative; GetProcAddress_t GetProcAddress; - /* EGL_MESA_screen extension */ +#ifdef EGL_MESA_screen_surface ChooseModeMESA_t ChooseModeMESA; GetModesMESA_t GetModesMESA; GetModeAttribMESA_t GetModeAttribMESA; @@ -117,10 +123,16 @@ struct _egl_api QueryScreenSurfaceMESA_t QueryScreenSurfaceMESA; QueryScreenModeMESA_t QueryScreenModeMESA; QueryModeStringMESA_t QueryModeStringMESA; +#endif /* EGL_MESA_screen_surface */ #ifdef EGL_VERSION_1_2 CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer; #endif + +#ifdef EGL_KHR_image_base + CreateImageKHR_t CreateImageKHR; + DestroyImageKHR_t DestroyImageKHR; +#endif /* EGL_KHR_image_base */ }; #endif /* EGLAPI_INCLUDED */ diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h index f7c93f14ce..d844fbb0ef 100644 --- a/src/egl/main/eglcompiler.h +++ b/src/egl/main/eglcompiler.h @@ -64,11 +64,30 @@ /** * Function visibility */ -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303 +#if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \ + || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define PUBLIC __attribute__((visibility("default"))) #else # define PUBLIC #endif +/** + * The __FUNCTION__ gcc variable is generally only used for debugging. + * If we're not using gcc, define __FUNCTION__ as a cpp symbol here. + * Don't define it if using a newer Windows compiler. + */ +#ifndef __FUNCTION__ +# if defined(__VMS) +# define __FUNCTION__ "VMS$NL:" +# elif ((!defined __GNUC__) || (__GNUC__ < 2)) && (!defined __xlC__) && \ + (!defined(_MSC_VER) || _MSC_VER < 1300) +# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \ + (defined(__SUNPRO_C) && defined(__C99FEATURES__)) +# define __FUNCTION__ __func__ +# else +# define __FUNCTION__ "<unknown>" +# endif +# endif +#endif #endif /* EGLCOMPILER_INCLUDED */ diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index 31d69a7708..1190f8cdd5 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -4,13 +4,11 @@ #include <stdlib.h> -#include <stdio.h> #include <string.h> #include <assert.h> #include "eglconfig.h" #include "egldisplay.h" -#include "egldriver.h" -#include "eglglobals.h" +#include "eglcurrent.h" #include "egllog.h" @@ -27,10 +25,12 @@ * IDs are from 1 to N respectively. */ void -_eglInitConfig(_EGLConfig *config, EGLint id) +_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id) { memset(config, 0, sizeof(*config)); + config->Display = dpy; + /* some attributes take non-zero default values */ SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id); SET_CONFIG_ATTRIB(config, EGL_CONFIG_CAVEAT, EGL_NONE); @@ -224,7 +224,8 @@ static const struct { { EGL_MATCH_NATIVE_PIXMAP, ATTRIB_TYPE_PSEUDO, ATTRIB_CRITERION_SPECIAL, EGL_NONE }, - { EGL_PRESERVED_RESOURCES, ATTRIB_TYPE_PSEUDO, + /* there is a gap before EGL_SAMPLES */ + { 0x3030, ATTRIB_TYPE_PSEUDO, ATTRIB_CRITERION_IGNORE, 0 }, { EGL_NONE, ATTRIB_TYPE_PSEUDO, @@ -328,6 +329,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) EGL_VG_ALPHA_FORMAT_PRE_BIT | EGL_MULTISAMPLE_RESOLVE_BOX_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; + if (conf->Display->Extensions.MESA_screen_surface) + mask |= EGL_SCREEN_BIT_MESA; break; case EGL_RENDERABLE_TYPE: case EGL_CONFORMANT: @@ -363,8 +366,11 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_SPECIAL) valid = EGL_TRUE; } - if (!valid) + if (!valid) { + _eglLog(_EGL_DEBUG, + "attribute 0x%04x has an invalid value 0x%x", attr, val); break; + } } /* any invalid attribute value should have been catched */ @@ -387,10 +393,18 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) valid = EGL_FALSE; break; } + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting color buffer type and channel sizes"); + return EGL_FALSE; + } val = GET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS); if (!val && GET_CONFIG_ATTRIB(conf, EGL_SAMPLES)) valid = EGL_FALSE; + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting samples and sample buffers"); + return EGL_FALSE; + } val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); if (!(val & EGL_WINDOW_BIT)) { @@ -403,6 +417,10 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA)) valid = EGL_FALSE; } + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding"); + return EGL_FALSE; + } return valid; } @@ -454,8 +472,14 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria) break; } - if (!matched) + if (!matched) { +#ifdef DEBUG + _eglLog(_EGL_DEBUG, + "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)", + val, attr, cmp); +#endif break; + } } return matched; @@ -730,7 +754,7 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, if (!num_configs) return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs"); - _eglInitConfig(&criteria, 0); + _eglInitConfig(&criteria, disp, 0); if (!_eglParseConfigAttribList(&criteria, attrib_list)) return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); @@ -772,7 +796,7 @@ _eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr) /* there are some holes in the range */ switch (attr) { - case EGL_PRESERVED_RESOURCES: + case 0x3030 /* a gap before EGL_SAMPLES */: case EGL_NONE: #ifdef EGL_VERSION_1_4 case EGL_MATCH_NATIVE_PIXMAP: diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index 799bf4ee24..56ec95fe9a 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -21,6 +21,9 @@ struct _egl_config }; +/** + * Macros for source level compatibility. + */ #define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL) #define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR) @@ -55,6 +58,10 @@ _eglResetConfigKeys(_EGLConfig *conf, EGLint val) /** * Update a config for a given key. + * + * Note that a valid key is not necessarily a valid attribute. There are gaps + * in the attribute enums. The separation is to catch application errors. + * Drivers should never set a key that is an invalid attribute. */ static INLINE void _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val) @@ -77,22 +84,8 @@ _eglGetConfigKey(const _EGLConfig *conf, EGLint key) } -/** - * Set a given attribute. - * - * Because _eglGetConfigAttrib is already used as a fallback driver - * function, this function is not considered to have a good name. - * SET_CONFIG_ATTRIB is preferred over this function. - */ -static INLINE void -_eglSetConfigAttrib(_EGLConfig *conf, EGLint attr, EGLint val) -{ - SET_CONFIG_ATTRIB(conf, attr, val); -} - - PUBLIC void -_eglInitConfig(_EGLConfig *config, EGLint id); +_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id); PUBLIC EGLConfig diff --git a/src/egl/main/eglconfigutil.c b/src/egl/main/eglconfigutil.c index 36e94f0d2d..e416b190f0 100644 --- a/src/egl/main/eglconfigutil.c +++ b/src/egl/main/eglconfigutil.c @@ -4,10 +4,8 @@ #include <stdlib.h> -#include <stdio.h> #include <string.h> #include "eglconfigutil.h" -#include "egllog.h" /** @@ -128,210 +126,3 @@ _eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m, return EGL_TRUE; } - - -/** - * Creates a set of \c _EGLConfigs that a driver will expose. - * - * A set of \c __GLcontextModes will be created based on the supplied - * parameters. The number of modes processed will be 2 * - * \c num_depth_stencil_bits * \c num_db_modes. - * - * For the most part, data is just copied from \c depth_bits, \c stencil_bits, - * \c db_modes, and \c visType into each \c __GLcontextModes element. - * However, the meanings of \c fb_format and \c fb_type require further - * explanation. The \c fb_format specifies which color components are in - * each pixel and what the default order is. For example, \c GL_RGB specifies - * that red, green, blue are available and red is in the "most significant" - * position and blue is in the "least significant". The \c fb_type specifies - * the bit sizes of each component and the actual ordering. For example, if - * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11] - * are the blue value, bits [10:5] are the green value, and bits [4:0] are - * the red value. - * - * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either - * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the - * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or - * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as - * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8 - * still uses 32-bits. - * - * If in doubt, look at the tables used in the function. - * - * \param configs the array of configs generated - * \param fb_format Format of the framebuffer. Currently only \c GL_RGB, - * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported. - * \param fb_type Type of the pixels in the framebuffer. Currently only - * \c GL_UNSIGNED_SHORT_5_6_5, - * \c GL_UNSIGNED_SHORT_5_6_5_REV, - * \c GL_UNSIGNED_INT_8_8_8_8, and - * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported. - * \param depth_bits Array of depth buffer sizes to be exposed. - * \param stencil_bits Array of stencil buffer sizes to be exposed. - * \param num_depth_stencil_bits Number of entries in both \c depth_bits and - * \c stencil_bits. - * \param db_modes Array of buffer swap modes. If an element has a - * value of \c GLX_NONE, then it represents a - * single-buffered mode. Other valid values are - * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and - * \c GLX_SWAP_UNDEFINED_OML. See the - * GLX_OML_swap_method extension spec for more details. - * \param num_db_modes Number of entries in \c db_modes. - * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or - * \c GLX_DIRECT_COLOR. - * - * \returns - * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only - * cause of failure is a bad parameter (i.e., unsupported \c fb_format or - * \c fb_type). - * - * \todo - * There is currently no way to support packed RGB modes (i.e., modes with - * exactly 3 bytes per pixel) or floating-point modes. This could probably - * be done by creating some new, private enums with clever names likes - * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, - * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. - */ -EGLBoolean -_eglFillInConfigs(_EGLConfig * configs, - GLenum fb_format, GLenum fb_type, - const uint8_t * depth_bits, const uint8_t * stencil_bits, - unsigned num_depth_stencil_bits, - const GLenum * db_modes, unsigned num_db_modes, - int visType) -{ - static const uint8_t bits_table[3][4] = { - /* R G B A */ - { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */ - { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */ - { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */ - }; - - /* The following arrays are all indexed by the fb_type masked with 0x07. - * Given the four supported fb_type values, this results in valid array - * indices of 3, 4, 5, and 7. - */ - static const uint32_t masks_table_rgb[8][4] = { - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */ - {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */ - {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */ - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */ - }; - - static const uint32_t masks_table_rgba[8][4] = { - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */ - {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */ - {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */ - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */ - }; - -#if 0 - static const uint32_t masks_table_bgr[8][4] = { - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */ - {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */ - {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */ - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */ - }; - - static const uint32_t masks_table_bgra[8][4] = { - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */ - {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */ - {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */ - {0x00000000, 0x00000000, 0x00000000, 0x00000000}, - {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */ - }; -#endif - - static const uint8_t bytes_per_pixel[8] = { - 0, 0, 0, 2, 2, 4, 0, 4 - }; - - const uint8_t * bits; - const uint32_t * masks; - const int index = fb_type & 0x07; - _EGLConfig *config; - unsigned i; - unsigned j; - unsigned k; - - if ( bytes_per_pixel[index] == 0 ) { - _eglLog(_EGL_INFO, - "[_eglFillInConfigs:%u] Framebuffer type 0x%04x has 0 bytes per pixel.", - __LINE__, fb_type); - return GL_FALSE; - } - - /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and - * the _REV versions. - * - * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA. - */ - switch ( fb_format ) { - case GL_RGB: - bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1]; - masks = masks_table_rgb[index]; - break; - - case GL_RGBA: - bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2]; - masks = masks_table_rgba[index]; - break; - -#if 0 - case GL_BGR: - bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1]; - masks = masks_table_bgr[index]; - break; - - case GL_BGRA: - bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2]; - masks = masks_table_bgra[index]; - break; -#endif - - default: - _eglLog(_EGL_WARNING, - "[_eglFillInConfigs:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.", - __LINE__, fb_format); - return GL_FALSE; - } - - config = configs; - for (k = 0; k < num_depth_stencil_bits; k++) { - for (i = 0; i < num_db_modes; i++) { - for (j = 0; j < 2; j++) { - _eglSetConfigAttrib(config, EGL_RED_SIZE, bits[0]); - _eglSetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]); - _eglSetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]); - _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]); - _eglSetConfigAttrib(config, EGL_BUFFER_SIZE, - bits[0] + bits[1] + bits[2] + bits[3]); - - _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]); - _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[i]); - - _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA | - EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT); - - config++; - } - } - } - return GL_TRUE; -} - diff --git a/src/egl/main/eglconfigutil.h b/src/egl/main/eglconfigutil.h index 9f8906dedb..c6f4819960 100644 --- a/src/egl/main/eglconfigutil.h +++ b/src/egl/main/eglconfigutil.h @@ -16,14 +16,4 @@ _eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m, EGLint conformant, EGLint renderable_type); -PUBLIC EGLBoolean -_eglFillInConfigs( _EGLConfig *configs, - EGLenum fb_format, EGLenum fb_type, - const uint8_t * depth_bits, const uint8_t * stencil_bits, - unsigned num_depth_stencil_bits, - const EGLenum * db_modes, unsigned num_db_modes, - int visType ); - - - #endif /* EGLCONFIGUTIL_INCLUDED */ diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index ee4b1b59f5..012d8dfe1f 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -4,9 +4,96 @@ #include "eglconfig.h" #include "eglcontext.h" #include "egldisplay.h" -#include "egldriver.h" -#include "eglglobals.h" +#include "eglcurrent.h" #include "eglsurface.h" +#include "egllog.h" + + +/** + * Return the API bit (one of EGL_xxx_BIT) of the context. + */ +static EGLint +_eglGetContextAPIBit(_EGLContext *ctx) +{ + EGLint bit = 0; + + switch (ctx->ClientAPI) { + case EGL_OPENGL_ES_API: + switch (ctx->ClientVersion) { + case 1: + bit = EGL_OPENGL_ES_BIT; + break; + case 2: + bit = EGL_OPENGL_ES2_BIT; + break; + default: + break; + } + break; + case EGL_OPENVG_API: + bit = EGL_OPENVG_BIT; + break; + case EGL_OPENGL_API: + bit = EGL_OPENGL_BIT; + break; + default: + break; + } + + return bit; +} + + +/** + * Parse the list of context attributes and return the proper error code. + */ +static EGLint +_eglParseContextAttribList(_EGLContext *ctx, const EGLint *attrib_list) +{ + EGLenum api = ctx->ClientAPI; + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + case EGL_CONTEXT_CLIENT_VERSION: + if (api != EGL_OPENGL_ES_API) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val != 1 && val != 2) { + err = EGL_BAD_ATTRIBUTE; + break; + } + ctx->ClientVersion = val; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_DEBUG, "bad context attribute 0x%04x", attr); + break; + } + } + + if (err == EGL_SUCCESS) { + EGLint renderable_type, api_bit; + + renderable_type = GET_CONFIG_ATTRIB(ctx->Config, EGL_RENDERABLE_TYPE); + api_bit = _eglGetContextAPIBit(ctx); + if (!(renderable_type & api_bit)) + err = EGL_BAD_CONFIG; + } + + return err; +} /** @@ -14,11 +101,11 @@ * in the attrib_list. */ EGLBoolean -_eglInitContext(_EGLDriver *drv, _EGLContext *ctx, - _EGLConfig *conf, const EGLint *attrib_list) +_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf, + const EGLint *attrib_list) { - EGLint i; const EGLenum api = eglQueryAPI(); + EGLint err; if (api == EGL_NONE) { _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); @@ -26,26 +113,16 @@ _eglInitContext(_EGLDriver *drv, _EGLContext *ctx, } memset(ctx, 0, sizeof(_EGLContext)); + ctx->Resource.Display = dpy; + ctx->ClientAPI = api; + ctx->Config = conf; + ctx->WindowRenderBuffer = EGL_NONE; ctx->ClientVersion = 1; /* the default, per EGL spec */ - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - case EGL_CONTEXT_CLIENT_VERSION: - i++; - ctx->ClientVersion = attrib_list[i]; - break; - default: - _eglError(EGL_BAD_ATTRIBUTE, "_eglInitContext"); - return EGL_FALSE; - } - } - - ctx->Config = conf; - ctx->DrawSurface = EGL_NO_SURFACE; - ctx->ReadSurface = EGL_NO_SURFACE; - ctx->ClientAPI = api; - ctx->WindowRenderBuffer = EGL_NONE; + err = _eglParseContextAttribList(ctx, attrib_list); + if (err != EGL_SUCCESS) + return _eglError(err, "eglCreateContext"); return EGL_TRUE; } @@ -58,20 +135,6 @@ _EGLContext * _eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) { -#if 0 /* example code */ - _EGLContext *context; - - context = (_EGLContext *) calloc(1, sizeof(_EGLContext)); - if (!context) - return NULL; - - if (!_eglInitContext(drv, context, conf, attrib_list)) { - free(context); - return NULL; - } - - return context; -#endif return NULL; } @@ -140,99 +203,169 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c, /** - * Drivers will typically call this to do the error checking and - * update the various flags. - * Then, the driver will do its device-dependent Make-Current stuff. + * Bind the context to the surfaces. Return the surfaces that are "orphaned". + * That is, when the context is not NULL, return the surfaces it previously + * bound to; when the context is NULL, the same surfaces are returned. */ -EGLBoolean -_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, - _EGLSurface *read, _EGLContext *ctx) +static void +_eglBindContextToSurfaces(_EGLContext *ctx, + _EGLSurface **draw, _EGLSurface **read) +{ + _EGLSurface *newDraw = *draw, *newRead = *read; + + if (newDraw->CurrentContext) + newDraw->CurrentContext->DrawSurface = NULL; + newDraw->CurrentContext = ctx; + + if (newRead->CurrentContext) + newRead->CurrentContext->ReadSurface = NULL; + newRead->CurrentContext = ctx; + + if (ctx) { + *draw = ctx->DrawSurface; + ctx->DrawSurface = newDraw; + + *read = ctx->ReadSurface; + ctx->ReadSurface = newRead; + } +} + + +/** + * Bind the context to the thread and return the previous context. + * + * Note that the context may be NULL. + */ +static _EGLContext * +_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t) { - _EGLThreadInfo *t = _eglGetCurrentThread(); - _EGLContext *oldContext = NULL; - _EGLSurface *oldDrawSurface = NULL; - _EGLSurface *oldReadSurface = NULL; EGLint apiIndex; + _EGLContext *oldCtx; + + apiIndex = (ctx) ? + _eglConvertApiToIndex(ctx->ClientAPI) : t->CurrentAPIIndex; + + oldCtx = t->CurrentContexts[apiIndex]; + if (ctx == oldCtx) + return NULL; + + if (oldCtx) + oldCtx->Binding = NULL; + if (ctx) + ctx->Binding = t; + + t->CurrentContexts[apiIndex] = ctx; + + return oldCtx; +} + + +/** + * Return true if the given context and surfaces can be made current. + */ +static EGLBoolean +_eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint conflict_api; if (_eglIsCurrentThreadDummy()) return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent"); - if (ctx) { - /* error checking */ - if (ctx->Binding && ctx->Binding != t) - return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); - if (draw == NULL || read == NULL) + /* this is easy */ + if (!ctx) { + if (draw || read) return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); - if (draw->Config != ctx->Config || read->Config != ctx->Config) - return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); - if ((draw->Binding && draw->Binding->Binding != t) || - (read->Binding && read->Binding->Binding != t)) - return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + return EGL_TRUE; + } + + /* ctx/draw/read must be all given */ + if (draw == NULL || read == NULL) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + + /* context stealing from another thread is not allowed */ + if (ctx->Binding && ctx->Binding != t) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + + /* + * The spec says + * + * "If ctx is current to some other thread, or if either draw or read are + * bound to contexts in another thread, an EGL_BAD_ACCESS error is + * generated." + * + * But it also says + * + * "at most one context may be bound to a particular surface at a given + * time" + * + * The latter is more restrictive so we can check only the latter case. + */ + if ((draw->CurrentContext && draw->CurrentContext != ctx) || + (read->CurrentContext && read->CurrentContext != ctx)) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + /* simply require the configs to be equal */ + if (draw->Config != ctx->Config || read->Config != ctx->Config) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + + switch (ctx->ClientAPI) { #ifdef EGL_VERSION_1_4 - /* OpenGL and OpenGL ES are conflicting */ - switch (ctx->ClientAPI) { - case EGL_OPENGL_ES_API: - if (t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_API)]) - return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); - break; - case EGL_OPENGL_API: - if (t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_ES_API)]) - return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); - break; - default: - break; - } + /* OpenGL and OpenGL ES are conflicting */ + case EGL_OPENGL_ES_API: + conflict_api = EGL_OPENGL_API; + break; + case EGL_OPENGL_API: + conflict_api = EGL_OPENGL_ES_API; + break; #endif - apiIndex = _eglConvertApiToIndex(ctx->ClientAPI); - } - else { - if (draw != NULL || read != NULL) - return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); - apiIndex = t->CurrentAPIIndex; + default: + conflict_api = -1; + break; } - oldContext = t->CurrentContexts[apiIndex]; - if (oldContext) { - oldDrawSurface = oldContext->DrawSurface; - oldReadSurface = oldContext->ReadSurface; - assert(oldDrawSurface); - assert(oldReadSurface); - - /* break old bindings */ - t->CurrentContexts[apiIndex] = NULL; - oldContext->Binding = NULL; - oldContext->DrawSurface = NULL; - oldContext->ReadSurface = NULL; - oldDrawSurface->Binding = NULL; - oldReadSurface->Binding = NULL; + if (conflict_api >= 0 && _eglGetAPIContext(conflict_api)) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + + return EGL_TRUE; +} + + +/** + * Bind the context to the current thread and given surfaces. Return the + * previously bound context and the surfaces it bound to. Each argument is + * both input and output. + */ +EGLBoolean +_eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + _EGLContext *newCtx = *ctx, *oldCtx; + + if (!_eglCheckMakeCurrent(newCtx, *draw, *read)) + return EGL_FALSE; + + /* bind the new context */ + oldCtx = _eglBindContextToThread(newCtx, t); + *ctx = oldCtx; + if (newCtx) + _eglBindContextToSurfaces(newCtx, draw, read); + /* unbind the old context from its binding surfaces */ + if (oldCtx) { /* - * check if the old context or surfaces need to be deleted + * If the new context replaces some old context, the new one should not + * be current before the replacement and it should not be bound to any + * surface. */ - if (!_eglIsSurfaceLinked(oldDrawSurface)) { - assert(draw != oldDrawSurface && read != oldDrawSurface); - drv->API.DestroySurface(drv, dpy, oldDrawSurface); - } - if (oldReadSurface != oldDrawSurface && - !_eglIsSurfaceLinked(oldReadSurface)) { - assert(draw != oldReadSurface && read != oldReadSurface); - drv->API.DestroySurface(drv, dpy, oldReadSurface); - } - if (!_eglIsContextLinked(oldContext)) { - assert(ctx != oldContext); - drv->API.DestroyContext(drv, dpy, oldContext); - } - } + if (newCtx) + assert(!*draw && !*read); - /* build new bindings */ - if (ctx) { - t->CurrentContexts[apiIndex] = ctx; - ctx->Binding = t; - ctx->DrawSurface = draw; - ctx->ReadSurface = read; - draw->Binding = ctx; - read->Binding = ctx; + *draw = oldCtx->DrawSurface; + *read = oldCtx->ReadSurface; + assert(*draw && *read); + + _eglBindContextToSurfaces(NULL, draw, read); } return EGL_TRUE; @@ -240,6 +373,17 @@ _eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, /** + * Just a placeholder/demo function. Drivers should override this. + */ +EGLBoolean +_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, + _EGLSurface *read, _EGLContext *ctx) +{ + return EGL_FALSE; +} + + +/** * This is defined by the EGL_MESA_copy_context extension. */ EGLBoolean diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index cb9e3f4a89..cfe92dd9f5 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -1,9 +1,9 @@ - #ifndef EGLCONTEXT_INCLUDED #define EGLCONTEXT_INCLUDED #include "egltypedefs.h" +#include "egldisplay.h" /** @@ -11,9 +11,8 @@ */ struct _egl_context { - /* Managed by EGLDisplay for linking */ - _EGLDisplay *Display; - _EGLContext *Next; + /* A context is a display resource */ + _EGLResource Resource; /* The bound status of the context */ _EGLThreadInfo *Binding; @@ -31,7 +30,7 @@ struct _egl_context PUBLIC EGLBoolean -_eglInitContext(_EGLDriver *drv, _EGLContext *ctx, +_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); @@ -48,6 +47,10 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint att PUBLIC EGLBoolean +_eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read); + + +extern EGLBoolean _eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); @@ -57,6 +60,9 @@ _eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLConte /** * Return true if the context is bound to a thread. + * + * The binding is considered a reference to the context. Drivers should not + * destroy a context when it is bound. */ static INLINE EGLBoolean _eglIsContextBound(_EGLContext *ctx) @@ -65,4 +71,67 @@ _eglIsContextBound(_EGLContext *ctx) } +/** + * Link a context to a display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLContext +_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy) +{ + _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy); + return (EGLContext) ctx; +} + + +/** + * Unlink a linked context from its display. + * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. + */ +static INLINE void +_eglUnlinkContext(_EGLContext *ctx) +{ + _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); +} + + +/** + * Lookup a handle to find the linked context. + * Return NULL if the handle has no corresponding linked context. + */ +static INLINE _EGLContext * +_eglLookupContext(EGLContext context, _EGLDisplay *dpy) +{ + _EGLContext *ctx = (_EGLContext *) context; + if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy)) + ctx = NULL; + return ctx; +} + + +/** + * Return the handle of a linked context, or EGL_NO_CONTEXT. + */ +static INLINE EGLContext +_eglGetContextHandle(_EGLContext *ctx) +{ + _EGLResource *res = (_EGLResource *) ctx; + return (res && _eglIsResourceLinked(res)) ? + (EGLContext) ctx : EGL_NO_CONTEXT; +} + + +/** + * Return true if the context is linked to a display. + * + * The link is considered a reference to the context (the display is owning the + * context). Drivers should not destroy a context when it is linked. + */ +static INLINE EGLBoolean +_eglIsContextLinked(_EGLContext *ctx) +{ + _EGLResource *res = (_EGLResource *) ctx; + return (res && _eglIsResourceLinked(res)); +} + + #endif /* EGLCONTEXT_INCLUDED */ diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index df506151b5..989c19a2fa 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -1,10 +1,9 @@ #include <stdlib.h> #include <string.h> -#include "eglcurrent.h" -#include "eglcontext.h" +#include "eglglobals.h" #include "egllog.h" #include "eglmutex.h" -#include "eglglobals.h" +#include "eglcurrent.h" /* This should be kept in sync with _eglInitThreadInfo() */ @@ -227,50 +226,24 @@ _eglIsCurrentThreadDummy(void) /** - * Return the currently bound context, or NULL. - */ -_EGLContext * -_eglGetCurrentContext(void) -{ - _EGLThreadInfo *t = _eglGetCurrentThread(); - return t->CurrentContexts[t->CurrentAPIIndex]; -} - - -/** - * Return the display of the currently bound context, or NULL. + * Return the currently bound context of the given API, or NULL. */ -_EGLDisplay * -_eglGetCurrentDisplay(void) +PUBLIC _EGLContext * +_eglGetAPIContext(EGLenum api) { _EGLThreadInfo *t = _eglGetCurrentThread(); - _EGLContext *ctx = t->CurrentContexts[t->CurrentAPIIndex]; - if (ctx) - return ctx->Display; - else - return NULL; + return t->CurrentContexts[_eglConvertApiToIndex(api)]; } /** - * Return the read or write surface of the currently bound context, or NULL. + * Return the currently bound context of the current API, or NULL. */ -_EGLSurface * -_eglGetCurrentSurface(EGLint readdraw) +_EGLContext * +_eglGetCurrentContext(void) { _EGLThreadInfo *t = _eglGetCurrentThread(); - _EGLContext *ctx = t->CurrentContexts[t->CurrentAPIIndex]; - if (ctx) { - switch (readdraw) { - case EGL_DRAW: - return ctx->DrawSurface; - case EGL_READ: - return ctx->ReadSurface; - default: - return NULL; - } - } - return NULL; + return t->CurrentContexts[t->CurrentAPIIndex]; } diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h index c4478b3891..e5c94ce60a 100644 --- a/src/egl/main/eglcurrent.h +++ b/src/egl/main/eglcurrent.h @@ -1,6 +1,7 @@ #ifndef EGLCURRENT_INCLUDED #define EGLCURRENT_INCLUDED + #include "egltypedefs.h" @@ -73,15 +74,11 @@ _eglIsCurrentThreadDummy(void); PUBLIC _EGLContext * -_eglGetCurrentContext(void); - +_eglGetAPIContext(EGLenum api); -PUBLIC _EGLDisplay * -_eglGetCurrentDisplay(void); - -PUBLIC _EGLSurface * -_eglGetCurrentSurface(EGLint readdraw); +PUBLIC _EGLContext * +_eglGetCurrentContext(void); PUBLIC EGLBoolean diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 896d60dbe1..d7a8d14292 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -10,7 +10,6 @@ #include "egldisplay.h" #include "egldriver.h" #include "eglglobals.h" -#include "eglstring.h" #include "eglmutex.h" #include "egllog.h" @@ -26,12 +25,18 @@ _eglFiniDisplay(void) /* atexit function is called with global mutex locked */ dpyList = _eglGlobal.DisplayList; while (dpyList) { + EGLint i; + /* pop list head */ dpy = dpyList; dpyList = dpyList->Next; - if (dpy->ContextList || dpy->SurfaceList) - _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy); + for (i = 0; i < _EGL_NUM_RESOURCES; i++) { + if (dpy->ResourceLists[i]) { + _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy); + break; + } + } free(dpy); } @@ -40,53 +45,17 @@ _eglFiniDisplay(void) /** - * If the first character is '!' we interpret it as specific driver name - * (i.e. "!r200" or "!i830"). Whatever follows ':' is interpreted as - * arguments. - * - * The caller may free() the returned driver name. - */ -char * -_eglSplitDisplayString(const char *dpyString, const char **args) -{ - char *drv, *p; - - if (!dpyString || dpyString[0] != '!') - return NULL; - drv = _eglstrdup(dpyString + 1); - if (!drv) - return NULL; - - p = strchr(dpyString, ':'); - if (p) { - drv[p - dpyString] = '\0'; - p++; - } - if (args) - *args = p; - - return drv; -} - - -/** * Allocate a new _EGLDisplay object for the given nativeDisplay handle. * We'll also try to determine the device driver name at this time. * * Note that nativeDisplay may be an X Display ptr, or a string. */ _EGLDisplay * -_eglNewDisplay(NativeDisplayType nativeDisplay) +_eglNewDisplay(EGLNativeDisplayType nativeDisplay) { _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); if (dpy) { dpy->NativeDisplay = nativeDisplay; - - dpy->DriverName = _eglPreloadDriver(dpy); - if (!dpy->DriverName) { - free(dpy); - return NULL; - } } return dpy; } @@ -144,7 +113,7 @@ _eglUnlinkDisplay(_EGLDisplay *dpy) * linked displays. */ _EGLDisplay * -_eglFindDisplay(NativeDisplayType nativeDisplay) +_eglFindDisplay(EGLNativeDisplayType nativeDisplay) { _EGLDisplay *dpy; @@ -171,29 +140,27 @@ _eglFindDisplay(NativeDisplayType nativeDisplay) void _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display) { - _EGLContext *contexts; - _EGLSurface *surfaces; - - contexts = display->ContextList; - surfaces = display->SurfaceList; + _EGLResource *list; - while (contexts) { - _EGLContext *ctx = contexts; - contexts = contexts->Next; + list = display->ResourceLists[_EGL_RESOURCE_CONTEXT]; + while (list) { + _EGLContext *ctx = (_EGLContext *) list; + list = list->Next; _eglUnlinkContext(ctx); drv->API.DestroyContext(drv, display, ctx); } - assert(!display->ContextList); + assert(!display->ResourceLists[_EGL_RESOURCE_CONTEXT]); - while (surfaces) { - _EGLSurface *surf = surfaces; - surfaces = surfaces->Next; + list = display->ResourceLists[_EGL_RESOURCE_SURFACE]; + while (list) { + _EGLSurface *surf = (_EGLSurface *) list; + list = list->Next; _eglUnlinkSurface(surf); drv->API.DestroySurface(drv, display, surf); } - assert(!display->SurfaceList); + assert(!display->ResourceLists[_EGL_RESOURCE_SURFACE]); } @@ -212,97 +179,13 @@ _eglCleanupDisplay(_EGLDisplay *disp) free(disp->Configs); disp->Configs = NULL; disp->NumConfigs = 0; + disp->MaxConfigs = 0; } /* XXX incomplete */ } -/** - * Link a context to a display and return the handle of the link. - * The handle can be passed to client directly. - */ -EGLContext -_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy) -{ - ctx->Display = dpy; - ctx->Next = dpy->ContextList; - dpy->ContextList = ctx; - return (EGLContext) ctx; -} - - -/** - * Unlink a linked context from its display. - * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. - */ -void -_eglUnlinkContext(_EGLContext *ctx) -{ - _EGLContext *prev; - - prev = ctx->Display->ContextList; - if (prev != ctx) { - while (prev) { - if (prev->Next == ctx) - break; - prev = prev->Next; - } - assert(prev); - prev->Next = ctx->Next; - } - else { - ctx->Display->ContextList = ctx->Next; - } - - ctx->Next = NULL; - ctx->Display = NULL; -} - - -/** - * Link a surface to a display and return the handle of the link. - * The handle can be passed to client directly. - */ -EGLSurface -_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy) -{ - surf->Display = dpy; - surf->Next = dpy->SurfaceList; - dpy->SurfaceList = surf; - return (EGLSurface) surf; -} - - -/** - * Unlink a linked surface from its display. - * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. - */ -void -_eglUnlinkSurface(_EGLSurface *surf) -{ - _EGLSurface *prev; - - prev = surf->Display->SurfaceList; - if (prev != surf) { - while (prev) { - if (prev->Next == surf) - break; - prev = prev->Next; - } - assert(prev); - prev->Next = surf->Next; - } - else { - prev = NULL; - surf->Display->SurfaceList = surf->Next; - } - - surf->Next = NULL; - surf->Display = NULL; -} - - #ifndef _EGL_SKIP_HANDLE_CHECK @@ -327,45 +210,70 @@ _eglCheckDisplayHandle(EGLDisplay dpy) /** - * Return EGL_TRUE if the given handle is a valid handle to a context. + * Return EGL_TRUE if the given resource is valid. That is, the display does + * own the resource. */ EGLBoolean -_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy) { - _EGLContext *cur = NULL; - - if (dpy) - cur = dpy->ContextList; - while (cur) { - if (cur == (_EGLContext *) ctx) { - assert(cur->Display == dpy); + _EGLResource *list = dpy->ResourceLists[type]; + + if (!res) + return EGL_FALSE; + + while (list) { + if (res == (void *) list) { + assert(list->Display == dpy); break; } - cur = cur->Next; + list = list->Next; } - return (cur != NULL); + + return (list != NULL); } +#endif /* !_EGL_SKIP_HANDLE_CHECK */ + + /** - * Return EGL_TRUE if the given handle is a valid handle to a surface. + * Link a resource to a display. */ -EGLBoolean -_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) +void +_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy) { - _EGLSurface *cur = NULL; + assert(!res->Display || res->Display == dpy); - if (dpy) - cur = dpy->SurfaceList; - while (cur) { - if (cur == (_EGLSurface *) surf) { - assert(cur->Display == dpy); - break; - } - cur = cur->Next; - } - return (cur != NULL); + res->Display = dpy; + res->IsLinked = EGL_TRUE; + res->Next = dpy->ResourceLists[type]; + dpy->ResourceLists[type] = res; } -#endif /* !_EGL_SKIP_HANDLE_CHECK */ +/** + * Unlink a linked resource from its display. + */ +void +_eglUnlinkResource(_EGLResource *res, _EGLResourceType type) +{ + _EGLResource *prev; + + prev = res->Display->ResourceLists[type]; + if (prev != res) { + while (prev) { + if (prev->Next == res) + break; + prev = prev->Next; + } + assert(prev); + prev->Next = res->Next; + } + else { + res->Display->ResourceLists[type] = res->Next; + } + + res->Next = NULL; + /* do not reset res->Display */ + res->IsLinked = EGL_FALSE; +} diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 4f619e5371..03903290fd 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -1,10 +1,32 @@ #ifndef EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED + #include "egltypedefs.h" #include "egldefines.h" -#include "eglcontext.h" -#include "eglsurface.h" + + +enum _egl_resource_type { + _EGL_RESOURCE_CONTEXT, + _EGL_RESOURCE_SURFACE, + _EGL_RESOURCE_IMAGE, + + _EGL_NUM_RESOURCES +}; + + +/** + * A resource of a display. + */ +struct _egl_resource +{ + /* which display the resource belongs to */ + _EGLDisplay *Display; + EGLBoolean IsLinked; + + /* used to link resources of the same type */ + _EGLResource *Next; +}; /** @@ -14,6 +36,13 @@ struct _egl_extensions { EGLBoolean MESA_screen_surface; EGLBoolean MESA_copy_context; + EGLBoolean KHR_image_base; + EGLBoolean KHR_image_pixmap; + EGLBoolean KHR_vg_parent_image; + EGLBoolean KHR_gl_texture_2D_image; + EGLBoolean KHR_gl_texture_cubemap_image; + EGLBoolean KHR_gl_texture_3D_image; + EGLBoolean KHR_gl_renderbuffer_image; char String[_EGL_MAX_EXTENSIONS_LEN]; }; @@ -26,7 +55,7 @@ struct _egl_display EGLNativeDisplayType NativeDisplay; - const char *DriverName; + EGLBoolean Initialized; /**< True if the display is initialized */ _EGLDriver *Driver; void *DriverData; /* private to driver */ @@ -39,8 +68,6 @@ struct _egl_display _EGLExtensions Extensions; - int LargestPbuffer; - EGLint NumScreens; _EGLScreen **Screens; /* array [NumScreens] */ @@ -48,9 +75,8 @@ struct _egl_display EGLint NumConfigs; _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */ - /* lists of linked contexts and surface */ - _EGLContext *ContextList; - _EGLSurface *SurfaceList; + /* lists of resources */ + _EGLResource *ResourceLists[_EGL_NUM_RESOURCES]; }; @@ -58,12 +84,8 @@ extern void _eglFiniDisplay(void); -extern char * -_eglSplitDisplayString(const char *dpyString, const char **args); - - extern _EGLDisplay * -_eglNewDisplay(NativeDisplayType displayName); +_eglNewDisplay(EGLNativeDisplayType displayName); extern EGLDisplay @@ -75,7 +97,7 @@ _eglUnlinkDisplay(_EGLDisplay *dpy); extern _EGLDisplay * -_eglFindDisplay(NativeDisplayType nativeDisplay); +_eglFindDisplay(EGLNativeDisplayType nativeDisplay); PUBLIC void @@ -86,22 +108,6 @@ PUBLIC void _eglCleanupDisplay(_EGLDisplay *disp); -extern EGLContext -_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy); - - -extern void -_eglUnlinkContext(_EGLContext *ctx); - - -extern EGLSurface -_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy); - - -extern void -_eglUnlinkSurface(_EGLSurface *surf); - - #ifndef _EGL_SKIP_HANDLE_CHECK @@ -109,12 +115,8 @@ extern EGLBoolean _eglCheckDisplayHandle(EGLDisplay dpy); -extern EGLBoolean -_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy); - - -extern EGLBoolean -_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy); +PUBLIC EGLBoolean +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy); #else /* !_EGL_SKIP_HANDLE_CHECK */ @@ -129,18 +131,9 @@ _eglCheckDisplayHandle(EGLDisplay dpy) static INLINE EGLBoolean -_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy); { - _EGLContext *c = (_EGLContext *) ctx; - return (dpy && c && c->Display == dpy); -} - - -static INLINE EGLBoolean -_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) -{ - _EGLSurface *s = (_EGLSurface *) surf; - return (dpy && s && s->Display == dpy); + return (((_EGLResource *) res)->Display == dpy); } @@ -181,92 +174,21 @@ _eglIsDisplayLinked(_EGLDisplay *dpy) } -/** - * Lookup a handle to find the linked context. - * Return NULL if the handle has no corresponding linked context. - */ -static INLINE _EGLContext * -_eglLookupContext(EGLContext context, _EGLDisplay *dpy) -{ - _EGLContext *ctx = (_EGLContext *) context; - if (!_eglCheckContextHandle(context, dpy)) - ctx = NULL; - return ctx; -} - - -/** - * Return the handle of a linked context, or EGL_NO_CONTEXT. - */ -static INLINE EGLContext -_eglGetContextHandle(_EGLContext *ctx) -{ - return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT); -} - - -/** - * Return true if the context is linked to a display. - */ -static INLINE EGLBoolean -_eglIsContextLinked(_EGLContext *ctx) -{ - return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT); -} - - -/** - * Lookup a handle to find the linked surface. - * Return NULL if the handle has no corresponding linked surface. - */ -static INLINE _EGLSurface * -_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) -{ - _EGLSurface *surf = (_EGLSurface *) surface; - if (!_eglCheckSurfaceHandle(surf, dpy)) - surf = NULL; - return surf; -} +extern void +_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy); -/** - * Return the handle of a linked surface, or EGL_NO_SURFACE. - */ -static INLINE EGLSurface -_eglGetSurfaceHandle(_EGLSurface *surf) -{ - return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE); -} +extern void +_eglUnlinkResource(_EGLResource *res, _EGLResourceType type); /** - * Return true if the surface is linked to a display. + * Return true if the resource is linked. */ static INLINE EGLBoolean -_eglIsSurfaceLinked(_EGLSurface *surf) -{ - return (EGLBoolean) (_eglGetSurfaceHandle(surf) != EGL_NO_SURFACE); -} - - -/** - * Cast an unsigned int to a pointer. - */ -static INLINE void * -_eglUIntToPointer(unsigned int v) -{ - return (void *) ((uintptr_t) v); -} - - -/** - * Cast a pointer to an unsigned int. The pointer must be one that is - * returned by _eglUIntToPointer. - */ -static INLINE unsigned int -_eglPointerToUInt(const void *p) +_eglIsResourceLinked(_EGLResource *res) { - return (unsigned int) ((uintptr_t) p); + return res->IsLinked; } diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 018b06d3be..a87c697b11 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -19,9 +19,13 @@ #include "eglscreen.h" #include "eglstring.h" #include "eglsurface.h" +#include "eglimage.h" -#if defined(_EGL_PLATFORM_X) +#if defined(_EGL_PLATFORM_POSIX) #include <dlfcn.h> +#include <sys/types.h> +#include <dirent.h> +#include <unistd.h> #endif @@ -49,10 +53,17 @@ close_library(HMODULE lib) } -#elif defined(_EGL_PLATFORM_X) +static const char * +library_suffix(void) +{ + return ".dll"; +} + + +#elif defined(_EGL_PLATFORM_POSIX) -static const char DefaultDriverName[] = "egl_softpipe"; +static const char DefaultDriverName[] = "egl_glx"; typedef void * lib_handle; @@ -68,8 +79,17 @@ close_library(void *lib) dlclose(lib); } + +static const char * +library_suffix(void) +{ + return ".so"; +} + + #else /* _EGL_PLATFORM_NO_OS */ + static const char DefaultDriverName[] = "builtin"; typedef void *lib_handle; @@ -86,67 +106,21 @@ close_library(void *lib) } -#endif +static const char * +library_suffix(void) +{ + return NULL; +} -/** - * Choose a driver for a given display. - * The caller may free() the returned strings. - */ -static char * -_eglChooseDriver(_EGLDisplay *dpy, char **argsRet) -{ - char *path = NULL; - const char *args = NULL; - const char *suffix = NULL; - const char *p; - - path = getenv("EGL_DRIVER"); - if (path) - path = _eglstrdup(path); - -#if defined(_EGL_PLATFORM_X) - if (!path && dpy && dpy->NativeDisplay) { - /* assume (wrongly!) that the native display is a display string */ - path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args); - } - suffix = "so"; -#elif defined(_EGL_PLATFORM_WINDOWS) - suffix = "dll"; -#else /* _EGL_PLATFORM_NO_OS */ - if (path) { - /* force the use of the default driver */ - _eglLog(_EGL_DEBUG, "ignore EGL_DRIVER"); - free(path); - path = NULL; - } - suffix = NULL; #endif - if (!path) - path = _eglstrdup(DefaultDriverName); - - /* append suffix if there isn't */ - p = strrchr(path, '.'); - if (!p && suffix) { - size_t len = strlen(path); - char *tmp = malloc(len + strlen(suffix) + 2); - if (tmp) { - memcpy(tmp, path, len); - tmp[len++] = '.'; - tmp[len] = '\0'; - strcat(tmp + len, suffix); - - free(path); - path = tmp; - } - } - - if (argsRet) - *argsRet = (args) ? _eglstrdup(args) : NULL; - return path; -} +#define NUM_PROBE_CACHE_SLOTS 8 +static struct { + EGLint keys[NUM_PROBE_CACHE_SLOTS]; + const void *values[NUM_PROBE_CACHE_SLOTS]; +} _eglProbeCache; /** @@ -168,7 +142,7 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle) /* XXX untested */ if (lib) mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); -#elif defined(_EGL_PLATFORM_X) +#elif defined(_EGL_PLATFORM_POSIX) if (lib) { mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain"); if (!mainFunc) @@ -208,11 +182,10 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle) /** - * Load the named driver. The path and args passed will be - * owned by the driver and freed. + * Load the named driver. */ static _EGLDriver * -_eglLoadDriver(char *path, char *args) +_eglLoadDriver(const char *path, const char *args) { _EGLMain_t mainFunc; lib_handle lib; @@ -234,8 +207,19 @@ _eglLoadDriver(char *path, char *args) drv->Name = "UNNAMED"; } - drv->Path = path; - drv->Args = args; + drv->Path = _eglstrdup(path); + drv->Args = (args) ? _eglstrdup(args) : NULL; + if (!drv->Path || (args && !drv->Args)) { + if (drv->Path) + free((char *) drv->Path); + if (drv->Args) + free((char *) drv->Args); + drv->Unload(drv); + if (lib) + close_library(lib); + return NULL; + } + drv->LibHandle = lib; return drv; @@ -244,89 +228,316 @@ _eglLoadDriver(char *path, char *args) /** * Match a display to a preloaded driver. + * + * The matching is done by finding the driver with the highest score. */ -static _EGLDriver * +_EGLDriver * _eglMatchDriver(_EGLDisplay *dpy) { - _EGLDriver *defaultDriver = NULL; - EGLint i; + _EGLDriver *best_drv = NULL; + EGLint best_score = -1, i; for (i = 0; i < _eglGlobal.NumDrivers; i++) { _EGLDriver *drv = _eglGlobal.Drivers[i]; + EGLint score; + + score = (drv->Probe) ? drv->Probe(drv, dpy) : 0; + if (score > best_score) { + if (best_drv) { + _eglLog(_EGL_DEBUG, "driver %s has higher score than %s", + drv->Name, best_drv->Name); + } + + best_drv = drv; + best_score = score; + /* perfect match */ + if (score >= 100) + break; + } + } + + return best_drv; +} - /* display specifies a driver */ - if (dpy->DriverName) { - if (strcmp(dpy->DriverName, drv->Name) == 0) - return drv; + +/** + * A loader function for use with _eglPreloadForEach. The loader data is the + * filename of the driver. This function stops on the first valid driver. + */ +static EGLBoolean +_eglLoaderFile(const char *dir, size_t len, void *loader_data) +{ + _EGLDriver *drv; + char path[1024]; + const char *filename = (const char *) loader_data; + size_t flen = strlen(filename); + + /* make a full path */ + if (len + flen + 2 > sizeof(path)) + return EGL_TRUE; + if (len) { + memcpy(path, dir, len); + path[len++] = '/'; + } + memcpy(path + len, filename, flen); + len += flen; + path[len] = '\0'; + + drv = _eglLoadDriver(path, NULL); + /* fix the path and load again */ + if (!drv && library_suffix()) { + const char *suffix = library_suffix(); + size_t slen = strlen(suffix); + const char *p; + EGLBoolean need_suffix; + + p = filename + flen - slen; + need_suffix = (p < filename || strcmp(p, suffix) != 0); + if (need_suffix && len + slen + 1 <= sizeof(path)) { + strcpy(path + len, suffix); + drv = _eglLoadDriver(path, NULL); } - else if (drv->Probe) { - if (drv->Probe(drv, dpy)) - return drv; + } + if (!drv) + return EGL_TRUE; + + /* remember the driver and stop */ + _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv; + return EGL_FALSE; +} + + +/** + * A loader function for use with _eglPreloadForEach. The loader data is the + * pattern (prefix) of the files to look for. + */ +static EGLBoolean +_eglLoaderPattern(const char *dir, size_t len, void *loader_data) +{ +#if defined(_EGL_PLATFORM_POSIX) + const char *prefix, *suffix; + size_t prefix_len, suffix_len; + DIR *dirp; + struct dirent *dirent; + char path[1024]; + + if (len + 2 > sizeof(path)) + return EGL_TRUE; + if (len) { + memcpy(path, dir, len); + path[len++] = '/'; + } + path[len] = '\0'; + + dirp = opendir(path); + if (!dirp) + return EGL_TRUE; + + prefix = (const char *) loader_data; + prefix_len = strlen(prefix); + suffix = library_suffix(); + suffix_len = (suffix) ? strlen(suffix) : 0; + + while ((dirent = readdir(dirp))) { + _EGLDriver *drv; + size_t dirent_len = strlen(dirent->d_name); + const char *p; + + /* match the prefix */ + if (strncmp(dirent->d_name, prefix, prefix_len) != 0) + continue; + /* match the suffix */ + if (suffix) { + p = dirent->d_name + dirent_len - suffix_len; + if (p < dirent->d_name || strcmp(p, suffix) != 0) + continue; } - else { - if (!defaultDriver) - defaultDriver = drv; + + /* make a full path and load the driver */ + if (len + dirent_len + 1 <= sizeof(path)) { + strcpy(path + len, dirent->d_name); + drv = _eglLoadDriver(path, NULL); + if (drv) + _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv; } } - return defaultDriver; + closedir(dirp); + + return EGL_TRUE; +#else /* _EGL_PLATFORM_POSIX */ + /* stop immediately */ + return EGL_FALSE; +#endif } /** - * Load a driver and save it. + * Run the preload function on each driver directory and return the number of + * drivers loaded. + * + * The process may end prematurely if the callback function returns false. */ -const char * -_eglPreloadDriver(_EGLDisplay *dpy) +static EGLint +_eglPreloadForEach(const char *search_path, + EGLBoolean (*loader)(const char *, size_t, void *), + void *loader_data) { - char *path, *args; - _EGLDriver *drv; - EGLint i; + const char *cur, *next; + size_t len; + EGLint num_drivers = _eglGlobal.NumDrivers; - path = _eglChooseDriver(dpy, &args); - if (!path) - return NULL; + cur = search_path; + while (cur) { + next = strchr(cur, ':'); + len = (next) ? next - cur : strlen(cur); - for (i = 0; i < _eglGlobal.NumDrivers; i++) { - drv = _eglGlobal.Drivers[i]; - if (strcmp(drv->Path, path) == 0) { - _eglLog(_EGL_DEBUG, "Driver %s is already preloaded", - drv->Name); - free(path); - if (args) - free(args); - return drv->Name; + if (!loader(cur, len, loader_data)) + break; + + cur = (next) ? next + 1 : NULL; + } + + return (_eglGlobal.NumDrivers - num_drivers); +} + + +/** + * Return a list of colon-separated driver directories. + */ +static const char * +_eglGetSearchPath(void) +{ + static const char *search_path; + +#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS) + if (!search_path) { + static char buffer[1024]; + const char *p; + int ret; + + p = getenv("EGL_DRIVERS_PATH"); +#if defined(_EGL_PLATFORM_POSIX) + if (p && (geteuid() != getuid() || getegid() != getgid())) { + _eglLog(_EGL_DEBUG, + "ignore EGL_DRIVERS_PATH for setuid/setgid binaries"); + p = NULL; + } +#endif /* _EGL_PLATFORM_POSIX */ + + if (p) { + ret = snprintf(buffer, sizeof(buffer), + "%s:%s", p, _EGL_DRIVER_SEARCH_DIR); + if (ret > 0 && ret < sizeof(buffer)) + search_path = buffer; } } + if (!search_path) + search_path = _EGL_DRIVER_SEARCH_DIR; +#else + search_path = ""; +#endif - drv = _eglLoadDriver(path, args); - if (!drv) - return NULL; + return search_path; +} - _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv; - return drv->Name; +/** + * Preload a user driver. + * + * A user driver can be specified by EGL_DRIVER. + */ +static EGLBoolean +_eglPreloadUserDriver(void) +{ + const char *search_path = _eglGetSearchPath(); + char *env; + + env = getenv("EGL_DRIVER"); +#if defined(_EGL_PLATFORM_POSIX) + if (env && strchr(env, '/')) { + search_path = ""; + if ((geteuid() != getuid() || getegid() != getgid())) { + _eglLog(_EGL_DEBUG, + "ignore EGL_DRIVER for setuid/setgid binaries"); + env = NULL; + } + } +#endif /* _EGL_PLATFORM_POSIX */ + if (!env) + return EGL_FALSE; + + if (!_eglPreloadForEach(search_path, _eglLoaderFile, (void *) env)) { + _eglLog(_EGL_WARNING, "EGL_DRIVER is set to an invalid driver"); + return EGL_FALSE; + } + + return EGL_TRUE; } /** - * Open a preloaded driver. + * Preload display drivers. + * + * Display drivers are a set of drivers that support a certain display system. + * The display system may be specified by EGL_DISPLAY. + * + * FIXME This makes libEGL a memory hog if an user driver is not specified and + * there are many display drivers. */ -_EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy) +static EGLBoolean +_eglPreloadDisplayDrivers(void) { - _EGLDriver *drv = _eglMatchDriver(dpy); - return drv; + const char *dpy; + char prefix[32]; + int ret; + + dpy = getenv("EGL_DISPLAY"); + if (!dpy || !dpy[0]) + dpy = _EGL_DEFAULT_DISPLAY; + if (!dpy || !dpy[0]) + return EGL_FALSE; + + ret = snprintf(prefix, sizeof(prefix), "egl_%s_", dpy); + if (ret < 0 || ret >= sizeof(prefix)) + return EGL_FALSE; + + return (_eglPreloadForEach(_eglGetSearchPath(), + _eglLoaderPattern, (void *) prefix) > 0); +} + + +/** + * Preload the default driver. + */ +static EGLBoolean +_eglPreloadDefaultDriver(void) +{ + return (_eglPreloadForEach(_eglGetSearchPath(), + _eglLoaderFile, (void *) DefaultDriverName) > 0); } /** - * Close a preloaded driver. + * Preload drivers. + * + * This function loads the driver modules and creates the corresponding + * _EGLDriver objects. */ EGLBoolean -_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy) +_eglPreloadDrivers(void) { - return EGL_TRUE; + EGLBoolean loaded; + + /* already preloaded */ + if (_eglGlobal.NumDrivers) + return EGL_TRUE; + + loaded = (_eglPreloadUserDriver() || + _eglPreloadDisplayDrivers() || + _eglPreloadDefaultDriver()); + + return loaded; } @@ -360,20 +571,6 @@ _eglUnloadDrivers(void) /** - * Given a display handle, return the _EGLDriver for that display. - */ -_EGLDriver * -_eglLookupDriver(EGLDisplay dpy) -{ - _EGLDisplay *d = _eglLookupDisplay(dpy); - if (d) - return d->Driver; - else - return NULL; -} - - -/** * Plug all the available fallback routines into the given driver's * dispatch table. */ @@ -428,56 +625,50 @@ _eglInitDriverFallbacks(_EGLDriver *drv) #ifdef EGL_VERSION_1_2 drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer; #endif /* EGL_VERSION_1_2 */ -} +#ifdef EGL_KHR_image_base + drv->API.CreateImageKHR = _eglCreateImageKHR; + drv->API.DestroyImageKHR = _eglDestroyImageKHR; +#endif /* EGL_KHR_image_base */ +} /** - * Try to determine which EGL APIs (OpenGL, OpenGL ES, OpenVG, etc) - * are supported on the system by looking for standard library names. + * Set the probe cache at the given key. + * + * A key, instead of a _EGLDriver, is used to allow the probe cache to be share + * by multiple drivers. */ -EGLint -_eglFindAPIs(void) +void +_eglSetProbeCache(EGLint key, const void *val) { - EGLint mask = 0x0; - lib_handle lib; -#if defined(_EGL_PLATFORM_WINDOWS) - /* XXX not sure about these names */ - const char *es1_libname = "libGLESv1_CM.dll"; - const char *es2_libname = "libGLESv2.dll"; - const char *gl_libname = "OpenGL32.dll"; - const char *vg_libname = "libOpenVG.dll"; -#elif defined(_EGL_PLATFORM_X) - const char *es1_libname = "libGLESv1_CM.so"; - const char *es2_libname = "libGLESv2.so"; - const char *gl_libname = "libGL.so"; - const char *vg_libname = "libOpenVG.so"; -#else /* _EGL_PLATFORM_NO_OS */ - const char *es1_libname = NULL; - const char *es2_libname = NULL; - const char *gl_libname = NULL; - const char *vg_libname = NULL; -#endif + EGLint idx; - if ((lib = open_library(es1_libname))) { - close_library(lib); - mask |= EGL_OPENGL_ES_BIT; + for (idx = 0; idx < NUM_PROBE_CACHE_SLOTS; idx++) { + if (!_eglProbeCache.keys[idx] || _eglProbeCache.keys[idx] == key) + break; } + assert(key > 0); + assert(idx < NUM_PROBE_CACHE_SLOTS); - if ((lib = open_library(es2_libname))) { - close_library(lib); - mask |= EGL_OPENGL_ES2_BIT; - } + _eglProbeCache.keys[idx] = key; + _eglProbeCache.values[idx] = val; +} - if ((lib = open_library(gl_libname))) { - close_library(lib); - mask |= EGL_OPENGL_BIT; - } - if ((lib = open_library(vg_libname))) { - close_library(lib); - mask |= EGL_OPENVG_BIT; +/** + * Return the probe cache at the given key. + */ +const void * +_eglGetProbeCache(EGLint key) +{ + EGLint idx; + + for (idx = 0; idx < NUM_PROBE_CACHE_SLOTS; idx++) { + if (!_eglProbeCache.keys[idx] || _eglProbeCache.keys[idx] == key) + break; } - return mask; + return (idx < NUM_PROBE_CACHE_SLOTS && _eglProbeCache.keys[idx] == key) ? + _eglProbeCache.values[idx] : NULL; } diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 59bd1954aa..55686681dc 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -7,6 +7,36 @@ /** + * Define an inline driver typecast function. + * + * Note that this macro defines a function and should not be ended with a + * semicolon when used. + */ +#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \ + static INLINE struct drvtype *drvtype(const egltype *obj) \ + { return (struct drvtype *) code; } + + +/** + * Define the driver typecast functions for _EGLDriver, _EGLDisplay, + * _EGLContext, _EGLSurface, and _EGLConfig. + * + * Note that this macro defines several functions and should not be ended with + * a semicolon when used. + */ +#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \ + _EGL_DRIVER_TYPECAST(drvname ## _driver, _EGLDriver, obj) \ + /* note that this is not a direct cast */ \ + _EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) \ + _EGL_DRIVER_TYPECAST(drvname ## _context, _EGLContext, obj) \ + _EGL_DRIVER_TYPECAST(drvname ## _surface, _EGLSurface, obj) \ + _EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj) + + +typedef _EGLDriver *(*_EGLMain_t)(const char *args); + + +/** * Base class for device drivers. */ struct _egl_driver @@ -16,9 +46,22 @@ struct _egl_driver const char *Args; /**< args to load this driver */ const char *Name; /**< name of this driver */ - /**< probe a display to see if it is supported */ - EGLBoolean (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); - /**< called before dlclose to release this driver */ + + /** + * Probe a display and return a score. + * + * Roughly, + * 50 means the driver supports the display; + * 90 means the driver can accelerate the display; + * 100 means a perfect match. + */ + EGLint (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); + + /** + * Release the driver resource. + * + * It is called before dlclose(). + */ void (*Unload)(_EGLDriver *drv); _EGLAPI API; /**< EGL API dispatch table */ @@ -29,32 +72,28 @@ PUBLIC _EGLDriver * _eglMain(const char *args); -extern const char * -_eglPreloadDriver(_EGLDisplay *dpy); - - extern _EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy); +_eglMatchDriver(_EGLDisplay *dpy); extern EGLBoolean -_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy); +_eglPreloadDrivers(void); -void +extern void _eglUnloadDrivers(void); -extern _EGLDriver * -_eglLookupDriver(EGLDisplay d); +PUBLIC void +_eglInitDriverFallbacks(_EGLDriver *drv); PUBLIC void -_eglInitDriverFallbacks(_EGLDriver *drv); +_eglSetProbeCache(EGLint key, const void *val); -PUBLIC EGLint -_eglFindAPIs(void); +PUBLIC const void * +_eglGetProbeCache(EGLint key); #endif /* EGLDRIVER_INCLUDED */ diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index 443d0f072c..5182b18e22 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -1,8 +1,8 @@ #include <stdlib.h> #include <assert.h> #include "eglglobals.h" +#include "egldisplay.h" #include "egldriver.h" -#include "egllog.h" #include "eglmutex.h" diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h index 5ebb914ca7..cd1dd5851b 100644 --- a/src/egl/main/eglglobals.h +++ b/src/egl/main/eglglobals.h @@ -1,9 +1,8 @@ #ifndef EGLGLOBALS_INCLUDED #define EGLGLOBALS_INCLUDED + #include "egltypedefs.h" -#include "egldisplay.h" -#include "eglcurrent.h" #include "eglmutex.h" diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c new file mode 100644 index 0000000000..5732ef35ec --- /dev/null +++ b/src/egl/main/eglimage.c @@ -0,0 +1,90 @@ +#include <assert.h> +#include <string.h> + +#include "eglimage.h" +#include "eglcurrent.h" +#include "egllog.h" + + +#ifdef EGL_KHR_image_base + + +/** + * Parse the list of image attributes and return the proper error code. + */ +static EGLint +_eglParseImageAttribList(_EGLImage *img, const EGLint *attrib_list) +{ + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + case EGL_IMAGE_PRESERVED_KHR: + img->Preserved = val; + break; + case EGL_GL_TEXTURE_LEVEL_KHR: + img->GLTextureLevel = val; + break; + case EGL_GL_TEXTURE_ZOFFSET_KHR: + img->GLTextureZOffset = val; + break; + default: + /* unknown attrs are ignored */ + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +EGLBoolean +_eglInitImage(_EGLImage *img, _EGLDisplay *dpy, const EGLint *attrib_list) +{ + EGLint err; + + memset(img, 0, sizeof(_EGLImage)); + img->Resource.Display = dpy; + + img->Preserved = EGL_FALSE; + img->GLTextureLevel = 0; + img->GLTextureZOffset = 0; + + err = _eglParseImageAttribList(img, attrib_list); + if (err != EGL_SUCCESS) + return _eglError(err, "eglCreateImageKHR"); + + return EGL_TRUE; +} + + +_EGLImage * +_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, + const EGLint *attr_list) +{ + /* driver should override this function */ + return NULL; +} + + +EGLBoolean +_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image) +{ + /* driver should override this function */ + return EGL_FALSE; +} + + +#endif /* EGL_KHR_image_base */ diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h new file mode 100644 index 0000000000..2c0fb16d1d --- /dev/null +++ b/src/egl/main/eglimage.h @@ -0,0 +1,96 @@ +#ifndef EGLIMAGE_INCLUDED +#define EGLIMAGE_INCLUDED + + +#include "egltypedefs.h" +#include "egldisplay.h" + + +/** + * "Base" class for device driver images. + */ +struct _egl_image +{ + /* An image is a display resource */ + _EGLResource Resource; + + EGLBoolean Preserved; + EGLint GLTextureLevel; + EGLint GLTextureZOffset; +}; + + +PUBLIC EGLBoolean +_eglInitImage(_EGLImage *img, _EGLDisplay *dpy, const EGLint *attrib_list); + + +extern _EGLImage * +_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list); + + +extern EGLBoolean +_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image); + + +/** + * Link an image to a display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLImageKHR +_eglLinkImage(_EGLImage *img, _EGLDisplay *dpy) +{ + _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE, dpy); + return (EGLImageKHR) img; +} + + +/** + * Unlink a linked image from its display. + * Accessing an unlinked image should generate EGL_BAD_PARAMETER error. + */ +static INLINE void +_eglUnlinkImage(_EGLImage *img) +{ + _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); +} + + +/** + * Lookup a handle to find the linked image. + * Return NULL if the handle has no corresponding linked image. + */ +static INLINE _EGLImage * +_eglLookupImage(EGLImageKHR image, _EGLDisplay *dpy) +{ + _EGLImage *img = (_EGLImage *) image; + if (!dpy || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, dpy)) + img = NULL; + return img; +} + + +/** + * Return the handle of a linked image, or EGL_NO_IMAGE_KHR. + */ +static INLINE EGLImageKHR +_eglGetImageHandle(_EGLImage *img) +{ + _EGLResource *res = (_EGLResource *) img; + return (res && _eglIsResourceLinked(res)) ? + (EGLImageKHR) img : EGL_NO_IMAGE_KHR; +} + + +/** + * Return true if the image is linked to a display. + */ +static INLINE EGLBoolean +_eglIsImageLinked(_EGLImage *img) +{ + _EGLResource *res = (_EGLResource *) img; + return (res && _eglIsResourceLinked(res)); +} + + +#endif /* EGLIMAGE_INCLUDED */ diff --git a/src/egl/main/egllog.h b/src/egl/main/egllog.h index 3a99bfea4b..03bef2670f 100644 --- a/src/egl/main/egllog.h +++ b/src/egl/main/egllog.h @@ -1,8 +1,10 @@ #ifndef EGLLOG_INCLUDED #define EGLLOG_INCLUDED + #include "egltypedefs.h" + #define _EGL_FATAL 0 /* unrecoverable error */ #define _EGL_WARNING 1 /* recoverable error/problem */ #define _EGL_INFO 2 /* just useful info */ diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c index e66913320b..984e426686 100644 --- a/src/egl/main/eglmisc.c +++ b/src/egl/main/eglmisc.c @@ -33,28 +33,70 @@ #include <assert.h> #include <string.h> -#include "eglglobals.h" +#include "eglcurrent.h" #include "eglmisc.h" #include "egldisplay.h" /** + * Copy the extension into the string and update the string pointer. + */ +static EGLint +_eglAppendExtension(char **str, const char *ext) +{ + char *s = *str; + EGLint len = strlen(ext); + + if (s) { + memcpy(s, ext, len); + s[len++] = ' '; + s[len] = '\0'; + + *str += len; + } + else { + len++; + } + + return len; +} + + +/** * Examine the individual extension enable/disable flags and recompute * the driver's Extensions string. */ static void _eglUpdateExtensionsString(_EGLDisplay *dpy) { +#define _EGL_CHECK_EXTENSION(ext) \ + do { \ + if (dpy->Extensions.ext) { \ + _eglAppendExtension(&exts, "EGL_" #ext); \ + assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \ + } \ + } while (0) + char *exts = dpy->Extensions.String; if (exts[0]) return; - if (dpy->Extensions.MESA_screen_surface) - strcat(exts, "EGL_MESA_screen_surface "); - if (dpy->Extensions.MESA_copy_context) - strcat(exts, "EGL_MESA_copy_context "); - assert(strlen(exts) < _EGL_MAX_EXTENSIONS_LEN); + _EGL_CHECK_EXTENSION(MESA_screen_surface); + _EGL_CHECK_EXTENSION(MESA_copy_context); + + _EGL_CHECK_EXTENSION(KHR_image_base); + _EGL_CHECK_EXTENSION(KHR_image_pixmap); + if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap) + _eglAppendExtension(&exts, "EGL_KHR_image"); + + _EGL_CHECK_EXTENSION(KHR_vg_parent_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image); + _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image); + +#undef _EGL_CHECK_EXTENSION } diff --git a/src/egl/main/eglmisc.h b/src/egl/main/eglmisc.h index 829d4cde79..5e6a2d41df 100644 --- a/src/egl/main/eglmisc.h +++ b/src/egl/main/eglmisc.h @@ -29,7 +29,8 @@ #ifndef EGLMISC_INCLUDED #define EGLMISC_INCLUDED -#include "egldriver.h" + +#include "egltypedefs.h" extern const char * diff --git a/src/egl/main/eglmode.c b/src/egl/main/eglmode.c index 0f3ba6e5c0..66446c0495 100644 --- a/src/egl/main/eglmode.c +++ b/src/egl/main/eglmode.c @@ -1,4 +1,3 @@ -#include <stdio.h> #include <assert.h> #include <stdlib.h> #include <string.h> @@ -6,29 +5,14 @@ #include "egldisplay.h" #include "egldriver.h" #include "eglmode.h" -#include "eglglobals.h" +#include "eglcurrent.h" #include "eglscreen.h" +#include "eglstring.h" #define MIN2(A, B) (((A) < (B)) ? (A) : (B)) -static char * -my_strdup(const char *s) -{ - if (s) { - int l = strlen(s); - char *s2 = malloc(l + 1); - if (s2) - strcpy(s2, s); - return s2; - } - else { - return NULL; - } -} - - /** * Given an EGLModeMESA handle, return the corresponding _EGLMode object * or null if non-existant. @@ -82,7 +66,7 @@ _eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height, screen->Modes[n].RefreshRate = refreshRate; screen->Modes[n].Optimal = EGL_FALSE; screen->Modes[n].Interlaced = EGL_FALSE; - screen->Modes[n].Name = my_strdup(name); + screen->Modes[n].Name = _eglstrdup(name); screen->NumModes++; return screen->Modes + n; } @@ -366,41 +350,3 @@ _eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m) { return m->Name; } - - -#if 0 -static int -_eglRand(int max) -{ - return rand() % max; -} - -void -_eglTestModeModule(void) -{ - EGLint count = 30; - _EGLMode *modes = (_EGLMode *) malloc(count * sizeof(_EGLMode)); - _EGLMode **modeList = (_EGLMode **) malloc(count * sizeof(_EGLMode*)); - EGLint i; - - for (i = 0; i < count; i++) { - modes[i].Handle = _eglRand(20); - modes[i].Width = 512 + 256 * _eglRand(2); - modes[i].Height = 512 + 256 * _eglRand(2); - modes[i].RefreshRate = 50 + 5 * _eglRand(3); - modes[i].Interlaced = _eglRand(2); - modes[i].Optimal = _eglRand(4) == 0; - modeList[i] = modes + i; - } - - /* sort array of pointers */ - qsort(modeList, count, sizeof(_EGLMode *), compareModes); - - for (i = 0; i < count; i++) { - _EGLMode *m = modeList[i]; - printf("%2d: %3d %4d x %4d @ %3d opt %d int %d\n", i, - m->Handle, m->Width, m->Height, m->RefreshRate, - m->Optimal, m->Interlaced); - } -} -#endif diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c index 14a1e9f8fe..97a405a4b4 100644 --- a/src/egl/main/eglscreen.c +++ b/src/egl/main/eglscreen.c @@ -17,6 +17,7 @@ #include "egldisplay.h" #include "eglglobals.h" +#include "eglcurrent.h" #include "eglmode.h" #include "eglconfig.h" #include "eglsurface.h" @@ -110,27 +111,12 @@ _eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *display, EGLScreenMESA *screens /** - * Example function - drivers should do a proper implementation. + * Drivers should do a proper implementation. */ _EGLSurface * _eglCreateScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { -#if 0 /* THIS IS JUST EXAMPLE CODE */ - _EGLSurface *surf; - - surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); - if (!surf) - return NULL; - - if (!_eglInitSurface(drv, surf, EGL_SCREEN_BIT_MESA, - conf, attrib_list)) { - free(surf); - return NULL; - } - - return surf; -#endif return NULL; } diff --git a/src/egl/main/eglscreen.h b/src/egl/main/eglscreen.h index d52e5388c3..c400ac3d15 100644 --- a/src/egl/main/eglscreen.h +++ b/src/egl/main/eglscreen.h @@ -2,6 +2,9 @@ #define EGLSCREEN_INCLUDED +#include "egltypedefs.h" + + /** * Per-screen information. * Note that an EGL screen doesn't have a size. A screen may be set to diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 940a1b760c..8026a6314d 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -9,8 +9,7 @@ #include "egldisplay.h" #include "eglcontext.h" #include "eglconfig.h" -#include "egldriver.h" -#include "eglglobals.h" +#include "eglcurrent.h" #include "egllog.h" #include "eglsurface.h" @@ -32,23 +31,168 @@ _eglClampSwapInterval(_EGLSurface *surf, EGLint interval) /** + * Parse the list of surface attributes and return the proper error code. + */ +static EGLint +_eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) +{ + EGLint type = surf->Type; + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + /* common (except for screen surfaces) attributes */ + case EGL_VG_COLORSPACE: + if (type == EGL_SCREEN_BIT_MESA) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_VG_COLORSPACE_sRGB: + case EGL_VG_COLORSPACE_LINEAR: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->VGColorspace = val; + break; + case EGL_VG_ALPHA_FORMAT: + if (type == EGL_SCREEN_BIT_MESA) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_VG_ALPHA_FORMAT_NONPRE: + case EGL_VG_ALPHA_FORMAT_PRE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->VGAlphaFormat = val; + break; + /* window surface attributes */ + case EGL_RENDER_BUFFER: + if (type != EGL_WINDOW_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val != EGL_BACK_BUFFER && val != EGL_SINGLE_BUFFER) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->RenderBuffer = val; + break; + /* pbuffer surface attributes */ + case EGL_WIDTH: + if (type != EGL_PBUFFER_BIT && type != EGL_SCREEN_BIT_MESA) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Width = val; + break; + case EGL_HEIGHT: + if (type != EGL_PBUFFER_BIT && type != EGL_SCREEN_BIT_MESA) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Height = val; + break; + case EGL_LARGEST_PBUFFER: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->LargestPbuffer = !!val; + break; + case EGL_TEXTURE_FORMAT: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_TEXTURE_RGB: + case EGL_TEXTURE_RGBA: + case EGL_NO_TEXTURE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->TextureFormat = val; + break; + case EGL_TEXTURE_TARGET: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_TEXTURE_2D: + case EGL_NO_TEXTURE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->TextureTarget = val; + break; + case EGL_MIPMAP_TEXTURE: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->MipmapTexture = !!val; + break; + /* no pixmap surface specific attributes */ + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_WARNING, "bad surface attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +/** * Do error check on parameters and initialize the given _EGLSurface object. * \return EGL_TRUE if no errors, EGL_FALSE otherwise. */ EGLBoolean -_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type, +_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, _EGLConfig *conf, const EGLint *attrib_list) { const char *func; - EGLint width = 0, height = 0, largest = 0; - EGLint texFormat = EGL_NO_TEXTURE, texTarget = EGL_NO_TEXTURE; - EGLint mipmapTex = EGL_FALSE; EGLint renderBuffer = EGL_BACK_BUFFER; -#ifdef EGL_VERSION_1_2 - EGLint colorspace = EGL_COLORSPACE_sRGB; - EGLint alphaFormat = EGL_ALPHA_FORMAT_NONPRE; -#endif - EGLint i; + EGLint err; switch (type) { case EGL_WINDOW_BIT: @@ -70,158 +214,41 @@ _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type, return EGL_FALSE; } - if (!conf) { - _eglError(EGL_BAD_CONFIG, func); - return EGL_FALSE; - } - if ((GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE) & type) == 0) { /* The config can't be used to create a surface of this type */ _eglError(EGL_BAD_CONFIG, func); return EGL_FALSE; } - /* - * Parse attribute list. Different kinds of surfaces support different - * attributes. - */ - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - case EGL_WIDTH: - if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { - width = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_HEIGHT: - if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { - height = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_LARGEST_PBUFFER: - if (type == EGL_PBUFFER_BIT) { - largest = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_TEXTURE_FORMAT: - if (type == EGL_PBUFFER_BIT) { - texFormat = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_TEXTURE_TARGET: - if (type == EGL_PBUFFER_BIT) { - texTarget = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_MIPMAP_TEXTURE: - if (type == EGL_PBUFFER_BIT) { - mipmapTex = attrib_list[++i]; - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; -#ifdef EGL_VERSION_1_2 - case EGL_RENDER_BUFFER: - if (type == EGL_WINDOW_BIT) { - renderBuffer = attrib_list[++i]; - if (renderBuffer != EGL_BACK_BUFFER && - renderBuffer != EGL_SINGLE_BUFFER) { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_COLORSPACE: - if (type == EGL_WINDOW_BIT || - type == EGL_PBUFFER_BIT || - type == EGL_PIXMAP_BIT) { - colorspace = attrib_list[++i]; - if (colorspace != EGL_COLORSPACE_sRGB && - colorspace != EGL_COLORSPACE_LINEAR) { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - case EGL_ALPHA_FORMAT: - if (type == EGL_WINDOW_BIT || - type == EGL_PBUFFER_BIT || - type == EGL_PIXMAP_BIT) { - alphaFormat = attrib_list[++i]; - if (alphaFormat != EGL_ALPHA_FORMAT_NONPRE && - alphaFormat != EGL_ALPHA_FORMAT_PRE) { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - } - else { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - break; - -#endif /* EGL_VERSION_1_2 */ - default: - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - } - - if (width < 0 || height < 0) { - _eglError(EGL_BAD_ATTRIBUTE, func); - return EGL_FALSE; - } - memset(surf, 0, sizeof(_EGLSurface)); - surf->Config = conf; + surf->Resource.Display = dpy; surf->Type = type; - surf->Width = width; - surf->Height = height; - surf->TextureFormat = texFormat; - surf->TextureTarget = texTarget; - surf->MipmapTexture = mipmapTex; + surf->Config = conf; + + surf->Width = 0; + surf->Height = 0; + surf->TextureFormat = EGL_NO_TEXTURE; + surf->TextureTarget = EGL_NO_TEXTURE; + surf->MipmapTexture = EGL_FALSE; + surf->LargestPbuffer = EGL_FALSE; + surf->RenderBuffer = renderBuffer; + surf->VGAlphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE; + surf->VGColorspace = EGL_VG_COLORSPACE_sRGB; + surf->MipmapLevel = 0; + surf->MultisampleResolve = EGL_MULTISAMPLE_RESOLVE_DEFAULT; + surf->SwapBehavior = EGL_BUFFER_DESTROYED; + + surf->HorizontalResolution = EGL_UNKNOWN; + surf->VerticalResolution = EGL_UNKNOWN; + surf->AspectRatio = EGL_UNKNOWN; + /* the default swap interval is 1 */ _eglClampSwapInterval(surf, 1); -#ifdef EGL_VERSION_1_2 - surf->SwapBehavior = EGL_BUFFER_DESTROYED; /* XXX ok? */ - surf->HorizontalResolution = EGL_UNKNOWN; /* set by caller */ - surf->VerticalResolution = EGL_UNKNOWN; /* set by caller */ - surf->AspectRatio = EGL_UNKNOWN; /* set by caller */ - surf->RenderBuffer = renderBuffer; - surf->AlphaFormat = alphaFormat; - surf->Colorspace = colorspace; -#endif + err = _eglParseSurfaceAttribList(surf, attrib_list); + if (err != EGL_SUCCESS) + return _eglError(err, func); return EGL_TRUE; } @@ -237,7 +264,7 @@ _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) EGLBoolean _eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, - NativePixmapType target) + EGLNativePixmapType target) { /* copy surface to native pixmap */ /* All implementation burdon for this is in the device driver */ @@ -252,139 +279,95 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, switch (attribute) { case EGL_WIDTH: *value = surface->Width; - return EGL_TRUE; + break; case EGL_HEIGHT: *value = surface->Height; - return EGL_TRUE; + break; case EGL_CONFIG_ID: *value = GET_CONFIG_ATTRIB(surface->Config, EGL_CONFIG_ID); - return EGL_TRUE; + break; case EGL_LARGEST_PBUFFER: - *value = dpy->LargestPbuffer; - return EGL_TRUE; - case EGL_SURFACE_TYPE: - *value = surface->Type; - return EGL_TRUE; -#ifdef EGL_VERSION_1_1 + *value = surface->LargestPbuffer; + break; case EGL_TEXTURE_FORMAT: /* texture attributes: only for pbuffers, no error otherwise */ if (surface->Type == EGL_PBUFFER_BIT) *value = surface->TextureFormat; - return EGL_TRUE; + break; case EGL_TEXTURE_TARGET: if (surface->Type == EGL_PBUFFER_BIT) *value = surface->TextureTarget; - return EGL_TRUE; + break; case EGL_MIPMAP_TEXTURE: if (surface->Type == EGL_PBUFFER_BIT) *value = surface->MipmapTexture; - return EGL_TRUE; + break; case EGL_MIPMAP_LEVEL: if (surface->Type == EGL_PBUFFER_BIT) *value = surface->MipmapLevel; - return EGL_TRUE; -#endif /* EGL_VERSION_1_1 */ -#ifdef EGL_VERSION_1_2 + break; case EGL_SWAP_BEHAVIOR: *value = surface->SwapBehavior; - return EGL_TRUE; + break; case EGL_RENDER_BUFFER: *value = surface->RenderBuffer; - return EGL_TRUE; + break; case EGL_PIXEL_ASPECT_RATIO: *value = surface->AspectRatio; - return EGL_TRUE; + break; case EGL_HORIZONTAL_RESOLUTION: *value = surface->HorizontalResolution; - return EGL_TRUE; + break; case EGL_VERTICAL_RESOLUTION: *value = surface->VerticalResolution; - return EGL_TRUE; - case EGL_ALPHA_FORMAT: - *value = surface->AlphaFormat; - return EGL_TRUE; - case EGL_COLORSPACE: - *value = surface->Colorspace; - return EGL_TRUE; -#endif /* EGL_VERSION_1_2 */ + break; + case EGL_MULTISAMPLE_RESOLVE: + *value = surface->MultisampleResolve; + break; + case EGL_VG_ALPHA_FORMAT: + *value = surface->VGAlphaFormat; + break; + case EGL_VG_COLORSPACE: + *value = surface->VGColorspace; + break; default: _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); return EGL_FALSE; } + + return EGL_TRUE; } /** - * Example function - drivers should do a proper implementation. + * Drivers should do a proper implementation. */ _EGLSurface * _eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - NativeWindowType window, const EGLint *attrib_list) + EGLNativeWindowType window, const EGLint *attrib_list) { -#if 0 /* THIS IS JUST EXAMPLE CODE */ - _EGLSurface *surf; - - surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); - if (!surf) - return NULL; - - if (!_eglInitSurface(drv, surf, EGL_WINDOW_BIT, conf, attrib_list)) { - free(surf); - return NULL; - } - - return surf; -#endif return NULL; } /** - * Example function - drivers should do a proper implementation. + * Drivers should do a proper implementation. */ _EGLSurface * _eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - NativePixmapType pixmap, const EGLint *attrib_list) + EGLNativePixmapType pixmap, const EGLint *attrib_list) { -#if 0 /* THIS IS JUST EXAMPLE CODE */ - _EGLSurface *surf; - - surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); - if (!surf) - return NULL; - - if (!_eglInitSurface(drv, surf, EGL_PIXMAP_BIT, conf, attrib_list)) { - free(surf); - return NULL; - } - - return surf; -#endif return NULL; } /** - * Example function - drivers should do a proper implementation. + * Drivers should do a proper implementation. */ _EGLSurface * _eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { -#if 0 /* THIS IS JUST EXAMPLE CODE */ - _EGLSurface *surf; - - surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); - if (!surf) - return NULL; - - if (!_eglInitSurface(drv, surf, EGL_PBUFFER_BIT, conf, attrib_list)) { - free(surf); - return NULL; - } - - return NULL; -#endif return NULL; } @@ -408,14 +391,59 @@ EGLBoolean _eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value) { + EGLint confval; + EGLint err = EGL_SUCCESS; + switch (attribute) { case EGL_MIPMAP_LEVEL: + confval = GET_CONFIG_ATTRIB(surface->Config, EGL_RENDERABLE_TYPE); + if (!(confval & (EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT))) { + err = EGL_BAD_PARAMETER; + break; + } surface->MipmapLevel = value; break; + case EGL_MULTISAMPLE_RESOLVE: + switch (value) { + case EGL_MULTISAMPLE_RESOLVE_DEFAULT: + break; + case EGL_MULTISAMPLE_RESOLVE_BOX: + confval = GET_CONFIG_ATTRIB(surface->Config, EGL_SURFACE_TYPE); + if (!(confval & EGL_MULTISAMPLE_RESOLVE_BOX_BIT)) + err = EGL_BAD_MATCH; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surface->MultisampleResolve = value; + break; + case EGL_SWAP_BEHAVIOR: + switch (value) { + case EGL_BUFFER_DESTROYED: + break; + case EGL_BUFFER_PRESERVED: + confval = GET_CONFIG_ATTRIB(surface->Config, EGL_SURFACE_TYPE); + if (!(confval & EGL_SWAP_BEHAVIOR_PRESERVED_BIT)) + err = EGL_BAD_MATCH; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surface->SwapBehavior = value; + break; default: - _eglError(EGL_BAD_ATTRIBUTE, "eglSurfaceAttrib"); - return EGL_FALSE; + err = EGL_BAD_ATTRIBUTE; + break; } + + if (err != EGL_SUCCESS) + return _eglError(err, "eglSurfaceAttrib"); return EGL_TRUE; } diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index dacdf7e63c..0a00035730 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -3,6 +3,7 @@ #include "egltypedefs.h" +#include "egldisplay.h" /** @@ -10,38 +11,43 @@ */ struct _egl_surface { - /* Managed by EGLDisplay for linking */ - _EGLDisplay *Display; - _EGLSurface *Next; + /* A surface is a display resource */ + _EGLResource Resource; - /* The bound status of the surface */ - _EGLContext *Binding; - EGLBoolean BoundToTexture; + /* The context that is currently bound to the surface */ + _EGLContext *CurrentContext; _EGLConfig *Config; EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ - EGLint Width, Height; - EGLint TextureFormat, TextureTarget; - EGLint MipmapTexture, MipmapLevel; - EGLint SwapInterval; - /* If type == EGL_SCREEN_BIT: */ - EGLint VisibleRefCount; /* number of screens I'm displayed on */ + /* attributes set by attribute list */ + EGLint Width, Height; + EGLenum TextureFormat; + EGLenum TextureTarget; + EGLBoolean MipmapTexture; + EGLBoolean LargestPbuffer; + EGLenum RenderBuffer; + EGLenum VGAlphaFormat; + EGLenum VGColorspace; + + /* attributes set by eglSurfaceAttrib */ + EGLint MipmapLevel; + EGLenum MultisampleResolve; + EGLenum SwapBehavior; -#ifdef EGL_VERSION_1_2 - EGLint SwapBehavior; /* one of EGL_BUFFER_PRESERVED/DESTROYED */ EGLint HorizontalResolution, VerticalResolution; EGLint AspectRatio; - EGLint RenderBuffer; /* EGL_BACK_BUFFER or EGL_SINGLE_BUFFER */ - EGLint AlphaFormat; /* EGL_ALPHA_FORMAT_NONPRE or EGL_ALPHA_FORMAT_PRE */ - EGLint Colorspace; /* EGL_COLORSPACE_sRGB or EGL_COLORSPACE_LINEAR */ -#endif /* EGL_VERSION_1_2 */ + + EGLint SwapInterval; + + /* True if the surface is bound to an OpenGL ES texture */ + EGLBoolean BoundToTexture; }; PUBLIC EGLBoolean -_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type, +_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, _EGLConfig *config, const EGLint *attrib_list); @@ -50,7 +56,7 @@ _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf); extern EGLBoolean -_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, NativePixmapType target); +_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLNativePixmapType target); extern EGLBoolean @@ -58,11 +64,11 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint at extern _EGLSurface * -_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list); +_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativeWindowType window, const EGLint *attrib_list); extern _EGLSurface * -_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list); +_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativePixmapType pixmap, const EGLint *attrib_list); extern _EGLSurface * @@ -100,14 +106,78 @@ _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy, /** - * Return true if the surface is bound to a thread. - * A surface bound to a texutre is not considered bound by - * this function. + * Return true if there is a context bound to the surface. + * + * The binding is considered a reference to the surface. Drivers should not + * destroy a surface when it is bound. */ static INLINE EGLBoolean _eglIsSurfaceBound(_EGLSurface *surf) { - return (surf->Binding != NULL); + return (surf->CurrentContext != NULL); +} + + +/** + * Link a surface to a display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLSurface +_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy) +{ + _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE, dpy); + return (EGLSurface) surf; +} + + +/** + * Unlink a linked surface from its display. + * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. + */ +static INLINE void +_eglUnlinkSurface(_EGLSurface *surf) +{ + _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); +} + + +/** + * Lookup a handle to find the linked surface. + * Return NULL if the handle has no corresponding linked surface. + */ +static INLINE _EGLSurface * +_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) +{ + _EGLSurface *surf = (_EGLSurface *) surface; + if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy)) + surf = NULL; + return surf; +} + + +/** + * Return the handle of a linked surface, or EGL_NO_SURFACE. + */ +static INLINE EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surf) +{ + _EGLResource *res = (_EGLResource *) surf; + return (res && _eglIsResourceLinked(res)) ? + (EGLSurface) surf : EGL_NO_SURFACE; +} + + +/** + * Return true if the surface is linked to a display. + * + * The link is considered a reference to the surface (the display is owning the + * surface). Drivers should not destroy a surface when it is linked. + */ +static INLINE EGLBoolean +_eglIsSurfaceLinked(_EGLSurface *surf) +{ + _EGLResource *res = (_EGLResource *) surf; + return (res && _eglIsResourceLinked(res)); } diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h index 4461440b9b..e0c95762c6 100644 --- a/src/egl/main/egltypedefs.h +++ b/src/egl/main/egltypedefs.h @@ -8,6 +8,8 @@ #include "eglcompiler.h" +typedef enum _egl_resource_type _EGLResourceType; + typedef struct _egl_api _EGLAPI; typedef struct _egl_config _EGLConfig; @@ -20,16 +22,16 @@ typedef struct _egl_driver _EGLDriver; typedef struct _egl_extensions _EGLExtensions; +typedef struct _egl_image _EGLImage; + typedef struct _egl_mode _EGLMode; +typedef struct _egl_resource _EGLResource; + typedef struct _egl_screen _EGLScreen; typedef struct _egl_surface _EGLSurface; typedef struct _egl_thread_info _EGLThreadInfo; - -typedef _EGLDriver *(*_EGLMain_t)(const char *args); - - #endif /* EGLTYPEDEFS_INCLUDED */ |