Migrated layer shell to the scene graph API

This commit is contained in:
Keith Bowes 2022-02-28 09:07:17 -05:00
parent d7b799ab80
commit 5a3ac6055d
7 changed files with 415 additions and 304 deletions

View file

@ -1,40 +1,5 @@
#include "waybox/output.h"
#if !WLR_CHECK_VERSION(0, 16, 0)
static void render_layer_surface(struct wlr_surface *surface,
int sx, int sy, void *data) {
struct wb_layer_surface *layer_surface = data;
struct wlr_texture *texture = wlr_surface_get_texture(surface);
if (texture == NULL) {
return;
}
struct wlr_output *output = layer_surface->layer_surface->output;
double ox = 0, oy = 0;
wlr_output_layout_output_coords(
layer_surface->server->output_layout, output, &ox, &oy);
ox += layer_surface->geo.x + sx, oy += layer_surface->geo.y + sy;
float matrix[9];
struct wlr_box box;
memcpy(&box, &layer_surface->geo, sizeof(struct wlr_box));
wlr_render_texture_with_matrix(layer_surface->server->renderer,
texture, matrix, 1);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(surface, &now);
}
static void render_layer(
struct wb_output *output, struct wl_list *layer_surfaces) {
struct wb_layer_surface *layer_surface;
wl_list_for_each(layer_surface, layer_surfaces, link) {
struct wlr_layer_surface_v1 *wlr_layer_surface_v1 =
layer_surface->layer_surface;
wlr_surface_for_each_surface(wlr_layer_surface_v1->surface,
render_layer_surface, layer_surface);
}
}
#endif
void output_frame_notify(struct wl_listener *listener, void *data) {
struct wb_output *output = wl_container_of(listener, output, frame);
struct wlr_scene *scene = output->server->scene;
@ -42,21 +7,14 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(
scene, output->wlr_output);
wlr_scene_rect_set_size(output->scene_rect, output->wlr_output->width, output->wlr_output->height);
#if !WLR_CHECK_VERSION(0, 16, 0)
render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
wlr_scene_rect_set_size(output->scene_rect,
output->wlr_output->width, output->wlr_output->height);
#endif
/* Render the scene if needed and commit the output */
wlr_scene_output_commit(scene_output);
#if !WLR_CHECK_VERSION(0, 16, 0)
render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
render_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
#endif
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_scene_output_send_frame_done(scene_output, &now);
@ -69,6 +27,14 @@ void output_destroy_notify(struct wl_listener *listener, void *data) {
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->frame.link);
/* Frees the layers */
size_t num_layers = sizeof(output->layers) / sizeof(struct wlr_scene_node *);
for (size_t i = 0; i < num_layers; i++) {
struct wlr_scene_node *node =
((struct wlr_scene_node **) &output->layers)[i];
wlr_scene_node_destroy(node);
}
free(output);
}
@ -98,15 +64,22 @@ void new_output_notify(struct wl_listener *listener, void *data) {
output->server = server;
output->wlr_output = wlr_output;
wlr_output->data = output;
wl_list_insert(&server->outputs, &output->link);
float color[4] = {0.3, 0.3, 0.3, 1.0};
#if !WLR_CHECK_VERSION(0, 16, 0)
/* Allows setting the traditional background color. However, it
* interferes with the wlr_scene layer shell helper in 0.16.0+. */
float color[4] = {0.1875, 0.1875, 0.1875, 1.0};
output->scene_rect = wlr_scene_rect_create(&server->scene->node, 0, 0, color);
#endif
wl_list_init(&output->layers[0]);
wl_list_init(&output->layers[1]);
wl_list_init(&output->layers[2]);
wl_list_init(&output->layers[3]);
/* Initializes the layers */
size_t num_layers = sizeof(output->layers) / sizeof(struct wlr_scene_node *);
for (size_t i = 0; i < num_layers; i++) {
((struct wlr_scene_node **) &output->layers)[i] =
&wlr_scene_tree_create(&server->scene->node)->node;
}
wl_list_insert(&server->outputs, &output->link);
output->destroy.notify = output_destroy_notify;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);