Add wl_list_for_each() and simplify some loops

dev
Kristian Høgsberg 15 years ago
parent d923e9d93b
commit a5db589efa
  1. 31
      wayland-client.c
  2. 77
      wayland-system-compositor.c
  3. 9
      wayland-util.h
  4. 22
      wayland.c

@ -152,16 +152,10 @@ wl_display_add_global_listener(struct wl_display *display,
/* FIXME: Need a destructor for void *data? */ /* FIXME: Need a destructor for void *data? */
global = container_of(display->global_list.next, wl_list_for_each(global, &display->global_list, link)
struct wl_global, link);
while (&global->link != &display->global_list) {
if (global->proxy != NULL) if (global->proxy != NULL)
(*handler)(display, &global->proxy->base, data); (*handler)(display, &global->proxy->base, data);
global = container_of(global->link.next,
struct wl_global, link);
}
return listener; return listener;
} }
@ -192,13 +186,8 @@ wl_proxy_create_for_global(struct wl_display *display,
wl_list_init(&proxy->listener_list); wl_list_init(&proxy->listener_list);
wl_hash_insert(display->objects, &proxy->base); wl_hash_insert(display->objects, &proxy->base);
listener = container_of(display->global_listener_list.next, wl_list_for_each(listener, &display->global_listener_list, link)
struct wl_global_listener, link);
while (&listener->link != &display->global_listener_list) {
(*listener->handler)(display, &proxy->base, listener->data); (*listener->handler)(display, &proxy->base, listener->data);
listener = container_of(listener->link.next,
struct wl_global_listener, link);
}
return proxy; return proxy;
} }
@ -427,17 +416,11 @@ wl_display_get_object_id(struct wl_display *display,
{ {
struct wl_global *global; struct wl_global *global;
global = container_of(display->global_list.next, wl_list_for_each(global, &display->global_list, link)
struct wl_global, link);
while (&global->link != &display->global_list) {
if (strcmp(global->interface, interface) == 0 && if (strcmp(global->interface, interface) == 0 &&
global->version >= version) global->version >= version)
return global->id; return global->id;
global = container_of(global->link.next,
struct wl_global, link);
}
return 0; return 0;
} }
@ -473,10 +456,7 @@ handle_event(struct wl_display *display,
id, opcode); id, opcode);
} }
listener = container_of(proxy->listener_list.next, wl_list_for_each(listener, &proxy->listener_list, link)
struct wl_listener, link);
while (&listener->link != &proxy->listener_list) {
wl_connection_demarshal(display->connection, wl_connection_demarshal(display->connection,
size, size,
display->objects, display->objects,
@ -485,9 +465,6 @@ handle_event(struct wl_display *display,
&proxy->base, &proxy->base,
&proxy->base.interface->events[opcode]); &proxy->base.interface->events[opcode]);
listener = container_of(listener->link.next,
struct wl_listener, link);
}
} }
wl_connection_consume(display->connection, size); wl_connection_consume(display->connection, size);

@ -133,7 +133,6 @@ struct wlsc_compositor {
struct wl_event_source *drm_source; struct wl_event_source *drm_source;
uint32_t modifier_state; uint32_t modifier_state;
struct wl_list animate_list;
}; };
#define MODIFIER_CTRL (1 << 8) #define MODIFIER_CTRL (1 << 8)
@ -143,13 +142,6 @@ struct wlsc_vector {
GLdouble x, y, z; GLdouble x, y, z;
}; };
struct wlsc_animate {
struct wl_list link;
void (*animate)(struct wlsc_animate *animate,
struct wlsc_compositor *compositor,
uint32_t frame, uint32_t msecs);
};
struct wlsc_surface { struct wlsc_surface {
struct wl_surface base; struct wl_surface base;
struct wlsc_compositor *compositor; struct wlsc_compositor *compositor;
@ -193,8 +185,7 @@ screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter)
int i, j; int i, j;
i = 0; i = 0;
output = container_of(ec->output_list.next, struct wlsc_output, link); wl_list_for_each(output, &ec->output_list, link) {
while (&output->link != &ec->output_list) {
snprintf(buffer, sizeof buffer, "wayland-screenshot-%d.png", i++); snprintf(buffer, sizeof buffer, "wayland-screenshot-%d.png", i++);
data = malloc(output->width * output->height * 4); data = malloc(output->width * output->height * 4);
if (data == NULL) { if (data == NULL) {
@ -219,9 +210,6 @@ screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter)
gdk_pixbuf_unref(normal); gdk_pixbuf_unref(normal);
gdk_pixbuf_unref(pixbuf); gdk_pixbuf_unref(pixbuf);
free(data); free(data);
output = container_of(output->link.next,
struct wlsc_output, link);
} }
} }
@ -368,19 +356,14 @@ static void
wlsc_surface_destroy(struct wlsc_surface *surface, wlsc_surface_destroy(struct wlsc_surface *surface,
struct wlsc_compositor *compositor) struct wlsc_compositor *compositor)
{ {
struct wlsc_listener *l, *next; struct wlsc_listener *l;
wl_list_remove(&surface->link); wl_list_remove(&surface->link);
glDeleteTextures(1, &surface->texture); glDeleteTextures(1, &surface->texture);
wl_client_remove_surface(surface->base.client, &surface->base); wl_client_remove_surface(surface->base.client, &surface->base);
l = container_of(compositor->surface_destroy_listener_list.next, wl_list_for_each(l, &compositor->surface_destroy_listener_list, link)
struct wlsc_listener, link);
while (&l->link != &compositor->surface_destroy_listener_list) {
next = container_of(l->link.next, struct wlsc_listener, link);
l->func(l, surface); l->func(l, surface);
l = next;
}
free(surface); free(surface);
} }
@ -578,7 +561,6 @@ page_flip_handler(int fd, unsigned int frame,
unsigned int sec, unsigned int usec, void *data) unsigned int sec, unsigned int usec, void *data)
{ {
struct wlsc_output *output = data; struct wlsc_output *output = data;
struct wlsc_animate *animate, *next;
struct wlsc_compositor *compositor = output->compositor; struct wlsc_compositor *compositor = output->compositor;
uint32_t msecs; uint32_t msecs;
@ -590,14 +572,6 @@ page_flip_handler(int fd, unsigned int frame,
wl_event_source_timer_update(compositor->timer_source, 5); wl_event_source_timer_update(compositor->timer_source, 5);
compositor->repaint_on_timeout = 1; compositor->repaint_on_timeout = 1;
animate = container_of(compositor->animate_list.next, struct wlsc_animate, link);
while (&animate->link != &compositor->animate_list) {
next = container_of(animate->link.next,
struct wlsc_animate, link);
animate->animate(animate, compositor, compositor->current_frame, msecs);
animate = next;
}
compositor->current_frame++; compositor->current_frame++;
} }
@ -626,23 +600,12 @@ repaint_output(struct wlsc_output *output)
else else
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
es = container_of(ec->surface_list.next, wl_list_for_each(es, &ec->surface_list, link)
struct wlsc_surface, link);
while (&es->link != &ec->surface_list) {
wlsc_surface_draw(es); wlsc_surface_draw(es);
es = container_of(es->link.next,
struct wlsc_surface, link);
}
eid = container_of(ec->input_device_list.next, wl_list_for_each(eid, &ec->input_device_list, link)
struct wlsc_input_device, link);
while (&eid->link != &ec->input_device_list) {
wlsc_surface_draw(eid->sprite); wlsc_surface_draw(eid->sprite);
eid = container_of(eid->link.next,
struct wlsc_input_device, link);
}
fd = eglGetDisplayFD(ec->display); fd = eglGetDisplayFD(ec->display);
output->current ^= 1; output->current ^= 1;
@ -666,12 +629,8 @@ repaint(void *data)
return; return;
} }
output = container_of(ec->output_list.next, struct wlsc_output, link); wl_list_for_each(output, &ec->output_list, link)
while (&output->link != &ec->output_list) {
repaint_output(output); repaint_output(output);
output = container_of(output->link.next,
struct wlsc_output, link);
}
ec->repaint_needed = 0; ec->repaint_needed = 0;
} }
@ -687,15 +646,10 @@ wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor)
return; return;
fd = eglGetDisplayFD(compositor->display); fd = eglGetDisplayFD(compositor->display);
output = container_of(compositor->output_list.next, wl_list_for_each(output, &compositor->output_list, link)
struct wlsc_output, link);
while (&output->link != &compositor->output_list) {
drmModePageFlip(fd, output->crtc_id, drmModePageFlip(fd, output->crtc_id,
output->fb_id[output->current ^ 1], output->fb_id[output->current ^ 1],
DRM_MODE_PAGE_FLIP_EVENT, output); DRM_MODE_PAGE_FLIP_EVENT, output);
output = container_of(output->link.next,
struct wlsc_output, link);
}
} }
static void static void
@ -876,9 +830,7 @@ pick_surface(struct wlsc_input_device *device, int32_t *sx, int32_t *sy)
return device->grab_surface; return device->grab_surface;
} }
es = container_of(ec->surface_list.prev, wl_list_for_each(es, &ec->surface_list, link)
struct wlsc_surface, link);
while (&es->link != &ec->surface_list) {
if (es->map.x <= device->x && if (es->map.x <= device->x &&
device->x < es->map.x + es->map.width && device->x < es->map.x + es->map.width &&
es->map.y <= device->y && es->map.y <= device->y &&
@ -887,11 +839,6 @@ pick_surface(struct wlsc_input_device *device, int32_t *sx, int32_t *sy)
return es; return es;
} }
es = container_of(es->link.prev,
struct wlsc_surface, link);
}
return NULL; return NULL;
} }
@ -1333,17 +1280,13 @@ static void on_enter_vt(int signal_number, void *data)
ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ); ioctl(ec->tty_fd, VT_RELDISP, VT_ACKACQ);
ec->vt_active = TRUE; ec->vt_active = TRUE;
output = container_of(ec->output_list.next, struct wlsc_output, link); wl_list_for_each(output, &ec->output_list, link) {
while (&output->link != &ec->output_list) {
ret = drmModeSetCrtc(fd, output->crtc_id, ret = drmModeSetCrtc(fd, output->crtc_id,
output->fb_id[output->current ^ 1], 0, 0, output->fb_id[output->current ^ 1], 0, 0,
&output->connector_id, 1, &output->mode); &output->connector_id, 1, &output->mode);
if (ret) if (ret)
fprintf(stderr, "failed to set mode for connector %d: %m\n", fprintf(stderr, "failed to set mode for connector %d: %m\n",
output->connector_id); output->connector_id);
output = container_of(output->link.next,
struct wlsc_output, link);
} }
} }
@ -1524,8 +1467,6 @@ wlsc_compositor_create(struct wl_display *display)
ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec); ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec);
wlsc_compositor_schedule_repaint(ec); wlsc_compositor_schedule_repaint(ec);
wl_list_init(&ec->animate_list);
return ec; return ec;
} }

@ -82,6 +82,15 @@ void wl_list_remove(struct wl_list *elm);
int wl_list_length(struct wl_list *list); int wl_list_length(struct wl_list *list);
int wl_list_empty(struct wl_list *list); int wl_list_empty(struct wl_list *list);
#define __container_of(ptr, sample, member) \
(void *)((char *)(ptr) - \
((char *)&(sample)->member - (char *)(sample)))
#define wl_list_for_each(pos, head, member) \
for (pos = __container_of((head)->next, pos, member); \
&pos->member != (head); \
pos = __container_of(pos->member.next, pos, member))
struct wl_array { struct wl_array {
uint32_t size; uint32_t size;
uint32_t alloc; uint32_t alloc;

@ -186,26 +186,16 @@ wl_client_create(struct wl_display *display, int fd)
wl_display_post_range(display, client); wl_display_post_range(display, client);
global = container_of(display->global_list.next, wl_list_for_each(global, &display->global_list, link)
struct wl_global, link);
while (&global->link != &display->global_list) {
wl_client_post_event(client, &client->display->base, wl_client_post_event(client, &client->display->base,
WL_DISPLAY_GLOBAL, WL_DISPLAY_GLOBAL,
global->object, global->object,
global->object->interface->name, global->object->interface->name,
global->object->interface->version); global->object->interface->version);
global = container_of(global->link.next,
struct wl_global, link);
}
global = container_of(display->global_list.next, wl_list_for_each(global, &display->global_list, link)
struct wl_global, link);
while (&global->link != &display->global_list) {
if (global->func) if (global->func)
global->func(client, global->object); global->func(client, global->object);
global = container_of(global->link.next,
struct wl_global, link);
}
return client; return client;
} }
@ -384,15 +374,9 @@ wl_display_post_frame(struct wl_display *display,
{ {
struct wl_client *client; struct wl_client *client;
client = container_of(display->pending_frame_list.next, wl_list_for_each(client, &display->pending_frame_list, link)
struct wl_client, link);
while (&client->link != &display->pending_frame_list) {
wl_client_post_event(client, &compositor->base, wl_client_post_event(client, &compositor->base,
WL_COMPOSITOR_FRAME, frame, msecs); WL_COMPOSITOR_FRAME, frame, msecs);
client = container_of(client->link.next,
struct wl_client, link);
}
wl_list_remove(&display->pending_frame_list); wl_list_remove(&display->pending_frame_list);
wl_list_init(&display->pending_frame_list); wl_list_init(&display->pending_frame_list);

Loading…
Cancel
Save