Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

scene: add support for damage tracking #3117

Merged
merged 6 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 4 additions & 18 deletions examples/scene-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,15 @@ struct output {
struct wl_list link;
struct server *server;
struct wlr_output *wlr;
struct wlr_scene_output *scene_output;

struct wl_listener frame;
};

static void output_handle_frame(struct wl_listener *listener, void *data) {
struct output *output = wl_container_of(listener, output, frame);

if (!wlr_output_attach_render(output->wlr, NULL)) {
return;
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(output->wlr->backend);
assert(renderer != NULL);

int width, height;
wlr_output_effective_resolution(output->wlr, &width, &height);
wlr_renderer_begin(renderer, width, height);
wlr_renderer_clear(renderer, (float[4]){ 0.3, 0.3, 0.3, 1.0 });

wlr_scene_render_output(output->server->scene, output->wlr, 0, 0, NULL);
wlr_output_render_software_cursors(output->wlr, NULL);

wlr_renderer_end(renderer);

if (!wlr_output_commit(output->wlr)) {
if (!wlr_scene_output_commit(output->scene_output)) {
return;
}

Expand All @@ -97,6 +81,8 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link);

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

if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
wlr_output_set_mode(wlr_output, mode);
Expand Down
42 changes: 42 additions & 0 deletions include/wlr/types/wlr_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct wlr_scene_node {
/** The root scene-graph node. */
struct wlr_scene {
struct wlr_scene_node node;

struct wl_list outputs; // wlr_scene_output.link
};

/** A scene-graph node displaying a single surface. */
Expand All @@ -66,6 +68,7 @@ struct wlr_scene_surface {
// private state

struct wl_listener surface_destroy;
struct wl_listener surface_commit;
};

/** A scene-graph node displaying a solid-colored rectangle */
Expand All @@ -75,6 +78,18 @@ struct wlr_scene_rect {
float color[4];
};

/** A viewport for an output in the scene-graph */
struct wlr_scene_output {
struct wlr_output *output;
struct wl_list link; // wlr_scene.outputs
struct wlr_scene *scene;
struct wlr_addon addon;

struct wlr_output_damage *damage;

int x, y;
};

typedef void (*wlr_scene_node_iterator_func_t)(struct wlr_scene_node *node,
int sx, int sy, void *data);

Expand Down Expand Up @@ -106,6 +121,12 @@ void wlr_scene_node_place_below(struct wlr_scene_node *node,
*/
void wlr_scene_node_reparent(struct wlr_scene_node *node,
struct wlr_scene_node *new_parent);
/**
* Get the node's layout-local coordinates.
*
* True is returned if the node and all of its ancestors are enabled.
*/
bool wlr_scene_node_coords(struct wlr_scene_node *node, int *lx, int *ly);
/**
* Call `iterator` on each surface in the scene-graph, with the surface's
* position in layout coordinates. The function is called from root to leaves
Expand Down Expand Up @@ -161,4 +182,25 @@ void wlr_scene_rect_set_size(struct wlr_scene_rect *rect, int width, int height)
*/
void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[static 4]);

/**
* Add a viewport for the specified output to the scene-graph.
*
* An output can only be added once to the scene-graph.
*/
struct wlr_scene_output *wlr_scene_output_create(struct wlr_scene *scene,
struct wlr_output *output);
/**
* Destroy a scene-graph output.
*/
void wlr_scene_output_destroy(struct wlr_scene_output *scene_output);
/**
* Set the output's position in the scene-graph.
*/
void wlr_scene_output_set_position(struct wlr_scene_output *scene_output,
int lx, int ly);
/**
* Render and commit an output.
*/
bool wlr_scene_output_commit(struct wlr_scene_output *scene_output);

#endif