mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
texture: Handle premult conversions when getting texture data
cogl_texture_get_data uses find_best_gl_get_data_format from the texture driver which returns the closest format to use for retrieving pixel data given an intended format. However this function doesn't know about the texture we are reading data from so it doesn't know that the data we will actually receive will have the same premult status as the texture's format. With the GL driver, this function ends up returning exactly the same format as passed in which means it will never do a premult conversion. Under GLES it always returns COGL_PIXEL_FORMAT_RGBA_8888 so it will always make the data unpremult even if the final requested format is premultiplied. This patch fixes it so that it copies the premult status of the closest_format from the format of the underlying texture. That way it will later convert or not depending on the requested target format. Note this patch breaks test-sub-texture with the GL driver because that is incorrectly trying to read the texture data back as RGBA_8888 even though it depends on it not doing a premult conversion. The test was already broken with GLES2 and remains broken. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
31bd4cb22c
commit
39c6bf59cb
@ -1198,14 +1198,17 @@ cogl_texture_get_data (CoglTexture *texture,
|
||||
int y;
|
||||
int tex_width;
|
||||
int tex_height;
|
||||
CoglPixelFormat texture_format;
|
||||
|
||||
CoglTextureGetData tg_data;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, 0);
|
||||
|
||||
texture_format = cogl_texture_get_format (texture);
|
||||
|
||||
/* Default to internal format if none specified */
|
||||
if (format == COGL_PIXEL_FORMAT_ANY)
|
||||
format = cogl_texture_get_format (texture);
|
||||
format = texture_format;
|
||||
|
||||
tex_width = cogl_texture_get_width (texture);
|
||||
tex_height = cogl_texture_get_height (texture);
|
||||
@ -1226,6 +1229,12 @@ cogl_texture_get_data (CoglTexture *texture,
|
||||
&closest_gl_type);
|
||||
closest_bpp = _cogl_pixel_format_get_bytes_per_pixel (closest_format);
|
||||
|
||||
/* We can assume that whatever data GL gives us will have the
|
||||
premult status of the original texture */
|
||||
if ((closest_format & COGL_A_BIT))
|
||||
closest_format = ((closest_format & ~COGL_PREMULT_BIT) |
|
||||
(texture_format & COGL_PREMULT_BIT));
|
||||
|
||||
/* Is the requested format supported? */
|
||||
if (closest_format == format)
|
||||
/* Target user data directly */
|
||||
|
Loading…
Reference in New Issue
Block a user