[PATCH 05/12] glamor: Move glamor_render.c pict handling to glamor_picture.c

2015-07-08 Thread Eric Anholt
These functions aren't used by anything else, and are specific to the
temporary-upload-as-a-weird-format path of glamor_render.c, called
through glamor_upload_picture_to_texture().

Signed-off-by: Eric Anholt e...@anholt.net
---
 glamor/glamor_picture.c | 870 
 glamor/glamor_pixmap.c  | 870 
 glamor/glamor_priv.h|   7 -
 3 files changed, 870 insertions(+), 877 deletions(-)

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 20b9de2..3b0b7c9 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -31,6 +31,876 @@
 #include glamor_priv.h
 #include mipict.h
 
+/*
+ * 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.
+ **/
+static int
+glamor_get_tex_format_type_from_pictformat_gl(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:
+return -1;
+}
+return 0;
+}
+
+#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
+
+static int
+glamor_get_tex_format_type_from_pictformat_gles2(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;
+  

Re: [PATCH 05/12] glamor: Move glamor_render.c pict handling to glamor_picture.c

2015-07-08 Thread Dave Airlie
On 9 July 2015 at 05:45, Eric Anholt e...@anholt.net wrote:
 These functions aren't used by anything else, and are specific to the
 temporary-upload-as-a-weird-format path of glamor_render.c, called
 through glamor_upload_picture_to_texture().

 Signed-off-by: Eric Anholt e...@anholt.net
Reviewed-by: Dave Airlie airl...@redhat.com
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel