swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 682473bd7dc97c72031c5264637783fccd243d45
parent 7cde7c2fce350b32e1fb662405a41fdc49e0d56d
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 23 Dec 2013 14:59:13 -0800

Move surface state into compositor view

Now, each composited surface has its own view.

Diffstat:
Mlibswc/compositor.c | 194++++++++++++++++++++++++++++++++++++-------------------------------------------
Mlibswc/compositor.h | 7+++++--
Mlibswc/surface.c | 8--------
Mlibswc/view.h | 3---
Mlibswc/window.c | 2+-
5 files changed, 95 insertions(+), 119 deletions(-)

diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -19,8 +19,9 @@ #include <wld/drm.h> #include <xkbcommon/xkbcommon-keysyms.h> -struct surface_state +struct view { + struct swc_view base; struct swc_compositor * compositor; /* The box that the surface covers (including it's border). */ @@ -39,7 +40,7 @@ struct surface_state bool mapped; - struct wl_listener event_listener; + struct wl_listener surface_event_listener; }; /* Rendering {{{ */ @@ -115,7 +116,7 @@ static void repaint_surface(struct render_target * target, pixman_region32_t border_damage; pixman_region32_t surface_region; struct buffer_state * state; - struct surface_state * surface_state = surface->view_state; + struct view * view = (void *) surface->view; if (!surface->state.buffer) return; @@ -123,15 +124,14 @@ static void repaint_surface(struct render_target * target, state = buffer_state(surface->state.buffer); assert(state); - pixman_region32_init_with_extents(&surface_damage, &surface_state->extents); + pixman_region32_init_with_extents(&surface_damage, &view->extents); pixman_region32_init(&border_damage); pixman_region32_init_rect (&surface_region, surface->geometry.x, surface->geometry.y, surface->geometry.width, surface->geometry.height); pixman_region32_intersect(&surface_damage, &surface_damage, damage); - pixman_region32_subtract(&surface_damage, &surface_damage, - &surface_state->clip); + pixman_region32_subtract(&surface_damage, &surface_damage, &view->clip); pixman_region32_subtract(&border_damage, &surface_damage, &surface_region); pixman_region32_intersect(&surface_damage, &surface_damage, &surface_region); @@ -161,8 +161,7 @@ static void repaint_surface(struct render_target * target, pixman_region32_translate(&border_damage, -target->geometry.x, -target->geometry.y); - wld_fill_region(target->drawable, surface_state->border.color, - &border_damage); + wld_fill_region(target->drawable, view->border.color, &border_damage); } pixman_region32_fini(&border_damage); @@ -274,13 +273,12 @@ static void renderer_flush_surface(struct swc_surface * surface) */ static void damage_below_surface(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; + struct swc_compositor * compositor = view->compositor; pixman_region32_t damage_below; - pixman_region32_init_with_extents(&damage_below, &state->extents); - pixman_region32_subtract(&damage_below, &damage_below, &state->clip); + pixman_region32_init_with_extents(&damage_below, &view->extents); + pixman_region32_subtract(&damage_below, &damage_below, &view->clip); pixman_region32_union(&compositor->damage, &compositor->damage, &damage_below); pixman_region32_fini(&damage_below); @@ -291,43 +289,42 @@ static void damage_below_surface(struct swc_surface * surface) */ static void damage_surface(struct swc_surface * surface) { - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; printf("damaging surface\n"); pixman_region32_fini(&surface->state.damage); pixman_region32_init_rect(&surface->state.damage, 0, 0, surface->geometry.width, surface->geometry.height); - state->border.damaged = true; + view->border.damaged = true; } static void update_extents(struct swc_surface * surface) { - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; - state->extents.x1 = surface->geometry.x - state->border.width; - state->extents.y1 = surface->geometry.y - state->border.width; - state->extents.x2 = surface->geometry.x + surface->geometry.width - + state->border.width; - state->extents.y2 = surface->geometry.y + surface->geometry.height - + state->border.width; + view->extents.x1 = surface->geometry.x - view->border.width; + view->extents.y1 = surface->geometry.y - view->border.width; + view->extents.x2 = surface->geometry.x + surface->geometry.width + + view->border.width; + view->extents.y2 = surface->geometry.y + surface->geometry.height + + view->border.width; /* Damage border. */ - state->border.damaged = true; + view->border.damaged = true; } static void update_outputs(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; + struct swc_compositor * compositor = view->compositor; uint32_t old_outputs = surface->outputs, new_outputs = 0, entered_outputs, left_outputs, changed_outputs; struct swc_output * output; struct wl_client * client; struct wl_resource * resource; - if (state->mapped) + if (view->mapped) { wl_list_for_each(output, &compositor->outputs, link) { @@ -367,8 +364,8 @@ static void update(struct swc_surface * surface); static void handle_surface_event(struct wl_listener * listener, void * data) { - struct surface_state * state - = CONTAINER_OF(listener, typeof(*state), event_listener); + struct view * view + = CONTAINER_OF(listener, typeof(*view), surface_event_listener); struct swc_event * event = data; struct swc_surface_event_data * event_data = event->data; struct swc_surface * surface = event_data->surface; @@ -386,49 +383,16 @@ static void handle_surface_event(struct wl_listener * listener, void * data) } } -static bool add(struct swc_surface * surface) -{ - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state; - - state = malloc(sizeof *state); - - if (!state) - return false; - - state->compositor = compositor; - state->extents.x1 = surface->geometry.x; - state->extents.y1 = surface->geometry.y; - state->extents.x2 = surface->geometry.x + surface->geometry.width; - state->extents.y2 = surface->geometry.y + surface->geometry.height; - state->border.width = 0; - state->border.color = 0x000000; - state->border.damaged = false; - state->mapped = false; - state->event_listener.notify = &handle_surface_event; - - wl_signal_add(&surface->event_signal, &state->event_listener); - - pixman_region32_init(&state->clip); - - surface->view_state = state; - - return true; -} - static void remove_(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; swc_compositor_surface_hide(surface); - wl_list_remove(&state->event_listener.link); - pixman_region32_fini(&state->clip); + wl_list_remove(&view->surface_event_listener.link); + pixman_region32_fini(&view->clip); - free(state); + free(view); } static void attach(struct swc_surface * surface, struct wl_resource * resource) @@ -438,12 +402,11 @@ static void attach(struct swc_surface * surface, struct wl_resource * resource) static void update(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; + struct swc_compositor * compositor = view->compositor; struct swc_output * output; - if (!state->mapped) + if (!view->mapped) return; wl_list_for_each(output, &compositor->outputs, link) @@ -455,14 +418,12 @@ static void update(struct swc_surface * surface) static void move(struct swc_surface * surface, int32_t x, int32_t y) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; if (x == surface->geometry.x && y == surface->geometry.y) return; - if (state->mapped) + if (view->mapped) damage_below_surface(surface); surface->geometry.x = x; @@ -470,11 +431,11 @@ static void move(struct swc_surface * surface, int32_t x, int32_t y) update_extents(surface); - if (state->mapped) + if (view->mapped) { /* Assume worst-case no clipping until we draw the next frame (in case * the surface gets moved again before that). */ - pixman_region32_init(&state->clip); + pixman_region32_init(&view->clip); damage_below_surface(surface); update(surface); @@ -484,32 +445,58 @@ static void move(struct swc_surface * surface, int32_t x, int32_t y) } const struct swc_view_impl view_impl = { - .add = &add, .remove = &remove_, .attach = &attach, .update = &update, .move = &move }; +bool swc_compositor_add_surface(struct swc_compositor * compositor, + struct swc_surface * surface) +{ + struct view * view; + + view = malloc(sizeof *view); + + if (!view) + return false; + + swc_view_initialize(&view->base, &view_impl); + view->compositor = compositor; + view->mapped = false; + view->extents.x1 = surface->geometry.x; + view->extents.y1 = surface->geometry.y; + view->extents.x2 = surface->geometry.x + surface->geometry.width; + view->extents.y2 = surface->geometry.y + surface->geometry.height; + view->border.width = 0; + view->border.color = 0x000000; + view->border.damaged = false; + view->surface_event_listener.notify = &handle_surface_event; + wl_signal_add(&surface->event_signal, &view->surface_event_listener); + pixman_region32_init(&view->clip); + swc_surface_set_view(surface, &view->base); + + return true; +} + void swc_compositor_surface_show(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; + struct swc_compositor * compositor = view->compositor; - if (surface->view->impl != &view_impl) + if (view->base.impl != &view_impl) return; - if (state->mapped) + if (view->mapped) return; printf("showing surface %u\n", wl_resource_get_id(surface->resource)); - state->mapped = true; + view->mapped = true; /* Assume worst-case no clipping until we draw the next frame (in case the * surface gets moved before that. */ - pixman_region32_clear(&state->clip); + pixman_region32_clear(&view->clip); damage_surface(surface); update_outputs(surface); @@ -519,20 +506,18 @@ void swc_compositor_surface_show(struct swc_surface * surface) void swc_compositor_surface_hide(struct swc_surface * surface) { - struct swc_compositor * compositor = CONTAINER_OF - (surface->view, typeof(*compositor), compositor_view); - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; - if (surface->view->impl != &view_impl) + if (view->base.impl != &view_impl) return; - if (!state->mapped) + if (!view->mapped) return; /* Update all the outputs the surface was on. */ update(surface); - state->mapped = false; + view->mapped = false; damage_below_surface(surface); update_outputs(surface); @@ -542,13 +527,13 @@ void swc_compositor_surface_hide(struct swc_surface * surface) void swc_compositor_surface_set_border_width(struct swc_surface * surface, uint32_t width) { - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; - if (state->border.width == width) + if (view->border.width == width) return; - state->border.width = width; - state->border.damaged = true; + view->border.width = width; + view->border.damaged = true; /* XXX: Damage above surface for transparent surfaces? */ @@ -559,13 +544,13 @@ void swc_compositor_surface_set_border_width(struct swc_surface * surface, void swc_compositor_surface_set_border_color(struct swc_surface * surface, uint32_t color) { - struct surface_state * state = surface->view_state; + struct view * view = (void *) surface->view; - if (state->border.color == color) + if (view->border.color == color) return; - state->border.color = color; - state->border.damaged = true; + view->border.color = color; + view->border.damaged = true; /* XXX: Damage above surface for transparent surfaces? */ @@ -577,7 +562,7 @@ void swc_compositor_surface_set_border_color(struct swc_surface * surface, static void calculate_damage(struct swc_compositor * compositor) { struct swc_surface * surface; - struct surface_state * state; + struct view * view; pixman_region32_t surface_opaque; pixman_region32_clear(&compositor->opaque); @@ -586,10 +571,10 @@ static void calculate_damage(struct swc_compositor * compositor) /* Go through surfaces top-down to calculate clipping regions. */ wl_list_for_each(surface, &compositor->surfaces, link) { - state = surface->view_state; + view = (void *) surface->view; /* Clip the surface by the opaque region covering it. */ - pixman_region32_copy(&state->clip, &compositor->opaque); + pixman_region32_copy(&view->clip, &compositor->opaque); /* Translate the opaque region to global coordinates. */ pixman_region32_copy(&surface_opaque, &surface->state.opaque); @@ -616,11 +601,11 @@ static void calculate_damage(struct swc_compositor * compositor) pixman_region32_clear(&surface->state.damage); } - if (state->border.damaged) + if (view->border.damaged) { pixman_region32_t border_region, surface_region; - pixman_region32_init_with_extents(&border_region, &state->extents); + pixman_region32_init_with_extents(&border_region, &view->extents); pixman_region32_init_rect (&surface_region, surface->geometry.x, surface->geometry.y, surface->geometry.width, surface->geometry.height); @@ -634,7 +619,7 @@ static void calculate_damage(struct swc_compositor * compositor) pixman_region32_fini(&border_region); pixman_region32_fini(&surface_region); - state->border.damaged = false; + view->border.damaged = false; } } @@ -891,7 +876,6 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, compositor->pointer_listener.notify = &handle_pointer_event; compositor->scheduled_updates = 0; compositor->pending_flips = 0; - swc_view_initialize(&compositor->compositor_view, &view_impl); swc_view_initialize(&compositor->cursor_view, &swc_cursor_view_impl); compositor->pointer_handler = (struct swc_pointer_handler) { .focus = &handle_focus, diff --git a/libswc/compositor.h b/libswc/compositor.h @@ -2,7 +2,6 @@ #define SWC_COMPOSITOR_H #include "pointer.h" -#include "view.h" #include <wayland-server.h> @@ -30,7 +29,6 @@ struct swc_compositor uint32_t scheduled_updates; }; - struct swc_view compositor_view; struct swc_view cursor_view; struct swc_pointer_handler pointer_handler; @@ -51,6 +49,11 @@ void swc_compositor_add_globals(struct swc_compositor * compositor, void swc_compositor_schedule_update(struct swc_compositor * compositor, struct swc_output * output); +bool swc_compositor_add_surface(struct swc_compositor * compositor, + struct swc_surface * surface); +bool swc_compositor_remove_surface(struct swc_compositor * compositor, + struct swc_surface * surface); + void swc_compositor_surface_show(struct swc_surface * surface); void swc_compositor_surface_hide(struct swc_surface * surface); void swc_compositor_surface_set_border_color(struct swc_surface * surface, diff --git a/libswc/surface.c b/libswc/surface.c @@ -419,14 +419,6 @@ void swc_surface_set_view(struct swc_surface * surface, if (surface->view) { - if (surface->view->impl->add - && !surface->view->impl->add(surface)) - { - surface->view = NULL; - return; - } - - surface->view->impl->attach(surface, surface->state.buffer); surface->view->impl->update(surface); } diff --git a/libswc/view.h b/libswc/view.h @@ -42,9 +42,6 @@ struct swc_view */ struct swc_view_impl { - /* Called when a surface is added to the view. */ - bool (* add)(struct swc_surface * surface); - /* Called when a surface is removed from the view. */ void (* remove)(struct swc_surface * surface); diff --git a/libswc/window.c b/libswc/window.c @@ -124,7 +124,7 @@ bool swc_window_initialize(struct swc_window * window, INTERNAL(window)->impl = impl; surface->window = window; - swc_surface_set_view(surface, &swc.compositor->compositor_view); + swc_compositor_add_surface(swc.compositor, surface); swc.manager->new_window(window);