Skip to content

Commit

Permalink
Use scene-graph for damage tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Sep 9, 2021
1 parent 7749855 commit 65f4e17
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 289 deletions.
12 changes: 0 additions & 12 deletions cage.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ usage(FILE *file, const char *cage)
"Usage: %s [OPTIONS] [--] APPLICATION\n"
"\n"
" -d\t Don't draw client side decorations, when possible\n"
#ifdef DEBUG
" -D\t Turn on damage tracking debugging\n"
#endif
" -h\t Display this help message\n"
" -m extend Extend the display across all connected outputs (default)\n"
" -m last Use only the last connected output\n"
Expand All @@ -204,20 +201,11 @@ static bool
parse_args(struct cg_server *server, int argc, char *argv[])
{
int c;
#ifdef DEBUG
while ((c = getopt(argc, argv, "dDhm:rsv")) != -1) {
#else
while ((c = getopt(argc, argv, "dhm:rsv")) != -1) {
#endif
switch (c) {
case 'd':
server->xdg_decoration = true;
break;
#ifdef DEBUG
case 'D':
server->debug_damage_tracking = true;
break;
#endif
case 'h':
usage(stdout, argv[0]);
return false;
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ cage_sources = [
'cage.c',
'idle_inhibit_v1.c',
'output.c',
'render.c',
'seat.c',
'util.c',
'view.c',
Expand Down
90 changes: 9 additions & 81 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,50 +225,9 @@ output_disable(struct cg_output *output)
}

static void
damage_surface_iterator(struct cg_output *output, struct wlr_surface *surface, struct wlr_box *box, void *user_data)
handle_output_frame(struct wl_listener *listener, void *data)
{
struct wlr_output *wlr_output = output->wlr_output;
bool whole = *(bool *) user_data;

scale_box(box, output->wlr_output->scale);

if (whole) {
wlr_output_damage_add_box(output->damage, box);
} else if (pixman_region32_not_empty(&surface->buffer_damage)) {
pixman_region32_t damage;
pixman_region32_init(&damage);
wlr_surface_get_effective_damage(surface, &damage);

wlr_region_scale(&damage, &damage, wlr_output->scale);
if (ceil(wlr_output->scale) > surface->current.scale) {
/* When scaling up a surface it'll become
blurry, so we need to expand the damage
region. */
wlr_region_expand(&damage, &damage, ceil(wlr_output->scale) - surface->current.scale);
}
pixman_region32_translate(&damage, box->x, box->y);
wlr_output_damage_add(output->damage, &damage);
pixman_region32_fini(&damage);
}
}

void
output_damage_surface(struct cg_output *output, struct wlr_surface *surface, double lx, double ly, bool whole)
{
if (!output->wlr_output->enabled) {
wlr_log(WLR_DEBUG, "Not adding damage for disabled output %s", output->wlr_output->name);
return;
}

double ox = lx, oy = ly;
wlr_output_layout_output_coords(output->server->output_layout, output->wlr_output, &ox, &oy);
output_surface_for_each_surface(output, surface, ox, oy, damage_surface_iterator, &whole);
}

static void
handle_output_damage_frame(struct wl_listener *listener, void *data)
{
struct cg_output *output = wl_container_of(listener, output, damage_frame);
struct cg_output *output = wl_container_of(listener, output, frame);
struct send_frame_done_data frame_data = {0};

if (!output->wlr_output->enabled) {
Expand All @@ -287,33 +246,12 @@ handle_output_damage_frame(struct wl_listener *listener, void *data)
}
last_scanned_out = scanned_out;

if (scanned_out) {
goto frame_done;
}

bool needs_frame;
pixman_region32_t damage;
pixman_region32_init(&damage);
if (!wlr_output_damage_attach_render(output->damage, &needs_frame, &damage)) {
wlr_log(WLR_ERROR, "Cannot make damage output current");
goto damage_finish;
if (!scanned_out) {
wlr_scene_output_commit(output->scene_output);
}

if (!needs_frame) {
wlr_output_rollback(output->wlr_output);
goto damage_finish;
}

output_render(output, &damage);

damage_finish:
pixman_region32_fini(&damage);

frame_done:
clock_gettime(CLOCK_MONOTONIC, &frame_data.when);
send_frame_done(output, &frame_data);

wlr_output_damage_add_whole(output->damage);
}

static void
Expand Down Expand Up @@ -357,8 +295,7 @@ output_destroy(struct cg_output *output)
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->commit.link);
wl_list_remove(&output->mode.link);
wl_list_remove(&output->damage_frame.link);
wl_list_remove(&output->damage_destroy.link);
wl_list_remove(&output->frame.link);
wl_list_remove(&output->link);

wlr_output_layout_remove(server->output_layout, output->wlr_output);
Expand All @@ -380,18 +317,10 @@ output_destroy(struct cg_output *output)
}
}

static void
handle_output_damage_destroy(struct wl_listener *listener, void *data)
{
struct cg_output *output = wl_container_of(listener, output, damage_destroy);
output_destroy(output);
}

static void
handle_output_destroy(struct wl_listener *listener, void *data)
{
struct cg_output *output = wl_container_of(listener, output, destroy);
wlr_output_damage_destroy(output->damage);
output_destroy(output);
}

Expand All @@ -409,7 +338,8 @@ handle_new_output(struct wl_listener *listener, void *data)

output->wlr_output = wlr_output;
output->server = server;
output->damage = wlr_output_damage_create(wlr_output);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output);

wl_list_insert(&server->outputs, &output->link);

output->commit.notify = handle_output_commit;
Expand All @@ -418,10 +348,8 @@ handle_new_output(struct wl_listener *listener, void *data)
wl_signal_add(&wlr_output->events.mode, &output->mode);
output->destroy.notify = handle_output_destroy;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
output->damage_frame.notify = handle_output_damage_frame;
wl_signal_add(&output->damage->events.frame, &output->damage_frame);
output->damage_destroy.notify = handle_output_damage_destroy;
wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
output->frame.notify = handle_output_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);

struct wlr_output_mode *preferred_mode = wlr_output_preferred_mode(wlr_output);
if (preferred_mode) {
Expand Down
8 changes: 2 additions & 6 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
struct cg_output {
struct cg_server *server;
struct wlr_output *wlr_output;
struct wlr_output_damage *damage;
struct wlr_scene_output *scene_output;

struct wl_listener commit;
struct wl_listener mode;
struct wl_listener destroy;
struct wl_listener damage_frame;
struct wl_listener damage_destroy;
struct wl_listener frame;

struct wl_list link; // cg_server::outputs
};
Expand All @@ -26,9 +25,6 @@ typedef void (*cg_surface_iterator_func_t)(struct cg_output *output, struct wlr_
void *user_data);

void handle_new_output(struct wl_listener *listener, void *data);
void output_surface_for_each_surface(struct cg_output *output, struct wlr_surface *surface, double ox, double oy,
cg_surface_iterator_func_t iterator, void *user_data);
void output_damage_surface(struct cg_output *output, struct wlr_surface *surface, double lx, double ly, bool whole);
void output_set_window_title(struct cg_output *output, const char *title);

#endif
117 changes: 0 additions & 117 deletions render.c

This file was deleted.

14 changes: 0 additions & 14 deletions seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,24 +597,13 @@ handle_cursor_motion(struct wl_listener *listener, void *data)
wlr_idle_notify_activity(seat->server->idle, seat->seat);
}

static void
drag_icon_damage(struct cg_drag_icon *drag_icon)
{
struct cg_output *output;
wl_list_for_each (output, &drag_icon->seat->server->outputs, link) {
output_damage_surface(output, drag_icon->wlr_drag_icon->surface, drag_icon->lx, drag_icon->ly, true);
}
}

static void
drag_icon_update_position(struct cg_drag_icon *drag_icon)
{
struct wlr_drag_icon *wlr_icon = drag_icon->wlr_drag_icon;
struct cg_seat *seat = drag_icon->seat;
struct wlr_touch_point *point;

drag_icon_damage(drag_icon);

switch (wlr_icon->drag->grab_type) {
case WLR_DRAG_GRAB_KEYBOARD:
return;
Expand All @@ -632,8 +621,6 @@ drag_icon_update_position(struct cg_drag_icon *drag_icon)
break;
}

drag_icon_damage(drag_icon);

wlr_scene_node_set_position(drag_icon->scene_node, drag_icon->lx, drag_icon->ly);
}

Expand All @@ -642,7 +629,6 @@ handle_drag_icon_destroy(struct wl_listener *listener, void *data)
{
struct cg_drag_icon *drag_icon = wl_container_of(listener, drag_icon, destroy);

drag_icon_damage(drag_icon);
wl_list_remove(&drag_icon->link);
wl_list_remove(&drag_icon->destroy.link);
wlr_scene_node_destroy(drag_icon->scene_node);
Expand Down
3 changes: 0 additions & 3 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ struct cg_server {
bool xdg_decoration;
bool allow_vt_switch;
enum wl_output_transform output_transform;
#ifdef DEBUG
bool debug_damage_tracking;
#endif
};

#endif

0 comments on commit 65f4e17

Please sign in to comment.