st/egl: Remove depth/stencil format from the native interface.
authorChia-I Wu <olv@lunarg.com>
Fri, 9 Apr 2010 16:36:50 +0000 (00:36 +0800)
committerChia-I Wu <olv@lunarg.com>
Sat, 10 Apr 2010 17:17:47 +0000 (01:17 +0800)
A native display has no interest in depth/stencil format.  Remove it
from the interface and let the common code derive the supported
depth/stencil formats from the pipe screen.

src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/kms/native_kms.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index 96959ec012aefd09e3d60bc0ab0d18b92510647e..e4f858d179f2bbdaa4801153e8f089607b28a504 100644 (file)
@@ -212,8 +212,8 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
  * Initialize and validate the EGL config attributes.
  */
 static EGLBoolean
-init_config_attributes(_EGLConfig *conf, EGLint api_mask,
-                       const struct native_config *nconf)
+init_config_attributes(_EGLConfig *conf, const struct native_config *nconf,
+                       EGLint api_mask, enum pipe_format depth_stencil_format)
 {
    uint rgba[4], depth_stencil[2], buffer_size;
    EGLint surface_type;
@@ -228,8 +228,9 @@ init_config_attributes(_EGLConfig *conf, EGLint api_mask,
       buffer_size += rgba[i];
    }
    for (i = 0; i < 2; i++) {
-      if (nconf->depth_format != PIPE_FORMAT_NONE) {
-         depth_stencil[i] = util_format_get_component_bits(nconf->depth_format,
+      if (depth_stencil_format != PIPE_FORMAT_NONE) {
+         depth_stencil[i] =
+            util_format_get_component_bits(depth_stencil_format,
                UTIL_FORMAT_COLORSPACE_ZS, i);
       }
       else {
@@ -307,7 +308,8 @@ init_config_attributes(_EGLConfig *conf, EGLint api_mask,
  */
 static EGLBoolean
 egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
-                    _EGLConfig *conf, const struct native_config *nconf)
+                    _EGLConfig *conf, const struct native_config *nconf,
+                    enum pipe_format depth_stencil_format)
 {
    struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
    struct egl_g3d_config *gconf = egl_g3d_config(conf);
@@ -327,7 +329,7 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
 
    gconf->stvis.buffer_mask = buffer_mask;
    gconf->stvis.color_format = nconf->color_format;
-   gconf->stvis.depth_stencil_format = nconf->depth_format;
+   gconf->stvis.depth_stencil_format = depth_stencil_format;
    gconf->stvis.accum_format = PIPE_FORMAT_NONE;
    gconf->stvis.samples = nconf->samples;
 
@@ -352,7 +354,8 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
             nconf->native_visual_id);
    }
 
-   valid = init_config_attributes(&gconf->base, api_mask, nconf);
+   valid = init_config_attributes(&gconf->base,
+         nconf, api_mask, depth_stencil_format);
    if (!valid) {
       _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id);
       return EGL_FALSE;
@@ -363,6 +366,46 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
    return EGL_TRUE;
 }
 
+/**
+ * Get all interested depth/stencil formats of a display.
+ */
+static EGLint
+egl_g3d_fill_depth_stencil_formats(_EGLDisplay *dpy,
+                                   enum pipe_format formats[8])
+{
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+   struct pipe_screen *screen = gdpy->native->screen;
+   const EGLint candidates[] = {
+      1, PIPE_FORMAT_Z16_UNORM,
+      1, PIPE_FORMAT_Z32_UNORM,
+      2, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+      2, PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM,
+      0
+   };
+   const EGLint *fmt = candidates;
+   EGLint count;
+
+   count = 0;
+   formats[count++] = PIPE_FORMAT_NONE;
+
+   while (*fmt) {
+      EGLint i, n = *fmt++;
+
+      /* pick the first supported format */
+      for (i = 0; i < n; i++) {
+         if (screen->is_format_supported(screen, fmt[i],
+                  PIPE_TEXTURE_2D, PIPE_BIND_DEPTH_STENCIL, 0)) {
+            formats[count++] = fmt[i];
+            break;
+         }
+      }
+
+      fmt += n;
+   }
+
+   return count;
+}
+
 /**
  * Add configs to display and return the next config ID.
  */
@@ -371,7 +414,8 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
 {
    struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
    const struct native_config **native_configs;
-   int num_configs, i;
+   enum pipe_format depth_stencil_formats[8];
+   int num_formats, num_configs, i, j;
 
    native_configs = gdpy->native->get_configs(gdpy->native, &num_configs);
    if (!num_configs) {
@@ -380,19 +424,25 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
       return id;
    }
 
+   num_formats = egl_g3d_fill_depth_stencil_formats(dpy,
+         depth_stencil_formats);
+
    for (i = 0; i < num_configs; i++) {
-      struct egl_g3d_config *gconf;
-
-      gconf = CALLOC_STRUCT(egl_g3d_config);
-      if (gconf) {
-         _eglInitConfig(&gconf->base, dpy, id);
-         if (!egl_g3d_init_config(drv, dpy, &gconf->base, native_configs[i])) {
-            free(gconf);
-            continue;
+      for (j = 0; j < num_formats; j++) {
+         struct egl_g3d_config *gconf;
+
+         gconf = CALLOC_STRUCT(egl_g3d_config);
+         if (gconf) {
+            _eglInitConfig(&gconf->base, dpy, id);
+            if (!egl_g3d_init_config(drv, dpy, &gconf->base,
+                     native_configs[i], depth_stencil_formats[j])) {
+               free(gconf);
+               break;
+            }
+
+            _eglAddConfig(dpy, &gconf->base);
+            id++;
          }
-
-         _eglAddConfig(dpy, &gconf->base);
-         id++;
       }
    }
 
index 628befeae26b8f04e7d4d801599e0ce280cf6e0e..9a163d0c869241a5bf0989c05de24313b0ae711b 100644 (file)
@@ -107,8 +107,6 @@ struct native_config {
    /* available buffers and their format */
    uint buffer_mask;
    enum pipe_format color_format;
-   enum pipe_format depth_format;
-   enum pipe_format stencil_format;
 
    /* supported surface types */
    boolean window_bit;
index f8c55990237ed156a3754485c8cf44bd37822b3f..d1ff0f47b67c50ffbfc3b4a41d47c9a6d4a051a4 100644 (file)
@@ -597,20 +597,14 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs)
          if (!kms_display_is_format_supported(&kdpy->base, format, TRUE))
             format = PIPE_FORMAT_NONE;
       }
-      if (format == PIPE_FORMAT_NONE)
+      if (format == PIPE_FORMAT_NONE) {
+         free(kdpy->config);
+         kdpy->config = NULL;
          return NULL;
+      }
 
       nconf->color_format = format;
 
-      format = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
-      if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) {
-         format = PIPE_FORMAT_S8_USCALED_Z24_UNORM;
-         if (!kms_display_is_format_supported(&kdpy->base, format, FALSE))
-            format = PIPE_FORMAT_NONE;
-      }
-      nconf->depth_format = format;
-      nconf->stencil_format = format;
-
       nconf->scanout_bit = TRUE;
    }
 
index 167115708cb0861c38c58a7a2cc64ffd285724f1..9499319424e48e382c09f6c65c4526484b89213c 100644 (file)
@@ -483,36 +483,6 @@ choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32])
    return count;
 }
 
-static int
-choose_depth_stencil_format(const __GLcontextModes *mode,
-                            enum pipe_format formats[32])
-{
-   int count = 0;
-
-   switch (mode->depthBits) {
-   case 32:
-      formats[count++] = PIPE_FORMAT_Z32_UNORM;
-      break;
-   case 24:
-      if (mode->stencilBits) {
-         formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
-         formats[count++] = PIPE_FORMAT_S8_USCALED_Z24_UNORM;
-      }
-      else {
-         formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
-         formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
-      }
-      break;
-   case 16:
-      formats[count++] = PIPE_FORMAT_Z16_UNORM;
-      break;
-   default:
-      break;
-   }
-
-   return count;
-}
-
 static boolean
 is_format_supported(struct pipe_screen *screen,
                     enum pipe_format fmt, boolean is_color)
@@ -541,10 +511,6 @@ dri2_display_convert_config(struct native_display *ndpy,
    if (!mode->xRenderable || !mode->drawableType)
       return FALSE;
 
-   nconf->color_format = PIPE_FORMAT_NONE;
-   nconf->depth_format = PIPE_FORMAT_NONE;
-   nconf->stencil_format = PIPE_FORMAT_NONE;
-
    nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_FRONT_LEFT;
    if (mode->doubleBufferMode)
       nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_LEFT;
@@ -565,19 +531,6 @@ dri2_display_convert_config(struct native_display *ndpy,
    if (nconf->color_format == PIPE_FORMAT_NONE)
       return FALSE;
 
-   /* choose depth/stencil format */
-   num_formats = choose_depth_stencil_format(mode, formats);
-   for (i = 0; i < num_formats; i++) {
-      if (is_format_supported(ndpy->screen, formats[i], FALSE)) {
-         nconf->depth_format = formats[i];
-         nconf->stencil_format = formats[i];
-         break;
-      }
-   }
-   if ((mode->depthBits && nconf->depth_format == PIPE_FORMAT_NONE) ||
-       (mode->stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE))
-      return FALSE;
-
    if (mode->drawableType & GLX_WINDOW_BIT)
       nconf->window_bit = TRUE;
    if (mode->drawableType & GLX_PIXMAP_BIT)
index 9d6d63344c39743a32a275f63ebd32c4c91b764b..203e06e17777525ab2bca58a9925f39444dcb02c 100644 (file)
@@ -466,7 +466,7 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
    /* first time */
    if (!xdpy->configs) {
       const XVisualInfo *visuals;
-      int num_visuals, count, j;
+      int num_visuals, count;
 
       visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals);
       if (!visuals)
@@ -482,40 +482,30 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
 
       count = 0;
       for (i = 0; i < num_visuals; i++) {
-         for (j = 0; j < 2; j++) {
-            struct ximage_config *xconf = &xdpy->configs[count];
-
-            xconf->visual = &visuals[i];
-            xconf->base.color_format = choose_format(xconf->visual);
-            if (xconf->base.color_format == PIPE_FORMAT_NONE)
-               continue;
-
-            xconf->base.buffer_mask =
-               (1 << NATIVE_ATTACHMENT_FRONT_LEFT) |
-               (1 << NATIVE_ATTACHMENT_BACK_LEFT);
-
-            xconf->base.depth_format = PIPE_FORMAT_NONE;
-            xconf->base.stencil_format = PIPE_FORMAT_NONE;
-            /* create the second config with depth/stencil buffer */
-            if (j == 1) {
-               xconf->base.depth_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
-               xconf->base.stencil_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
-            }
-
-            xconf->base.window_bit = TRUE;
-            xconf->base.pixmap_bit = TRUE;
-
-            xconf->base.native_visual_id = xconf->visual->visualid;
+         struct ximage_config *xconf = &xdpy->configs[count];
+
+         xconf->visual = &visuals[i];
+         xconf->base.color_format = choose_format(xconf->visual);
+         if (xconf->base.color_format == PIPE_FORMAT_NONE)
+            continue;
+
+         xconf->base.buffer_mask =
+            (1 << NATIVE_ATTACHMENT_FRONT_LEFT) |
+            (1 << NATIVE_ATTACHMENT_BACK_LEFT);
+
+         xconf->base.window_bit = TRUE;
+         xconf->base.pixmap_bit = TRUE;
+
+         xconf->base.native_visual_id = xconf->visual->visualid;
 #if defined(__cplusplus) || defined(c_plusplus)
-            xconf->base.native_visual_type = xconf->visual->c_class;
+         xconf->base.native_visual_type = xconf->visual->c_class;
 #else
-            xconf->base.native_visual_type = xconf->visual->class;
+         xconf->base.native_visual_type = xconf->visual->class;
 #endif
 
-            xconf->base.slow_config = TRUE;
+         xconf->base.slow_config = TRUE;
 
-            count++;
-         }
+         count++;
       }
 
       xdpy->num_configs = count;