[Glamor] [PATCH 07/34] glamor: Move glamor_get_tex_format_type_from_pictformat to a .c file.

Alex Deucher alexdeucher at gmail.com
Fri Feb 28 10:02:02 PST 2014


From: Eric Anholt <eric at anholt.net>

A pair of 150 lines of inlined switch statements in a header file is
crazy.

Ported from Eric's xserver glamor tree.

Signed-off-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
---
 src/glamor_pixmap.c | 305 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/glamor_utils.h  | 306 ----------------------------------------------------
 2 files changed, 305 insertions(+), 306 deletions(-)

diff --git a/src/glamor_pixmap.c b/src/glamor_pixmap.c
index 9756163..ad94733 100644
--- a/src/glamor_pixmap.c
+++ b/src/glamor_pixmap.c
@@ -182,6 +182,311 @@ glamor_set_alu(struct glamor_gl_dispatch *dispatch, unsigned char alu)
 	return TRUE;
 }
 
+/*
+ * Map picture's format to the correct gl texture format and type.
+ * no_alpha is used to indicate whehter we need to wire alpha to 1.
+ *
+ * Although opengl support A1/GL_BITMAP, we still don't use it
+ * here, it seems that mesa has bugs when uploading a A1 bitmap.
+ *
+ * Return 0 if find a matched texture type. Otherwise return -1.
+ **/
+#ifndef GLAMOR_GLES2
+static int
+glamor_get_tex_format_type_from_pictformat(PictFormatShort format,
+					   GLenum * tex_format,
+					   GLenum * tex_type,
+					   int *no_alpha,
+					   int *revert,
+					   int *swap_rb,
+					   int is_upload)
+
+{
+	*no_alpha = 0;
+	*revert = REVERT_NONE;
+	*swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+	switch (format) {
+	case PICT_a1:
+		*tex_format = GL_ALPHA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		*revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+		break;
+	case PICT_b8g8r8x8:
+		*no_alpha = 1;
+	case PICT_b8g8r8a8:
+		*tex_format = GL_BGRA;
+		*tex_type = GL_UNSIGNED_INT_8_8_8_8;
+		break;
+
+	case PICT_x8r8g8b8:
+		*no_alpha = 1;
+	case PICT_a8r8g8b8:
+		*tex_format = GL_BGRA;
+		*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+		break;
+	case PICT_x8b8g8r8:
+		*no_alpha = 1;
+	case PICT_a8b8g8r8:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+		break;
+	case PICT_x2r10g10b10:
+		*no_alpha = 1;
+	case PICT_a2r10g10b10:
+		*tex_format = GL_BGRA;
+		*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+		break;
+	case PICT_x2b10g10r10:
+		*no_alpha = 1;
+	case PICT_a2b10g10r10:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+		break;
+
+	case PICT_r5g6b5:
+		*tex_format = GL_RGB;
+		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
+		break;
+	case PICT_b5g6r5:
+		*tex_format = GL_RGB;
+		*tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
+		break;
+	case PICT_x1b5g5r5:
+		*no_alpha = 1;
+	case PICT_a1b5g5r5:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+		break;
+
+	case PICT_x1r5g5b5:
+		*no_alpha = 1;
+	case PICT_a1r5g5b5:
+		*tex_format = GL_BGRA;
+		*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+		break;
+	case PICT_a8:
+		*tex_format = GL_ALPHA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		break;
+	case PICT_x4r4g4b4:
+		*no_alpha = 1;
+	case PICT_a4r4g4b4:
+		*tex_format = GL_BGRA;
+		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+		break;
+
+	case PICT_x4b4g4r4:
+		*no_alpha = 1;
+	case PICT_a4b4g4r4:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+		break;
+
+	default:
+		LogMessageVerb(X_INFO, 0,
+			       "fail to get matched format for %x \n",
+			       format);
+		return -1;
+	}
+	return 0;
+}
+
+#else
+#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
+
+static int
+glamor_get_tex_format_type_from_pictformat(PictFormatShort format,
+					   GLenum * tex_format,
+					   GLenum * tex_type,
+					   int *no_alpha,
+					   int *revert,
+					   int *swap_rb,
+					   int is_upload)
+{
+	int need_swap_rb = 0;
+
+	*no_alpha = 0;
+	*revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
+
+	switch (format) {
+	case PICT_b8g8r8x8:
+		*no_alpha = 1;
+	case PICT_b8g8r8a8:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		need_swap_rb = 1;
+		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+		break;
+
+	case PICT_x8r8g8b8:
+		*no_alpha = 1;
+	case PICT_a8r8g8b8:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		need_swap_rb = 1;
+		break;
+
+	case PICT_x8b8g8r8:
+		*no_alpha = 1;
+	case PICT_a8b8g8r8:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		break;
+
+	case PICT_x2r10g10b10:
+		*no_alpha = 1;
+	case PICT_a2r10g10b10:
+		*tex_format = GL_RGBA;
+		/* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
+		 * we have to use GL_UNSIGNED_BYTE and do the conversion in
+		 * shader latter.*/
+		*tex_type = GL_UNSIGNED_BYTE;
+		if (is_upload == 1) {
+			if (!IS_LITTLE_ENDIAN)
+				*revert = REVERT_UPLOADING_10_10_10_2;
+			else
+				*revert = REVERT_UPLOADING_2_10_10_10;
+		}
+		else {
+			if (!IS_LITTLE_ENDIAN) {
+				*revert = REVERT_DOWNLOADING_10_10_10_2;
+			}
+			else {
+				*revert = REVERT_DOWNLOADING_2_10_10_10;
+			}
+		}
+		need_swap_rb = 1;
+
+		break;
+
+	case PICT_x2b10g10r10:
+		*no_alpha = 1;
+	case PICT_a2b10g10r10:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		if (is_upload == 1) {
+			if (!IS_LITTLE_ENDIAN)
+				*revert = REVERT_UPLOADING_10_10_10_2;
+			else
+				*revert = REVERT_UPLOADING_2_10_10_10;
+		}
+		else {
+			if (!IS_LITTLE_ENDIAN) {
+				*revert = REVERT_DOWNLOADING_10_10_10_2;
+			}
+			else {
+				*revert = REVERT_DOWNLOADING_2_10_10_10;
+			}
+		}
+		break;
+
+	case PICT_r5g6b5:
+		*tex_format = GL_RGB;
+		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
+		*revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
+
+		break;
+
+	case PICT_b5g6r5:
+		*tex_format = GL_RGB;
+		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
+		need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;;
+		break;
+
+	case PICT_x1b5g5r5:
+		*no_alpha = 1;
+	case PICT_a1b5g5r5:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+		if (IS_LITTLE_ENDIAN) {
+			*revert = is_upload ? REVERT_UPLOADING_1_5_5_5 : REVERT_DOWNLOADING_1_5_5_5;
+		} else
+			*revert = REVERT_NONE;
+		break;
+
+	case PICT_x1r5g5b5:
+		*no_alpha = 1;
+	case PICT_a1r5g5b5:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+		if (IS_LITTLE_ENDIAN) {
+			*revert = is_upload ? REVERT_UPLOADING_1_5_5_5 : REVERT_DOWNLOADING_1_5_5_5;
+		} else
+			*revert = REVERT_NONE;
+		need_swap_rb = 1;
+		break;
+
+	case PICT_a1:
+		*tex_format = GL_ALPHA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		*revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+		break;
+
+	case PICT_a8:
+		*tex_format = GL_ALPHA;
+		*tex_type = GL_UNSIGNED_BYTE;
+		*revert = REVERT_NONE;
+		break;
+
+	case PICT_x4r4g4b4:
+		*no_alpha = 1;
+	case PICT_a4r4g4b4:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+		need_swap_rb = 1;
+		break;
+
+	case PICT_x4b4g4r4:
+		*no_alpha = 1;
+	case PICT_a4b4g4r4:
+		*tex_format = GL_RGBA;
+		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+		break;
+
+	default:
+		LogMessageVerb(X_INFO, 0,
+			       "fail to get matched format for %x \n",
+			       format);
+		return -1;
+	}
+
+	if (need_swap_rb)
+		*swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING;
+	else
+		*swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+	return 0;
+}
+
+#endif
+
+static int
+glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
+				       GLenum * format,
+				       GLenum * type,
+				       int *no_alpha,
+				       int *revert,
+				       int *swap_rb,
+				       int is_upload)
+{
+	glamor_pixmap_private *pixmap_priv;
+	PictFormatShort pict_format;
+
+	pixmap_priv = glamor_get_pixmap_private(pixmap);
+	if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
+		pict_format = pixmap_priv->base.picture->format;
+	else
+		pict_format = format_for_depth(pixmap->drawable.depth);
+
+	return glamor_get_tex_format_type_from_pictformat(pict_format,
+							  format, type,
+							  no_alpha,
+							  revert,
+							  swap_rb,
+							  is_upload);
+}
+
 static void *
 _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h, int stride, int revert)
 {
diff --git a/src/glamor_utils.h b/src/glamor_utils.h
index 1ffd728..d5c7b5f 100644
--- a/src/glamor_utils.h
+++ b/src/glamor_utils.h
@@ -945,285 +945,6 @@ format_for_pixmap(PixmapPtr pixmap)
 #define SWAP_UPLOADING	  	2
 #define SWAP_NONE_UPLOADING	3
 
-/*
- * Map picture's format to the correct gl texture format and type.
- * no_alpha is used to indicate whehter we need to wire alpha to 1.
- *
- * Although opengl support A1/GL_BITMAP, we still don't use it
- * here, it seems that mesa has bugs when uploading a A1 bitmap.
- *
- * Return 0 if find a matched texture type. Otherwise return -1.
- **/
-#ifndef GLAMOR_GLES2
-static inline int
-glamor_get_tex_format_type_from_pictformat(PictFormatShort format,
-					   GLenum * tex_format,
-					   GLenum * tex_type,
-					   int *no_alpha,
-					   int *revert,
-					   int *swap_rb,
-					   int is_upload)
-
-{
-	*no_alpha = 0;
-	*revert = REVERT_NONE;
-	*swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
-	switch (format) {
-	case PICT_a1:
-		*tex_format = GL_ALPHA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		*revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
-		break;
-	case PICT_b8g8r8x8:
-		*no_alpha = 1;
-	case PICT_b8g8r8a8:
-		*tex_format = GL_BGRA;
-		*tex_type = GL_UNSIGNED_INT_8_8_8_8;
-		break;
-
-	case PICT_x8r8g8b8:
-		*no_alpha = 1;
-	case PICT_a8r8g8b8:
-		*tex_format = GL_BGRA;
-		*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-		break;
-	case PICT_x8b8g8r8:
-		*no_alpha = 1;
-	case PICT_a8b8g8r8:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-		break;
-	case PICT_x2r10g10b10:
-		*no_alpha = 1;
-	case PICT_a2r10g10b10:
-		*tex_format = GL_BGRA;
-		*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-		break;
-	case PICT_x2b10g10r10:
-		*no_alpha = 1;
-	case PICT_a2b10g10r10:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-		break;
-
-	case PICT_r5g6b5:
-		*tex_format = GL_RGB;
-		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
-		break;
-	case PICT_b5g6r5:
-		*tex_format = GL_RGB;
-		*tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
-		break;
-	case PICT_x1b5g5r5:
-		*no_alpha = 1;
-	case PICT_a1b5g5r5:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-		break;
-
-	case PICT_x1r5g5b5:
-		*no_alpha = 1;
-	case PICT_a1r5g5b5:
-		*tex_format = GL_BGRA;
-		*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-		break;
-	case PICT_a8:
-		*tex_format = GL_ALPHA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		break;
-	case PICT_x4r4g4b4:
-		*no_alpha = 1;
-	case PICT_a4r4g4b4:
-		*tex_format = GL_BGRA;
-		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-		break;
-
-	case PICT_x4b4g4r4:
-		*no_alpha = 1;
-	case PICT_a4b4g4r4:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-		break;
-
-	default:
-		LogMessageVerb(X_INFO, 0,
-			       "fail to get matched format for %x \n",
-			       format);
-		return -1;
-	}
-	return 0;
-}
-
-#else
-#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
-
-static inline int
-glamor_get_tex_format_type_from_pictformat(PictFormatShort format,
-					   GLenum * tex_format,
-					   GLenum * tex_type,
-					   int *no_alpha,
-					   int *revert,
-					   int *swap_rb,
-					   int is_upload)
-{
-	int need_swap_rb = 0;
-
-	*no_alpha = 0;
-	*revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
-	switch (format) {
-	case PICT_b8g8r8x8:
-		*no_alpha = 1;
-	case PICT_b8g8r8a8:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		need_swap_rb = 1;
-		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-		break;
-
-	case PICT_x8r8g8b8:
-		*no_alpha = 1;
-	case PICT_a8r8g8b8:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		need_swap_rb = 1;
-		break;
-
-	case PICT_x8b8g8r8:
-		*no_alpha = 1;
-	case PICT_a8b8g8r8:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		break;
-
-	case PICT_x2r10g10b10:
-		*no_alpha = 1;
-	case PICT_a2r10g10b10:
-		*tex_format = GL_RGBA;
-		/* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
-		 * we have to use GL_UNSIGNED_BYTE and do the conversion in
-		 * shader latter.*/
-		*tex_type = GL_UNSIGNED_BYTE;
-		if (is_upload == 1) {
-			if (!IS_LITTLE_ENDIAN)
-				*revert = REVERT_UPLOADING_10_10_10_2;
-			else
-				*revert = REVERT_UPLOADING_2_10_10_10;
-		}
-		else {
-			if (!IS_LITTLE_ENDIAN) {
-				*revert = REVERT_DOWNLOADING_10_10_10_2;
-			}
-			else {
-				*revert = REVERT_DOWNLOADING_2_10_10_10;
-			}
-		}
-		need_swap_rb = 1;
-
-		break;
-
-	case PICT_x2b10g10r10:
-		*no_alpha = 1;
-	case PICT_a2b10g10r10:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		if (is_upload == 1) {
-			if (!IS_LITTLE_ENDIAN)
-				*revert = REVERT_UPLOADING_10_10_10_2;
-			else
-				*revert = REVERT_UPLOADING_2_10_10_10;
-		}
-		else {
-			if (!IS_LITTLE_ENDIAN) {
-				*revert = REVERT_DOWNLOADING_10_10_10_2;
-			}
-			else {
-				*revert = REVERT_DOWNLOADING_2_10_10_10;
-			}
-		}
-		break;
-
-	case PICT_r5g6b5:
-		*tex_format = GL_RGB;
-		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
-		*revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
-		break;
-
-	case PICT_b5g6r5:
-		*tex_format = GL_RGB;
-		*tex_type = GL_UNSIGNED_SHORT_5_6_5;
-		need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;;
-		break;
-
-	case PICT_x1b5g5r5:
-		*no_alpha = 1;
-	case PICT_a1b5g5r5:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-		if (IS_LITTLE_ENDIAN) {
-			*revert = is_upload ? REVERT_UPLOADING_1_5_5_5 : REVERT_DOWNLOADING_1_5_5_5;
-		} else
-			*revert = REVERT_NONE;
-		break;
-
-	case PICT_x1r5g5b5:
-		*no_alpha = 1;
-	case PICT_a1r5g5b5:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-		if (IS_LITTLE_ENDIAN) {
-			*revert = is_upload ? REVERT_UPLOADING_1_5_5_5 : REVERT_DOWNLOADING_1_5_5_5;
-		} else
-			*revert = REVERT_NONE;
-		need_swap_rb = 1;
-		break;
-
-	case PICT_a1:
-		*tex_format = GL_ALPHA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		*revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
-		break;
-
-	case PICT_a8:
-		*tex_format = GL_ALPHA;
-		*tex_type = GL_UNSIGNED_BYTE;
-		*revert = REVERT_NONE;
-		break;
-
-	case PICT_x4r4g4b4:
-		*no_alpha = 1;
-	case PICT_a4r4g4b4:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-		need_swap_rb = 1;
-		break;
-
-	case PICT_x4b4g4r4:
-		*no_alpha = 1;
-	case PICT_a4b4g4r4:
-		*tex_format = GL_RGBA;
-		*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-		*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-		break;
-
-	default:
-		LogMessageVerb(X_INFO, 0,
-			       "fail to get matched format for %x \n",
-			       format);
-		return -1;
-	}
-
-	if (need_swap_rb)
-		*swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING;
-	else
-		*swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
-	return 0;
-}
-
-#endif
-
 inline static int cache_format(GLenum format)
 {
 	switch (format) {
@@ -1238,33 +959,6 @@ inline static int cache_format(GLenum format)
 	}
 }
 
-static inline int
-glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
-				       GLenum * format,
-				       GLenum * type,
-				       int *no_alpha,
-				       int *revert,
-				       int *swap_rb,
-				       int is_upload)
-{
-	glamor_pixmap_private *pixmap_priv;
-	PictFormatShort pict_format;
-
-	pixmap_priv = glamor_get_pixmap_private(pixmap);
-	if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
-		pict_format = pixmap_priv->base.picture->format;
-	else
-		pict_format = format_for_depth(pixmap->drawable.depth);
-
-	return glamor_get_tex_format_type_from_pictformat(pict_format,
-							  format, type,
-							  no_alpha,
-							  revert,
-							  swap_rb,
-							  is_upload);
-}
-
-
 /* borrowed from uxa */
 static inline Bool
 glamor_get_rgba_from_pixel(CARD32 pixel,
-- 
1.8.3.1



More information about the Glamor mailing list