Commit 35ca23f3 authored by Manuel Stoeckl's avatar Manuel Stoeckl
Browse files

Simplify interval logic with min/max/clamp fns

parent 67ba7e5c
......@@ -318,13 +318,22 @@ void request_wl_surface_commit(
struct damage_record *rec = surface->damage_stack;
while (rec) {
// TODO: take into account transformations
int low = buf->shm_offset + buf->shm_stride * rec->y +
rec->x;
int high = buf->shm_offset +
buf->shm_stride * (rec->y + rec->height) +
(rec->x + rec->width);
intv_max = intv_max > high ? intv_max : high;
intv_min = intv_min < low ? intv_min : low;
/* Clip the damage rectangle to the containing buffer.
*/
int xlow = clamp(rec->x, 0, buf->shm_width);
int xhigh = clamp(
rec->x + rec->width, 0, buf->shm_width);
int ylow = clamp(rec->y, 0, buf->shm_height);
int yhigh = clamp(rec->y + rec->height, 0,
buf->shm_height);
int low = buf->shm_offset + buf->shm_stride * ylow +
xlow;
int high = buf->shm_offset + buf->shm_stride * yhigh +
xhigh;
intv_max = max(intv_max, high);
intv_min = min(intv_min, low);
struct damage_record *nxt = rec->next;
free(rec);
......@@ -333,13 +342,9 @@ void request_wl_surface_commit(
surface->damage_stack = NULL;
sfd->dirty_interval_max =
intv_max > sfd->dirty_interval_max
? intv_max
: sfd->dirty_interval_max;
max(sfd->dirty_interval_max, intv_max);
sfd->dirty_interval_min =
intv_min < sfd->dirty_interval_min
? intv_min
: sfd->dirty_interval_min;
min(sfd->dirty_interval_min, intv_min);
}
}
static void request_wl_surface_destroy(
......
......@@ -1041,12 +1041,10 @@ void collect_updates(struct fd_translation_map *map, int *ntransfers,
}
// Clear dirty state
cur->is_dirty = false;
int intv_min = cur->dirty_interval_min > 0
? cur->dirty_interval_min
: 0;
int intv_max = cur->dirty_interval_max < (int)cur->file_size
? cur->dirty_interval_max
: (int)cur->file_size;
int intv_min = clamp(cur->dirty_interval_min, 0,
(int)cur->file_size);
int intv_max = clamp(cur->dirty_interval_max, 0,
(int)cur->file_size);
cur->dirty_interval_min = INT32_MAX;
cur->dirty_interval_max = INT32_MIN;
......@@ -1067,7 +1065,7 @@ void collect_updates(struct fd_translation_map *map, int *ntransfers,
transfers[nt].obj_id = cur->remote_id;
transfers[nt].special = 0;
}
if (intv_min == intv_max) {
if (intv_min >= intv_max) {
continue;
}
bool delta = memcmp(cur->file_mem_local + intv_min,
......
......@@ -36,6 +36,14 @@ extern bool shutdown_flag;
void handle_sigint(int sig);
/** Basic mathematical operations */
static inline int max(int a, int b) { return a > b ? a : b; }
static inline int min(int a, int b) { return a < b ? a : b; }
static inline int clamp(int v, int lower, int upper)
{
return max(min(v, upper), lower);
}
/** Set the given flag with fcntl. Silently return -1 on failure. */
int set_fnctl_flag(int fd, int the_flag);
/** Create a nonblocking AF_UNIX/SOCK_STREAM socket, and listen with
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment