minor overhaul/re-org of driver selection/loading code
This commit is contained in:
@@ -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 $@
|
||||
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user