wayland/surface: Do not uncoditionally process surface damage

Most clients nowadays switched to buffer damage, most notably Mesa
and Xwayland. Thus lets avoid the extra cost of allocating three
`cairo_region_t`s and doing some calculations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2168>
This commit is contained in:
Robert Mader 2021-12-18 22:00:41 +01:00 committed by Marge Bot
parent c166811695
commit c498ae337f

View File

@ -323,12 +323,7 @@ surface_process_damage (MetaWaylandSurface *surface,
cairo_region_t *buffer_region) cairo_region_t *buffer_region)
{ {
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
cairo_rectangle_int_t surface_rect;
cairo_rectangle_int_t buffer_rect; cairo_rectangle_int_t buffer_rect;
cairo_region_t *scaled_region;
cairo_region_t *transformed_region;
cairo_region_t *viewport_region;
graphene_rect_t src_rect;
MetaSurfaceActor *actor; MetaSurfaceActor *actor;
/* If the client destroyed the buffer it attached before committing, but /* If the client destroyed the buffer it attached before committing, but
@ -343,9 +338,17 @@ surface_process_damage (MetaWaylandSurface *surface,
.height = get_buffer_height (surface), .height = get_buffer_height (surface),
}; };
if (!cairo_region_is_empty (surface_region))
{
cairo_rectangle_int_t surface_rect;
cairo_region_t *scaled_region;
cairo_region_t *transformed_region;
cairo_region_t *viewport_region;
graphene_rect_t src_rect;
/* Intersect the damage region with the surface region before scaling in /* Intersect the damage region with the surface region before scaling in
* order to avoid integer overflow when scaling a damage region is too large * order to avoid integer overflow when scaling a damage region is too
* (for example INT32_MAX which mesa passes). */ * large (for example INT32_MAX which mesa passes). */
surface_rect = (cairo_rectangle_int_t) { surface_rect = (cairo_rectangle_int_t) {
.width = meta_wayland_surface_get_width (surface), .width = meta_wayland_surface_get_width (surface),
.height = meta_wayland_surface_get_height (surface), .height = meta_wayland_surface_get_height (surface),
@ -394,9 +397,15 @@ surface_process_damage (MetaWaylandSurface *surface,
buffer_rect.height); buffer_rect.height);
/* Now add the scaled, cropped and transformed damage region to the /* Now add the scaled, cropped and transformed damage region to the
* buffer damage. Buffer damage is already in the correct coordinate space. */ * buffer damage. Buffer damage is already in the correct coordinate
* space. */
cairo_region_union (buffer_region, transformed_region); cairo_region_union (buffer_region, transformed_region);
cairo_region_destroy (viewport_region);
cairo_region_destroy (scaled_region);
cairo_region_destroy (transformed_region);
}
cairo_region_intersect_rectangle (buffer_region, &buffer_rect); cairo_region_intersect_rectangle (buffer_region, &buffer_rect);
meta_wayland_buffer_process_damage (buffer, surface->texture, buffer_region); meta_wayland_buffer_process_damage (buffer, surface->texture, buffer_region);
@ -417,10 +426,6 @@ surface_process_damage (MetaWaylandSurface *surface,
rect.width, rect.height); rect.width, rect.height);
} }
} }
cairo_region_destroy (viewport_region);
cairo_region_destroy (scaled_region);
cairo_region_destroy (transformed_region);
} }
MetaWaylandBuffer * MetaWaylandBuffer *