glamor: Merge the two GL-type-from-pictformat paths.
It clarifies what the difference is between the two paths, and would potentially encourage us to handle GLES extensions that expose additional types. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
c7574c63c6
commit
f667d51770
|
@ -40,275 +40,195 @@
|
||||||
*
|
*
|
||||||
* Return 0 if find a matched texture type. Otherwise return -1.
|
* Return 0 if find a matched texture type. Otherwise return -1.
|
||||||
**/
|
**/
|
||||||
static int
|
static Bool
|
||||||
glamor_get_tex_format_type_from_pictformat_gl(ScreenPtr pScreen,
|
glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
|
||||||
PictFormatShort format,
|
PictFormatShort format,
|
||||||
GLenum *tex_format,
|
GLenum *tex_format,
|
||||||
GLenum *tex_type,
|
GLenum *tex_type,
|
||||||
int *no_alpha,
|
int *no_alpha,
|
||||||
int *revert,
|
int *revert,
|
||||||
int *swap_rb)
|
int *swap_rb)
|
||||||
{
|
{
|
||||||
glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
|
||||||
|
Bool is_little_endian = IMAGE_BYTE_ORDER == LSBFirst;
|
||||||
|
|
||||||
*no_alpha = 0;
|
*no_alpha = 0;
|
||||||
*revert = REVERT_NONE;
|
*revert = REVERT_NONE;
|
||||||
*swap_rb = SWAP_NONE_UPLOADING;
|
*swap_rb = SWAP_NONE_UPLOADING;
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case PICT_a1:
|
case PICT_a1:
|
||||||
*tex_format = glamor_priv->one_channel_format;
|
*tex_format = glamor_priv->one_channel_format;
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
*revert = REVERT_UPLOADING_A1;
|
*revert = REVERT_UPLOADING_A1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_b8g8r8x8:
|
case PICT_b8g8r8x8:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_b8g8r8a8:
|
case PICT_b8g8r8a8:
|
||||||
*tex_format = GL_BGRA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_INT_8_8_8_8;
|
*tex_format = GL_BGRA;
|
||||||
|
*tex_type = GL_UNSIGNED_INT_8_8_8_8;
|
||||||
|
} else {
|
||||||
|
*tex_format = GL_RGBA;
|
||||||
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
|
*swap_rb = SWAP_UPLOADING;
|
||||||
|
*revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x8r8g8b8:
|
case PICT_x8r8g8b8:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a8r8g8b8:
|
case PICT_a8r8g8b8:
|
||||||
*tex_format = GL_BGRA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
*tex_format = GL_BGRA;
|
||||||
break;
|
*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||||
case PICT_x8b8g8r8:
|
} else {
|
||||||
*no_alpha = 1;
|
*tex_format = GL_RGBA;
|
||||||
case PICT_a8b8g8r8:
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
*tex_format = GL_RGBA;
|
*swap_rb = SWAP_UPLOADING;
|
||||||
*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
*revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
|
||||||
break;
|
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 = glamor_priv->one_channel_format;
|
|
||||||
*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(ScreenPtr pScreen,
|
|
||||||
PictFormatShort format,
|
|
||||||
GLenum *tex_format,
|
|
||||||
GLenum *tex_type,
|
|
||||||
int *no_alpha,
|
|
||||||
int *revert,
|
|
||||||
int *swap_rb)
|
|
||||||
{
|
|
||||||
glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
|
|
||||||
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;
|
break;
|
||||||
|
|
||||||
case PICT_x8b8g8r8:
|
case PICT_x8b8g8r8:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a8b8g8r8:
|
case PICT_a8b8g8r8:
|
||||||
*tex_format = GL_RGBA;
|
*tex_format = GL_RGBA;
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
|
*tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||||
|
} else {
|
||||||
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
|
*revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x2r10g10b10:
|
case PICT_x2r10g10b10:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a2r10g10b10:
|
case PICT_a2r10g10b10:
|
||||||
*tex_format = GL_RGBA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
/* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
|
*tex_format = GL_BGRA;
|
||||||
* we have to use GL_UNSIGNED_BYTE and do the conversion in
|
*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
|
||||||
* shader latter.*/
|
} else {
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
/* glReadPixmap doesn't support
|
||||||
if (!IS_LITTLE_ENDIAN)
|
* GL_UNSIGNED_INT_10_10_10_2. We have to use
|
||||||
*revert = REVERT_UPLOADING_10_10_10_2;
|
* GL_UNSIGNED_BYTE and do the conversion in a shader
|
||||||
else
|
* later.
|
||||||
*revert = REVERT_UPLOADING_2_10_10_10;
|
*/
|
||||||
need_swap_rb = 1;
|
*tex_format = GL_RGBA;
|
||||||
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
|
if (!is_little_endian)
|
||||||
|
*revert = REVERT_UPLOADING_10_10_10_2;
|
||||||
|
else
|
||||||
|
*revert = REVERT_UPLOADING_2_10_10_10;
|
||||||
|
*swap_rb = SWAP_UPLOADING;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x2b10g10r10:
|
case PICT_x2b10g10r10:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a2b10g10r10:
|
case PICT_a2b10g10r10:
|
||||||
*tex_format = GL_RGBA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
*tex_format = GL_RGBA;
|
||||||
if (!IS_LITTLE_ENDIAN)
|
*tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
|
||||||
*revert = REVERT_UPLOADING_10_10_10_2;
|
} else {
|
||||||
else
|
*tex_format = GL_RGBA;
|
||||||
*revert = REVERT_UPLOADING_2_10_10_10;
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
|
if (!is_little_endian)
|
||||||
|
*revert = REVERT_UPLOADING_10_10_10_2;
|
||||||
|
else
|
||||||
|
*revert = REVERT_UPLOADING_2_10_10_10;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_r5g6b5:
|
case PICT_r5g6b5:
|
||||||
*tex_format = GL_RGB;
|
*tex_format = GL_RGB;
|
||||||
*tex_type = GL_UNSIGNED_SHORT_5_6_5;
|
*tex_type = GL_UNSIGNED_SHORT_5_6_5;
|
||||||
*revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
|
if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP)
|
||||||
|
*revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_b5g6r5:
|
case PICT_b5g6r5:
|
||||||
*tex_format = GL_RGB;
|
*tex_format = GL_RGB;
|
||||||
*tex_type = GL_UNSIGNED_SHORT_5_6_5;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;
|
*tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
|
||||||
|
} else {
|
||||||
|
*tex_type = GL_UNSIGNED_SHORT_5_6_5;
|
||||||
|
if (is_little_endian)
|
||||||
|
*swap_rb = SWAP_UPLOADING;
|
||||||
|
*revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x1b5g5r5:
|
case PICT_x1b5g5r5:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a1b5g5r5:
|
case PICT_a1b5g5r5:
|
||||||
*tex_format = GL_RGBA;
|
*tex_format = GL_RGBA;
|
||||||
*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
if (IS_LITTLE_ENDIAN)
|
*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||||
*revert = REVERT_UPLOADING_1_5_5_5;
|
} else {
|
||||||
else
|
*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||||
*revert = REVERT_NONE;
|
if (is_little_endian)
|
||||||
|
*revert = REVERT_UPLOADING_1_5_5_5;
|
||||||
|
else
|
||||||
|
*revert = REVERT_NONE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x1r5g5b5:
|
case PICT_x1r5g5b5:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a1r5g5b5:
|
case PICT_a1r5g5b5:
|
||||||
*tex_format = GL_RGBA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
|
*tex_format = GL_BGRA;
|
||||||
if (IS_LITTLE_ENDIAN)
|
*tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||||
*revert = REVERT_UPLOADING_1_5_5_5;
|
} else {
|
||||||
else
|
*tex_format = GL_RGBA;
|
||||||
*revert = REVERT_NONE;
|
*tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||||
need_swap_rb = 1;
|
if (is_little_endian)
|
||||||
break;
|
*revert = REVERT_UPLOADING_1_5_5_5;
|
||||||
|
else
|
||||||
case PICT_a1:
|
*revert = REVERT_NONE;
|
||||||
*tex_format = glamor_priv->one_channel_format;
|
*swap_rb = SWAP_UPLOADING;
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
}
|
||||||
*revert = REVERT_UPLOADING_A1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_a8:
|
case PICT_a8:
|
||||||
*tex_format = glamor_priv->one_channel_format;
|
*tex_format = glamor_priv->one_channel_format;
|
||||||
*tex_type = GL_UNSIGNED_BYTE;
|
*tex_type = GL_UNSIGNED_BYTE;
|
||||||
*revert = REVERT_NONE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x4r4g4b4:
|
case PICT_x4r4g4b4:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a4r4g4b4:
|
case PICT_a4r4g4b4:
|
||||||
*tex_format = GL_RGBA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
|
*tex_format = GL_BGRA;
|
||||||
*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
|
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
||||||
need_swap_rb = 1;
|
} else {
|
||||||
|
*tex_format = GL_RGBA;
|
||||||
|
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||||
|
*revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
|
||||||
|
*swap_rb = SWAP_UPLOADING;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PICT_x4b4g4r4:
|
case PICT_x4b4g4r4:
|
||||||
*no_alpha = 1;
|
*no_alpha = 1;
|
||||||
case PICT_a4b4g4r4:
|
case PICT_a4b4g4r4:
|
||||||
*tex_format = GL_RGBA;
|
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
||||||
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
|
*tex_format = GL_RGBA;
|
||||||
*revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
|
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
||||||
|
} else {
|
||||||
|
*tex_format = GL_RGBA;
|
||||||
|
*tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||||
|
*revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LogMessageVerb(X_INFO, 0,
|
return FALSE;
|
||||||
"fail to get matched format for %x \n", format);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (need_swap_rb)
|
|
||||||
*swap_rb = SWAP_UPLOADING;
|
|
||||||
else
|
|
||||||
*swap_rb = SWAP_NONE_UPLOADING;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
|
|
||||||
PictFormatShort pict_format,
|
|
||||||
GLenum *format,
|
|
||||||
GLenum *type,
|
|
||||||
int *no_alpha,
|
|
||||||
int *revert, int *swap_rb)
|
|
||||||
{
|
|
||||||
glamor_screen_private *glamor_priv =
|
|
||||||
glamor_get_screen_private(pixmap->drawable.pScreen);
|
|
||||||
|
|
||||||
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
|
|
||||||
return glamor_get_tex_format_type_from_pictformat_gl(pixmap->drawable.pScreen,
|
|
||||||
pict_format,
|
|
||||||
format, type,
|
|
||||||
no_alpha,
|
|
||||||
revert,
|
|
||||||
swap_rb);
|
|
||||||
} else {
|
|
||||||
return glamor_get_tex_format_type_from_pictformat_gles2(pixmap->drawable.pScreen,
|
|
||||||
pict_format,
|
|
||||||
format, type,
|
|
||||||
no_alpha,
|
|
||||||
revert,
|
|
||||||
swap_rb);
|
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
@ -738,12 +658,12 @@ glamor_upload_picture_to_texture(PicturePtr picture)
|
||||||
assert(glamor_pixmap_is_memory(pixmap));
|
assert(glamor_pixmap_is_memory(pixmap));
|
||||||
assert(!pixmap_priv->fbo);
|
assert(!pixmap_priv->fbo);
|
||||||
|
|
||||||
if (glamor_get_tex_format_type_from_pixmap(pixmap,
|
if (!glamor_get_tex_format_type_from_pictformat(screen,
|
||||||
picture->format,
|
picture->format,
|
||||||
&format,
|
&format,
|
||||||
&type,
|
&type,
|
||||||
&no_alpha,
|
&no_alpha,
|
||||||
&revert, &swap_rb)) {
|
&revert, &swap_rb)) {
|
||||||
glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
|
glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue