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"
20 #if defined(_EGL_PLATFORM_X)
22 #elif defined(_EGL_PLATFORM_WINDOWS)
24 #elif defined(_EGL_PLATFORM_WINCE)
28 const char *DefaultDriverName
= "demodriver";
32 * Determine/return the name of the driver to use for the given _EGLDisplay.
34 * Try to be clever and determine if nativeDisplay is an Xlib Display
35 * ptr or a string (naming a driver or screen number, etc).
37 * If the first character is ':' we interpret it as a screen or card index
38 * number (i.e. ":0" or ":1", etc)
39 * Else if the first character is '!' we interpret it as specific driver name
40 * (i.e. "!r200" or "!i830".
42 * The caller should make a copy of the returned string.
45 _eglChooseDriver(_EGLDisplay
*dpy
)
47 const char *name
= (const char *) dpy
->NativeDisplay
;
48 const char *driverName
= NULL
;
50 if (!dpy
->NativeDisplay
) {
51 /* choose a default */
52 driverName
= DefaultDriverName
;
54 else if (name
&& name
[0] == ':' &&
55 (name
[1] >= '0' && name
[1] <= '9') && !name
[2]) {
56 /* XXX probe hardware here to determine which driver to open */
57 driverName
= "libEGLdri";
59 else if (name
&& name
[0] == '!') {
60 /* use specified driver name */
61 driverName
= name
+ 1;
64 #if defined(_EGL_PLATFORM_X)
65 driverName
= _xeglChooseDriver(dpy
);
66 #elif defined(_EGL_PLATFORM_WINDOWS)
68 driverName
= _weglChooseDriver(dpy
);
69 #elif defined(_EGL_PLATFORM_WINCE)
79 * Open/load the named driver and call its bootstrap function: _eglMain().
80 * By the time this function is called, the dpy->DriverName should have
83 * \return new _EGLDriver object.
86 _eglOpenDriver(_EGLDisplay
*dpy
, const char *driverName
)
91 char driverFilename
[1000];
95 /* XXX also prepend a directory path??? */
96 sprintf(driverFilename
, "%s.so", driverName
);
98 _eglLog(_EGL_DEBUG
, "dlopen(%s)", driverFilename
);
99 lib
= dlopen(driverFilename
, RTLD_NOW
);
101 _eglLog(_EGL_WARNING
, "Could not open %s (%s)",
102 driverFilename
, dlerror());
106 mainFunc
= (_EGLMain_t
) dlsym(lib
, "_eglMain");
108 _eglLog(_EGL_WARNING
, "_eglMain not found in %s", driverFilename
);
118 /* with a recurvise open you want the inner most handle */
120 drv
->LibHandle
= lib
;
130 _eglCloseDriver(_EGLDriver
*drv
, EGLDisplay dpy
)
132 void *handle
= drv
->LibHandle
;
135 _eglLog(_EGL_INFO
, "Closing driver");
138 * XXX check for currently bound context/surfaces and delete them?
141 b
= drv
->API
.Terminate(drv
, dpy
);
148 * Given a display handle, return the _EGLDriver for that display.
151 _eglLookupDriver(EGLDisplay dpy
)
153 _EGLDisplay
*d
= _eglLookupDisplay(dpy
);
162 * Plug all the available fallback routines into the given driver's
166 _eglInitDriverFallbacks(_EGLDriver
*drv
)
168 /* If a pointer is set to NULL, then the device driver _really_ has
171 drv
->API
.Initialize
= NULL
;
172 drv
->API
.Terminate
= NULL
;
174 drv
->API
.GetConfigs
= _eglGetConfigs
;
175 drv
->API
.ChooseConfig
= _eglChooseConfig
;
176 drv
->API
.GetConfigAttrib
= _eglGetConfigAttrib
;
178 drv
->API
.CreateContext
= _eglCreateContext
;
179 drv
->API
.DestroyContext
= _eglDestroyContext
;
180 drv
->API
.MakeCurrent
= _eglMakeCurrent
;
181 drv
->API
.QueryContext
= _eglQueryContext
;
183 drv
->API
.CreateWindowSurface
= _eglCreateWindowSurface
;
184 drv
->API
.CreatePixmapSurface
= _eglCreatePixmapSurface
;
185 drv
->API
.CreatePbufferSurface
= _eglCreatePbufferSurface
;
186 drv
->API
.DestroySurface
= _eglDestroySurface
;
187 drv
->API
.QuerySurface
= _eglQuerySurface
;
188 drv
->API
.SurfaceAttrib
= _eglSurfaceAttrib
;
189 drv
->API
.BindTexImage
= _eglBindTexImage
;
190 drv
->API
.ReleaseTexImage
= _eglReleaseTexImage
;
191 drv
->API
.SwapInterval
= _eglSwapInterval
;
192 drv
->API
.SwapBuffers
= _eglSwapBuffers
;
193 drv
->API
.CopyBuffers
= _eglCopyBuffers
;
195 drv
->API
.QueryString
= _eglQueryString
;
196 drv
->API
.WaitGL
= _eglWaitGL
;
197 drv
->API
.WaitNative
= _eglWaitNative
;
199 #ifdef EGL_MESA_screen_surface
200 drv
->API
.ChooseModeMESA
= _eglChooseModeMESA
;
201 drv
->API
.GetModesMESA
= _eglGetModesMESA
;
202 drv
->API
.GetModeAttribMESA
= _eglGetModeAttribMESA
;
203 drv
->API
.GetScreensMESA
= _eglGetScreensMESA
;
204 drv
->API
.CreateScreenSurfaceMESA
= _eglCreateScreenSurfaceMESA
;
205 drv
->API
.ShowScreenSurfaceMESA
= _eglShowScreenSurfaceMESA
;
206 drv
->API
.ScreenPositionMESA
= _eglScreenPositionMESA
;
207 drv
->API
.QueryScreenMESA
= _eglQueryScreenMESA
;
208 drv
->API
.QueryScreenSurfaceMESA
= _eglQueryScreenSurfaceMESA
;
209 drv
->API
.QueryScreenModeMESA
= _eglQueryScreenModeMESA
;
210 drv
->API
.QueryModeStringMESA
= _eglQueryModeStringMESA
;
211 #endif /* EGL_MESA_screen_surface */
213 #ifdef EGL_VERSION_1_2
214 drv
->API
.CreatePbufferFromClientBuffer
= _eglCreatePbufferFromClientBuffer
;
215 #endif /* EGL_VERSION_1_2 */
220 * Examine the individual extension enable/disable flags and recompute
221 * the driver's Extensions string.
224 _eglUpdateExtensionsString(_EGLDriver
*drv
)
226 drv
->Extensions
.String
[0] = 0;
228 if (drv
->Extensions
.MESA_screen_surface
)
229 strcat(drv
->Extensions
.String
, "EGL_MESA_screen_surface ");
230 if (drv
->Extensions
.MESA_copy_context
)
231 strcat(drv
->Extensions
.String
, "EGL_MESA_copy_context ");
232 assert(strlen(drv
->Extensions
.String
) < MAX_EXTENSIONS_LEN
);
238 _eglQueryString(_EGLDriver
*drv
, EGLDisplay dpy
, EGLint name
)
244 return "Mesa Project";
248 _eglUpdateExtensionsString(drv
);
249 return drv
->Extensions
.String
;
250 #ifdef EGL_VERSION_1_2
251 case EGL_CLIENT_APIS
:
252 /* XXX need to initialize somewhere */
253 return drv
->ClientAPIs
;
256 _eglError(EGL_BAD_PARAMETER
, "eglQueryString");
263 _eglWaitGL(_EGLDriver
*drv
, EGLDisplay dpy
)
265 /* just a placeholder */
273 _eglWaitNative(_EGLDriver
*drv
, EGLDisplay dpy
, EGLint engine
)
275 /* just a placeholder */
279 case EGL_CORE_NATIVE_ENGINE
:
282 _eglError(EGL_BAD_PARAMETER
, "eglWaitNative(engine)");