Replace supported_formats with is_format_supported interface.
authorMichal Krol <michal@tungstengraphics.com>
Sun, 28 Oct 2007 17:19:39 +0000 (17:19 +0000)
committerMichal Krol <michal@tungstengraphics.com>
Sun, 28 Oct 2007 17:34:39 +0000 (17:34 +0000)
The old supported_formats interface returned a list of formats
supported by a pipe/winsys implementation. This was reasonable
when gallium had a fixed list of predefined format.
Now things has changed and the definition of PIPE_FORMAT is
more flexible.
The new shiny is_format_supported interface gets PIPE_FORMAT
as an argument and returns a boolean whether this particular
format is supported.

src/mesa/drivers/x11/xm_api.c
src/mesa/drivers/x11/xm_surface.c
src/mesa/drivers/x11/xmesaP.h
src/mesa/pipe/failover/fo_context.c
src/mesa/pipe/i915simple/i915_context.c
src/mesa/pipe/p_context.h
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_winsys.h
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_format.c

index 1d2b93d100bea0dd5204478db2128f7b95d05ed7..4b31447bbd56e862d1bb54eb5c495ee424ead367 100644 (file)
@@ -1616,7 +1616,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
 #if 0
    mesaCtx->st->pipe->surface_alloc = xmesa_surface_alloc;
 #endif
-   mesaCtx->st->pipe->supported_formats = xmesa_supported_formats;
+   mesaCtx->st->pipe->is_format_supported = xmesa_is_format_supported;
    mesaCtx->st->pipe->get_tile_rgba = xmesa_get_tile_rgba;
    mesaCtx->st->pipe->put_tile_rgba = xmesa_put_tile_rgba;
 
index dbbf26e33ffd880a3936ea096a0ed21ade1cb44b..5533158ece00b8904b48939e617a5bdfe2e26230 100644 (file)
@@ -195,18 +195,16 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint pipeFormat)
 }
 
 
-const GLuint *
-xmesa_supported_formats(struct pipe_context *pipe, GLuint *numFormats)
+boolean
+xmesa_is_format_supported(struct pipe_context *pipe, uint format)
 {
-   static const GLuint formats[] = {
-      PIPE_FORMAT_U_A8_R8_G8_B8,
-      PIPE_FORMAT_S_R16_G16_B16_A16,
-      PIPE_FORMAT_S8_Z24
+   switch( format ) {
+   case PIPE_FORMAT_U_A8_R8_G8_B8:
+   case PIPE_FORMAT_S_R16_G16_B16_A16:
+   case PIPE_FORMAT_S8_Z24:
+      return TRUE;
    };
-
-   *numFormats = sizeof(formats) / sizeof(formats[0]);
-
-   return formats;
+   return FALSE;
 }
 
 
index 8af95504fb67525cb0c6fed4a2081f5bee7db504..4709d633942e73b5d905e14185476f6c0133f917 100644 (file)
@@ -618,8 +618,8 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint format);
 extern struct pipe_surface *
 xmesa_new_color_surface(struct pipe_context *pipe, GLuint format);
 
-extern const uint *
-xmesa_supported_formats(struct pipe_context *pipe, uint *numFormats);
+extern boolean
+xmesa_is_format_supported(struct pipe_context *pipe, uint format);
 
 extern void
 xmesa_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps,
index 7e02b751bb3f19b33494f82e90fb6cfd99fdcc71..aa5d0885e6a9b0eecaef9e7470efb1982ed74d03 100644 (file)
@@ -116,7 +116,7 @@ struct pipe_context *failover_create( struct pipe_context *hw,
 
    failover->pipe.winsys = hw->winsys;
    failover->pipe.destroy = failover_destroy;
-   failover->pipe.supported_formats = hw->supported_formats;
+   failover->pipe.is_format_supported = hw->is_format_supported;
    failover->pipe.max_texture_size = hw->max_texture_size;
    failover->pipe.get_name = hw->get_name;
    failover->pipe.get_vendor = hw->get_vendor;
index 161f8ce697280fa9b2813ea3a650840914527c24..6541f0e8484ea1cc1b8587709ca0c5e1151e5da4 100644 (file)
 
 
 /**
- * Return list of supported surface/texture formats.
+ * Query format support.
  * If we find texture and drawable support differs, add a selector
  * parameter or another function.
  */
-static const unsigned *
-i915_supported_formats(struct pipe_context *pipe, 
-//                        unsigned type,
-                          unsigned *numFormats)
+static boolean
+i915_is_format_supported( struct pipe_context *pipe,
+                          uint format )
 {
 #if 0
+   /* XXX: This is broken -- rewrite if still needed. */
    static const unsigned tex_supported[] = {
       PIPE_FORMAT_U_R8_G8_B8_A8,
       PIPE_FORMAT_U_A8_R8_G8_B8,
@@ -97,13 +97,13 @@ i915_supported_formats(struct pipe_context *pipe,
       return NULL;
    }
 #else
-   static const unsigned render_supported[] = {
-      PIPE_FORMAT_U_A8_R8_G8_B8,
-      PIPE_FORMAT_U_R5_G6_B5,
-      PIPE_FORMAT_S8_Z24,
+   switch( format ) {
+   case PIPE_FORMAT_U_A8_R8_G8_B8:
+   case PIPE_FORMAT_U_R5_G6_B5:
+   case PIPE_FORMAT_S8_Z24:
+      return TRUE;
    };
-   *numFormats = 3;
-   return render_supported;
+   return FALSE;
 #endif
 }
 
@@ -303,7 +303,7 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
    i915->pipe.winsys = pipe_winsys;
 
    i915->pipe.destroy = i915_destroy;
-   i915->pipe.supported_formats = i915_supported_formats;
+   i915->pipe.is_format_supported = i915_is_format_supported;
    i915->pipe.max_texture_size = i915_max_texture_size;
    i915->pipe.get_param = i915_get_param;
 
index dbbf48c57603c25a3366a3bc1c2b5799d14756a4..a1441a7e430cadb546925deafd1f141c67ed69bd 100644 (file)
@@ -44,8 +44,8 @@ struct pipe_context {
    /*
     * Queries
     */
-   const unsigned *(*supported_formats)(struct pipe_context *pipe,
-                                      unsigned *numFormats);
+   boolean (*is_format_supported)( struct pipe_context *pipe,
+                                   uint format );
 
    void (*max_texture_size)(struct pipe_context *pipe,
                             unsigned textureType, /* PIPE_TEXTURE_x */
index 3a1861cb62f118215c900489f9573f4326106e34..f67588783be08d1911aeb0c15270f53a87286699 100644 (file)
 
 
 /**
- * Return list of supported surface/texture formats.
+ * Query format support.
  * If we find texture and drawable support differs, add a selector
  * parameter or another function.
  */
-static const unsigned *
-softpipe_supported_formats(struct pipe_context *pipe, unsigned *numFormats)
+static boolean
+softpipe_is_format_supported( struct pipe_context *pipe,
+                              uint format )
 {
 #if 0
+   /* XXX: This is broken -- rewrite if still needed. */
    static const unsigned supported[] = {
       PIPE_FORMAT_U_R8_G8_B8_A8,
       PIPE_FORMAT_U_A8_R8_G8_B8,
@@ -76,7 +78,7 @@ softpipe_supported_formats(struct pipe_context *pipe, unsigned *numFormats)
    return supported;
 #else
    struct softpipe_context *softpipe = softpipe_context( pipe );
-   return softpipe->winsys->supported_formats( softpipe->winsys, numFormats );
+   return softpipe->winsys->is_format_supported( softpipe->winsys, format );
 #endif
 }
 
@@ -298,7 +300,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
    softpipe->pipe.destroy = softpipe_destroy;
 
    /* queries */
-   softpipe->pipe.supported_formats = softpipe_supported_formats;
+   softpipe->pipe.is_format_supported = softpipe_is_format_supported;
    softpipe->pipe.max_texture_size = softpipe_max_texture_size;
    softpipe->pipe.get_param = softpipe_get_param;
 
index 726e4c8bb6b7f7bd3c4136df83f48611da71b5c7..d8ae97118841ed3ded01450277da35c211fb33f2 100644 (file)
@@ -35,8 +35,8 @@
  */
 
 struct softpipe_winsys {
-   const unsigned *(*supported_formats)(struct softpipe_winsys *sws, 
-                                       unsigned *numFormats);
+   boolean (*is_format_supported)( struct softpipe_winsys *sws,
+                                   uint format );
 
 };
 
index 896ba2b905e3469e80d86e2766a9853c4ceca2fa..99e1e3ed25d573682b088ba4d42b213ba67e5c67 100644 (file)
@@ -937,31 +937,26 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
 {
    struct pipe_context *pipe = ctx->st->pipe;
    const uint flags = PIPE_SURFACE_FLAG_TEXTURE;
-   uint numFormats, i, format = 0, cpp, comp, pitch;
-   const uint *formats = ctx->st->pipe->supported_formats(pipe, &numFormats);
+   uint format = 0, cpp, comp, pitch;
    ubyte *dest;
    struct pipe_mipmap_tree *mt;
    int row, col;
 
    /* find a texture format we know */
-   for (i = 0; i < numFormats; i++) {
-      switch (formats[i]) {
-      case PIPE_FORMAT_U_I8:
-         format = formats[i];
-         cpp = 1;
-         comp = 0;
-         break;
-      case PIPE_FORMAT_U_A8_R8_G8_B8:
-         format = formats[i];
-         cpp = 4;
-         comp = 3; /* alpha channel */ /*XXX little-endian dependency */
-         break;
-      default:
-         /* XXX support more formats */
-         ;
-      }
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) {
+      format = PIPE_FORMAT_U_I8;
+      cpp = 1;
+      comp = 0;
+   }
+   else if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) {
+      format = PIPE_FORMAT_U_A8_R8_G8_B8;
+      cpp = 4;
+      comp = 3; /* alpha channel */ /*XXX little-endian dependency */
+   }
+   else {
+      /* XXX support more formats */
+      assert( 0 );
    }
-   assert(format);
 
    /**
     * Create a mipmap tree.
index 5a50d2d63a49dcd24a18ca59fc319c9e1467ae88..c0e1a79bad0e4eaae3adac93f756879597f291d2 100644 (file)
@@ -342,24 +342,6 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat)
    }
 }
 
-/* XXX: This function should be implemented by pipe object. */
-static GLboolean
-allow_format(
-   struct pipe_context *pipe,
-   unsigned format )
-{
-   const GLuint *supported;
-   GLuint i, n;
-
-   supported = pipe->supported_formats( pipe, &n );
-   for (i = 0; i < n; i++) {
-      if (supported[i] == format) {
-         return GL_TRUE;
-      }
-   }
-   return GL_FALSE;
-}
-
 /**
  * Search list of formats for first RGBA format.
  */
@@ -367,13 +349,13 @@ static GLuint
 default_rgba_format(
    struct pipe_context *pipe )
 {
-   if (allow_format( pipe, PIPE_FORMAT_U_R8_G8_B8_A8 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R8_G8_B8_A8 )) {
       return PIPE_FORMAT_U_R8_G8_B8_A8;
    }
-   if (allow_format( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) {
       return PIPE_FORMAT_U_A8_R8_G8_B8;
    }
-   if (allow_format( pipe, PIPE_FORMAT_U_R5_G6_B5 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 )) {
       return PIPE_FORMAT_U_R5_G6_B5;
    }
    return PIPE_FORMAT_NONE;
@@ -387,7 +369,7 @@ static GLuint
 default_deep_rgba_format(
    struct pipe_context *pipe )
 {
-   if (allow_format( pipe, PIPE_FORMAT_S_R16_G16_B16_A16 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_S_R16_G16_B16_A16 )) {
       return PIPE_FORMAT_S_R16_G16_B16_A16;
    }
    return PIPE_FORMAT_NONE;
@@ -401,13 +383,13 @@ static GLuint
 default_depth_format(
    struct pipe_context *pipe )
 {
-   if (allow_format( pipe, PIPE_FORMAT_U_Z16 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 )) {
       return PIPE_FORMAT_U_Z16;
    }
-   if (allow_format( pipe, PIPE_FORMAT_U_Z32 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 )) {
       return PIPE_FORMAT_U_Z32;
    }
-   if (allow_format( pipe, PIPE_FORMAT_S8_Z24 )) {
+   if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) {
       return PIPE_FORMAT_S8_Z24;
    }
    return PIPE_FORMAT_NONE;
@@ -437,15 +419,15 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_COMPRESSED_RGBA:
       if (format == GL_BGRA) {
          if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
-            if (allow_format( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 ))
+            if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 ))
                return PIPE_FORMAT_U_A8_R8_G8_B8;
          }
          else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
-            if (allow_format( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
+            if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
                return PIPE_FORMAT_U_A4_R4_G4_B4;
          }
          else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
-            if (allow_format( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
+            if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
                return PIPE_FORMAT_U_A1_R5_G5_B5;
          }
       }
@@ -455,7 +437,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_RGB:
    case GL_COMPRESSED_RGB:
       if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
-         if (allow_format( pipe, PIPE_FORMAT_U_R5_G6_B5 ))
+         if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 ))
             return PIPE_FORMAT_U_R5_G6_B5;
       }
       return default_rgba_format( pipe );
@@ -469,12 +451,12 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
 
    case GL_RGBA4:
    case GL_RGBA2:
-      if (allow_format( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
          return PIPE_FORMAT_U_A4_R4_G4_B4;
       return default_rgba_format( pipe );
 
    case GL_RGB5_A1:
-      if (allow_format( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
          return PIPE_FORMAT_U_A1_R5_G5_B5;
       return default_rgba_format( pipe );
 
@@ -487,7 +469,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_RGB5:
    case GL_RGB4:
    case GL_R3_G3_B2:
-      if (allow_format( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
          return PIPE_FORMAT_U_A1_R5_G5_B5;
       return default_rgba_format( pipe );
 
@@ -497,7 +479,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_ALPHA12:
    case GL_ALPHA16:
    case GL_COMPRESSED_ALPHA:
-      if (allow_format( pipe, PIPE_FORMAT_U_A8 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 ))
          return PIPE_FORMAT_U_A8;
       return default_rgba_format( pipe );
 
@@ -508,7 +490,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_LUMINANCE12:
    case GL_LUMINANCE16:
    case GL_COMPRESSED_LUMINANCE:
-      if (allow_format( pipe, PIPE_FORMAT_U_A8 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 ))
          return PIPE_FORMAT_U_A8;
       return default_rgba_format( pipe );
 
@@ -521,7 +503,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_LUMINANCE12_ALPHA12:
    case GL_LUMINANCE16_ALPHA16:
    case GL_COMPRESSED_LUMINANCE_ALPHA:
-      if (allow_format( pipe, PIPE_FORMAT_U_A8_L8 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8 ))
          return PIPE_FORMAT_U_A8_L8;
       return default_rgba_format( pipe );
 
@@ -531,17 +513,17 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_INTENSITY12:
    case GL_INTENSITY16:
    case GL_COMPRESSED_INTENSITY:
-      if (allow_format( pipe, PIPE_FORMAT_U_I8 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 ))
          return PIPE_FORMAT_U_I8;
       return default_rgba_format( pipe );
 
    case GL_YCBCR_MESA:
       if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) {
-         if (allow_format( pipe, PIPE_FORMAT_YCBCR ))
+         if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR ))
             return PIPE_FORMAT_YCBCR;
       }
       else {
-         if (allow_format( pipe, PIPE_FORMAT_YCBCR_REV ))
+         if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV ))
             return PIPE_FORMAT_YCBCR_REV;
       }
       return PIPE_FORMAT_NONE;
@@ -570,15 +552,15 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
 #endif
 
    case GL_DEPTH_COMPONENT16:
-      if (allow_format( pipe, PIPE_FORMAT_U_Z16 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 ))
          return PIPE_FORMAT_U_Z16;
       /* fall-through */
    case GL_DEPTH_COMPONENT24:
-      if (allow_format( pipe, PIPE_FORMAT_S8_Z24 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
          return PIPE_FORMAT_S8_Z24;
       /* fall-through */
    case GL_DEPTH_COMPONENT32:
-      if (allow_format( pipe, PIPE_FORMAT_U_Z32 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 ))
          return PIPE_FORMAT_U_Z32;
       /* fall-through */
    case GL_DEPTH_COMPONENT:
@@ -589,15 +571,15 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
    case GL_STENCIL_INDEX4_EXT:
    case GL_STENCIL_INDEX8_EXT:
    case GL_STENCIL_INDEX16_EXT:
-      if (allow_format( pipe, PIPE_FORMAT_U_S8 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8 ))
          return PIPE_FORMAT_U_S8;
-      if (allow_format( pipe, PIPE_FORMAT_S8_Z24 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
          return PIPE_FORMAT_S8_Z24;
       return PIPE_FORMAT_NONE;
 
    case GL_DEPTH_STENCIL_EXT:
    case GL_DEPTH24_STENCIL8_EXT:
-      if (allow_format( pipe, PIPE_FORMAT_S8_Z24 ))
+      if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
          return PIPE_FORMAT_S8_Z24;
       return PIPE_FORMAT_NONE;