Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / egl / main / eglscreen.c
index e213e9a8472dc8b8a3104b111c16b4bbebb8db3f..9c9a8377bf206a89447ebdb7feac915c2681d5be 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;
 }
 
 
@@ -106,67 +120,30 @@ _eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens,
 
 
 /**
- * Initialize the given _EGLSurface object.  Do error checking.
- * Assign it an EGLSurface handle and insert into hash table.
- * \return EGLSurface handle or EGL_NO_SURFACE if error.
+ * Example function - drivers should do a proper implementation.
  */
 EGLSurface
-_eglInitScreenSurface(_EGLSurface *surf, _EGLDriver *drv, EGLDisplay dpy,
-                      EGLConfig config, const EGLint *attrib_list)
+_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
+                            const EGLint *attrib_list)
 {
-   EGLint width = 0, height = 0;
-   EGLint i;
+#if 0 /* THIS IS JUST EXAMPLE CODE */
+   _EGLSurface *surf;
 
-   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
-      switch (attrib_list[i]) {
-      case EGL_WIDTH:
-         width = attrib_list[++i];
-         break;
-      case EGL_HEIGHT:
-         height = attrib_list[++i];
-         break;
-      default:
-         _eglError(EGL_BAD_ATTRIBUTE, "eglCreateScreenSurfaceMESA");
-         return EGL_NO_SURFACE;
-      }
-   }
+   surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface));
+   if (!surf)
+      return EGL_NO_SURFACE;
 
-   if (width <= 0 || height <= 0) {
-      _eglError(EGL_BAD_ATTRIBUTE,
-                "eglCreateScreenSurfaceMESA(width or height)");
+   if (!_eglInitSurface(drv, dpy, surf, EGL_SCREEN_BIT_MESA,
+                        config, attrib_list)) {
+      free(surf);
       return EGL_NO_SURFACE;
    }
 
-   _eglInitSurface(surf);
-   surf->Width = width;
-   surf->Height = height;
-   surf->Type = EGL_SCREEN_BIT_MESA;
-   surf->Config =  _eglLookupConfig(drv, dpy, config);
-
-   /* insert into hash table */
    _eglSaveSurface(surf);
-   assert(surf->Handle);
 
    return surf->Handle;
-}
-
-
-/**
- * Create a drawing surface which can be directly displayed on a screen.
- */
-EGLSurface
-_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
-                            const EGLint *attrib_list)
-{
-   _EGLSurface *surf;
-   EGLSurface surface;
-   
-   surf = (_EGLSurface *) malloc(sizeof(_EGLSurface));
-   surface = _eglInitScreenSurface(surf, drv, dpy, config, attrib_list);
-   if (surface == EGL_NO_SURFACE)
-      free(surf);
-
-   return surface;
+#endif
+   return EGL_NO_SURFACE;
 }
 
 
@@ -178,8 +155,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);
@@ -195,7 +173,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");
@@ -306,6 +285,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;
@@ -315,10 +298,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;
 }