While overhauling the driver api, one of the goals is to make it
possible that a _EGLDriver can drive multiple _EGLDisplay.
Most drivers still store per-display data in _EGLDriver. This patch
series moves per-display data to where they should be, _EGLDisplay.
Along the way, the last users of Xdpy are removed. The last commit
removes Xdpy from _EGLDisplay.
--
Regards,
olv
>From 111bf44d8ca954490b2cae9cdff9d24176883cda Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Wed, 26 Aug 2009 16:39:29 +0800
Subject: [PATCH 1/4] EGL_i915: Make struct drm_device per display.
This is to allow a driver to drive multiple displays.
Signed-off-by: Chia-I Wu <[email protected]>
---
src/gallium/state_trackers/egl/egl_context.c | 2 +-
src/gallium/state_trackers/egl/egl_surface.c | 18 ++++----
src/gallium/state_trackers/egl/egl_tracker.c | 67 ++++++++++++++-----------
src/gallium/state_trackers/egl/egl_tracker.h | 11 +++-
4 files changed, 55 insertions(+), 43 deletions(-)
diff --git a/src/gallium/state_trackers/egl/egl_context.c b/src/gallium/state_trackers/egl/egl_context.c
index 52b6453..c4f7361 100644
--- a/src/gallium/state_trackers/egl/egl_context.c
+++ b/src/gallium/state_trackers/egl/egl_context.c
@@ -86,7 +86,7 @@ const struct dri_extension card_extensions[] = {
_EGLContext *
drm_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_context *ctx;
struct drm_context *share = NULL;
struct st_context *st_share = NULL;
diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c
index 0cca68d..3ef1945 100644
--- a/src/gallium/state_trackers/egl/egl_surface.c
+++ b/src/gallium/state_trackers/egl/egl_surface.c
@@ -67,11 +67,11 @@ drm_create_framebuffer(const __GLcontextModes *visual,
}
static void
-drm_create_texture(_EGLDriver *drv,
+drm_create_texture(_EGLDisplay *dpy,
struct drm_screen *scrn,
unsigned w, unsigned h)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct pipe_screen *screen = dev->screen;
struct pipe_surface *surface;
struct pipe_texture *texture;
@@ -137,9 +137,9 @@ err_tex:
*/
void
-drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen)
+drm_takedown_shown_screen(_EGLDisplay *dpy, struct drm_screen *screen)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
screen->surf = NULL;
@@ -244,17 +244,17 @@ drm_show_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLScreen *screen,
_EGLSurface *surface, _EGLMode *mode)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_surface *surf = lookup_drm_surface(surface);
struct drm_screen *scrn = lookup_drm_screen(screen);
int ret;
unsigned int i, k;
if (scrn->shown)
- drm_takedown_shown_screen(drv, scrn);
+ drm_takedown_shown_screen(dpy, scrn);
- drm_create_texture(drv, scrn, mode->Width, mode->Height);
+ drm_create_texture(dpy, scrn, mode->Width, mode->Height);
if (!scrn->buffer)
return EGL_FALSE;
@@ -341,7 +341,7 @@ drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
struct drm_surface *surf = lookup_drm_surface(surface);
if (!_eglIsSurfaceBound(&surf->base)) {
if (surf->screen)
- drm_takedown_shown_screen(drv, surf->screen);
+ drm_takedown_shown_screen(dpy, surf->screen);
st_unreference_framebuffer(surf->stfb);
free(surf);
}
@@ -351,7 +351,7 @@ drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
EGLBoolean
drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_surface *surf = lookup_drm_surface(draw);
struct pipe_surface *back_surf;
diff --git a/src/gallium/state_trackers/egl/egl_tracker.c b/src/gallium/state_trackers/egl/egl_tracker.c
index 57c81da..5140755 100644
--- a/src/gallium/state_trackers/egl/egl_tracker.c
+++ b/src/gallium/state_trackers/egl/egl_tracker.c
@@ -26,9 +26,7 @@ extern const struct dri_extension card_extensions[];
static void
drm_unload(_EGLDriver *drv)
{
- struct drm_device *dev = (struct drm_device *)drv;
- dev->api->destroy(dev->api);
- free(dev);
+ free(drv);
}
/**
@@ -38,35 +36,33 @@ drm_unload(_EGLDriver *drv)
_EGLDriver *
_eglMain(const char *args)
{
- struct drm_device *drm;
+ _EGLDriver *drv;
- drm = (struct drm_device *) calloc(1, sizeof(struct drm_device));
- if (!drm) {
+ drv = (_EGLDriver *) calloc(1, sizeof(_EGLDriver));
+ if (!drv) {
return NULL;
}
- drm->api = drm_api_create();
-
/* First fill in the dispatch table with defaults */
- _eglInitDriverFallbacks(&drm->base);
+ _eglInitDriverFallbacks(drv);
/* then plug in our Drm-specific functions */
- drm->base.API.Initialize = drm_initialize;
- drm->base.API.Terminate = drm_terminate;
- drm->base.API.CreateContext = drm_create_context;
- drm->base.API.MakeCurrent = drm_make_current;
- drm->base.API.CreateWindowSurface = drm_create_window_surface;
- drm->base.API.CreatePixmapSurface = drm_create_pixmap_surface;
- drm->base.API.CreatePbufferSurface = drm_create_pbuffer_surface;
- drm->base.API.DestroySurface = drm_destroy_surface;
- drm->base.API.DestroyContext = drm_destroy_context;
- drm->base.API.CreateScreenSurfaceMESA = drm_create_screen_surface_mesa;
- drm->base.API.ShowScreenSurfaceMESA = drm_show_screen_surface_mesa;
- drm->base.API.SwapBuffers = drm_swap_buffers;
-
- drm->base.Name = "DRM/Gallium/Win";
- drm->base.Unload = drm_unload;
-
- return &drm->base;
+ drv->API.Initialize = drm_initialize;
+ drv->API.Terminate = drm_terminate;
+ drv->API.CreateContext = drm_create_context;
+ drv->API.MakeCurrent = drm_make_current;
+ drv->API.CreateWindowSurface = drm_create_window_surface;
+ drv->API.CreatePixmapSurface = drm_create_pixmap_surface;
+ drv->API.CreatePbufferSurface = drm_create_pbuffer_surface;
+ drv->API.DestroySurface = drm_destroy_surface;
+ drv->API.DestroyContext = drm_destroy_context;
+ drv->API.CreateScreenSurfaceMESA = drm_create_screen_surface_mesa;
+ drv->API.ShowScreenSurfaceMESA = drm_show_screen_surface_mesa;
+ drv->API.SwapBuffers = drm_swap_buffers;
+
+ drv->Name = "DRM/Gallium/Win";
+ drv->Unload = drm_unload;
+
+ return drv;
}
static void
@@ -145,7 +141,7 @@ static int drm_open_minor(int minor)
EGLBoolean
drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev;
struct drm_screen *screen = NULL;
drmModeConnectorPtr connector = NULL;
drmModeResPtr res = NULL;
@@ -154,6 +150,11 @@ drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
EGLint i;
int fd;
+ dev = (struct drm_device *) calloc(1, sizeof(struct drm_device));
+ if (!dev)
+ return EGL_FALSE;
+ dev->api = drm_api_create();
+
/* try the first node */
fd = drm_open_minor(0);
if (fd < 0)
@@ -200,6 +201,8 @@ drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
}
dev->count_screens = num_screens;
+ disp->DriverData = dev;
+
/* for now we only have one config */
_EGLConfig *config = calloc(1, sizeof(*config));
memset(config, 1, sizeof(*config));
@@ -227,17 +230,19 @@ drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor)
err_screen:
drmClose(fd);
err_fd:
+ free(dev);
return EGL_FALSE;
}
EGLBoolean
drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
- struct drm_device *dev = (struct drm_device *)drv;
+ struct drm_device *dev = lookup_drm_device(dpy);
struct drm_screen *screen;
int i = 0;
_eglReleaseDisplayResources(drv, dpy);
+ _eglCleanupDisplay(dpy);
drmFreeVersion(dev->version);
@@ -245,7 +250,7 @@ drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
screen = dev->screens[i];
if (screen->shown)
- drm_takedown_shown_screen(drv, screen);
+ drm_takedown_shown_screen(dpy, screen);
drmModeFreeProperty(screen->dpms);
drmModeFreeConnector(screen->connector);
@@ -258,7 +263,9 @@ drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
drmClose(dev->drmFD);
- _eglCleanupDisplay(dpy);
+ dev->api->destroy(dev->api);
+ free(dev);
+ dpy->DriverData = NULL;
return EGL_TRUE;
}
diff --git a/src/gallium/state_trackers/egl/egl_tracker.h b/src/gallium/state_trackers/egl/egl_tracker.h
index 25f70d8..dd4730f 100644
--- a/src/gallium/state_trackers/egl/egl_tracker.h
+++ b/src/gallium/state_trackers/egl/egl_tracker.h
@@ -32,8 +32,6 @@ struct drm_context;
struct drm_device
{
- _EGLDriver base; /* base class/object */
-
/*
* pipe
*/
@@ -136,6 +134,13 @@ struct drm_screen
};
+static INLINE struct drm_device *
+lookup_drm_device(_EGLDisplay *d)
+{
+ return (struct drm_device *) d->DriverData;
+}
+
+
static INLINE struct drm_context *
lookup_drm_context(_EGLContext *c)
{
@@ -168,7 +173,7 @@ __GLcontextModes* drm_visual_from_config(_EGLConfig *conf);
* egl_surface.h
*/
/*...@{*/
-void drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen);
+void drm_takedown_shown_screen(_EGLDisplay *dpy, struct drm_screen *screen);
/*...@}*/
/**
--
1.6.2.4
>From 1b69b4137fefd9a584d3272c9680da987e7622b0 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Wed, 26 Aug 2009 15:42:35 +0800
Subject: [PATCH 2/4] egl_softpipe: Make winsys and pipe screen per display.
This is to allow a driver to drive multiple displays. Remove the use of
_EGL_PLATFORM_X along the way.
Signed-off-by: Chia-I Wu <[email protected]>
---
src/gallium/winsys/egl_xlib/Makefile | 2 +-
src/gallium/winsys/egl_xlib/egl_xlib.c | 102 ++++++++++++++++++++++++--------
2 files changed, 77 insertions(+), 27 deletions(-)
diff --git a/src/gallium/winsys/egl_xlib/Makefile b/src/gallium/winsys/egl_xlib/Makefile
index a33a50e..3efb7ed 100644
--- a/src/gallium/winsys/egl_xlib/Makefile
+++ b/src/gallium/winsys/egl_xlib/Makefile
@@ -37,7 +37,7 @@ UNUSED_LIBS = \
$(TOP)/src/mesa/libmesagallium.a \
-LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1
+LOCAL_CFLAGS =
.c.o:
diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c
index 96f460f..d02f825 100644
--- a/src/gallium/winsys/egl_xlib/egl_xlib.c
+++ b/src/gallium/winsys/egl_xlib/egl_xlib.c
@@ -33,6 +33,7 @@
#include <dlfcn.h>
+#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "pipe/p_compiler.h"
@@ -61,8 +62,15 @@
struct xlib_egl_driver
{
_EGLDriver Base; /**< base class */
-
EGLint apis;
+};
+
+
+/** driver data of _EGLDisplay */
+struct xlib_egl_display
+{
+ Display *Dpy;
+
struct pipe_winsys *winsys;
struct pipe_screen *screen;
};
@@ -95,6 +103,12 @@ struct xlib_egl_surface
};
+static void
+flush_frontbuffer(struct pipe_winsys *pws,
+ struct pipe_surface *psurf,
+ void *context_private);
+
+
/** cast wrapper */
static INLINE struct xlib_egl_driver *
xlib_egl_driver(_EGLDriver *drv)
@@ -103,6 +117,13 @@ xlib_egl_driver(_EGLDriver *drv)
}
+static INLINE struct xlib_egl_display *
+xlib_egl_display(_EGLDisplay *dpy)
+{
+ return (struct xlib_egl_display *) dpy->DriverData;
+}
+
+
static INLINE struct xlib_egl_surface *
lookup_surface(_EGLSurface *surf)
{
@@ -132,7 +153,7 @@ bitcount(unsigned int n)
* Create the EGLConfigs. (one per X visual)
*/
static void
-create_configs(_EGLDriver *drv, _EGLDisplay *disp)
+create_configs(struct xlib_egl_display *xdpy, _EGLDisplay *disp)
{
static const EGLint all_apis = (EGL_OPENGL_ES_BIT |
EGL_OPENGL_ES2_BIT |
@@ -142,8 +163,8 @@ create_configs(_EGLDriver *drv, _EGLDisplay *disp)
int num_visuals, i;
/* get list of all X visuals, create an EGL config for each */
- visTemplate.screen = DefaultScreen(disp->Xdpy);
- visInfo = XGetVisualInfo(disp->Xdpy, VisualScreenMask,
+ visTemplate.screen = DefaultScreen(xdpy->Dpy);
+ visInfo = XGetVisualInfo(xdpy->Dpy, VisualScreenMask,
&visTemplate, &num_visuals);
if (!visInfo) {
printf("egl_xlib.c: couldn't get any X visuals\n");
@@ -185,6 +206,8 @@ create_configs(_EGLDriver *drv, _EGLDisplay *disp)
_eglAddConfig(disp, config);
}
+
+ XFree(visInfo);
}
@@ -193,21 +216,46 @@ create_configs(_EGLDriver *drv, _EGLDisplay *disp)
*/
static EGLBoolean
xlib_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
- EGLint *minor, EGLint *major)
+ EGLint *major, EGLint *minor)
{
struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
-
- if (!dpy->Xdpy) {
- dpy->Xdpy = XOpenDisplay(NULL);
+ struct xlib_egl_display *xdpy;
+
+ xdpy = CALLOC_STRUCT(xlib_egl_display);
+ if (!xdpy)
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+
+ xdpy->Dpy = (Display *) dpy->NativeDisplay;
+ if (!xdpy->Dpy) {
+ xdpy->Dpy = XOpenDisplay(NULL);
+ if (!xdpy->Dpy) {
+ free(xdpy);
+ return EGL_FALSE;
+ }
}
- create_configs(drv, dpy);
+ /* create winsys and pipe screen */
+ xdpy->winsys = create_sw_winsys();
+ if (!xdpy->winsys) {
+ free(xdpy);
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+ }
+ xdpy->winsys->flush_frontbuffer = flush_frontbuffer;
+ xdpy->screen = softpipe_create_screen(xdpy->winsys);
+ if (!xdpy->screen) {
+ free(xdpy->winsys);
+ free(xdpy);
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+ }
+ dpy->DriverData = (void *) xdpy;
dpy->ClientAPIsMask = xdrv->apis;
+ create_configs(xdpy, dpy);
+
/* we're supporting EGL 1.4 */
- *minor = 1;
- *major = 4;
+ *major = 1;
+ *minor = 4;
return EGL_TRUE;
}
@@ -219,8 +267,18 @@ xlib_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy,
static EGLBoolean
xlib_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
+ struct xlib_egl_display *xdpy = xlib_egl_display(dpy);
+
_eglReleaseDisplayResources(drv, dpy);
_eglCleanupDisplay(dpy);
+
+ xdpy->screen->destroy(xdpy->screen);
+ free(xdpy->winsys);
+
+ if (!dpy->NativeDisplay)
+ XCloseDisplay(xdpy->Dpy);
+ free(xdpy);
+
return EGL_TRUE;
}
@@ -352,7 +410,7 @@ static _EGLContext *
xlib_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
_EGLContext *share_list, const EGLint *attrib_list)
{
- struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
+ struct xlib_egl_display *xdpy = xlib_egl_display(dpy);
struct xlib_egl_context *ctx;
struct st_context *share_ctx = NULL; /* XXX fix */
__GLcontextModes visual;
@@ -376,7 +434,7 @@ xlib_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
/* fall-through */
case EGL_OPENGL_API:
/* create a softpipe context */
- ctx->pipe = softpipe_create(xdrv->screen);
+ ctx->pipe = softpipe_create(xdpy->screen);
/* Now do xlib / state tracker inits here */
_eglConfigToContextModesRec(conf, &visual);
ctx->Context = st_create_context(ctx->pipe, &visual, share_ctx);
@@ -494,7 +552,7 @@ static _EGLSurface *
xlib_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
NativeWindowType window, const EGLint *attrib_list)
{
- struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
+ struct xlib_egl_display *xdpy = xlib_egl_display(disp);
struct xlib_egl_surface *surf;
__GLcontextModes visual;
uint width, height;
@@ -514,10 +572,10 @@ xlib_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf
* Now init the Xlib and gallium stuff
*/
surf->Win = (Window) window; /* The X window ID */
- surf->Dpy = disp->Xdpy; /* The X display */
+ surf->Dpy = xdpy->Dpy; /* The X display */
surf->Gc = XCreateGC(surf->Dpy, surf->Win, 0, NULL);
- surf->winsys = xdrv->winsys;
+ surf->winsys = xdpy->winsys;
_eglConfigToContextModesRec(conf, &visual);
get_drawable_size(surf->Dpy, surf->Win, &width, &height);
@@ -544,7 +602,7 @@ static _EGLSurface *
xlib_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list)
{
- struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
+ struct xlib_egl_display *xdpy = xlib_egl_display(disp);
struct xlib_egl_surface *surf;
__GLcontextModes visual;
uint width, height;
@@ -589,7 +647,7 @@ xlib_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *con
return NULL;
}
- surf->winsys = xdrv->winsys;
+ surf->winsys = xdpy->winsys;
_eglConfigToContextModesRec(conf, &visual);
@@ -762,8 +820,6 @@ static void
xlib_Unload(_EGLDriver *drv)
{
struct xlib_egl_driver *xdrv = xlib_egl_driver(drv);
- xdrv->screen->destroy(xdrv->screen);
- free(xdrv->winsys);
free(xdrv);
}
@@ -809,11 +865,5 @@ _eglMain(const char *args)
xdrv->Base.Name = "Xlib/softpipe";
xdrv->Base.Unload = xlib_Unload;
- /* create one winsys and use it for all contexts/surfaces */
- xdrv->winsys = create_sw_winsys();
- xdrv->winsys->flush_frontbuffer = flush_frontbuffer;
-
- xdrv->screen = softpipe_create_screen(xdrv->winsys);
-
return &xdrv->Base;
}
--
1.6.2.4
>From 81cf660226e2fe68e9359f040214e0ac53355650 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Wed, 26 Aug 2009 14:45:17 +0800
Subject: [PATCH 3/4] egl_glx: Make fbconfigs and visuals per display.
This is to allow a driver to drive multiple displays. Remove the use of
_EGL_PLATFORM_X and obsolete code along the way.
Signed-off-by: Chia-I Wu <[email protected]>
---
src/egl/drivers/glx/egl_glx.c | 249 ++++++++++++++++++++++-------------------
1 files changed, 135 insertions(+), 114 deletions(-)
diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c
index 3c8f8b6..4685f60 100644
--- a/src/egl/drivers/glx/egl_glx.c
+++ b/src/egl/drivers/glx/egl_glx.c
@@ -50,8 +50,6 @@
#include <GL/gl.h>
#include "glxclient.h"
-#define _EGL_PLATFORM_X
-
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldisplay.h"
@@ -105,7 +103,13 @@ struct visual_attribs
struct GLX_egl_driver
{
_EGLDriver Base; /**< base class */
+};
+
+/** driver data of _EGLDisplay */
+struct GLX_egl_display
+{
+ Display *dpy;
XVisualInfo *visuals;
GLXFBConfig *fbconfigs;
@@ -135,6 +139,7 @@ struct GLX_egl_surface
struct GLX_egl_config
{
_EGLConfig Base; /**< base class */
+ int index;
};
/** cast wrapper */
@@ -144,6 +149,12 @@ 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)
{
@@ -157,10 +168,9 @@ GLX_egl_surface(_EGLSurface *surf)
}
static int
-GLX_egl_config_id(_EGLConfig *conf)
+GLX_egl_config_index(_EGLConfig *conf)
{
- /* see create_configs */
- return (int) _eglPointerToUInt(_eglGetConfigHandle(conf)) - 1;
+ return ((struct GLX_egl_config *) conf)->index;
}
static GLboolean
@@ -273,6 +283,7 @@ glx_token_to_visual_class(int visual_type)
return None;
}
}
+
static int
get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
struct visual_attribs *attribs)
@@ -351,7 +362,7 @@ get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
#endif
static EGLBoolean
-create_configs(_EGLDisplay *disp, struct GLX_egl_driver *GLX_drv)
+create_configs(_EGLDisplay *disp, struct GLX_egl_display *GLX_dpy)
{
XVisualInfo theTemplate;
int numVisuals;
@@ -359,14 +370,14 @@ create_configs(_EGLDisplay *disp, struct GLX_egl_driver *GLX_drv)
int i;
struct visual_attribs attribs;
- GLX_drv->fbconfigs = NULL;
+ GLX_dpy->fbconfigs = NULL;
#ifdef GLX_VERSION_1_3
/* get list of all fbconfigs on this screen */
- GLX_drv->fbconfigs = glXGetFBConfigs(disp->Xdpy, DefaultScreen(disp->Xdpy), &numVisuals);
+ GLX_dpy->fbconfigs = glXGetFBConfigs(GLX_dpy->dpy, DefaultScreen(GLX_dpy->dpy), &numVisuals);
if (numVisuals == 0) {
- GLX_drv->fbconfigs = NULL;
+ GLX_dpy->fbconfigs = NULL;
goto xvisual;
}
@@ -374,12 +385,13 @@ create_configs(_EGLDisplay *disp, struct GLX_egl_driver *GLX_drv)
struct GLX_egl_config *config;
int bit;
- bit = get_fbconfig_attribs(disp->Xdpy, GLX_drv->fbconfigs[i], &attribs);
+ bit = get_fbconfig_attribs(GLX_dpy->dpy, GLX_dpy->fbconfigs[i], &attribs);
if (!bit)
continue;
config = CALLOC_STRUCT(GLX_egl_config);
+ config->index = i;
_eglInitConfig(&config->Base, (i+1));
SET_CONFIG_ATTRIB(&config->Base, EGL_NATIVE_VISUAL_ID, attribs.id);
SET_CONFIG_ATTRIB(&config->Base, EGL_BUFFER_SIZE, attribs.bufferSize);
@@ -405,18 +417,19 @@ create_configs(_EGLDisplay *disp, struct GLX_egl_driver *GLX_drv)
xvisual:
/* get list of all visuals on this screen */
- theTemplate.screen = DefaultScreen(disp->Xdpy);
+ theTemplate.screen = DefaultScreen(GLX_dpy->dpy);
mask = VisualScreenMask;
- GLX_drv->visuals = XGetVisualInfo(disp->Xdpy, mask, &theTemplate, &numVisuals);
+ GLX_dpy->visuals = XGetVisualInfo(GLX_dpy->dpy, mask, &theTemplate, &numVisuals);
for (i = 0; i < numVisuals; i++) {
struct GLX_egl_config *config;
- if (!get_visual_attribs(disp->Xdpy, &GLX_drv->visuals[i], &attribs))
+ if (!get_visual_attribs(GLX_dpy->dpy, &GLX_dpy->visuals[i], &attribs))
continue;
config = CALLOC_STRUCT(GLX_egl_config);
+ config->index = i;
_eglInitConfig(&config->Base, (i+1));
SET_CONFIG_ATTRIB(&config->Base, EGL_NATIVE_VISUAL_ID, attribs.id);
SET_CONFIG_ATTRIB(&config->Base, EGL_BUFFER_SIZE, attribs.bufferSize);
@@ -447,75 +460,60 @@ end:
*/
static EGLBoolean
GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
- EGLint *minor, EGLint *major)
+ EGLint *major, EGLint *minor)
{
- struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ struct GLX_egl_display *GLX_dpy;
- _eglLog(_EGL_DEBUG, "GLX: eglInitialize");
+ GLX_dpy = CALLOC_STRUCT(GLX_egl_display);
+ if (!GLX_dpy)
+ return _eglError(EGL_BAD_ALLOC, "eglInitialize");
- if (!disp->Xdpy) {
- disp->Xdpy = XOpenDisplay(NULL);
- if (!disp->Xdpy) {
+ GLX_dpy->dpy = (Display *) disp->NativeDisplay;
+ if (!GLX_dpy->dpy) {
+ GLX_dpy->dpy = XOpenDisplay(NULL);
+ if (!GLX_dpy->dpy) {
_eglLog(_EGL_WARNING, "GLX: XOpenDisplay failed");
+ free(GLX_dpy);
return EGL_FALSE;
}
- }
+ }
+ disp->DriverData = (void *) GLX_dpy;
disp->ClientAPIsMask = all_apis;
- glXQueryVersion(disp->Xdpy, &GLX_drv->glx_maj, &GLX_drv->glx_min);
-
- GLX_drv->Base.Name = "GLX";
+ glXQueryVersion(GLX_dpy->dpy, &GLX_dpy->glx_maj, &GLX_dpy->glx_min);
/* we're supporting EGL 1.4 */
- *minor = 1;
- *major = 4;
+ *major = 1;
+ *minor = 4;
- create_configs(disp, GLX_drv);
+ create_configs(disp, GLX_dpy);
return EGL_TRUE;
}
-/*
- * Do some clean-up that normally occurs in XCloseDisplay().
- * We do this here because we're about to unload a dynamic library
- * that has added some per-display extension data and callbacks.
- * If we don't do this here we'll crash in XCloseDisplay() because it'll
- * try to call functions that went away when the driver library was unloaded.
- */
-static void
-FreeDisplayExt(Display *dpy)
-{
- _XExtension *ext, *next;
-
- for (ext = dpy->ext_procs; ext; ext = next) {
- next = ext->next;
- if (ext->close_display) {
- ext->close_display(dpy, &ext->codes);
- ext->close_display = NULL;
- }
- if (ext->name)
- Xfree(ext->name);
- Xfree(ext);
- }
- dpy->ext_procs = NULL;
-
- _XFreeExtData (dpy->ext_data);
- dpy->ext_data = NULL;
-}
-
/**
* Called via eglTerminate(), drv->API.Terminate().
*/
static EGLBoolean
GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp)
{
- _eglLog(_EGL_DEBUG, "GLX: eglTerminate");
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
_eglReleaseDisplayResources(drv, disp);
- FreeDisplayExt(disp->Xdpy);
_eglCleanupDisplay(disp);
+ if (GLX_dpy->visuals)
+ XFree(GLX_dpy->visuals);
+ if (GLX_dpy->fbconfigs)
+ XFree(GLX_dpy->fbconfigs);
+
+ if (!disp->NativeDisplay)
+ XCloseDisplay(GLX_dpy->dpy);
+ free(GLX_dpy);
+
+ disp->DriverData = NULL;
+
return EGL_TRUE;
}
@@ -528,11 +526,13 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
_EGLContext *share_list, const EGLint *attrib_list)
{
struct GLX_egl_context *GLX_ctx = CALLOC_STRUCT(GLX_egl_context);
- struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_context *GLX_ctx_shared = GLX_egl_context(share_list);
- if (!GLX_ctx)
+ if (!GLX_ctx) {
+ _eglError(EGL_BAD_ALLOC, "eglCreateContext");
return NULL;
+ }
if (!_eglInitContext(drv, &GLX_ctx->Base, conf, attrib_list)) {
free(GLX_ctx);
@@ -540,27 +540,32 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
}
#ifdef GLX_VERSION_1_3
- if (GLX_drv->fbconfigs)
+ if (GLX_dpy->fbconfigs)
GLX_ctx->context =
- glXCreateNewContext(disp->Xdpy,
- GLX_drv->fbconfigs[GLX_egl_config_id(conf)],
+ glXCreateNewContext(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
GLX_RGBA_TYPE,
GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
GL_TRUE);
else
#endif
GLX_ctx->context =
- glXCreateContext(disp->Xdpy,
- &GLX_drv->visuals[GLX_egl_config_id(conf)],
+ glXCreateContext(GLX_dpy->dpy,
+ &GLX_dpy->visuals[GLX_egl_config_index(conf)],
GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
GL_TRUE);
- if (!GLX_ctx->context)
- return EGL_FALSE;
+ if (!GLX_ctx->context) {
+ free(GLX_ctx);
+ return NULL;
+ }
#if 1
/* (maybe?) need to have a direct rendering context */
- if (!glXIsDirect(disp->Xdpy, GLX_ctx->context))
- return EGL_FALSE;
+ if (!glXIsDirect(GLX_dpy->dpy, GLX_ctx->context)) {
+ glXDestroyContext(GLX_dpy->dpy, GLX_ctx->context);
+ free(GLX_ctx);
+ return NULL;
+ }
#endif
return &GLX_ctx->Base;
@@ -574,20 +579,29 @@ static EGLBoolean
GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
_EGLSurface *rsurf, _EGLContext *ctx)
{
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_dsurf = GLX_egl_surface(dsurf);
struct GLX_egl_surface *GLX_rsurf = GLX_egl_surface(rsurf);
struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx);
+ GLXDrawable ddraw, rdraw;
+ GLXContext cctx;
if (!_eglMakeCurrent(drv, disp, dsurf, rsurf, ctx))
return EGL_FALSE;
+ ddraw = (GLX_dsurf) ? GLX_dsurf->drawable : None;
+ rdraw = (GLX_rsurf) ? GLX_rsurf->drawable : None;
+ cctx = (GLX_ctx) ? GLX_ctx->context : NULL;
+
#ifdef GLX_VERSION_1_3
- if (!glXMakeContextCurrent(disp->Xdpy, GLX_dsurf ? GLX_dsurf->drawable : 0, GLX_rsurf ? GLX_rsurf->drawable : 0, GLX_ctx ? GLX_ctx->context : NULL))
+ if (glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx))
+ return EGL_TRUE;
#endif
- if (!glXMakeCurrent(disp->Xdpy, GLX_dsurf ? GLX_dsurf->drawable : 0, GLX_ctx ? GLX_ctx->context : NULL))
- return EGL_FALSE;
- return EGL_TRUE;
+ if (ddraw == rdraw && glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx))
+ return EGL_TRUE;
+
+ return EGL_FALSE;
}
/** Get size of given window */
@@ -611,12 +625,15 @@ static _EGLSurface *
GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
NativeWindowType window, const EGLint *attrib_list)
{
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
uint width, height;
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
- if (!GLX_surf)
+ if (!GLX_surf) {
+ _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
return NULL;
+ }
if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_WINDOW_BIT,
conf, attrib_list)) {
@@ -625,7 +642,7 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
}
GLX_surf->drawable = window;
- get_drawable_size(disp->Xdpy, window, &width, &height);
+ get_drawable_size(GLX_dpy->dpy, window, &width, &height);
GLX_surf->Base.Width = width;
GLX_surf->Base.Height = height;
@@ -637,13 +654,19 @@ static _EGLSurface *
GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
NativePixmapType pixmap, const EGLint *attrib_list)
{
- struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
int i;
+ /* GLX must >= 1.3 */
+ if (!(GLX_dpy->glx_maj == 1 && GLX_dpy->glx_min >= 3))
+ return NULL;
+
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
- if (!GLX_surf)
+ if (!GLX_surf) {
+ _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
return NULL;
+ }
if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PIXMAP_BIT,
conf, attrib_list)) {
@@ -656,30 +679,41 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
/* no attribs at this time */
default:
_eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface");
+ free(GLX_surf);
return NULL;
}
}
GLX_surf->drawable =
- glXCreatePixmap(disp->Xdpy,
- GLX_drv->fbconfigs[GLX_egl_config_id(conf)],
+ glXCreatePixmap(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
pixmap, NULL);
+ if (!GLX_surf->drawable) {
+ free(GLX_surf);
+ return NULL;
+ }
return &GLX_surf->Base;
}
static _EGLSurface *
-GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
- const EGLint *attrib_list)
+GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, const EGLint *attrib_list)
{
- struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
int attribs[5];
int i = 0, j = 0;
+ /* GLX must >= 1.3 */
+ if (!(GLX_dpy->glx_maj == 1 && GLX_dpy->glx_min >= 3))
+ return NULL;
+
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
- if (!GLX_surf)
+ if (!GLX_surf) {
+ _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
return NULL;
+ }
if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PBUFFER_BIT,
conf, attrib_list)) {
@@ -703,8 +737,13 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf
attribs[j++] = 0;
GLX_surf->drawable =
- glXCreatePbuffer(disp->Xdpy,
- GLX_drv->fbconfigs[GLX_egl_config_id(conf)], attribs);
+ glXCreatePbuffer(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
+ attribs);
+ if (!GLX_surf->drawable) {
+ free(GLX_surf);
+ return NULL;
+ }
return &GLX_surf->Base;
}
@@ -713,14 +752,15 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf
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);
switch (surf->Type) {
case EGL_PBUFFER_BIT:
- glXDestroyPbuffer(disp->Xdpy, GLX_surf->drawable);
+ glXDestroyPbuffer(GLX_dpy->dpy, GLX_surf->drawable);
break;
case EGL_PIXMAP_BIT:
- glXDestroyPixmap(disp->Xdpy, GLX_surf->drawable);
+ glXDestroyPixmap(GLX_dpy->dpy, GLX_surf->drawable);
break;
default:
break;
@@ -736,10 +776,12 @@ static EGLBoolean
GLX_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
EGLint buffer)
{
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf);
/* buffer ?? */
- glXBindTexImageEXT(disp->Xdpy, GLX_surf->drawable, GLX_FRONT_LEFT_EXT, NULL);
+ glXBindTexImageEXT(GLX_dpy->dpy, GLX_surf->drawable,
+ GLX_FRONT_LEFT_EXT, NULL);
return EGL_TRUE;
}
@@ -749,10 +791,12 @@ static EGLBoolean
GLX_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
EGLint buffer)
{
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf);
/* buffer ?? */
- glXReleaseTexImageEXT(disp->Xdpy, GLX_surf->drawable, GLX_FRONT_LEFT_EXT);
+ glXReleaseTexImageEXT(GLX_dpy->dpy, GLX_surf->drawable,
+ GLX_FRONT_LEFT_EXT);
return EGL_TRUE;
}
@@ -761,15 +805,12 @@ GLX_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
static EGLBoolean
GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
{
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf = GLX_egl_surface(draw);
_eglLog(_EGL_DEBUG, "GLX: EGL SwapBuffers 0x%x",draw);
- /* error checking step: */
- if (!_eglSwapBuffers(drv, disp, draw))
- return EGL_FALSE;
-
- glXSwapBuffers(disp->Xdpy, GLX_surf->drawable);
+ glXSwapBuffers(GLX_dpy->dpy, GLX_surf->drawable);
return EGL_TRUE;
}
@@ -814,7 +855,6 @@ _EGLDriver *
_eglMain(const char *args)
{
struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver);
- char *env;
if (!GLX_drv)
return NULL;
@@ -826,13 +866,8 @@ _eglMain(const char *args)
GLX_drv->Base.API.MakeCurrent = GLX_eglMakeCurrent;
GLX_drv->Base.API.CreateWindowSurface = GLX_eglCreateWindowSurface;
#ifdef GLX_VERSION_1_3
- if (GLX_drv->glx_maj == 1 && GLX_drv->glx_min >= 3) {
- GLX_drv->Base.API.CreatePixmapSurface = GLX_eglCreatePixmapSurface;
- GLX_drv->Base.API.CreatePbufferSurface = GLX_eglCreatePbufferSurface;
- printf("GLX: Pbuffer and Pixmap support\n");
- } else {
- printf("GLX: No pbuffer or pixmap support\n");
- }
+ GLX_drv->Base.API.CreatePixmapSurface = GLX_eglCreatePixmapSurface;
+ GLX_drv->Base.API.CreatePbufferSurface = GLX_eglCreatePbufferSurface;
#endif
GLX_drv->Base.API.DestroySurface = GLX_eglDestroySurface;
GLX_drv->Base.API.BindTexImage = GLX_eglBindTexImage;
@@ -843,19 +878,5 @@ _eglMain(const char *args)
GLX_drv->Base.Name = "GLX";
GLX_drv->Base.Unload = GLX_Unload;
- _eglLog(_EGL_DEBUG, "GLX: main(%s)", args);
-
- /* set new DRI path to pick up EGL version (which doesn't contain any mesa
- * code), but don't override if one is already set.
- */
- env = getenv("LIBGL_DRIVERS_PATH");
- if (env) {
- if (!strstr(env, "egl")) {
- sprintf(env, "%s/egl", env);
- setenv("LIBGL_DRIVERS_PATH", env, 1);
- }
- } else
- setenv("LIBGL_DRIVERS_PATH", DEFAULT_DRIVER_DIR"/egl", 0);
-
return &GLX_drv->Base;
}
--
1.6.2.4
>From 2260e2b57a397cc207cb7cab96e2c2e3f065a627 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Wed, 26 Aug 2009 16:06:39 +0800
Subject: [PATCH 4/4] egl: Remove Xdpy from EGLDisplay.
It is not used anymore.
Signed-off-by: Chia-I Wu <[email protected]>
---
src/egl/main/egldisplay.c | 3 ---
src/egl/main/egldisplay.h | 8 --------
2 files changed, 0 insertions(+), 11 deletions(-)
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 2c271ef..896d60d 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -81,9 +81,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay)
_EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
if (dpy) {
dpy->NativeDisplay = nativeDisplay;
-#if defined(_EGL_PLATFORM_X)
- dpy->Xdpy = (Display *) nativeDisplay;
-#endif
dpy->DriverName = _eglPreloadDriver(dpy);
if (!dpy->DriverName) {
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index c7a41cd..6575fdf 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -1,10 +1,6 @@
#ifndef EGLDISPLAY_INCLUDED
#define EGLDISPLAY_INCLUDED
-#ifdef _EGL_PLATFORM_X
-#include <X11/Xlib.h>
-#endif
-
#include "egltypedefs.h"
#include "egldefines.h"
#include "eglcontext.h"
@@ -54,10 +50,6 @@ struct _egl_display
/* lists of linked contexts and surface */
_EGLContext *ContextList;
_EGLSurface *SurfaceList;
-
-#ifdef _EGL_PLATFORM_X
- Display *Xdpy;
-#endif
};
--
1.6.2.4
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev