aboutsummaryrefslogtreecommitdiffstats
path: root/src/egl/main
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-05-27 16:48:23 -0600
committerBrian Paul <[email protected]>2008-05-27 16:48:23 -0600
commit6052af172f0241e6678cd16efac0a0f14f40146c (patch)
treedefc05f9ffee989aac7faf6d7ba690f5f11e4e93 /src/egl/main
parent721ba15bf4596b2e9589e7656005b387724875c3 (diff)
minor overhaul/re-org of driver selection/loading code
Diffstat (limited to 'src/egl/main')
-rw-r--r--src/egl/main/Makefile11
-rw-r--r--src/egl/main/eglapi.c27
-rw-r--r--src/egl/main/eglconfig.c4
-rw-r--r--src/egl/main/eglconfig.h6
-rw-r--r--src/egl/main/egldisplay.c57
-rw-r--r--src/egl/main/egldisplay.h14
-rw-r--r--src/egl/main/egldriver.c61
-rw-r--r--src/egl/main/egldriver.h6
8 files changed, 124 insertions, 62 deletions
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index e1058a23f70..0efcd4e605b 100644
--- a/src/egl/main/Makefile
+++ b/src/egl/main/Makefile
@@ -16,7 +16,8 @@ HEADERS = \
eglhash.h \
eglmode.h \
eglscreen.h \
- eglsurface.h
+ eglsurface.h \
+ eglx.h
SOURCES = \
eglapi.c \
@@ -29,13 +30,17 @@ SOURCES = \
eglhash.c \
eglmode.c \
eglscreen.c \
- eglsurface.c
+ eglsurface.c \
+ eglx.c
OBJECTS = $(SOURCES:.c=.o)
+LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1
+
+
.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index e4eec26de0a..fe63d36b803 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -43,27 +43,38 @@
/**
- * NOTE: displayName is treated as a string in _eglChooseDriver()!!!
- * This will probably change!
- * See _eglChooseDriver() for details!
+ * This is typically the first EGL function that an application calls.
+ * We initialize our global vars and create a private _EGLDisplay object.
*/
EGLDisplay EGLAPIENTRY
-eglGetDisplay(NativeDisplayType displayName)
+eglGetDisplay(NativeDisplayType nativeDisplay)
{
_EGLDisplay *dpy;
_eglInitGlobals();
- dpy = _eglNewDisplay(displayName);
+ dpy = _eglNewDisplay(nativeDisplay);
return _eglGetDisplayHandle(dpy);
}
+/**
+ * This is typically the second EGL function that an application calls.
+ * Here we load/initialize the actual hardware driver.
+ */
EGLBoolean EGLAPIENTRY
eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
{
if (dpy) {
- _EGLDriver *drv = _eglChooseDriver(dpy);
- if (drv)
- return drv->API.Initialize(drv, dpy, major, minor);
+ _EGLDisplay *dpyPriv = _eglLookupDisplay(dpy);
+ if (!dpyPriv) {
+ return EGL_FALSE;
+ }
+ dpyPriv->Driver = _eglOpenDriver(dpyPriv, dpyPriv->DriverName);
+ if (!dpyPriv->Driver) {
+ return EGL_FALSE;
+ }
+ /* Initialize the particular driver now */
+ return dpyPriv->Driver->API.Initialize(dpyPriv->Driver, dpy,
+ major, minor);
}
return EGL_FALSE;
}
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index 1b49f7afd92..eb2c34a8028 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -17,7 +17,6 @@
#define MIN2(A, B) (((A) < (B)) ? (A) : (B))
-#if 0
/**
* Convert an _EGLConfig to a __GLcontextModes object.
* NOTE: This routine may be incomplete - we're only making sure that
@@ -58,7 +57,6 @@ _eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode)
mode->visualType = GLX_TRUE_COLOR;
mode->renderType = GLX_RGBA_BIT;
}
-#endif
void
@@ -445,6 +443,7 @@ _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs,
}
+#if 0
/**
* Creates a set of \c __GLcontextModes that a driver will expose.
*
@@ -512,7 +511,6 @@ _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs,
* \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.
*/
-#if 0
GLboolean
_eglFillInConfigs(_EGLConfig * configs,
GLenum fb_format, GLenum fb_type,
diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h
index 4a806129805..e025f7f8451 100644
--- a/src/egl/main/eglconfig.h
+++ b/src/egl/main/eglconfig.h
@@ -3,9 +3,8 @@
#include "egltypedefs.h"
-#if 0
+#include <GLES/gl.h>
#include "GL/internal/glcore.h"
-#endif
#define MAX_ATTRIBS 100
@@ -68,10 +67,9 @@ _eglFillInConfigs( _EGLConfig *configs,
int visType );
#endif
-#if 0
+
extern void
_eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode);
-#endif
#endif /* EGLCONFIG_INCLUDED */
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index fd24f222739..9c42194c611 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -1,7 +1,14 @@
+
+/**
+ * Functions related to EGLDisplay.
+ */
+
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "eglcontext.h"
#include "egldisplay.h"
+#include "egldriver.h"
#include "eglglobals.h"
#include "eglhash.h"
@@ -9,31 +16,41 @@
static char *
my_strdup(const char *s)
{
- int l = strlen(s);
- char *s2 = malloc(l + 1);
- strcpy(s2, s);
- return s2;
+ if (s) {
+ int l = strlen(s);
+ char *s2 = malloc(l + 1);
+ if (s2)
+ strcpy(s2, s);
+ return s2;
+ }
+ return NULL;
}
/**
- * We're assuming that the NativeDisplayType parameter is actually
- * a string.
- * Return a new _EGLDisplay object for the given displayName
+ * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
+ * We'll also try to determine the device driver name at this time.
*/
_EGLDisplay *
-_eglNewDisplay(NativeDisplayType displayName)
+_eglNewDisplay(NativeDisplayType nativeDisplay)
{
_EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
if (dpy) {
EGLuint key = _eglHashGenKey(_eglGlobal.Displays);
+
dpy->Handle = (EGLDisplay) key;
_eglHashInsert(_eglGlobal.Displays, key, dpy);
- if (displayName)
- dpy->Name = my_strdup((char *) displayName);
- else
- dpy->Name = NULL;
- dpy->Driver = NULL; /* this gets set later */
+
+ dpy->NativeDisplay = nativeDisplay;
+#if defined(_EGL_PLATFORM_X)
+ dpy->Xdpy = (Display *) nativeDisplay;
+#endif
+
+ dpy->DriverName = my_strdup(_eglChooseDriver(dpy));
+ if (!dpy->DriverName) {
+ free(dpy);
+ return NULL;
+ }
}
return dpy;
}
@@ -67,6 +84,18 @@ _eglLookupDisplay(EGLDisplay dpy)
}
+void
+_eglSaveDisplay(_EGLDisplay *dpy)
+{
+ EGLuint key = _eglHashGenKey(_eglGlobal.Displays);
+ assert(dpy);
+ assert(!dpy->Handle);
+ dpy->Handle = (EGLDisplay) key;
+ assert(dpy->Handle);
+ _eglHashInsert(_eglGlobal.Displays, key, dpy);
+}
+
+
_EGLDisplay *
_eglGetCurrentDisplay(void)
{
@@ -83,6 +112,6 @@ _eglCleanupDisplay(_EGLDisplay *disp)
{
/* XXX incomplete */
free(disp->Configs);
- free(disp->Name);
+ free((void *) disp->DriverName);
/* driver deletes _EGLDisplay */
}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index fe7b7884555..be134374ca4 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -1,15 +1,19 @@
#ifndef EGLDISPLAY_INCLUDED
#define EGLDISPLAY_INCLUDED
+#ifdef _EGL_PLATFORM_X
+#include <X11/Xlib.h>
+#endif
#include "egltypedefs.h"
struct _egl_display
{
+ EGLNativeDisplayType NativeDisplay;
EGLDisplay Handle;
- char *Name;
+ const char *DriverName;
_EGLDriver *Driver;
EGLint NumScreens;
@@ -17,6 +21,10 @@ struct _egl_display
EGLint NumConfigs;
_EGLConfig *Configs; /* array [NumConfigs] */
+
+#ifdef _EGL_PLATFORM_X
+ Display *Xdpy;
+#endif
};
@@ -32,6 +40,10 @@ extern _EGLDisplay *
_eglLookupDisplay(EGLDisplay dpy);
+extern void
+_eglSaveDisplay(_EGLDisplay *dpy);
+
+
extern _EGLDisplay *
_eglGetCurrentDisplay(void);
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index bda06dd827d..50c466c2582 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -1,3 +1,8 @@
+/**
+ * Functions for choosing and opening/loading device drivers.
+ */
+
+
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
@@ -11,62 +16,64 @@
#include "eglmode.h"
#include "eglscreen.h"
#include "eglsurface.h"
+#include "eglx.h"
const char *DefaultDriverName = "demodriver";
/**
- * Choose and open/init the hardware driver for the given EGLDisplay.
- * Previously, the EGLDisplay was created with _eglNewDisplay() where
- * we recorded the user's NativeDisplayType parameter.
+ * Determine/return the name of the driver to use for the given _EGLDisplay.
*
- * Now we'll use the NativeDisplayType value.
+ * Try to be clever and determine if nativeDisplay is an Xlib Display
+ * ptr or a string (naming a driver or screen number, etc).
*
- * Currently, the native display value is treated as a string.
* If the first character is ':' we interpret it as a screen or card index
* number (i.e. ":0" or ":1", etc)
* Else if the first character is '!' we interpret it as specific driver name
* (i.e. "!r200" or "!i830".
+ *
+ * The caller should make a copy of the returned string.
*/
-_EGLDriver *
-_eglChooseDriver(EGLDisplay display)
+const char *
+_eglChooseDriver(_EGLDisplay *dpy)
{
- _EGLDisplay *dpy = _eglLookupDisplay(display);
- _EGLDriver *drv;
- const char *driverName = DefaultDriverName;
- const char *name;
+ const char *name = (const char *) dpy->NativeDisplay;
+ const char *driverName = NULL;
- assert(dpy);
-
- name = dpy->Name;
- if (!name) {
- /* use default */
+ if (!dpy->NativeDisplay) {
+ /* choose a default */
+ driverName = DefaultDriverName;
}
- else if (name[0] == ':' && (name[1] >= '0' && name[1] <= '9') && !name[2]) {
+ else if (name && name[0] == ':' &&
+ (name[1] >= '0' && name[1] <= '9') && !name[2]) {
/* XXX probe hardware here to determine which driver to open */
driverName = "libEGLdri";
}
- else if (name[0] == '!') {
+ else if (name && name[0] == '!') {
/* use specified driver name */
driverName = name + 1;
}
else {
- /* Maybe display was returned by XOpenDisplay? */
- _eglLog(_EGL_FATAL, "eglChooseDriver() bad name");
+#if defined(_EGL_PLATFORM_X)
+ driverName = _xeglChooseDriver(dpy);
+#elif defined(_EGL_PLATFORM_WINDOWS)
+ /* XXX to do */
+ driverName = _weglChooseDriver(dpy);
+#elif defined(_EGL_PLATFORM_WINCE)
+ /* XXX to do */
+#endif
}
- _eglLog(_EGL_INFO, "eglChooseDriver() choosing %s", driverName);
-
- drv = _eglOpenDriver(dpy, driverName);
- dpy->Driver = drv;
-
- return drv;
+ return driverName;
}
/**
* Open/load the named driver and call its bootstrap function: _eglMain().
+ * By the time this function is called, the dpy->DriverName should have
+ * been determined.
+ *
* \return new _EGLDriver object.
*/
_EGLDriver *
@@ -77,6 +84,8 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName)
void *lib;
char driverFilename[1000];
+ assert(driverName);
+
/* XXX also prepend a directory path??? */
sprintf(driverFilename, "%s.so", driverName);
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 88526e973d1..bde726e25e0 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -45,12 +45,12 @@ struct _egl_driver
extern _EGLDriver *_eglMain(_EGLDisplay *dpy);
-extern _EGLDriver *
-_eglChooseDriver(EGLDisplay dpy);
+extern const char *
+_eglChooseDriver(_EGLDisplay *dpy);
extern _EGLDriver *
-_eglOpenDriver(_EGLDisplay *dpy, const char *driverName);
+_eglOpenDriver(_EGLDisplay *dpy, const char *DriverName);
extern EGLBoolean