2 * Functions for choosing and opening/loading device drivers.
10 #include "eglconfig.h"
11 #include "eglcontext.h"
12 #include "egldisplay.h"
13 #include "egldriver.h"
14 #include "eglglobals.h"
17 #include "eglscreen.h"
18 #include "eglsurface.h"
22 const char *DefaultDriverName = "demodriver";
26 * Determine/return the name of the driver to use for the given _EGLDisplay.
28 * Try to be clever and determine if nativeDisplay is an Xlib Display
29 * ptr or a string (naming a driver or screen number, etc).
31 * If the first character is ':' we interpret it as a screen or card index
32 * number (i.e. ":0" or ":1", etc)
33 * Else if the first character is '!' we interpret it as specific driver name
34 * (i.e. "!r200" or "!i830".
36 * The caller should make a copy of the returned string.
39 _eglChooseDriver(_EGLDisplay *dpy)
41 const char *name = (const char *) dpy->NativeDisplay;
42 const char *driverName = NULL;
44 if (!dpy->NativeDisplay) {
45 /* choose a default */
46 driverName = DefaultDriverName;
48 else if (name && name[0] == ':' &&
49 (name[1] >= '0' && name[1] <= '9') && !name[2]) {
50 /* XXX probe hardware here to determine which driver to open */
51 driverName = "libEGLdri";
53 else if (name && name[0] == '!') {
54 /* use specified driver name */
55 driverName = name + 1;
58 #if defined(_EGL_PLATFORM_X)
59 driverName = _xeglChooseDriver(dpy);
60 #elif defined(_EGL_PLATFORM_WINDOWS)
62 driverName = _weglChooseDriver(dpy);
63 #elif defined(_EGL_PLATFORM_WINCE)
73 * Open/load the named driver and call its bootstrap function: _eglMain().
74 * By the time this function is called, the dpy->DriverName should have
77 * \return new _EGLDriver object.
80 _eglOpenDriver(_EGLDisplay *dpy, const char *driverName)
85 char driverFilename[1000];
89 /* XXX also prepend a directory path??? */
90 sprintf(driverFilename, "%s.so", driverName);
92 _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
93 lib = dlopen(driverFilename, RTLD_NOW);
95 _eglLog(_EGL_WARNING, "Could not open %s (%s)",
96 driverFilename, dlerror());
100 mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
102 _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename);
112 /* with a recurvise open you want the inner most handle */
114 drv->LibHandle = lib;
124 _eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy)
126 void *handle = drv->LibHandle;
129 _eglLog(_EGL_INFO, "Closing driver");
132 * XXX check for currently bound context/surfaces and delete them?
135 b = drv->API.Terminate(drv, dpy);
142 * Given a display handle, return the _EGLDriver for that display.
145 _eglLookupDriver(EGLDisplay dpy)
147 _EGLDisplay *d = _eglLookupDisplay(dpy);
156 * Plug all the available fallback routines into the given driver's
160 _eglInitDriverFallbacks(_EGLDriver *drv)
162 /* If a pointer is set to NULL, then the device driver _really_ has
165 drv->API.Initialize = NULL;
166 drv->API.Terminate = NULL;
168 drv->API.GetConfigs = _eglGetConfigs;
169 drv->API.ChooseConfig = _eglChooseConfig;
170 drv->API.GetConfigAttrib = _eglGetConfigAttrib;
172 drv->API.CreateContext = _eglCreateContext;
173 drv->API.DestroyContext = _eglDestroyContext;
174 drv->API.MakeCurrent = _eglMakeCurrent;
175 drv->API.QueryContext = _eglQueryContext;
177 drv->API.CreateWindowSurface = _eglCreateWindowSurface;
178 drv->API.CreatePixmapSurface = _eglCreatePixmapSurface;
179 drv->API.CreatePbufferSurface = _eglCreatePbufferSurface;
180 drv->API.DestroySurface = _eglDestroySurface;
181 drv->API.QuerySurface = _eglQuerySurface;
182 drv->API.SurfaceAttrib = _eglSurfaceAttrib;
183 drv->API.BindTexImage = _eglBindTexImage;
184 drv->API.ReleaseTexImage = _eglReleaseTexImage;
185 drv->API.SwapInterval = _eglSwapInterval;
186 drv->API.SwapBuffers = _eglSwapBuffers;
187 drv->API.CopyBuffers = _eglCopyBuffers;
189 drv->API.QueryString = _eglQueryString;
190 drv->API.WaitGL = _eglWaitGL;
191 drv->API.WaitNative = _eglWaitNative;
193 #ifdef EGL_MESA_screen_surface
194 drv->API.ChooseModeMESA = _eglChooseModeMESA;
195 drv->API.GetModesMESA = _eglGetModesMESA;
196 drv->API.GetModeAttribMESA = _eglGetModeAttribMESA;
197 drv->API.GetScreensMESA = _eglGetScreensMESA;
198 drv->API.CreateScreenSurfaceMESA = _eglCreateScreenSurfaceMESA;
199 drv->API.ShowScreenSurfaceMESA = _eglShowScreenSurfaceMESA;
200 drv->API.ScreenPositionMESA = _eglScreenPositionMESA;
201 drv->API.QueryScreenMESA = _eglQueryScreenMESA;
202 drv->API.QueryScreenSurfaceMESA = _eglQueryScreenSurfaceMESA;
203 drv->API.QueryScreenModeMESA = _eglQueryScreenModeMESA;
204 drv->API.QueryModeStringMESA = _eglQueryModeStringMESA;
205 #endif /* EGL_MESA_screen_surface */
207 #ifdef EGL_VERSION_1_2
208 drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer;
209 #endif /* EGL_VERSION_1_2 */
214 * Examine the individual extension enable/disable flags and recompute
215 * the driver's Extensions string.
218 _eglUpdateExtensionsString(_EGLDriver *drv)
220 drv->Extensions.String[0] = 0;
222 if (drv->Extensions.MESA_screen_surface)
223 strcat(drv->Extensions.String, "EGL_MESA_screen_surface ");
224 if (drv->Extensions.MESA_copy_context)
225 strcat(drv->Extensions.String, "EGL_MESA_copy_context ");
226 assert(strlen(drv->Extensions.String) < MAX_EXTENSIONS_LEN);
232 _eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name)
238 return "Mesa Project";
242 _eglUpdateExtensionsString(drv);
243 return drv->Extensions.String;
244 #ifdef EGL_VERSION_1_2
245 case EGL_CLIENT_APIS:
246 /* XXX need to initialize somewhere */
247 return drv->ClientAPIs;
250 _eglError(EGL_BAD_PARAMETER, "eglQueryString");
257 _eglWaitGL(_EGLDriver *drv, EGLDisplay dpy)
259 /* just a placeholder */
267 _eglWaitNative(_EGLDriver *drv, EGLDisplay dpy, EGLint engine)
269 /* just a placeholder */
273 case EGL_CORE_NATIVE_ENGINE:
276 _eglError(EGL_BAD_PARAMETER, "eglWaitNative(engine)");