mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
cogl: Prefer swizzling to convert BGRA buffers
If the GL implementation/hw supports the GL_*_texture_swizzle extension, pretend that BGRA textures shall contain RGBA data, and let the flipping happen when the texture will be used in the rendering pipeline. This avoids rather expensive format conversions when forcing BGRA buffers into RGBA textures, which happens rather often with WL_SHM_FORMAT_ARGB8888 buffers (like gtk+ uses) in little-endian machines. In intel/mesa/wayland, the performance improvement is rather noticeable, CPU% as seen by top decreases from 45-50% to 25-30% when running gtk+/tests/scrolling-performance with a cairo renderer. https://bugzilla.gnome.org/show_bug.cgi?id=779234
This commit is contained in:
parent
95c924460a
commit
1705a26fc7
@ -174,6 +174,14 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
|
|||||||
case COGL_PIXEL_FORMAT_BGRA_8888:
|
case COGL_PIXEL_FORMAT_BGRA_8888:
|
||||||
case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
|
case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
|
||||||
glintformat = GL_RGBA;
|
glintformat = GL_RGBA;
|
||||||
|
/* If the driver has texture_swizzle, pretend internal
|
||||||
|
* and buffer format are the same here, the pixels
|
||||||
|
* will be flipped through this extension.
|
||||||
|
*/
|
||||||
|
if (_cogl_has_private_feature
|
||||||
|
(context, COGL_PRIVATE_FEATURE_TEXTURE_SWIZZLE))
|
||||||
|
glformat = GL_RGBA;
|
||||||
|
else
|
||||||
glformat = GL_BGRA;
|
glformat = GL_BGRA;
|
||||||
gltype = GL_UNSIGNED_BYTE;
|
gltype = GL_UNSIGNED_BYTE;
|
||||||
break;
|
break;
|
||||||
|
@ -114,6 +114,18 @@ _cogl_texture_driver_gen (CoglContext *ctx,
|
|||||||
red_swizzle) );
|
red_swizzle) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If swizzle extension is available, prefer it to flip bgra buffers to rgba */
|
||||||
|
if ((internal_format == COGL_PIXEL_FORMAT_BGRA_8888 ||
|
||||||
|
internal_format == COGL_PIXEL_FORMAT_BGRA_8888_PRE) &&
|
||||||
|
_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_TEXTURE_SWIZZLE))
|
||||||
|
{
|
||||||
|
static const GLint bgra_swizzle[] = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
|
||||||
|
|
||||||
|
GE( ctx, glTexParameteriv (gl_target,
|
||||||
|
GL_TEXTURE_SWIZZLE_RGBA,
|
||||||
|
bgra_swizzle) );
|
||||||
|
}
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user