Merge branch 'output-damage' of github.com:emersion/wlroots into output-damage

This commit is contained in:
emersion 2018-01-24 18:49:47 +01:00
commit 3f96427d08
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
6 changed files with 166 additions and 49 deletions

View file

@ -37,9 +37,14 @@ struct roots_output {
void output_add_notify(struct wl_listener *listener, void *data); void output_add_notify(struct wl_listener *listener, void *data);
void output_remove_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data);
struct roots_view;
struct roots_drag_icon;
void output_damage_whole_view(struct roots_output *output, void output_damage_whole_view(struct roots_output *output,
struct roots_view *view); struct roots_view *view);
void output_damage_from_view(struct roots_output *output, void output_damage_from_view(struct roots_output *output,
struct roots_view *view); struct roots_view *view);
void output_damage_whole_drag_icon(struct roots_output *output,
struct roots_drag_icon *icon);
#endif #endif

View file

@ -46,6 +46,8 @@ struct roots_drag_icon {
struct wlr_drag_icon *wlr_drag_icon; struct wlr_drag_icon *wlr_drag_icon;
struct wl_list link; struct wl_list link;
double x, y;
struct wl_listener surface_commit; struct wl_listener surface_commit;
struct wl_listener map; struct wl_listener map;
struct wl_listener destroy; struct wl_listener destroy;
@ -103,6 +105,10 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view); void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view);
struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat, struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat,
struct roots_view *view); struct roots_view *view);
void roots_drag_icon_update_position(struct roots_drag_icon *icon);
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon);
#endif #endif

View file

@ -138,6 +138,11 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
} else { } else {
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
} }
struct roots_drag_icon *drag_icon;
wl_list_for_each(drag_icon, &seat->drag_icons, link) {
roots_drag_icon_update_position(drag_icon);
}
break; break;
case ROOTS_CURSOR_MOVE: case ROOTS_CURSOR_MOVE:
view = roots_seat_get_focus(seat); view = roots_seat_get_focus(seat);

View file

@ -27,6 +27,12 @@ void view_get_box(const struct roots_view *view, struct wlr_box *box) {
if (view->get_size) { if (view->get_size) {
view->get_size(view, box); view->get_size(view, box);
} else { } else {
if (view->wlr_surface == NULL) {
// View is unmapped
box->width = box->height = 0;
return;
}
box->width = view->wlr_surface->current->width; box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height; box->height = view->wlr_surface->current->height;
} }

View file

@ -174,7 +174,6 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
struct render_data *data = _data; struct render_data *data = _data;
struct roots_output *output = data->output; struct roots_output *output = data->output;
struct timespec *when = data->when; struct timespec *when = data->when;
pixman_region32_t *damage = data->damage;
if (!wlr_surface_has_buffer(surface)) { if (!wlr_surface_has_buffer(surface)) {
return; return;
@ -188,14 +187,14 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
} }
// TODO: output scale, output transform support // TODO: output scale, output transform support
pixman_region32_t surface_damage; pixman_region32_t damage;
pixman_region32_init(&surface_damage); pixman_region32_init(&damage);
pixman_region32_union_rect(&surface_damage, &surface_damage, box.x, box.y, pixman_region32_union_rect(&damage, &damage, box.x, box.y,
box.width, box.height); box.width, box.height);
pixman_region32_intersect(&surface_damage, &surface_damage, damage); pixman_region32_intersect(&damage, &damage, data->damage);
bool damaged = pixman_region32_not_empty(&surface_damage); bool damaged = pixman_region32_not_empty(&damage);
if (!damaged) { if (!damaged) {
goto surface_damage_finish; goto damage_finish;
} }
float matrix[16]; float matrix[16];
@ -206,7 +205,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
int nrects; int nrects;
pixman_box32_t *rects = pixman_box32_t *rects =
pixman_region32_rectangles(&surface_damage, &nrects); pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) { for (int i = 0; i < nrects; ++i) {
struct wlr_box scissor = { struct wlr_box scissor = {
.x = rects[i].x1, .x = rects[i].x1,
@ -221,17 +220,12 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
wlr_surface_send_frame_done(surface, when); wlr_surface_send_frame_done(surface, when);
surface_damage_finish: damage_finish:
pixman_region32_fini(&surface_damage); pixman_region32_fini(&damage);
} }
static void render_decorations(struct roots_view *view, static void get_decoration_box(struct roots_view *view,
struct render_data *data) { struct roots_output *output, struct wlr_box *box) {
if (!view->decorated) {
return;
}
struct roots_output *output = data->output;
struct wlr_output *wlr_output = output->wlr_output; struct wlr_output *wlr_output = output->wlr_output;
struct wlr_box deco_box; struct wlr_box deco_box;
@ -246,18 +240,56 @@ static void render_decorations(struct roots_view *view,
wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y); wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y);
struct wlr_box box = { box->x = x * wlr_output->scale;
.x = x * wlr_output->scale, box->y = y * wlr_output->scale;
.y = y * wlr_output->scale, box->width = deco_box.width * wlr_output->scale;
.width = deco_box.width * wlr_output->scale, box->height = deco_box.height * wlr_output->scale;
.height = deco_box.height * wlr_output->scale, }
};
static void render_decorations(struct roots_view *view,
struct render_data *data) {
if (!view->decorated || view->wlr_surface == NULL) {
return;
}
struct roots_output *output = data->output;
struct wlr_box box;
get_decoration_box(view, output, &box);
// TODO: output scale, output transform support
pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_union_rect(&damage, &damage, box.x, box.y,
box.width, box.height);
pixman_region32_intersect(&damage, &damage, data->damage);
bool damaged = pixman_region32_not_empty(&damage);
if (!damaged) {
goto damage_finish;
}
float matrix[16]; float matrix[16];
wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
view->rotation, &wlr_output->transform_matrix); view->rotation, &output->wlr_output->transform_matrix);
float color[4] = { 0.2, 0.2, 0.2, 1 }; float color[] = { 0.2, 0.2, 0.2, 1 };
wlr_render_colored_quad(output->desktop->server->renderer, &color, &matrix);
int nrects;
pixman_box32_t *rects =
pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
struct wlr_box scissor = {
.x = rects[i].x1,
.y = output->wlr_output->height - rects[i].y2,
.width = rects[i].x2 - rects[i].x1,
.height = rects[i].y2 - rects[i].y1,
};
wlr_renderer_scissor(output->desktop->server->renderer, &scissor);
wlr_render_colored_quad(output->desktop->server->renderer, &color,
&matrix);
}
damage_finish:
pixman_region32_fini(&damage);
} }
static void render_view(struct roots_view *view, struct render_data *data) { static void render_view(struct roots_view *view, struct render_data *data) {
@ -408,29 +440,15 @@ static void render_output(struct roots_output *output) {
} }
// Render drag icons // Render drag icons
struct wlr_drag_icon *drag_icon = NULL; struct roots_drag_icon *drag_icon = NULL;
struct roots_seat *seat = NULL; struct roots_seat *seat = NULL;
wl_list_for_each(seat, &server->input->seats, link) { wl_list_for_each(seat, &server->input->seats, link) {
wl_list_for_each(drag_icon, &seat->seat->drag_icons, link) { wl_list_for_each(drag_icon, &seat->drag_icons, link) {
if (!drag_icon->mapped) { if (!drag_icon->wlr_drag_icon->mapped) {
continue; continue;
} }
struct wlr_surface *icon = drag_icon->surface; render_surface(drag_icon->wlr_drag_icon->surface,
struct wlr_cursor *cursor = seat->cursor->cursor; drag_icon->x, drag_icon->y, 0, &data);
double icon_x = 0, icon_y = 0;
if (drag_icon->is_pointer) {
icon_x = cursor->x + drag_icon->sx;
icon_y = cursor->y + drag_icon->sy;
render_surface(icon, icon_x, icon_y, 0, &data);
} else {
struct wlr_touch_point *point =
wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id);
if (point) {
icon_x = seat->touch_x + drag_icon->sx;
icon_y = seat->touch_y + drag_icon->sy;
render_surface(icon, icon_x, icon_y, 0, &data);
}
}
} }
} }
@ -521,15 +539,35 @@ static void damage_whole_surface(struct wlr_surface *surface,
schedule_render(output); schedule_render(output);
} }
static void damage_whole_decoration(struct roots_view *view,
struct roots_output *output) {
if (!view->decorated || view->wlr_surface == NULL) {
return;
}
struct wlr_box box;
get_decoration_box(view, output, &box);
pixman_region32_union_rect(&output->damage, &output->damage,
box.x, box.y, box.width, box.height);
}
void output_damage_whole_view(struct roots_output *output, void output_damage_whole_view(struct roots_output *output,
struct roots_view *view) { struct roots_view *view) {
if (!view_accept_damage(output, view)) { if (!view_accept_damage(output, view)) {
return; return;
} }
damage_whole_decoration(view, output);
view_for_each_surface(view, damage_whole_surface, output); view_for_each_surface(view, damage_whole_surface, output);
} }
void output_damage_whole_drag_icon(struct roots_output *output,
struct roots_drag_icon *icon) {
surface_for_each_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, 0,
damage_whole_surface, output);
}
static void damage_from_surface(struct wlr_surface *surface, static void damage_from_surface(struct wlr_surface *surface,
double lx, double ly, float rotation, void *data) { double lx, double ly, float rotation, void *data) {
struct roots_output *output = data; struct roots_output *output = data;

View file

@ -245,6 +245,33 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
seat->cursor->request_set_cursor.notify = handle_request_set_cursor; seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
} }
static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, surface_commit);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_map(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, map);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, destroy);
roots_drag_icon_damage_whole(icon);
wl_list_remove(&icon->link);
wl_list_remove(&icon->surface_commit.link);
wl_list_remove(&icon->map.link);
wl_list_remove(&icon->destroy.link);
free(icon);
}
static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
void *data) { void *data) {
struct roots_seat *seat = wl_container_of(listener, seat, new_drag_icon); struct roots_seat *seat = wl_container_of(listener, seat, new_drag_icon);
@ -258,7 +285,7 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
icon->wlr_drag_icon = wlr_drag_icon; icon->wlr_drag_icon = wlr_drag_icon;
icon->surface_commit.notify = roots_drag_icon_handle_surface_commit; icon->surface_commit.notify = roots_drag_icon_handle_surface_commit;
wl_signal_add(&wlr_drag_icon->events.surface_commit, &icon->surface_commit); wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
icon->map.notify = roots_drag_icon_handle_map; icon->map.notify = roots_drag_icon_handle_map;
wl_signal_add(&wlr_drag_icon->events.map, &icon->map); wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
icon->destroy.notify = roots_drag_icon_handle_destroy; icon->destroy.notify = roots_drag_icon_handle_destroy;
@ -267,6 +294,36 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
wl_list_insert(&seat->drag_icons, &icon->link); wl_list_insert(&seat->drag_icons, &icon->link);
} }
void roots_drag_icon_update_position(struct roots_drag_icon *icon) {
roots_drag_icon_damage_whole(icon);
struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
struct roots_seat *seat = icon->seat;
struct wlr_cursor *cursor = seat->cursor->cursor;
if (wlr_icon->is_pointer) {
icon->x = cursor->x + wlr_icon->sx;
icon->y = cursor->y + wlr_icon->sy;
} else {
struct wlr_touch_point *point =
wlr_seat_touch_get_point(seat->seat, wlr_icon->touch_id);
if (point == NULL) {
return;
}
icon->x = seat->touch_x + wlr_icon->sx;
icon->y = seat->touch_y + wlr_icon->sy;
}
roots_drag_icon_damage_whole(icon);
}
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon) {
struct roots_output *output;
wl_list_for_each(output, &icon->seat->input->server->desktop->outputs,
link) {
output_damage_whole_drag_icon(output, icon);
}
}
static void seat_view_destroy(struct roots_seat_view *seat_view); static void seat_view_destroy(struct roots_seat_view *seat_view);
static void roots_seat_handle_destroy(struct wl_listener *listener, static void roots_seat_handle_destroy(struct wl_listener *listener,
@ -274,7 +331,7 @@ static void roots_seat_handle_destroy(struct wl_listener *listener,
struct roots_seat *seat = wl_container_of(listener, seat, destroy); struct roots_seat *seat = wl_container_of(listener, seat, destroy);
// TODO: probably more to be freed here // TODO: probably more to be freed here
wl_list_remove(&seat->seat_destroy.link); wl_list_remove(&seat->destroy.link);
struct roots_seat_view *view, *nview; struct roots_seat_view *view, *nview;
wl_list_for_each_safe(view, nview, &seat->views, link) { wl_list_for_each_safe(view, nview, &seat->views, link) {
@ -319,7 +376,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
seat->new_drag_icon.notify = roots_seat_handle_new_drag_icon; seat->new_drag_icon.notify = roots_seat_handle_new_drag_icon;
wl_signal_add(&seat->seat->events.new_drag_icon, &seat->new_drag_icon); wl_signal_add(&seat->seat->events.new_drag_icon, &seat->new_drag_icon);
seat->destroy.notify = roots_seat_handle_seat_destroy; seat->destroy.notify = roots_seat_handle_destroy;
wl_signal_add(&seat->seat->events.destroy, &seat->destroy); wl_signal_add(&seat->seat->events.destroy, &seat->destroy);
return seat; return seat;