egl: Make display and surface hash tables local.
[mesa.git] / src / egl / main / eglscreen.c
index c4cc8bfe1ac2a6eb5e1a349f788a2a37a3ddd43b..b6bde65e8b52a80c8611c8478a54b55775bb90a2 100644 (file)
 #include "eglscreen.h"
 
 
+/**
+ * Return a new screen handle/ID.
+ * NOTE: we never reuse these!
+ */
+EGLScreenMESA
+_eglAllocScreenHandle(void)
+{
+   EGLScreenMESA s = _eglGlobal.FreeScreenHandle;
+   _eglGlobal.FreeScreenHandle++;
+   return s;
+}
+
+
 /**
  * Initialize an _EGLScreen object to default values.
  */
 void
 _eglInitScreen(_EGLScreen *screen)
 {
-   /* just init to zero for now */
    memset(screen, 0, sizeof(_EGLScreen));
+   screen->StepX = 1;
+   screen->StepY = 1;
 }
 
 
@@ -114,20 +128,25 @@ _eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
 {
 #if 0 /* THIS IS JUST EXAMPLE CODE */
    _EGLSurface *surf;
+   _EGLConfig *conf;
+
+   conf = _eglLookupConfig(drv, dpy, config);
+   if (!conf) {
+      _eglError(EGL_BAD_CONFIG, "eglCreateScreenSurfaceMESA");
+      return EGL_NO_SURFACE;
+   }
 
    surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface));
    if (!surf)
       return EGL_NO_SURFACE;
 
-   if (!_eglInitSurface(drv, dpy, surf, EGL_SCREEN_BIT_MESA,
-                        config, attrib_list)) {
+   if (!_eglInitSurface(drv, surf, EGL_SCREEN_BIT_MESA,
+                        conf, attrib_list)) {
       free(surf);
       return EGL_NO_SURFACE;
    }
 
-   _eglSaveSurface(surf);
-
-   return surf->Handle;
+   return _eglLinkSurface(surf, _eglLookupDisplay(dpy));
 #endif
    return EGL_NO_SURFACE;
 }
@@ -141,8 +160,9 @@ _eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
  * this with code that _really_ shows the surface.
  */
 EGLBoolean
-_eglShowSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
-                    EGLSurface surface, EGLModeMESA m)
+_eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy,
+                          EGLScreenMESA screen, EGLSurface surface,
+                          EGLModeMESA m)
 {
    _EGLScreen *scrn = _eglLookupScreen(dpy, screen);
    _EGLMode *mode = _eglLookupMode(dpy, m);
@@ -158,7 +178,8 @@ _eglShowSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
 
    if (surface == EGL_NO_SURFACE) {
       scrn->CurrentSurface = NULL;
-   } else {
+   }
+   else {
       _EGLSurface *surf = _eglLookupSurface(surface);
       if (!surf || surf->Type != EGL_SCREEN_BIT_MESA) {
          _eglError(EGL_BAD_SURFACE, "eglShowSurfaceMESA");
@@ -269,6 +290,10 @@ _eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
       value[0] = scrn->OriginX;
       value[1] = scrn->OriginY;
       break;
+   case EGL_SCREEN_POSITION_GRANULARITY_MESA:
+      value[0] = scrn->StepX;
+      value[1] = scrn->StepY;
+      break;
    default:
       _eglError(EGL_BAD_ATTRIBUTE, "eglQueryScreenMESA");
       return EGL_FALSE;
@@ -278,10 +303,21 @@ _eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen,
 }
 
 
+/**
+ * Delete the modes associated with given screen.
+ */
 void
 _eglDestroyScreenModes(_EGLScreen *scrn)
 {
-   free(scrn->Modes);
+   EGLint i;
+   for (i = 0; i < scrn->NumModes; i++) {
+      if (scrn->Modes[i].Name)
+         free((char *) scrn->Modes[i].Name); /* cast away const */
+   }
+   if (scrn->Modes)
+      free(scrn->Modes);
+   scrn->Modes = NULL;
+   scrn->NumModes = 0;
 }