mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	Merge pull request #1261 from arandomhuman/damage-control
Fix damage tracking for surfaces with transforms
This commit is contained in:
		
						commit
						d7b010024a
					
				
					 3 changed files with 73 additions and 67 deletions
				
			
		| 
						 | 
					@ -17,14 +17,14 @@
 | 
				
			||||||
#include <wlr/types/wlr_output.h>
 | 
					#include <wlr/types/wlr_output.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum wlr_surface_state_field {
 | 
					enum wlr_surface_state_field {
 | 
				
			||||||
	WLR_SURFACE_STATE_BUFFER = 1,
 | 
						WLR_SURFACE_STATE_BUFFER = 1 << 0,
 | 
				
			||||||
	WLR_SURFACE_STATE_SURFACE_DAMAGE = 2,
 | 
						WLR_SURFACE_STATE_SURFACE_DAMAGE = 1 << 1,
 | 
				
			||||||
	WLR_SURFACE_STATE_BUFFER_DAMAGE = 4,
 | 
						WLR_SURFACE_STATE_BUFFER_DAMAGE = 1 << 2,
 | 
				
			||||||
	WLR_SURFACE_STATE_OPAQUE_REGION = 8,
 | 
						WLR_SURFACE_STATE_OPAQUE_REGION = 1 << 3,
 | 
				
			||||||
	WLR_SURFACE_STATE_INPUT_REGION = 16,
 | 
						WLR_SURFACE_STATE_INPUT_REGION = 1 << 4,
 | 
				
			||||||
	WLR_SURFACE_STATE_TRANSFORM = 32,
 | 
						WLR_SURFACE_STATE_TRANSFORM = 1 << 5,
 | 
				
			||||||
	WLR_SURFACE_STATE_SCALE = 64,
 | 
						WLR_SURFACE_STATE_SCALE = 1 << 6,
 | 
				
			||||||
	WLR_SURFACE_STATE_FRAME_CALLBACK_LIST = 128,
 | 
						WLR_SURFACE_STATE_FRAME_CALLBACK_LIST = 1 << 7,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_surface_state {
 | 
					struct wlr_surface_state {
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ struct wlr_surface_state {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_resource *buffer_resource;
 | 
						struct wl_resource *buffer_resource;
 | 
				
			||||||
	int32_t dx, dy; // relative to previous position
 | 
						int32_t dx, dy; // relative to previous position
 | 
				
			||||||
	pixman_region32_t surface_damage, buffer_damage;
 | 
						pixman_region32_t surface_damage, buffer_damage; // clipped to bounds
 | 
				
			||||||
	pixman_region32_t opaque, input;
 | 
						pixman_region32_t opaque, input;
 | 
				
			||||||
	enum wl_output_transform transform;
 | 
						enum wl_output_transform transform;
 | 
				
			||||||
	int32_t scale;
 | 
						int32_t scale;
 | 
				
			||||||
| 
						 | 
					@ -68,11 +68,12 @@ struct wlr_surface {
 | 
				
			||||||
	 * The last commit's buffer damage, in buffer-local coordinates. This
 | 
						 * The last commit's buffer damage, in buffer-local coordinates. This
 | 
				
			||||||
	 * contains both the damage accumulated by the client via
 | 
						 * contains both the damage accumulated by the client via
 | 
				
			||||||
	 * `wlr_surface_state.surface_damage` and `wlr_surface_state.buffer_damage`.
 | 
						 * `wlr_surface_state.surface_damage` and `wlr_surface_state.buffer_damage`.
 | 
				
			||||||
	 * If the buffer has changed its size or moved, the whole buffer is
 | 
						 * If the buffer has been resized, the whole buffer is damaged.
 | 
				
			||||||
	 * damaged.
 | 
					 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * This region needs to be scaled and transformed into output coordinates,
 | 
						 * This region needs to be scaled and transformed into output coordinates,
 | 
				
			||||||
	 * just like the buffer's texture.
 | 
						 * just like the buffer's texture. In addition, if the buffer has shrunk the
 | 
				
			||||||
 | 
						 * old size needs to be damaged and if the buffer has moved the old and new
 | 
				
			||||||
 | 
						 * positions need to be damaged.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	pixman_region32_t buffer_damage;
 | 
						pixman_region32_t buffer_damage;
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -234,4 +235,12 @@ struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource);
 | 
				
			||||||
void wlr_surface_for_each_surface(struct wlr_surface *surface,
 | 
					void wlr_surface_for_each_surface(struct wlr_surface *surface,
 | 
				
			||||||
	wlr_surface_iterator_func_t iterator, void *user_data);
 | 
						wlr_surface_iterator_func_t iterator, void *user_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Get the effective damage to the surface in terms of surface local
 | 
				
			||||||
 | 
					 * coordinates. This includes damage induced by resizing and moving the
 | 
				
			||||||
 | 
					 * surface. The damage is not expected to be bounded by the surface itself.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void wlr_surface_get_effective_damage(struct wlr_surface *surface,
 | 
				
			||||||
 | 
						pixman_region32_t *damage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -708,16 +708,11 @@ static void damage_from_surface(struct wlr_surface *surface, int sx, int sy,
 | 
				
			||||||
	int center_x = box.x + box.width/2;
 | 
						int center_x = box.x + box.width/2;
 | 
				
			||||||
	int center_y = box.y + box.height/2;
 | 
						int center_y = box.y + box.height/2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum wl_output_transform transform =
 | 
					 | 
				
			||||||
		wlr_output_transform_invert(surface->current.transform);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pixman_region32_t damage;
 | 
						pixman_region32_t damage;
 | 
				
			||||||
	pixman_region32_init(&damage);
 | 
						pixman_region32_init(&damage);
 | 
				
			||||||
	pixman_region32_copy(&damage, &surface->buffer_damage);
 | 
						wlr_surface_get_effective_damage(surface, &damage);
 | 
				
			||||||
	wlr_region_transform(&damage, &damage, transform,
 | 
					
 | 
				
			||||||
		surface->current.buffer_width, surface->current.buffer_height);
 | 
						wlr_region_scale(&damage, &damage, wlr_output->scale);
 | 
				
			||||||
	wlr_region_scale(&damage, &damage,
 | 
					 | 
				
			||||||
		wlr_output->scale / (float)surface->current.scale);
 | 
					 | 
				
			||||||
	if (ceil(wlr_output->scale) > surface->current.scale) {
 | 
						if (ceil(wlr_output->scale) > surface->current.scale) {
 | 
				
			||||||
		// When scaling up a surface, it'll become blurry so we need to
 | 
							// When scaling up a surface, it'll become blurry so we need to
 | 
				
			||||||
		// expand the damage region
 | 
							// expand the damage region
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@
 | 
				
			||||||
#include <wlr/types/wlr_matrix.h>
 | 
					#include <wlr/types/wlr_matrix.h>
 | 
				
			||||||
#include <wlr/types/wlr_region.h>
 | 
					#include <wlr/types/wlr_region.h>
 | 
				
			||||||
#include <wlr/types/wlr_surface.h>
 | 
					#include <wlr/types/wlr_surface.h>
 | 
				
			||||||
 | 
					#include <wlr/types/wlr_output.h>
 | 
				
			||||||
#include <wlr/util/log.h>
 | 
					#include <wlr/util/log.h>
 | 
				
			||||||
#include <wlr/util/region.h>
 | 
					#include <wlr/util/region.h>
 | 
				
			||||||
#include "util/signal.h"
 | 
					#include "util/signal.h"
 | 
				
			||||||
| 
						 | 
					@ -167,38 +168,28 @@ static void surface_state_finalize(struct wlr_surface *surface,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void surface_update_damage(pixman_region32_t *buffer_damage,
 | 
					static void surface_update_damage(pixman_region32_t *buffer_damage,
 | 
				
			||||||
		struct wlr_surface_state *previous, struct wlr_surface_state *current) {
 | 
							struct wlr_surface_state *current, struct wlr_surface_state *pending) {
 | 
				
			||||||
	pixman_region32_clear(buffer_damage);
 | 
						pixman_region32_clear(buffer_damage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (current->buffer_width != previous->buffer_width ||
 | 
						if (pending->width != current->width ||
 | 
				
			||||||
			current->buffer_height != previous->buffer_height ||
 | 
								pending->height != current->height) {
 | 
				
			||||||
			current->dx != 0 || current->dy != 0) {
 | 
							// Damage the whole buffer on resize
 | 
				
			||||||
		// Damage the whole surface on resize or move
 | 
					 | 
				
			||||||
		int prev_x = -current->dx;
 | 
					 | 
				
			||||||
		int prev_y = -current->dy;
 | 
					 | 
				
			||||||
		if ((previous->transform & WL_OUTPUT_TRANSFORM_90) != 0) {
 | 
					 | 
				
			||||||
			int tmp = prev_x;
 | 
					 | 
				
			||||||
			prev_x = prev_y;
 | 
					 | 
				
			||||||
			prev_y = tmp;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pixman_region32_union_rect(buffer_damage, buffer_damage,
 | 
					 | 
				
			||||||
			prev_x * previous->scale, prev_y * previous->scale,
 | 
					 | 
				
			||||||
			previous->buffer_width, previous->buffer_height);
 | 
					 | 
				
			||||||
		pixman_region32_union_rect(buffer_damage, buffer_damage, 0, 0,
 | 
							pixman_region32_union_rect(buffer_damage, buffer_damage, 0, 0,
 | 
				
			||||||
			current->buffer_width, current->buffer_height);
 | 
								pending->buffer_width, pending->buffer_height);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// Copy over surface damage + buffer damage
 | 
							// Copy over surface damage + buffer damage
 | 
				
			||||||
		pixman_region32_union(buffer_damage, buffer_damage,
 | 
					 | 
				
			||||||
			¤t->buffer_damage);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pixman_region32_t surface_damage;
 | 
							pixman_region32_t surface_damage;
 | 
				
			||||||
		pixman_region32_init(&surface_damage);
 | 
							pixman_region32_init(&surface_damage);
 | 
				
			||||||
		pixman_region32_copy(&surface_damage, ¤t->surface_damage);
 | 
					
 | 
				
			||||||
 | 
							pixman_region32_copy(&surface_damage, &pending->surface_damage);
 | 
				
			||||||
		wlr_region_transform(&surface_damage, &surface_damage,
 | 
							wlr_region_transform(&surface_damage, &surface_damage,
 | 
				
			||||||
			current->transform, current->buffer_width, current->buffer_height);
 | 
								wlr_output_transform_invert(pending->transform),
 | 
				
			||||||
		wlr_region_scale(&surface_damage, &surface_damage, current->scale);
 | 
								pending->width, pending->height);
 | 
				
			||||||
		pixman_region32_union(buffer_damage, buffer_damage, &surface_damage);
 | 
							wlr_region_scale(&surface_damage, &surface_damage, pending->scale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							pixman_region32_union(buffer_damage,
 | 
				
			||||||
 | 
								&pending->buffer_damage, &surface_damage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pixman_region32_fini(&surface_damage);
 | 
							pixman_region32_fini(&surface_damage);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -297,29 +288,8 @@ static void surface_apply_damage(struct wlr_surface *surface) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (surface->buffer != NULL && surface->buffer->released) {
 | 
						if (surface->buffer != NULL && surface->buffer->released) {
 | 
				
			||||||
		pixman_region32_t damage;
 | 
							struct wlr_buffer *updated_buffer = wlr_buffer_apply_damage(
 | 
				
			||||||
		pixman_region32_init(&damage);
 | 
								surface->buffer, resource, &surface->buffer_damage);
 | 
				
			||||||
		pixman_region32_copy(&damage, &surface->current.buffer_damage);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pixman_region32_t surface_damage;
 | 
					 | 
				
			||||||
		pixman_region32_init(&surface_damage);
 | 
					 | 
				
			||||||
		pixman_region32_copy(&surface_damage, &surface->current.surface_damage);
 | 
					 | 
				
			||||||
		wlr_region_transform(&surface_damage, &surface_damage,
 | 
					 | 
				
			||||||
			surface->current.transform,
 | 
					 | 
				
			||||||
			surface->current.buffer_width, surface->current.buffer_height);
 | 
					 | 
				
			||||||
		wlr_region_scale(&surface_damage, &surface_damage,
 | 
					 | 
				
			||||||
			surface->current.scale);
 | 
					 | 
				
			||||||
		pixman_region32_union(&damage, &damage, &surface_damage);
 | 
					 | 
				
			||||||
		pixman_region32_fini(&surface_damage);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pixman_region32_intersect_rect(&damage, &damage, 0, 0,
 | 
					 | 
				
			||||||
			surface->current.buffer_width, surface->current.buffer_height);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		struct wlr_buffer *updated_buffer =
 | 
					 | 
				
			||||||
			wlr_buffer_apply_damage(surface->buffer, resource, &damage);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pixman_region32_fini(&damage);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (updated_buffer != NULL) {
 | 
							if (updated_buffer != NULL) {
 | 
				
			||||||
			surface->buffer = updated_buffer;
 | 
								surface->buffer = updated_buffer;
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
| 
						 | 
					@ -1055,3 +1025,35 @@ void wlr_surface_get_extends(struct wlr_surface *surface, struct wlr_box *box) {
 | 
				
			||||||
	box->width = acc.max_x - acc.min_x;
 | 
						box->width = acc.max_x - acc.min_x;
 | 
				
			||||||
	box->height = acc.max_y - acc.min_y;
 | 
						box->height = acc.max_y - acc.min_y;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wlr_surface_get_effective_damage(struct wlr_surface *surface,
 | 
				
			||||||
 | 
							pixman_region32_t *damage) {
 | 
				
			||||||
 | 
						pixman_region32_clear(damage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Transform and copy the buffer damage in terms of surface coordinates.
 | 
				
			||||||
 | 
						wlr_region_transform(damage, &surface->buffer_damage,
 | 
				
			||||||
 | 
							surface->current.transform, surface->current.buffer_width,
 | 
				
			||||||
 | 
							surface->current.buffer_height);
 | 
				
			||||||
 | 
						wlr_region_scale(damage, damage, 1.0 / (float)surface->current.scale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// On resize, damage the previous bounds of the surface. The current bounds
 | 
				
			||||||
 | 
						// have already been damaged in surface_update_damage.
 | 
				
			||||||
 | 
						if (surface->previous.width > surface->current.width ||
 | 
				
			||||||
 | 
								surface->previous.height > surface->current.height) {
 | 
				
			||||||
 | 
							pixman_region32_union_rect(damage, damage, 0, 0,
 | 
				
			||||||
 | 
								surface->previous.width, surface->previous.height);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// On move, damage where the surface was with its old dimensions.
 | 
				
			||||||
 | 
						if (surface->current.dx != 0 || surface->current.dy != 0) {
 | 
				
			||||||
 | 
							int prev_x = -surface->current.dx;
 | 
				
			||||||
 | 
							int prev_y = -surface->current.dy;
 | 
				
			||||||
 | 
							if ((surface->previous.transform & WL_OUTPUT_TRANSFORM_90) != 0) {
 | 
				
			||||||
 | 
								int temp = prev_x;
 | 
				
			||||||
 | 
								prev_x = prev_y;
 | 
				
			||||||
 | 
								prev_y = temp;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							pixman_region32_union_rect(damage, damage, prev_x, prev_y,
 | 
				
			||||||
 | 
								surface->previous.width, surface->previous.height);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue