rootston: track subsurface damage

This commit is contained in:
emersion 2018-01-21 14:50:37 +01:00
parent eeffe11337
commit a636d72fc7
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
7 changed files with 162 additions and 18 deletions

View file

@ -64,7 +64,7 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
double ly, struct wlr_surface **surface, double *sx, double *sy); double ly, struct wlr_surface **surface, double *sx, double *sy);
void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_init(struct roots_view *view, struct roots_desktop *desktop);
void view_destroy(struct roots_view *view); void view_finish(struct roots_view *view);
void view_activate(struct roots_view *view, bool activate); void view_activate(struct roots_view *view, bool activate);
void view_apply_damage(struct roots_view *view); void view_apply_damage(struct roots_view *view);
void view_damage_whole(struct roots_view *view); void view_damage_whole(struct roots_view *view);

View file

@ -91,7 +91,11 @@ struct roots_view {
struct roots_xwayland_surface *roots_xwayland_surface; struct roots_xwayland_surface *roots_xwayland_surface;
#endif #endif
}; };
struct wlr_surface *wlr_surface; struct wlr_surface *wlr_surface;
struct wl_list children; // roots_view_child::link
struct wl_listener new_subsurface;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
@ -112,6 +116,21 @@ struct roots_view {
void (*close)(struct roots_view *view); void (*close)(struct roots_view *view);
}; };
struct roots_view_child {
struct roots_view *view;
struct wlr_surface *wlr_surface;
struct wl_list link;
struct wl_listener commit;
struct wl_listener new_subsurface;
};
struct roots_subsurface {
struct roots_view_child view_child;
struct wlr_subsurface *wlr_subsurface;
struct wl_listener destroy;
};
void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_get_box(const struct roots_view *view, struct wlr_box *box);
void view_activate(struct roots_view *view, bool active); void view_activate(struct roots_view *view, bool active);
void view_move(struct roots_view *view, double x, double y); void view_move(struct roots_view *view, double x, double y);
@ -126,4 +145,12 @@ bool view_center(struct roots_view *view);
void view_setup(struct roots_view *view); void view_setup(struct roots_view *view);
void view_teardown(struct roots_view *view); void view_teardown(struct roots_view *view);
void view_child_init(struct roots_view_child *child, struct roots_view *view,
struct wlr_surface *wlr_surface);
void view_child_finish(struct roots_view_child *child);
struct roots_subsurface *subsurface_create(struct roots_view *view,
struct wlr_subsurface *wlr_subsurface);
void subsurface_destroy(struct roots_subsurface *subsurface);
#endif #endif

View file

@ -254,20 +254,106 @@ bool view_center(struct roots_view *view) {
return true; return true;
} }
void view_destroy(struct roots_view *view) { void view_child_finish(struct roots_view_child *child) {
if (child == NULL) {
return;
}
view_damage_whole(child->view);
wl_list_remove(&child->link);
wl_list_remove(&child->commit.link);
wl_list_remove(&child->new_subsurface.link);
}
static void view_child_handle_commit(struct wl_listener *listener,
void *data) {
struct roots_view_child *child = wl_container_of(listener, child, commit);
view_apply_damage(child->view);
}
static void view_child_handle_new_subsurface(struct wl_listener *listener,
void *data) {
struct roots_view_child *child =
wl_container_of(listener, child, new_subsurface);
struct wlr_subsurface *wlr_subsurface = data;
subsurface_create(child->view, wlr_subsurface);
}
void view_child_init(struct roots_view_child *child, struct roots_view *view,
struct wlr_surface *wlr_surface) {
child->view = view;
child->wlr_surface = wlr_surface;
child->commit.notify = view_child_handle_commit;
wl_signal_add(&wlr_surface->events.commit, &child->commit);
child->new_subsurface.notify = view_child_handle_new_subsurface;
wl_signal_add(&wlr_surface->events.new_subsurface, &child->new_subsurface);
wl_list_insert(&view->children, &child->link);
}
static void subsurface_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_subsurface *subsurface =
wl_container_of(listener, subsurface, destroy);
subsurface_destroy(subsurface);
}
struct roots_subsurface *subsurface_create(struct roots_view *view,
struct wlr_subsurface *wlr_subsurface) {
struct roots_subsurface *subsurface =
calloc(1, sizeof(struct roots_subsurface));
if (subsurface == NULL) {
return NULL;
}
subsurface->wlr_subsurface = wlr_subsurface;
view_child_init(&subsurface->view_child, view, wlr_subsurface->surface);
subsurface->destroy.notify = subsurface_handle_destroy;
wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy);
return subsurface;
}
void subsurface_destroy(struct roots_subsurface *subsurface) {
if (subsurface == NULL) {
return;
}
wl_list_remove(&subsurface->destroy.link);
view_child_finish(&subsurface->view_child);
free(subsurface);
}
void view_finish(struct roots_view *view) {
view_damage_whole(view); view_damage_whole(view);
wl_signal_emit(&view->events.destroy, view); wl_signal_emit(&view->events.destroy, view);
wl_list_remove(&view->new_subsurface.link);
if (view->fullscreen_output) { if (view->fullscreen_output) {
view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output->fullscreen_view = NULL;
} }
}
free(view); static void view_handle_new_subsurface(struct wl_listener *listener,
void *data) {
struct roots_view *view = wl_container_of(listener, view, new_subsurface);
struct wlr_subsurface *wlr_subsurface = data;
subsurface_create(view, wlr_subsurface);
} }
void view_init(struct roots_view *view, struct roots_desktop *desktop) { void view_init(struct roots_view *view, struct roots_desktop *desktop) {
assert(view->wlr_surface);
view->desktop = desktop; view->desktop = desktop;
wl_signal_init(&view->events.destroy); wl_signal_init(&view->events.destroy);
wl_list_init(&view->children);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list,
parent_link) {
subsurface_create(view, subsurface);
}
view->new_subsurface.notify = view_handle_new_subsurface;
wl_signal_add(&view->wlr_surface->events.new_subsurface,
&view->new_subsurface);
view_damage_whole(view); view_damage_whole(view);
} }

View file

@ -444,7 +444,7 @@ static void output_damage_whole(struct roots_output *output) {
} }
static void output_damage_whole_surface(struct roots_output *output, static void output_damage_whole_surface(struct roots_output *output,
struct wlr_surface *surface, double lx, double ly) { struct wlr_surface *surface, double lx, double ly, float rotation) {
if (!wlr_surface_has_buffer(surface)) { if (!wlr_surface_has_buffer(surface)) {
return; return;
} }
@ -460,6 +460,18 @@ static void output_damage_whole_surface(struct roots_output *output,
box.x, box.y, box.width, box.height); box.x, box.y, box.width, box.height);
schedule_render(output); schedule_render(output);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
struct wlr_surface_state *state = subsurface->surface->current;
double sx = state->subsurface_position.x;
double sy = state->subsurface_position.y;
rotate_child_position(&sx, &sy, state->width, state->height,
surface->current->width, surface->current->height, rotation);
output_damage_whole_surface(output, subsurface->surface,
lx + sx, ly + sy, rotation);
}
} }
void output_damage_whole_view(struct roots_output *output, void output_damage_whole_view(struct roots_output *output,
@ -469,14 +481,15 @@ void output_damage_whole_view(struct roots_output *output,
} }
if (view->wlr_surface != NULL) { if (view->wlr_surface != NULL) {
output_damage_whole_surface(output, view->wlr_surface, view->x, view->y); output_damage_whole_surface(output, view->wlr_surface,
view->x, view->y, view->rotation);
} }
// TODO: subsurfaces, popups, etc // TODO: popups, etc
} }
static void output_damage_from_surface(struct roots_output *output, static void output_damage_from_surface(struct roots_output *output,
struct wlr_surface *surface, double lx, double ly) { struct wlr_surface *surface, double lx, double ly, float rotation) {
if (!wlr_surface_has_buffer(surface)) { if (!wlr_surface_has_buffer(surface)) {
return; return;
} }
@ -497,6 +510,18 @@ static void output_damage_from_surface(struct roots_output *output,
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
schedule_render(output); schedule_render(output);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
struct wlr_surface_state *state = subsurface->surface->current;
double sx = state->subsurface_position.x;
double sy = state->subsurface_position.y;
rotate_child_position(&sx, &sy, state->width, state->height,
surface->current->width, surface->current->height, rotation);
output_damage_from_surface(output, subsurface->surface,
lx + sx, ly + sy, rotation);
}
} }
void output_damage_from_view(struct roots_output *output, void output_damage_from_view(struct roots_output *output,
@ -506,10 +531,11 @@ void output_damage_from_view(struct roots_output *output,
} }
if (view->wlr_surface != NULL) { if (view->wlr_surface != NULL) {
output_damage_from_surface(output, view->wlr_surface, view->x, view->y); output_damage_from_surface(output, view->wlr_surface,
view->x, view->y, view->rotation);
} }
// TODO: subsurfaces, popups, etc // TODO: popups, etc
} }
static void output_handle_mode(struct wl_listener *listener, void *data) { static void output_handle_mode(struct wl_listener *listener, void *data) {

View file

@ -118,7 +118,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->set_state.link);
wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
view_destroy(roots_surface->view); view_finish(roots_surface->view);
free(roots_surface->view);
free(roots_surface); free(roots_surface);
} }

View file

@ -231,7 +231,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_move.link);
wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_resize.link);
wl_list_remove(&roots_xdg_surface->view->link); wl_list_remove(&roots_xdg_surface->view->link);
view_destroy(roots_xdg_surface->view); view_finish(roots_xdg_surface->view);
free(roots_xdg_surface->view);
free(roots_xdg_surface); free(roots_xdg_surface);
} }

View file

@ -121,7 +121,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
if (xwayland_surface->mapped) { if (xwayland_surface->mapped) {
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
} }
view_destroy(roots_surface->view); view_finish(roots_surface->view);
free(roots_surface->view);
free(roots_surface); free(roots_surface);
} }
@ -233,24 +234,26 @@ static void handle_map_notify(struct wl_listener *listener, void *data) {
view->wlr_surface = xsurface->surface; view->wlr_surface = xsurface->surface;
view->x = xsurface->x; view->x = xsurface->x;
view->y = xsurface->y; view->y = xsurface->y;
wl_list_insert(&desktop->views, &view->link);
view_damage_whole(view); view_damage_whole(view);
roots_surface->surface_commit.notify = handle_surface_commit; roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&xsurface->surface->events.commit, wl_signal_add(&xsurface->surface->events.commit,
&roots_surface->surface_commit); &roots_surface->surface_commit);
wl_list_insert(&desktop->views, &view->link);
} }
static void handle_unmap_notify(struct wl_listener *listener, void *data) { static void handle_unmap_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, unmap_notify); wl_container_of(listener, roots_surface, unmap_notify);
struct roots_view *view = roots_surface->view;
view_damage_whole(roots_surface->view);
roots_surface->view->wlr_surface = NULL;
wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link);
view_damage_whole(view);
view->wlr_surface = NULL;
wl_list_remove(&view->link);
} }
void handle_xwayland_surface(struct wl_listener *listener, void *data) { void handle_xwayland_surface(struct wl_listener *listener, void *data) {