egl: Display may be NULL in _eglLookup*.
[mesa.git] / src / egl / main / eglmode.c
index 0f3ba6e5c08021ca7d652aeed36d5ce5bef53ecb..ed107d5d7a71ace28dd51d245fc5af7c0a183566 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
@@ -6,27 +5,15 @@
 #include "egldisplay.h"
 #include "egldriver.h"
 #include "eglmode.h"
-#include "eglglobals.h"
+#include "eglcurrent.h"
 #include "eglscreen.h"
+#include "eglstring.h"
 
 
-#define MIN2(A, B)  (((A) < (B)) ? (A) : (B))
+#ifdef EGL_MESA_screen_surface
 
 
-static char *
-my_strdup(const char *s)
-{
-   if (s) {
-      int l = strlen(s);
-      char *s2 = malloc(l + 1);
-      if (s2)
-         strcpy(s2, s);
-      return s2;
-   }
-   else {
-      return NULL;
-   }
-}
+#define MIN2(A, B)  (((A) < (B)) ? (A) : (B))
 
 
 /**
@@ -38,9 +25,12 @@ _eglLookupMode(EGLModeMESA mode, _EGLDisplay *disp)
 {
    EGLint scrnum;
 
+   if (!disp || !disp->Screens)
+      return NULL;
+
    /* loop over all screens on the display */
-   for (scrnum = 0; scrnum < disp->NumScreens; scrnum++) {
-      const _EGLScreen *scrn = disp->Screens[scrnum];
+   for (scrnum = 0; scrnum < disp->Screens->Size; scrnum++) {
+      const _EGLScreen *scrn = disp->Screens->Elements[scrnum];
       EGLint i;
       /* search list of modes for handle */
       for (i = 0; i < scrn->NumModes; i++) {
@@ -82,7 +72,7 @@ _eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height,
       screen->Modes[n].RefreshRate = refreshRate;
       screen->Modes[n].Optimal = EGL_FALSE;
       screen->Modes[n].Interlaced = EGL_FALSE;
-      screen->Modes[n].Name = my_strdup(name);
+      screen->Modes[n].Name = _eglstrdup(name);
       screen->NumModes++;
       return screen->Modes + n;
    }
@@ -368,39 +358,4 @@ _eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m)
 }
 
 
-#if 0
-static int
-_eglRand(int max)
-{
-   return rand() % max;
-}
-
-void
-_eglTestModeModule(void)
-{
-   EGLint count = 30;
-   _EGLMode *modes = (_EGLMode *) malloc(count * sizeof(_EGLMode));
-   _EGLMode **modeList = (_EGLMode **) malloc(count * sizeof(_EGLMode*));
-   EGLint i;
-
-   for (i = 0; i < count; i++) {
-      modes[i].Handle = _eglRand(20);
-      modes[i].Width = 512 + 256 * _eglRand(2);
-      modes[i].Height = 512 + 256 * _eglRand(2);
-      modes[i].RefreshRate = 50 + 5 * _eglRand(3);
-      modes[i].Interlaced = _eglRand(2);
-      modes[i].Optimal = _eglRand(4) == 0;
-      modeList[i] = modes + i;
-   }
-
-   /* sort array of pointers */
-   qsort(modeList, count, sizeof(_EGLMode *), compareModes);
-
-   for (i = 0; i < count; i++) {
-      _EGLMode *m = modeList[i];
-      printf("%2d: %3d  %4d x %4d  @ %3d  opt %d  int %d\n", i,
-             m->Handle, m->Width, m->Height, m->RefreshRate,
-             m->Optimal, m->Interlaced);
-   }
-}
-#endif
+#endif /* EGL_MESA_screen_surface */