From 3747c260816a36352bb91ce06befcbffbbd747c7 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 27 Dec 2013 16:12:15 -0800 Subject: [PATCH] glamor: Move glamor_get_tex_format_type_from_pictformat to a .c file. A pair of 150 lines of inlined switch statements in a header file is crazy. Signed-off-by: Eric Anholt Reviewed-by: Keith Packard Reviewed-by: Adam Jackson --- glamor/glamor_pixmap.c | 303 +++++++++++++++++++++++++++++++++++++++++++++++++ glamor/glamor_utils.h | 303 ------------------------------------------------- 2 files changed, 303 insertions(+), 303 deletions(-) diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c index 30aeebe..1dbeb04 100644 --- a/glamor/glamor_pixmap.c +++ b/glamor/glamor_pixmap.c @@ -185,6 +185,309 @@ glamor_set_alu(ScreenPtr screen, 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/glamor/glamor_utils.h b/glamor/glamor_utils.h index 3de6133..9374c9d 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -914,286 +914,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) { @@ -1209,29 +929,6 @@ 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, -- 2.7.4