Recomposite screen in idle handler.
This commit is contained in:
parent
f921289954
commit
5ebb317383
6
client.c
6
client.c
|
@ -141,11 +141,11 @@ int main(int argc, char *argv[])
|
|||
cairo_image_surface_get_stride(s));
|
||||
|
||||
i = 0;
|
||||
while (ret = poll(p, 1, 200), ret >= 0) {
|
||||
while (ret = poll(p, 1, 20), ret >= 0) {
|
||||
if (ret == 0) {
|
||||
wl_surface_map(surface,
|
||||
x + cos(i / 10.0) * 150,
|
||||
y + sin(i / 10.0) * 150,
|
||||
x + cos(i / 10.0) * 200,
|
||||
y + sin(i / 11.0) * 200,
|
||||
width, height);
|
||||
i++;
|
||||
continue;
|
||||
|
|
|
@ -137,8 +137,9 @@ void notify_surface_attach(struct wl_compositor *compositor,
|
|||
}
|
||||
|
||||
static void
|
||||
repaint(struct egl_compositor *ec)
|
||||
repaint(void *data)
|
||||
{
|
||||
struct egl_compositor *ec = data;
|
||||
struct wl_surface_iterator *iterator;
|
||||
struct wl_surface *surface;
|
||||
struct surface_data *sd;
|
||||
|
@ -197,13 +198,16 @@ void notify_surface_map(struct wl_compositor *compositor,
|
|||
{
|
||||
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
||||
struct surface_data *sd;
|
||||
struct wl_event_loop *loop;
|
||||
|
||||
sd = wl_surface_get_data(surface);
|
||||
if (sd == NULL)
|
||||
return;
|
||||
|
||||
sd->map = *map;
|
||||
repaint(ec);
|
||||
|
||||
loop = wl_display_get_event_loop(ec->wl_display);
|
||||
wl_event_loop_add_idle(loop, repaint, ec);
|
||||
}
|
||||
|
||||
struct wl_compositor_interface interface = {
|
||||
|
|
46
event-loop.c
46
event-loop.c
|
@ -11,18 +11,20 @@
|
|||
|
||||
struct wl_event_loop {
|
||||
int epoll_fd;
|
||||
wl_event_loop_idle_func_t idle_func;
|
||||
void *idle_data;
|
||||
};
|
||||
|
||||
struct wl_event_source {
|
||||
int fd;
|
||||
wl_event_loop_func_t func;
|
||||
wl_event_loop_fd_func_t func;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wl_event_source *
|
||||
wl_event_loop_add_fd(struct wl_event_loop *loop,
|
||||
int fd, uint32_t mask,
|
||||
wl_event_loop_func_t func,
|
||||
wl_event_loop_fd_func_t func,
|
||||
void *data)
|
||||
{
|
||||
struct wl_event_source *source;
|
||||
|
@ -48,16 +50,23 @@ wl_event_loop_add_fd(struct wl_event_loop *loop,
|
|||
return source;
|
||||
}
|
||||
|
||||
struct wl_event_source idle_source;
|
||||
|
||||
int
|
||||
wl_event_loop_remove_source(struct wl_event_loop *loop,
|
||||
struct wl_event_source *source)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = source->fd;
|
||||
free(source);
|
||||
|
||||
return epoll_ctl(loop->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
||||
if (source == &idle_source) {
|
||||
loop->idle_func = NULL;
|
||||
return 0;
|
||||
} else {
|
||||
fd = source->fd;
|
||||
free(source);
|
||||
return epoll_ctl(loop->epoll_fd,
|
||||
EPOLL_CTL_DEL, fd, NULL);
|
||||
};
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -103,6 +112,17 @@ wl_event_loop_destroy(struct wl_event_loop *loop)
|
|||
free(loop);
|
||||
}
|
||||
|
||||
struct wl_event_source *
|
||||
wl_event_loop_add_idle(struct wl_event_loop *loop,
|
||||
wl_event_loop_idle_func_t func,
|
||||
void *data)
|
||||
{
|
||||
loop->idle_func = func;
|
||||
loop->idle_data = data;
|
||||
|
||||
return &idle_source;
|
||||
}
|
||||
|
||||
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
||||
|
||||
int
|
||||
|
@ -110,10 +130,15 @@ wl_event_loop_wait(struct wl_event_loop *loop)
|
|||
{
|
||||
struct epoll_event ep[32];
|
||||
struct wl_event_source *source;
|
||||
int i, count;
|
||||
int i, count, timeout;
|
||||
uint32_t mask;
|
||||
|
||||
count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), -1);
|
||||
if (loop->idle_func)
|
||||
timeout = 0;
|
||||
else
|
||||
timeout = -1;
|
||||
|
||||
count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout);
|
||||
if (count < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -128,5 +153,10 @@ wl_event_loop_wait(struct wl_event_loop *loop)
|
|||
source->func(source->fd, mask, source->data);
|
||||
}
|
||||
|
||||
if (count == 0 && loop->idle_func != NULL) {
|
||||
loop->idle_func(loop->idle_data);
|
||||
loop->idle_func = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -469,6 +469,12 @@ wl_display_set_compositor(struct wl_display *display,
|
|||
display->compositor = compositor;
|
||||
}
|
||||
|
||||
struct wl_event_loop *
|
||||
wl_display_get_event_loop(struct wl_display *display)
|
||||
{
|
||||
return display->loop;
|
||||
}
|
||||
|
||||
void
|
||||
wl_display_run(struct wl_display *display)
|
||||
{
|
||||
|
|
10
wayland.h
10
wayland.h
|
@ -10,13 +10,14 @@ enum {
|
|||
|
||||
struct wl_event_loop;
|
||||
struct wl_event_source;
|
||||
typedef void (*wl_event_loop_func_t)(int fd, uint32_t mask, void *data);
|
||||
typedef void (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
|
||||
typedef void (*wl_event_loop_idle_func_t)(void *data);
|
||||
|
||||
struct wl_event_loop *wl_event_loop_create(void);
|
||||
void wl_event_loop_destroy(struct wl_event_loop *loop);
|
||||
struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *loop,
|
||||
int fd, uint32_t mask,
|
||||
wl_event_loop_func_t func,
|
||||
wl_event_loop_fd_func_t func,
|
||||
void *data);
|
||||
int wl_event_loop_update_source(struct wl_event_loop *loop,
|
||||
struct wl_event_source *source,
|
||||
|
@ -25,6 +26,9 @@ int wl_event_loop_update_source(struct wl_event_loop *loop,
|
|||
int wl_event_loop_remove_source(struct wl_event_loop *loop,
|
||||
struct wl_event_source *source);
|
||||
int wl_event_loop_wait(struct wl_event_loop *loop);
|
||||
struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop,
|
||||
wl_event_loop_idle_func_t func,
|
||||
void *data);
|
||||
|
||||
struct wl_hash {
|
||||
struct wl_object **objects;
|
||||
|
@ -81,6 +85,8 @@ struct wl_map {
|
|||
int32_t x, y, width, height;
|
||||
};
|
||||
|
||||
struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
|
||||
|
||||
void wl_surface_set_data(struct wl_surface *surface, void *data);
|
||||
void *wl_surface_get_data(struct wl_surface *surface);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user