svga: add missing fallthrough comments
[mesa.git] / src / mesa / main / formats.c
index 325a1091ac9d801f6c1acbc05cc72ea3a9dbfc5a..0bca52fde50c697eb3728cda42e6e46f0aa95d38 100644 (file)
@@ -25,7 +25,7 @@
 
 
 #include "errors.h"
-#include "imports.h"
+
 #include "formats.h"
 #include "macros.h"
 #include "glformats.h"
@@ -85,6 +85,13 @@ _mesa_get_format_info(mesa_format format)
 {
    const struct mesa_format_info *info = &format_info[format];
    STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT);
+
+   /* The MESA_FORMAT_* enums are sparse, don't return a format info
+    * for empty entries.
+    */
+   if (info->Name == MESA_FORMAT_NONE && format != MESA_FORMAT_NONE)
+      return NULL;
+
    assert(info->Name == format);
    return info;
 }
@@ -95,6 +102,8 @@ const char *
 _mesa_get_format_name(mesa_format format)
 {
    const struct mesa_format_info *info = _mesa_get_format_info(format);
+   if (!info)
+      return NULL;
    return info->StrName;
 }
 
@@ -395,7 +404,7 @@ _mesa_array_format_flip_channels(mesa_array_format format)
    num_channels = _mesa_array_format_get_num_channels(format);
    _mesa_array_format_get_swizzle(format, swizzle);
 
-   if (num_channels == 1)
+   if (num_channels == 1 || num_channels == 3)
       return format;
 
    if (num_channels == 2) {
@@ -425,7 +434,7 @@ uint32_t
 _mesa_format_to_array_format(mesa_format format)
 {
    const struct mesa_format_info *info = _mesa_get_format_info(format);
-#if PIPE_ARCH_BIG_ENDIAN
+#if UTIL_ARCH_BIG_ENDIAN
    if (info->ArrayFormat && info->Layout == MESA_FORMAT_LAYOUT_PACKED)
       return _mesa_array_format_flip_channels(info->ArrayFormat);
    else
@@ -465,23 +474,21 @@ format_array_format_table_init(void)
 
    for (f = 1; f < MESA_FORMAT_COUNT; ++f) {
       info = _mesa_get_format_info(f);
-      if (!info->ArrayFormat)
+      if (!info || !info->ArrayFormat)
          continue;
 
-#if PIPE_ARCH_LITTLE_ENDIAN
+      /* All sRGB formats should have an equivalent UNORM format, and that's
+       * the one we want in the table.
+       */
+      if (_mesa_is_format_srgb(f))
+         continue;
+
+#if UTIL_ARCH_LITTLE_ENDIAN
          array_format = info->ArrayFormat;
 #else
          array_format = _mesa_array_format_flip_channels(info->ArrayFormat);
 #endif
 
-      /* This can happen and does for some of the BGR formats.  Let's take
-       * the first one in the list.
-       */
-      if (_mesa_hash_table_search_pre_hashed(format_array_format_table,
-                                             array_format,
-                                             (void *)(intptr_t)array_format))
-         continue;
-
       _mesa_hash_table_insert_pre_hashed(format_array_format_table,
                                          array_format,
                                          (void *)(intptr_t)array_format,
@@ -567,7 +574,7 @@ _mesa_is_format_unsigned(mesa_format format)
 bool
 _mesa_is_format_signed(mesa_format format)
 {
-   if (format == MESA_FORMAT_R11G11B10_FLOAT || 
+   if (format == MESA_FORMAT_R11G11B10_FLOAT ||
        format == MESA_FORMAT_R9G9B9E5_FLOAT) {
       /* these packed float formats only store unsigned values */
       return false;
@@ -1295,10 +1302,6 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 3;
       return;
-   case MESA_FORMAT_RGBA_UINT8:
-      *datatype = GL_UNSIGNED_BYTE;
-      *comps = 4;
-      return;
    case MESA_FORMAT_R_UINT16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 1;
@@ -1413,15 +1416,17 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
    case MESA_FORMAT_COUNT:
       assert(0);
       return;
-   default:
+   default: {
+      const char *name = _mesa_get_format_name(format);
       /* Warn if any formats are not handled */
       _mesa_problem(NULL, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
-                    _mesa_get_format_name(format));
+                    name ? name : "???");
       assert(format == MESA_FORMAT_NONE ||
              _mesa_is_format_compressed(format));
       *datatype = 0;
       *comps = 1;
    }
+   }
 }
 
 /**