mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 15:40:41 -05:00
wayland/buffer: use G_UNLIKELY for error paths
We do a lot of if-checks in `MetaWaylandBuffer` to deal with unexpected situations (as we should). However, that means we get a branching penalty for every time this leads to a misprediction. Although these should in theory be mitigated by a proper branch predictor, it doesn't hurt giving some hints to make sure that we don't sacrifice our hot path. Especially given that in the case of video streams, the `meta_wayland_buffer_attach` is called for example 60 times per second.
This commit is contained in:
parent
9004253c4e
commit
16a2aaf860
@ -232,15 +232,15 @@ shm_buffer_attach (MetaWaylandBuffer *buffer,
|
|||||||
|
|
||||||
cogl_object_unref (bitmap);
|
cogl_object_unref (bitmap);
|
||||||
|
|
||||||
if (!cogl_texture_allocate (COGL_TEXTURE (texture), error))
|
if (G_UNLIKELY (!cogl_texture_allocate (COGL_TEXTURE (texture), error)))
|
||||||
g_clear_pointer (&texture, cogl_object_unref);
|
cogl_clear_object (&texture);
|
||||||
|
|
||||||
wl_shm_buffer_end_access (shm_buffer);
|
wl_shm_buffer_end_access (shm_buffer);
|
||||||
|
|
||||||
buffer->texture = texture;
|
buffer->texture = texture;
|
||||||
buffer->is_y_inverted = TRUE;
|
buffer->is_y_inverted = TRUE;
|
||||||
|
|
||||||
if (!buffer->texture)
|
if (G_UNLIKELY (!buffer->texture))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -259,23 +259,27 @@ egl_image_buffer_attach (MetaWaylandBuffer *buffer,
|
|||||||
CoglPixelFormat cogl_format;
|
CoglPixelFormat cogl_format;
|
||||||
EGLImageKHR egl_image;
|
EGLImageKHR egl_image;
|
||||||
CoglTexture2D *texture;
|
CoglTexture2D *texture;
|
||||||
|
gboolean res = FALSE;
|
||||||
|
|
||||||
if (buffer->texture)
|
if (buffer->texture)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
res = meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
||||||
EGL_TEXTURE_FORMAT, &format,
|
EGL_TEXTURE_FORMAT, &format,
|
||||||
error))
|
error);
|
||||||
|
if (G_UNLIKELY (!res))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
res = meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
||||||
EGL_WIDTH, &width,
|
EGL_WIDTH, &width,
|
||||||
error))
|
error);
|
||||||
|
if (G_UNLIKELY (!res))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
res = meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
||||||
EGL_HEIGHT, &height,
|
EGL_HEIGHT, &height,
|
||||||
error))
|
error);
|
||||||
|
if (G_UNLIKELY (!res))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
||||||
@ -304,7 +308,7 @@ egl_image_buffer_attach (MetaWaylandBuffer *buffer,
|
|||||||
EGL_WAYLAND_BUFFER_WL, buffer->resource,
|
EGL_WAYLAND_BUFFER_WL, buffer->resource,
|
||||||
NULL,
|
NULL,
|
||||||
error);
|
error);
|
||||||
if (egl_image == EGL_NO_IMAGE_KHR)
|
if (G_UNLIKELY (egl_image == EGL_NO_IMAGE_KHR))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
texture = cogl_egl_texture_2d_new_from_image (cogl_context,
|
texture = cogl_egl_texture_2d_new_from_image (cogl_context,
|
||||||
@ -315,7 +319,7 @@ egl_image_buffer_attach (MetaWaylandBuffer *buffer,
|
|||||||
|
|
||||||
meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
|
meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
|
||||||
|
|
||||||
if (!texture)
|
if (G_UNLIKELY (!texture))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
buffer->texture = COGL_TEXTURE (texture);
|
buffer->texture = COGL_TEXTURE (texture);
|
||||||
@ -346,7 +350,7 @@ meta_wayland_buffer_attach (MetaWaylandBuffer *buffer,
|
|||||||
{
|
{
|
||||||
g_return_val_if_fail (buffer->resource, FALSE);
|
g_return_val_if_fail (buffer->resource, FALSE);
|
||||||
|
|
||||||
if (!meta_wayland_buffer_is_realized (buffer))
|
if (G_UNLIKELY (!meta_wayland_buffer_is_realized (buffer)))
|
||||||
{
|
{
|
||||||
/* The buffer should have been realized at surface commit time */
|
/* The buffer should have been realized at surface commit time */
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
@ -426,18 +430,17 @@ process_shm_buffer_damage (MetaWaylandBuffer *buffer,
|
|||||||
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
||||||
cairo_region_get_rectangle (region, i, &rect);
|
cairo_region_get_rectangle (region, i, &rect);
|
||||||
|
|
||||||
if (!_cogl_texture_set_region (buffer->texture,
|
set_texture_failed =
|
||||||
rect.width, rect.height,
|
!_cogl_texture_set_region (buffer->texture,
|
||||||
format,
|
rect.width, rect.height,
|
||||||
stride,
|
format,
|
||||||
data + rect.x * bpp + rect.y * stride,
|
stride,
|
||||||
rect.x, rect.y,
|
data + rect.x * bpp + rect.y * stride,
|
||||||
0,
|
rect.x, rect.y,
|
||||||
error))
|
0,
|
||||||
{
|
error);
|
||||||
set_texture_failed = TRUE;
|
if (G_UNLIKELY (set_texture_failed))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_shm_buffer_end_access (shm_buffer);
|
wl_shm_buffer_end_access (shm_buffer);
|
||||||
@ -474,7 +477,7 @@ meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res)
|
if (G_UNLIKELY (!res))
|
||||||
{
|
{
|
||||||
g_warning ("Failed to process Wayland buffer damage: %s", error->message);
|
g_warning ("Failed to process Wayland buffer damage: %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
Loading…
Reference in New Issue
Block a user