From 2a9dfc963f610abfbf12d5efdf5ba5b3f55a4305 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Thu, 8 Sep 2011 15:14:43 +0800 Subject: [PATCH] glamor: Re-arrange some macros/definitions in header files. Signed-off-by: Zhigang Gong --- glamor/glamor_glext.h | 32 +++ glamor/glamor_priv.h | 491 +++--------------------------------------- glamor/glamor_utils.h | 380 ++++++++++++++++++++++++++++++++ 3 files changed, 445 insertions(+), 458 deletions(-) create mode 100644 glamor/glamor_glext.h diff --git a/glamor/glamor_glext.h b/glamor/glamor_glext.h new file mode 100644 index 000000000..f734d1313 --- /dev/null +++ b/glamor/glamor_glext.h @@ -0,0 +1,32 @@ +#ifdef GLAMOR_GLES2 + +#define GL_BGRA GL_BGRA_EXT +#define GL_COLOR_INDEX 0x1900 +#define GL_BITMAP 0x1A00 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 + +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_CLAMP_TO_BORDER 0x812D + +#define GL_READ_WRITE 0x88BA +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 + +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 + +#define GL_PACK_INVERT_MESA 0x8758 + +#endif diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index 0cbc258f3..5f82c7883 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -35,89 +35,26 @@ #include "glamor.h" -#ifdef GLAMOR_GLES2 -#define GL_BGRA GL_BGRA_EXT -#define GL_COLOR_INDEX 0x1900 -#define GL_BITMAP 0x1A00 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 - -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_CLAMP_TO_BORDER 0x812D - -#define GL_READ_WRITE 0x88BA -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_PACK_ROW_LENGTH 0x0D02 -#define GL_UNPACK_ROW_LENGTH 0x0CF2 - -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 - -#define GL_PACK_INVERT_MESA 0x8758 - -#define glMapBuffer(x, y) NULL -#define glUnmapBuffer(x) -#define glRasterPos2i(x,y) -#define glDrawPixels(x,y,z,a,b) - -#endif - #define GL_GLEXT_PROTOTYPES + #ifdef GLAMOR_GLES2 #include #include -#define GLAMOR_DEFAULT_PRECISION \ - "precision mediump float;\n" - +#define GLAMOR_DEFAULT_PRECISION "precision mediump float;\n" +#include "glamor_glext.h" #else #include #include - #define GLAMOR_DEFAULT_PRECISION #endif - #ifdef RENDER #include "glyphstr.h" #endif - #include "glamor_debug.h" -#define glamor_check_fbo_size(_glamor_,_w_, _h_) ((_w_) > 0 && (_h_) > 0 \ - && (_w_) < _glamor_->max_fbo_size \ - && (_h_) < _glamor_->max_fbo_size) - -#define glamor_check_fbo_depth(_depth_) ( \ - _depth_ == 8 \ - || _depth_ == 15 \ - || _depth_ == 16 \ - || _depth_ == 24 \ - || _depth_ == 30 \ - || _depth_ == 32) - - -#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv->is_picture == 1) -#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) (pixmap_priv->gl_fbo == 1) - -typedef struct glamor_transform_uniforms { - GLint x_bias; - GLint x_scale; - GLint y_bias; - GLint y_scale; -} glamor_transform_uniforms; - typedef struct glamor_composite_shader { GLuint prog; GLint dest_to_dest_uniform_location; @@ -138,16 +75,6 @@ typedef struct { INT16 height; } glamor_composite_rect_t; -#define GLAMOR_NUM_GLYPH_CACHES 4 -#define GLAMOR_NUM_GLYPH_CACHE_FORMATS 2 - -typedef struct { - PicturePtr picture; /* Where the glyphs of the cache are stored */ - GlyphPtr *glyphs; - uint16_t count; - uint16_t evict; -} glamor_glyph_cache_t; - enum glamor_vertex_type { GLAMOR_VERTEX_POS, @@ -178,8 +105,6 @@ enum shader_in { SHADER_IN_COUNT, }; -#include "glamor_gl_dispatch.h" - struct glamor_screen_private; struct glamor_pixmap_private; typedef void (*glamor_pixmap_validate_function_t)(struct glamor_screen_private*, @@ -191,6 +116,20 @@ enum glamor_gl_flavor { }; #define GLAMOR_CREATE_PIXMAP_CPU 0x100 + +#define GLAMOR_NUM_GLYPH_CACHES 4 +#define GLAMOR_NUM_GLYPH_CACHE_FORMATS 2 + +typedef struct { + PicturePtr picture; /* Where the glyphs of the cache are stored */ + GlyphPtr *glyphs; + uint16_t count; + uint16_t evict; +} glamor_glyph_cache_t; + + +#include "glamor_gl_dispatch.h" + typedef struct glamor_screen_private { CloseScreenProcPtr saved_close_screen; CreateGCProcPtr saved_create_gc; @@ -235,7 +174,6 @@ typedef struct glamor_screen_private { /* glamor_putimage */ GLint put_image_xybitmap_prog; - glamor_transform_uniforms put_image_xybitmap_transform; GLint put_image_xybitmap_fg_uniform_location; GLint put_image_xybitmap_bg_uniform_location; @@ -252,7 +190,6 @@ typedef struct glamor_screen_private { glamor_glyph_cache_t glyphCaches[GLAMOR_NUM_GLYPH_CACHE_FORMATS]; Bool glyph_cache_initialized; - struct glamor_gl_dispatch dispatch; } glamor_screen_private; @@ -262,28 +199,6 @@ typedef enum glamor_access { GLAMOR_ACCESS_WO, } glamor_access_t; -/* - * glamor_pixmap_private - glamor pixmap's private structure. - * @gl_fbo: The pixmap is attached to a fbo originally. - * @gl_tex: The pixmap is in a gl texture originally. - * @pbo_valid: The pbo has a valid copy of the pixmap's data. - * @is_picture: The drawable is attached to a picture. - * @tex: attached texture. - * @fb: attached fbo. - * @pbo: attached pbo. - * @access_mode: access mode during the prepare/finish pair. - * @pict_format: the corresponding picture's format. - * #pending_op: currently only support pending filling. - * @container: The corresponding pixmap's pointer. - **/ - -#define GLAMOR_PIXMAP_PRIV_NEED_VALIDATE(pixmap_priv) \ - (GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) \ - && (pixmap_priv->pending_op.type != GLAMOR_PENDING_NONE)) - -#define GLAMOR_PIXMAP_PRIV_NO_PENDING(pixmap_priv) \ - (pixmap_priv->pending_op.type == GLAMOR_PENDING_NONE) - enum _glamor_pending_op_type{ GLAMOR_PENDING_NONE, GLAMOR_PENDING_FILL @@ -300,6 +215,20 @@ typedef union _glamor_pending_op { glamor_pending_fill fill; } glamor_pending_op; +/* + * glamor_pixmap_private - glamor pixmap's private structure. + * @gl_fbo: The pixmap is attached to a fbo originally. + * @gl_tex: The pixmap is in a gl texture originally. + * @pbo_valid: The pbo has a valid copy of the pixmap's data. + * @is_picture: The drawable is attached to a picture. + * @tex: attached texture. + * @fb: attached fbo. + * @pbo: attached pbo. + * @access_mode: access mode during the prepare/finish pair. + * @pict_format: the corresponding picture's format. + * #pending_op: currently only support pending filling. + * @container: The corresponding pixmap's pointer. + **/ typedef struct glamor_pixmap_private { unsigned char gl_fbo:1; @@ -316,15 +245,6 @@ typedef struct glamor_pixmap_private { glamor_screen_private *glamor_priv; } glamor_pixmap_private; -#define GLAMOR_CHECK_PENDING_FILL(_dispatch_, _glamor_priv_, _pixmap_priv_) do \ - { \ - if (_pixmap_priv_->pending_op.type == GLAMOR_PENDING_FILL) { \ - _dispatch_->glUseProgram(_glamor_priv_->solid_prog); \ - _dispatch_->glUniform4fv(_glamor_priv_->solid_color_uniform_location, 1, \ - _pixmap_priv_->pending_op.fill.color4fv); \ - } \ - } while(0) - /* * Pixmap dynamic status, used by dynamic upload feature. * @@ -356,347 +276,6 @@ glamor_get_pixmap_private(PixmapPtr pixmap) return dixLookupPrivate(&pixmap->devPrivates, glamor_pixmap_private_key); } -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) - -/** - * Borrow from uxa. - */ -static inline CARD32 -format_for_depth(int depth) -{ - switch (depth) { - case 1: return PICT_a1; - case 4: return PICT_a4; - case 8: return PICT_a8; - case 15: return PICT_x1r5g5b5; - case 16: return PICT_r5g6b5; - default: - case 24: return PICT_x8r8g8b8; -#if XORG_VERSION_CURRENT >= 10699900 - case 30: return PICT_x2r10g10b10; -#endif - case 32: return PICT_a8r8g8b8; - } -} - -static inline CARD32 -format_for_pixmap(PixmapPtr pixmap) -{ - 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->pict_format; - else - pict_format = format_for_depth(pixmap->drawable.depth); - - return pict_format; -} - -/* - * 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. - * - * 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 *no_revert) -{ - *no_alpha = 0; - *no_revert = 1; - switch (format) { - case PICT_a1: - *tex_format = GL_COLOR_INDEX; - *tex_type = GL_BITMAP; - 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 *no_revert) -{ - *no_alpha = 0; - *no_revert = IS_LITTLE_ENDIAN; - - switch (format) { - case PICT_b8g8r8x8: - *no_alpha = 1; - case PICT_b8g8r8a8: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_BYTE; - *no_revert = !IS_LITTLE_ENDIAN; - break; - - case PICT_x8r8g8b8: - *no_alpha = 1; - case PICT_a8r8g8b8: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_BYTE; - 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_BGRA; - *tex_type = GL_UNSIGNED_INT_10_10_10_2; - *no_revert = TRUE; - break; - - case PICT_x2b10g10r10: - *no_alpha = 1; - case PICT_a2b10g10r10: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_INT_10_10_10_2; - *no_revert = TRUE; - break; - - case PICT_r5g6b5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5; - *no_revert = TRUE; - break; - - case PICT_b5g6r5: - *tex_format = GL_RGB; - *tex_type = GL_UNSIGNED_SHORT_5_6_5; - *no_revert = FALSE; - break; - - case PICT_x1b5g5r5: - *no_alpha = 1; - case PICT_a1b5g5r5: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - *no_revert = TRUE; - break; - - case PICT_x1r5g5b5: - *no_alpha = 1; - case PICT_a1r5g5b5: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - *no_revert = TRUE; - break; - - case PICT_a8: - *tex_format = GL_ALPHA; - *tex_type = GL_UNSIGNED_BYTE; - *no_revert = TRUE; - break; - - case PICT_x4r4g4b4: - *no_alpha = 1; - case PICT_a4r4g4b4: - *tex_format = GL_BGRA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; - *no_revert = TRUE; - break; - - case PICT_x4b4g4r4: - *no_alpha = 1; - case PICT_a4b4g4r4: - *tex_format = GL_RGBA; - *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; - *no_revert = TRUE; - break; - - default: - LogMessageVerb(X_INFO, 0, "fail to get matched format for %x \n", format); - return -1; - } - return 0; -} - - -#endif - - -static inline int -glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap, - GLenum *format, - GLenum *type, - int *no_alpha, - int *no_revert) -{ - 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->pict_format; - else - pict_format = format_for_depth(pixmap->drawable.depth); - - return glamor_get_tex_format_type_from_pictformat(pict_format, - format, type, - no_alpha, no_revert); -} - - -/* borrowed from uxa */ -static inline Bool -glamor_get_rgba_from_pixel(CARD32 pixel, - float * red, - float * green, - float * blue, - float * alpha, - CARD32 format) -{ - int rbits, bbits, gbits, abits; - int rshift, bshift, gshift, ashift; - - rbits = PICT_FORMAT_R(format); - gbits = PICT_FORMAT_G(format); - bbits = PICT_FORMAT_B(format); - abits = PICT_FORMAT_A(format); - - if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) { - rshift = gshift = bshift = ashift = 0; - } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) { - bshift = 0; - gshift = bbits; - rshift = gshift + gbits; - ashift = rshift + rbits; - } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) { - rshift = 0; - gshift = rbits; - bshift = gshift + gbits; - ashift = bshift + bbits; -#if XORG_VERSION_CURRENT >= 10699900 - } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) { - ashift = 0; - rshift = abits; - if (abits == 0) - rshift = PICT_FORMAT_BPP(format) - (rbits+gbits+bbits); - gshift = rshift + rbits; - bshift = gshift + gbits; -#endif - } else { - return FALSE; - } -#define COLOR_INT_TO_FLOAT(_fc_, _p_, _s_, _bits_) \ - *_fc_ = (((_p_) >> (_s_)) & (( 1 << (_bits_)) - 1)) \ - / (float)((1<<(_bits_)) - 1) - - if (rbits) - COLOR_INT_TO_FLOAT(red, pixel, rshift, rbits); - else - *red = 0; - - if (gbits) - COLOR_INT_TO_FLOAT(green, pixel, gshift, gbits); - else - *green = 0; - - if (bbits) - COLOR_INT_TO_FLOAT(blue, pixel, bshift, bbits); - else - *blue = 0; - - if (abits) - COLOR_INT_TO_FLOAT(alpha, pixel, ashift, abits); - else - *alpha = 1; - - return TRUE; -} - /** * Returns TRUE if the given planemask covers all the significant bits in the @@ -775,10 +354,6 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, GLenum *format, void glamor_set_alu(struct glamor_gl_dispatch * dispatch, unsigned char alu); Bool glamor_set_planemask(PixmapPtr pixmap, unsigned long planemask); -void glamor_get_transform_uniform_locations(GLint prog, - glamor_transform_uniforms *uniform_locations); -void glamor_set_transform_for_pixmap(PixmapPtr pixmap, - glamor_transform_uniforms *uniform_locations); Bool glamor_change_window_attributes(WindowPtr pWin, unsigned long mask); RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap); Bool glamor_gl_has_extension(char *extension); @@ -977,6 +552,8 @@ glamor_upload_picture_to_texture(PicturePtr picture); void glamor_picture_format_fixup(PicturePtr picture, glamor_pixmap_private *pixmap_priv); +#include"glamor_utils.h" + /* Dynamic pixmap upload to texture if needed. * Sometimes, the target is a gl texture pixmap/picture, * but the source or mask is in cpu memory. In that case, @@ -984,11 +561,9 @@ glamor_picture_format_fixup(PicturePtr picture, glamor_pixmap_private *pixmap_pr * fallback the whole process to cpu. Most of the time, * this will increase performance obviously. */ - #define GLAMOR_PIXMAP_DYNAMIC_UPLOAD #define GLAMOR_DELAYED_FILLING -#include"glamor_utils.h" #endif /* GLAMOR_PRIV_H */ diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h index 30432cf1f..fe5bd4e1e 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -159,4 +159,384 @@ glamor_transform_boxes(BoxPtr boxes, int nbox, int dx, int dy) boxes[i].y2 += dy; } } + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +#define glamor_check_fbo_size(_glamor_,_w_, _h_) ((_w_) > 0 && (_h_) > 0 \ + && (_w_) < _glamor_->max_fbo_size \ + && (_h_) < _glamor_->max_fbo_size) + +#define glamor_check_fbo_depth(_depth_) ( \ + _depth_ == 8 \ + || _depth_ == 15 \ + || _depth_ == 16 \ + || _depth_ == 24 \ + || _depth_ == 30 \ + || _depth_ == 32) + + +#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv->is_picture == 1) +#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) (pixmap_priv->gl_fbo == 1) + +#define GLAMOR_PIXMAP_PRIV_NEED_VALIDATE(pixmap_priv) \ + (GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv) \ + && (pixmap_priv->pending_op.type != GLAMOR_PENDING_NONE)) + +#define GLAMOR_PIXMAP_PRIV_NO_PENDING(pixmap_priv) \ + (pixmap_priv->pending_op.type == GLAMOR_PENDING_NONE) + +#define GLAMOR_CHECK_PENDING_FILL(_dispatch_, _glamor_priv_, _pixmap_priv_) do \ + { \ + if (_pixmap_priv_->pending_op.type == GLAMOR_PENDING_FILL) { \ + _dispatch_->glUseProgram(_glamor_priv_->solid_prog); \ + _dispatch_->glUniform4fv(_glamor_priv_->solid_color_uniform_location, 1, \ + _pixmap_priv_->pending_op.fill.color4fv); \ + } \ + } while(0) + + +/** + * Borrow from uxa. + */ +static inline CARD32 +format_for_depth(int depth) +{ + switch (depth) { + case 1: return PICT_a1; + case 4: return PICT_a4; + case 8: return PICT_a8; + case 15: return PICT_x1r5g5b5; + case 16: return PICT_r5g6b5; + default: + case 24: return PICT_x8r8g8b8; +#if XORG_VERSION_CURRENT >= 10699900 + case 30: return PICT_x2r10g10b10; +#endif + case 32: return PICT_a8r8g8b8; + } +} + +static inline CARD32 +format_for_pixmap(PixmapPtr pixmap) +{ + 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->pict_format; + else + pict_format = format_for_depth(pixmap->drawable.depth); + + return pict_format; +} + +/* + * 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. + * + * 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 *no_revert) +{ + *no_alpha = 0; + *no_revert = 1; + switch (format) { + case PICT_a1: + *tex_format = GL_COLOR_INDEX; + *tex_type = GL_BITMAP; + 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 *no_revert) +{ + *no_alpha = 0; + *no_revert = IS_LITTLE_ENDIAN; + + switch (format) { + case PICT_b8g8r8x8: + *no_alpha = 1; + case PICT_b8g8r8a8: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_BYTE; + *no_revert = !IS_LITTLE_ENDIAN; + break; + + case PICT_x8r8g8b8: + *no_alpha = 1; + case PICT_a8r8g8b8: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_BYTE; + 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_BGRA; + *tex_type = GL_UNSIGNED_INT_10_10_10_2; + *no_revert = TRUE; + break; + + case PICT_x2b10g10r10: + *no_alpha = 1; + case PICT_a2b10g10r10: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_INT_10_10_10_2; + *no_revert = TRUE; + break; + + case PICT_r5g6b5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5; + *no_revert = TRUE; + break; + + case PICT_b5g6r5: + *tex_format = GL_RGB; + *tex_type = GL_UNSIGNED_SHORT_5_6_5; + *no_revert = FALSE; + break; + + case PICT_x1b5g5r5: + *no_alpha = 1; + case PICT_a1b5g5r5: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + *no_revert = TRUE; + break; + + case PICT_x1r5g5b5: + *no_alpha = 1; + case PICT_a1r5g5b5: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + *no_revert = TRUE; + break; + + case PICT_a8: + *tex_format = GL_ALPHA; + *tex_type = GL_UNSIGNED_BYTE; + *no_revert = TRUE; + break; + + case PICT_x4r4g4b4: + *no_alpha = 1; + case PICT_a4r4g4b4: + *tex_format = GL_BGRA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; + *no_revert = TRUE; + break; + + case PICT_x4b4g4r4: + *no_alpha = 1; + case PICT_a4b4g4r4: + *tex_format = GL_RGBA; + *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV; + *no_revert = TRUE; + break; + + default: + LogMessageVerb(X_INFO, 0, "fail to get matched format for %x \n", format); + return -1; + } + return 0; +} + + +#endif + + +static inline int +glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap, + GLenum *format, + GLenum *type, + int *no_alpha, + int *no_revert) +{ + 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->pict_format; + else + pict_format = format_for_depth(pixmap->drawable.depth); + + return glamor_get_tex_format_type_from_pictformat(pict_format, + format, type, + no_alpha, no_revert); +} + + +/* borrowed from uxa */ +static inline Bool +glamor_get_rgba_from_pixel(CARD32 pixel, + float * red, + float * green, + float * blue, + float * alpha, + CARD32 format) +{ + int rbits, bbits, gbits, abits; + int rshift, bshift, gshift, ashift; + + rbits = PICT_FORMAT_R(format); + gbits = PICT_FORMAT_G(format); + bbits = PICT_FORMAT_B(format); + abits = PICT_FORMAT_A(format); + + if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) { + rshift = gshift = bshift = ashift = 0; + } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) { + bshift = 0; + gshift = bbits; + rshift = gshift + gbits; + ashift = rshift + rbits; + } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) { + rshift = 0; + gshift = rbits; + bshift = gshift + gbits; + ashift = bshift + bbits; +#if XORG_VERSION_CURRENT >= 10699900 + } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) { + ashift = 0; + rshift = abits; + if (abits == 0) + rshift = PICT_FORMAT_BPP(format) - (rbits+gbits+bbits); + gshift = rshift + rbits; + bshift = gshift + gbits; +#endif + } else { + return FALSE; + } +#define COLOR_INT_TO_FLOAT(_fc_, _p_, _s_, _bits_) \ + *_fc_ = (((_p_) >> (_s_)) & (( 1 << (_bits_)) - 1)) \ + / (float)((1<<(_bits_)) - 1) + + if (rbits) + COLOR_INT_TO_FLOAT(red, pixel, rshift, rbits); + else + *red = 0; + + if (gbits) + COLOR_INT_TO_FLOAT(green, pixel, gshift, gbits); + else + *green = 0; + + if (bbits) + COLOR_INT_TO_FLOAT(blue, pixel, bshift, bbits); + else + *blue = 0; + + if (abits) + COLOR_INT_TO_FLOAT(alpha, pixel, ashift, abits); + else + *alpha = 1; + + return TRUE; +} + + + + + + #endif