diff options
Diffstat (limited to 'src/wayland/buffer.c')
| -rw-r--r-- | src/wayland/buffer.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/wayland/buffer.c b/src/wayland/buffer.c index 9776f13..76f6c0e 100644 --- a/src/wayland/buffer.c +++ b/src/wayland/buffer.c @@ -305,13 +305,19 @@ static void arm_frame(struct wayland_surface *w) } } +static const int8_t free_buf_lut[4][8] = { + [0] = { 1, 1, 2, 2, 1, 1, 0, -1 }, + [1] = { 0, 2, 0, 2, 0, 1, 0, -1 }, + [2] = { 0, 1, 0, 2, 0, 1, 0, -1 }, + [3] = { 0, 1, 0, 2, 0, 1, 0, -1 }, +}; + int buffer_pick_free_index(const struct buffer *bufs, int cur) { - if (!bufs[cur ^ 1].busy) return cur ^ 1; - for (int i = 0; i < NBUF; i++) - if (i != cur && i != (cur ^ 1) && !bufs[i].busy) return i; - if (!bufs[cur].busy) return cur; - return -1; + unsigned busy = ((unsigned)bufs[0].busy) | + (((unsigned)bufs[1].busy) << 1) | + (((unsigned)bufs[2].busy) << 2); + return free_buf_lut[(unsigned)cur & 3][busy]; } struct latency_feedback { @@ -523,14 +529,12 @@ void wayland_surface_set_title(struct wayland_surface *w, const char *title) uint32_t wayland_surface_state(const struct wayland_surface *w) { - if (!w) return 0; - uint32_t s = 0; - if (w->fullscreen) s |= YASL_STATE_FULLSCREEN; - if (w->maximized) s |= YASL_STATE_MAXIMIZED; - if (w->activated) s |= YASL_STATE_ACTIVATED; - if (w->suspended) s |= YASL_STATE_SUSPENDED; - if (!w->server_decorated) s |= YASL_STATE_CSD; - return s; + if (unlikely(!w)) return 0; + return ((uint32_t)w->fullscreen * YASL_STATE_FULLSCREEN) | + ((uint32_t)w->maximized * YASL_STATE_MAXIMIZED) | + ((uint32_t)w->activated * YASL_STATE_ACTIVATED) | + ((uint32_t)w->suspended * YASL_STATE_SUSPENDED) | + ((uint32_t)!w->server_decorated * YASL_STATE_CSD); } struct yasl_timing wayland_surface_timing(const struct wayland_surface *w) |
