egldriver.c revision e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986a
16052af172f0241e6678cd16efac0a0f14f40146cBrian Paul/**
26052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * Functions for choosing and opening/loading device drivers.
36052af172f0241e6678cd16efac0a0f14f40146cBrian Paul */
46052af172f0241e6678cd16efac0a0f14f40146cBrian Paul
56052af172f0241e6678cd16efac0a0f14f40146cBrian Paul
6adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <assert.h>
711a261ef4f1d4100c46f73ad51e7e4ed57cc1b5eBrian Paul#include <string.h>
8adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <dlfcn.h>
9adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <stdio.h>
100c8908c411c434eda318b41b4f2a370a1e794831Brian Paul#include <stdlib.h>
11adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglconfig.h"
12adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglcontext.h"
13e084fe54f93c9d51df99812b76d3299b0cff57a3Brian Paul#include "egldefines.h"
14adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "egldisplay.h"
15adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "egldriver.h"
16adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglglobals.h"
17b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul#include "egllog.h"
1811a261ef4f1d4100c46f73ad51e7e4ed57cc1b5eBrian Paul#include "eglmisc.h"
19adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglmode.h"
20c22990c29a5cdff89e6e3914aa565acc88a6a407Brian Paul#include "eglscreen.h"
210c8908c411c434eda318b41b4f2a370a1e794831Brian Paul#include "eglstring.h"
22adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglsurface.h"
23adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
24b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz#if defined(_EGL_PLATFORM_X)
25b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz#include "eglx.h"
26b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz#elif defined(_EGL_PLATFORM_WINDOWS)
27b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz/* XXX to do */
28b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz#elif defined(_EGL_PLATFORM_WINCE)
29b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz/* XXX to do */
30b870bf79b5387f26668285f44ccbf5812ad62e10Jakob Bornecrantz#endif
31adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
32e084fe54f93c9d51df99812b76d3299b0cff57a3Brian Paul
33e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paulstatic const char *DefaultDriverName = ":0";
34e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paulstatic const char *SysFS = "/sys/class";
359843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
369843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
379843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
389843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
399843c6420d88db0c43b831cf79a3d1872c636225Brian Paul/**
409843c6420d88db0c43b831cf79a3d1872c636225Brian Paul * Given a card number, use sysfs to determine the DRI driver name.
419843c6420d88db0c43b831cf79a3d1872c636225Brian Paul */
429843c6420d88db0c43b831cf79a3d1872c636225Brian Paulstatic const char *
439843c6420d88db0c43b831cf79a3d1872c636225Brian Paul_eglChooseDRMDriver(int card)
449843c6420d88db0c43b831cf79a3d1872c636225Brian Paul{
459843c6420d88db0c43b831cf79a3d1872c636225Brian Paul#if 0
469843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   return _eglstrdup("libEGLdri");
479843c6420d88db0c43b831cf79a3d1872c636225Brian Paul#else
489843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   char path[2000], driverName[2000];
499843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   FILE *f;
509843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   int length;
519843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
529843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card);
539843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
549843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   f = fopen(path, "r");
559843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   if (!f)
569843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      return NULL;
579843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
589843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   fgets(driverName, sizeof(driverName), f);
599843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   fclose(f);
609843c6420d88db0c43b831cf79a3d1872c636225Brian Paul
619843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   if ((length = strlen(driverName)) > 1) {
629843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      /* remove the trailing newline from sysfs */
639843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      driverName[length - 1] = '\0';
649843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      strncat(driverName, "_dri", sizeof(driverName));
659843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      return _eglstrdup(driverName);
669843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   }
679843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   else {
689843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      return NULL;
699843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   }
709843c6420d88db0c43b831cf79a3d1872c636225Brian Paul#endif
719843c6420d88db0c43b831cf79a3d1872c636225Brian Paul}
72adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
73adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
74adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
75e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul * XXX this function is totally subject change!!!
76e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul *
77e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul *
786052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * Determine/return the name of the driver to use for the given _EGLDisplay.
79adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul *
806052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * Try to be clever and determine if nativeDisplay is an Xlib Display
816052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * ptr or a string (naming a driver or screen number, etc).
82adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul *
83adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * If the first character is ':' we interpret it as a screen or card index
84adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * number (i.e. ":0" or ":1", etc)
85adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Else if the first character is '!' we interpret it as specific driver name
86adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * (i.e. "!r200" or "!i830".
876052af172f0241e6678cd16efac0a0f14f40146cBrian Paul *
889843c6420d88db0c43b831cf79a3d1872c636225Brian Paul * Whatever follows ':' is copied and put into dpy->DriverArgs.
899843c6420d88db0c43b831cf79a3d1872c636225Brian Paul *
909843c6420d88db0c43b831cf79a3d1872c636225Brian Paul * The caller may free() the returned string.
91adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
926052af172f0241e6678cd16efac0a0f14f40146cBrian Paulconst char *
936052af172f0241e6678cd16efac0a0f14f40146cBrian Paul_eglChooseDriver(_EGLDisplay *dpy)
94adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
950c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   const char *displayString = (const char *) dpy->NativeDisplay;
966052af172f0241e6678cd16efac0a0f14f40146cBrian Paul   const char *driverName = NULL;
97adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
98e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul   (void) DefaultDriverName;
99e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul
100834aa8cfbc25622256889624ee1768c10224feb2Brian Paul   /* First, if the EGL_DRIVER env var is set, use that */
101834aa8cfbc25622256889624ee1768c10224feb2Brian Paul   driverName = getenv("EGL_DRIVER");
102834aa8cfbc25622256889624ee1768c10224feb2Brian Paul   if (driverName)
103834aa8cfbc25622256889624ee1768c10224feb2Brian Paul      return _eglstrdup(driverName);
104834aa8cfbc25622256889624ee1768c10224feb2Brian Paul
105d5078b94323241a6482f54797756116b1c864327Brian Paul#if 0
1060c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   if (!displayString) {
1076052af172f0241e6678cd16efac0a0f14f40146cBrian Paul      /* choose a default */
1080c8908c411c434eda318b41b4f2a370a1e794831Brian Paul      displayString = DefaultDriverName;
109adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
110d5078b94323241a6482f54797756116b1c864327Brian Paul#endif
1110c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   /* extract default DriverArgs = whatever follows ':' */
112834aa8cfbc25622256889624ee1768c10224feb2Brian Paul   if (displayString &&
113834aa8cfbc25622256889624ee1768c10224feb2Brian Paul       (displayString[0] == '!' ||
114834aa8cfbc25622256889624ee1768c10224feb2Brian Paul        displayString[0] == ':')) {
1150c8908c411c434eda318b41b4f2a370a1e794831Brian Paul      const char *args = strchr(displayString, ':');
1160c8908c411c434eda318b41b4f2a370a1e794831Brian Paul      if (args)
1170c8908c411c434eda318b41b4f2a370a1e794831Brian Paul         dpy->DriverArgs = _eglstrdup(args + 1);
1180c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   }
1190c8908c411c434eda318b41b4f2a370a1e794831Brian Paul
1209843c6420d88db0c43b831cf79a3d1872c636225Brian Paul   /* determine driver name now */
1210c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   if (displayString && displayString[0] == ':' &&
1220c8908c411c434eda318b41b4f2a370a1e794831Brian Paul       (displayString[1] >= '0' && displayString[1] <= '9') &&
1230c8908c411c434eda318b41b4f2a370a1e794831Brian Paul       !displayString[2]) {
1249843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      int card = atoi(displayString + 1);
1259843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      driverName = _eglChooseDRMDriver(card);
126adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
1270c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   else if (displayString && displayString[0] == '!') {
1289843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      /* use user-specified driver name */
1299843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      driverName = _eglstrdup(displayString + 1);
1309843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      /* truncate driverName at ':' if present */
1319843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      {
1329843c6420d88db0c43b831cf79a3d1872c636225Brian Paul         char *args = strchr(driverName, ':');
1339843c6420d88db0c43b831cf79a3d1872c636225Brian Paul         if (args) {
1349843c6420d88db0c43b831cf79a3d1872c636225Brian Paul            *args = 0;
1359843c6420d88db0c43b831cf79a3d1872c636225Brian Paul         }
1369843c6420d88db0c43b831cf79a3d1872c636225Brian Paul      }
137adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
138adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   else {
1390c8908c411c434eda318b41b4f2a370a1e794831Brian Paul      /* NativeDisplay is not a string! */
1406052af172f0241e6678cd16efac0a0f14f40146cBrian Paul#if defined(_EGL_PLATFORM_X)
1416052af172f0241e6678cd16efac0a0f14f40146cBrian Paul      driverName = _xeglChooseDriver(dpy);
1426052af172f0241e6678cd16efac0a0f14f40146cBrian Paul#elif defined(_EGL_PLATFORM_WINDOWS)
1436052af172f0241e6678cd16efac0a0f14f40146cBrian Paul      /* XXX to do */
1446052af172f0241e6678cd16efac0a0f14f40146cBrian Paul      driverName = _weglChooseDriver(dpy);
1456052af172f0241e6678cd16efac0a0f14f40146cBrian Paul#elif defined(_EGL_PLATFORM_WINCE)
1466052af172f0241e6678cd16efac0a0f14f40146cBrian Paul      /* XXX to do */
147e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul#else
148e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul      driverName = DefaultDriverName;
1496052af172f0241e6678cd16efac0a0f14f40146cBrian Paul#endif
150adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
151adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
1526052af172f0241e6678cd16efac0a0f14f40146cBrian Paul   return driverName;
153adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
154adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
155adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
156adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
157adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Open/load the named driver and call its bootstrap function: _eglMain().
1586052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * By the time this function is called, the dpy->DriverName should have
1596052af172f0241e6678cd16efac0a0f14f40146cBrian Paul * been determined.
1606052af172f0241e6678cd16efac0a0f14f40146cBrian Paul *
161adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * \return  new _EGLDriver object.
162adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
163adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul_EGLDriver *
1640c8908c411c434eda318b41b4f2a370a1e794831Brian Paul_eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args)
165adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
166485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   _EGLDriver *drv;
167485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   _EGLMain_t mainFunc;
168adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   void *lib;
169adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   char driverFilename[1000];
170adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
1716052af172f0241e6678cd16efac0a0f14f40146cBrian Paul   assert(driverName);
1726052af172f0241e6678cd16efac0a0f14f40146cBrian Paul
173adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   /* XXX also prepend a directory path??? */
1747012d01d888d482f2c6ad1180231a482026d213aJon Smirl   sprintf(driverFilename, "%s.so", driverName);
175adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
176b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
177adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   lib = dlopen(driverFilename, RTLD_NOW);
178485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   if (!lib) {
179b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul      _eglLog(_EGL_WARNING, "Could not open %s (%s)",
180b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul              driverFilename, dlerror());
181485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      return NULL;
182485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   }
183adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
184485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
185485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   if (!mainFunc) {
186b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul      _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename);
187485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      dlclose(lib);
188485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      return NULL;
189adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
190485528f2acb69940a7c757638127f716c0cb2654Jon Smirl
1910c8908c411c434eda318b41b4f2a370a1e794831Brian Paul   drv = mainFunc(dpy, args);
192485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   if (!drv) {
193485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      dlclose(lib);
194adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      return NULL;
195adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
196485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   /* with a recurvise open you want the inner most handle */
197485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   if (!drv->LibHandle)
198485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      drv->LibHandle = lib;
199485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   else
200485528f2acb69940a7c757638127f716c0cb2654Jon Smirl      dlclose(lib);
201485528f2acb69940a7c757638127f716c0cb2654Jon Smirl
202d5078b94323241a6482f54797756116b1c864327Brian Paul   /* update the global notion of supported APIs */
203d5078b94323241a6482f54797756116b1c864327Brian Paul   _eglGlobal.ClientAPIsMask |= drv->ClientAPIsMask;
204d5078b94323241a6482f54797756116b1c864327Brian Paul
205e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul   _eglSaveDriver(drv);
206e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul
207485528f2acb69940a7c757638127f716c0cb2654Jon Smirl   return drv;
208adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
209adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
210adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
211adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
212adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul_eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy)
213adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
214adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   void *handle = drv->LibHandle;
215adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   EGLBoolean b;
216b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul
217b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul   _eglLog(_EGL_INFO, "Closing driver");
218adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
219adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   /*
220adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul    * XXX check for currently bound context/surfaces and delete them?
221adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul    */
222adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
223daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   b = drv->API.Terminate(drv, dpy);
224adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   dlclose(handle);
225adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return b;
226adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
227adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
228adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
229adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
230e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul * Save the given driver pointer in the list of all known drivers.
231e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul */
232e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paulvoid
233e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul_eglSaveDriver(_EGLDriver *drv)
234e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul{
235e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul   _eglGlobal.Drivers[ _eglGlobal.NumDrivers++ ] = drv;
236e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul}
237e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul
238e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul
239e3805cad0d15ed25ce8f6c5a1f1ea913e5d0986aBrian Paul/**
240adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Given a display handle, return the _EGLDriver for that display.
241adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
242adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul_EGLDriver *
243adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul_eglLookupDriver(EGLDisplay dpy)
244adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
245adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   _EGLDisplay *d = _eglLookupDisplay(dpy);
246adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   if (d)
247adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      return d->Driver;
248adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   else
249adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      return NULL;
250adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
251adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
252adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
253adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
254adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Plug all the available fallback routines into the given driver's
255adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * dispatch table.
256adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
257adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paulvoid
258adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul_eglInitDriverFallbacks(_EGLDriver *drv)
259adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
260adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   /* If a pointer is set to NULL, then the device driver _really_ has
261adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul    * to implement it.
262adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul    */
263daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.Initialize = NULL;
264daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.Terminate = NULL;
265daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul
266daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.GetConfigs = _eglGetConfigs;
267daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.ChooseConfig = _eglChooseConfig;
268daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.GetConfigAttrib = _eglGetConfigAttrib;
269daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul
270daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CreateContext = _eglCreateContext;
271daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.DestroyContext = _eglDestroyContext;
272daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.MakeCurrent = _eglMakeCurrent;
273daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryContext = _eglQueryContext;
274daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul
275daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CreateWindowSurface = _eglCreateWindowSurface;
276daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CreatePixmapSurface = _eglCreatePixmapSurface;
277daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CreatePbufferSurface = _eglCreatePbufferSurface;
278daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.DestroySurface = _eglDestroySurface;
279daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QuerySurface = _eglQuerySurface;
280daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.SurfaceAttrib = _eglSurfaceAttrib;
281daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.BindTexImage = _eglBindTexImage;
282daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.ReleaseTexImage = _eglReleaseTexImage;
283daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.SwapInterval = _eglSwapInterval;
284daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.SwapBuffers = _eglSwapBuffers;
285daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CopyBuffers = _eglCopyBuffers;
286daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul
287daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryString = _eglQueryString;
288daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.WaitGL = _eglWaitGL;
289daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.WaitNative = _eglWaitNative;
290adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
291b2006a40eb22899d38cd31691640555228e36975Brian Paul#ifdef EGL_MESA_screen_surface
292daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.ChooseModeMESA = _eglChooseModeMESA;
293daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.GetModesMESA = _eglGetModesMESA;
294daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.GetModeAttribMESA = _eglGetModeAttribMESA;
295daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.GetScreensMESA = _eglGetScreensMESA;
296daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.CreateScreenSurfaceMESA = _eglCreateScreenSurfaceMESA;
29748822796339cb4a55714dc3f1abbe379562ec538Brian Paul   drv->API.ShowScreenSurfaceMESA = _eglShowScreenSurfaceMESA;
298daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.ScreenPositionMESA = _eglScreenPositionMESA;
299daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryScreenMESA = _eglQueryScreenMESA;
300daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryScreenSurfaceMESA = _eglQueryScreenSurfaceMESA;
301daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryScreenModeMESA = _eglQueryScreenModeMESA;
302daf585d0f00df1d4d2e8dc5b465dad60a4bf0122Brian Paul   drv->API.QueryModeStringMESA = _eglQueryModeStringMESA;
303b2006a40eb22899d38cd31691640555228e36975Brian Paul#endif /* EGL_MESA_screen_surface */
304b2006a40eb22899d38cd31691640555228e36975Brian Paul
305b2006a40eb22899d38cd31691640555228e36975Brian Paul#ifdef EGL_VERSION_1_2
306b2006a40eb22899d38cd31691640555228e36975Brian Paul   drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer;
307b2006a40eb22899d38cd31691640555228e36975Brian Paul#endif /* EGL_VERSION_1_2 */
308adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
309