2019-12-25 18:53:58 +01:00
|
|
|
/*
|
|
|
|
* This an unstable interface of wlroots. No guarantees are made regarding the
|
|
|
|
* future consistency of this API.
|
|
|
|
*/
|
|
|
|
#ifndef WLR_USE_UNSTABLE
|
|
|
|
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WLR_TYPES_WLR_SCENE_H
|
|
|
|
#define WLR_TYPES_WLR_SCENE_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scene-graph API provides a declarative way to display surfaces. The
|
|
|
|
* compositor creates a scene, adds surfaces, then renders the scene on
|
|
|
|
* outputs.
|
|
|
|
*
|
|
|
|
* The scene-graph API only supports basic 2D composition operations (like the
|
|
|
|
* KMS API or the Wayland protocol does). For anything more complicated,
|
|
|
|
* compositors need to implement custom rendering logic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pixman.h>
|
|
|
|
#include <wayland-server-core.h>
|
2022-01-13 09:55:09 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2019-12-25 18:53:58 +01:00
|
|
|
|
|
|
|
struct wlr_output;
|
2021-09-02 12:47:28 +02:00
|
|
|
struct wlr_output_layout;
|
2021-10-25 18:29:24 +02:00
|
|
|
struct wlr_xdg_surface;
|
2022-01-09 23:48:24 +01:00
|
|
|
struct wlr_layer_surface_v1;
|
2019-12-25 18:53:58 +01:00
|
|
|
|
|
|
|
enum wlr_scene_node_type {
|
|
|
|
WLR_SCENE_NODE_ROOT,
|
2021-08-20 11:25:02 +02:00
|
|
|
WLR_SCENE_NODE_TREE,
|
2019-12-25 18:53:58 +01:00
|
|
|
WLR_SCENE_NODE_SURFACE,
|
2021-08-13 22:20:48 +02:00
|
|
|
WLR_SCENE_NODE_RECT,
|
2021-09-20 16:05:19 +02:00
|
|
|
WLR_SCENE_NODE_BUFFER,
|
2019-12-25 18:53:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wlr_scene_node_state {
|
|
|
|
struct wl_list link; // wlr_scene_node_state.children
|
|
|
|
|
|
|
|
struct wl_list children; // wlr_scene_node_state.link
|
|
|
|
|
2020-05-06 16:16:45 +02:00
|
|
|
bool enabled;
|
2019-12-25 18:53:58 +01:00
|
|
|
int x, y; // relative to parent
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A node is an object in the scene. */
|
|
|
|
struct wlr_scene_node {
|
|
|
|
enum wlr_scene_node_type type;
|
|
|
|
struct wlr_scene_node *parent;
|
|
|
|
struct wlr_scene_node_state state;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct wl_signal destroy;
|
|
|
|
} events;
|
2021-08-10 10:42:03 +02:00
|
|
|
|
|
|
|
void *data;
|
2019-12-25 18:53:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** The root scene-graph node. */
|
|
|
|
struct wlr_scene {
|
|
|
|
struct wlr_scene_node node;
|
2021-08-17 12:24:11 +02:00
|
|
|
|
|
|
|
struct wl_list outputs; // wlr_scene_output.link
|
2021-12-14 18:35:44 +01:00
|
|
|
|
|
|
|
// private state
|
|
|
|
|
|
|
|
// May be NULL
|
|
|
|
struct wlr_presentation *presentation;
|
|
|
|
struct wl_listener presentation_destroy;
|
2022-01-18 14:27:37 +01:00
|
|
|
|
|
|
|
// List of buffers which need to be imported as textures
|
|
|
|
struct wl_list pending_buffers; // wlr_scene_buffer.pending_link
|
2019-12-25 18:53:58 +01:00
|
|
|
};
|
|
|
|
|
2021-08-20 11:25:02 +02:00
|
|
|
/** A sub-tree in the scene-graph. */
|
|
|
|
struct wlr_scene_tree {
|
|
|
|
struct wlr_scene_node node;
|
|
|
|
};
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
/** A scene-graph node displaying a single surface. */
|
|
|
|
struct wlr_scene_surface {
|
|
|
|
struct wlr_scene_node node;
|
|
|
|
struct wlr_surface *surface;
|
|
|
|
|
2021-12-11 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* The output that the largest area of this surface is displayed on.
|
|
|
|
* This may be NULL if the surface is not currently displayed on any
|
|
|
|
* outputs. This is the output that should be used for frame callbacks,
|
|
|
|
* presentation feedback, etc.
|
|
|
|
*/
|
|
|
|
struct wlr_output *primary_output;
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
// private state
|
|
|
|
|
2021-12-09 23:17:16 +01:00
|
|
|
int prev_width, prev_height;
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
struct wl_listener surface_destroy;
|
2021-08-17 15:12:47 +02:00
|
|
|
struct wl_listener surface_commit;
|
2019-12-25 18:53:58 +01:00
|
|
|
};
|
|
|
|
|
2021-08-13 22:20:48 +02:00
|
|
|
/** A scene-graph node displaying a solid-colored rectangle */
|
|
|
|
struct wlr_scene_rect {
|
|
|
|
struct wlr_scene_node node;
|
|
|
|
int width, height;
|
|
|
|
float color[4];
|
|
|
|
};
|
|
|
|
|
2021-09-20 16:05:19 +02:00
|
|
|
/** A scene-graph node displaying a buffer */
|
|
|
|
struct wlr_scene_buffer {
|
|
|
|
struct wlr_scene_node node;
|
|
|
|
struct wlr_buffer *buffer;
|
|
|
|
|
|
|
|
// private state
|
|
|
|
|
|
|
|
struct wlr_texture *texture;
|
2021-09-20 17:41:52 +02:00
|
|
|
struct wlr_fbox src_box;
|
2021-09-20 18:05:11 +02:00
|
|
|
int dst_width, dst_height;
|
2021-09-20 18:19:05 +02:00
|
|
|
enum wl_output_transform transform;
|
2022-01-18 14:27:37 +01:00
|
|
|
struct wl_list pending_link; // wlr_scene.pending_buffers
|
2021-09-20 16:05:19 +02:00
|
|
|
};
|
|
|
|
|
2021-08-17 12:24:11 +02:00
|
|
|
/** 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;
|
|
|
|
|
2021-08-17 15:12:47 +02:00
|
|
|
struct wlr_output_damage *damage;
|
|
|
|
|
2021-08-17 12:24:11 +02:00
|
|
|
int x, y;
|
2021-10-20 16:08:47 +02:00
|
|
|
|
|
|
|
// private state
|
|
|
|
|
|
|
|
bool prev_scanout;
|
2021-08-17 12:24:11 +02:00
|
|
|
};
|
|
|
|
|
2022-01-09 23:48:24 +01:00
|
|
|
/** A layer shell scene helper */
|
|
|
|
struct wlr_scene_layer_surface_v1 {
|
|
|
|
struct wlr_scene_node *node;
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface;
|
|
|
|
|
|
|
|
// private state
|
|
|
|
|
|
|
|
struct wl_listener tree_destroy;
|
|
|
|
struct wl_listener layer_surface_destroy;
|
|
|
|
struct wl_listener layer_surface_map;
|
|
|
|
struct wl_listener layer_surface_unmap;
|
|
|
|
};
|
|
|
|
|
2021-08-13 22:18:29 +02:00
|
|
|
typedef void (*wlr_scene_node_iterator_func_t)(struct wlr_scene_node *node,
|
|
|
|
int sx, int sy, void *data);
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
/**
|
|
|
|
* Immediately destroy the scene-graph node.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_destroy(struct wlr_scene_node *node);
|
2020-05-06 16:16:45 +02:00
|
|
|
/**
|
|
|
|
* Enable or disable this node. If a node is disabled, all of its children are
|
|
|
|
* implicitly disabled as well.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled);
|
2019-12-25 18:53:58 +01:00
|
|
|
/**
|
|
|
|
* Set the position of the node relative to its parent.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y);
|
|
|
|
/**
|
|
|
|
* Move the node right above the specified sibling.
|
2021-10-13 16:00:53 +02:00
|
|
|
* Asserts that node and sibling are distinct and share the same parent.
|
2019-12-25 18:53:58 +01:00
|
|
|
*/
|
|
|
|
void wlr_scene_node_place_above(struct wlr_scene_node *node,
|
|
|
|
struct wlr_scene_node *sibling);
|
|
|
|
/**
|
|
|
|
* Move the node right below the specified sibling.
|
2021-10-13 16:00:53 +02:00
|
|
|
* Asserts that node and sibling are distinct and share the same parent.
|
2019-12-25 18:53:58 +01:00
|
|
|
*/
|
|
|
|
void wlr_scene_node_place_below(struct wlr_scene_node *node,
|
|
|
|
struct wlr_scene_node *sibling);
|
2021-10-13 16:11:54 +02:00
|
|
|
/**
|
|
|
|
* Move the node above all of its sibling nodes.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_raise_to_top(struct wlr_scene_node *node);
|
|
|
|
/**
|
|
|
|
* Move the node below all of its sibling nodes.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_lower_to_bottom(struct wlr_scene_node *node);
|
2021-08-23 21:32:59 +02:00
|
|
|
/**
|
|
|
|
* Move the node to another location in the tree.
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_reparent(struct wlr_scene_node *node,
|
|
|
|
struct wlr_scene_node *new_parent);
|
2021-08-17 13:20:32 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2019-12-25 18:53:58 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* (in rendering order).
|
|
|
|
*/
|
|
|
|
void wlr_scene_node_for_each_surface(struct wlr_scene_node *node,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data);
|
2021-08-10 11:26:34 +02:00
|
|
|
/**
|
2021-08-28 21:14:16 +02:00
|
|
|
* Find the topmost node in this scene-graph that contains the point at the
|
|
|
|
* given layout-local coordinates. (For surface nodes, this means accepting
|
|
|
|
* input events at that point.) Returns the node and coordinates relative to the
|
|
|
|
* returned node, or NULL if no node is found at that location.
|
2021-08-10 11:26:34 +02:00
|
|
|
*/
|
2021-08-28 21:14:16 +02:00
|
|
|
struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node,
|
|
|
|
double lx, double ly, double *nx, double *ny);
|
2019-12-25 18:53:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new scene-graph.
|
|
|
|
*/
|
|
|
|
struct wlr_scene *wlr_scene_create(void);
|
|
|
|
/**
|
|
|
|
* Manually render the scene-graph on an output. The compositor needs to call
|
|
|
|
* wlr_renderer_begin before and wlr_renderer_end after calling this function.
|
|
|
|
* Damage is given in output-buffer-local coordinates and can be set to NULL to
|
|
|
|
* disable damage tracking.
|
|
|
|
*/
|
|
|
|
void wlr_scene_render_output(struct wlr_scene *scene, struct wlr_output *output,
|
|
|
|
int lx, int ly, pixman_region32_t *damage);
|
2021-12-14 18:35:44 +01:00
|
|
|
/**
|
|
|
|
* Handle presentation feedback for all surfaces in the scene, assuming that
|
|
|
|
* scene outputs and the scene rendering functions are used.
|
|
|
|
*
|
|
|
|
* Asserts that a wlr_presentation hasn't already been set for the scene.
|
|
|
|
*/
|
|
|
|
void wlr_scene_set_presentation(struct wlr_scene *scene,
|
|
|
|
struct wlr_presentation *presentation);
|
2019-12-25 18:53:58 +01:00
|
|
|
|
2021-08-20 11:25:02 +02:00
|
|
|
/**
|
|
|
|
* Add a node displaying nothing but its children.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_tree *wlr_scene_tree_create(struct wlr_scene_node *parent);
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
/**
|
|
|
|
* Add a node displaying a single surface to the scene-graph.
|
|
|
|
*
|
|
|
|
* The child sub-surfaces are ignored.
|
2021-12-09 23:17:16 +01:00
|
|
|
*
|
|
|
|
* wlr_surface_send_enter()/wlr_surface_send_leave() will be called
|
|
|
|
* automatically based on the position of the surface and outputs in
|
|
|
|
* the scene.
|
2019-12-25 18:53:58 +01:00
|
|
|
*/
|
|
|
|
struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_node *parent,
|
|
|
|
struct wlr_surface *surface);
|
|
|
|
|
2021-08-28 21:14:16 +02:00
|
|
|
struct wlr_scene_surface *wlr_scene_surface_from_node(struct wlr_scene_node *node);
|
|
|
|
|
2021-08-13 22:20:48 +02:00
|
|
|
/**
|
|
|
|
* Add a node displaying a solid-colored rectangle to the scene-graph.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_rect *wlr_scene_rect_create(struct wlr_scene_node *parent,
|
|
|
|
int width, int height, const float color[static 4]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the width and height of an existing rectangle node.
|
|
|
|
*/
|
|
|
|
void wlr_scene_rect_set_size(struct wlr_scene_rect *rect, int width, int height);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the color of an existing rectangle node.
|
|
|
|
*/
|
|
|
|
void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[static 4]);
|
|
|
|
|
2021-09-20 16:05:19 +02:00
|
|
|
/**
|
|
|
|
* Add a node displaying a buffer to the scene-graph.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_buffer *wlr_scene_buffer_create(struct wlr_scene_node *parent,
|
|
|
|
struct wlr_buffer *buffer);
|
|
|
|
|
2021-09-20 17:41:52 +02:00
|
|
|
/**
|
|
|
|
* Set the source rectangle describing the region of the buffer which will be
|
|
|
|
* sampled to render this node. This allows cropping the buffer.
|
|
|
|
*
|
|
|
|
* If NULL, the whole buffer is sampled. By default, the source box is NULL.
|
|
|
|
*/
|
|
|
|
void wlr_scene_buffer_set_source_box(struct wlr_scene_buffer *scene_buffer,
|
|
|
|
const struct wlr_fbox *box);
|
|
|
|
|
2021-09-20 18:05:11 +02:00
|
|
|
/**
|
|
|
|
* Set the destination size describing the region of the scene-graph the buffer
|
|
|
|
* will be painted onto. This allows scaling the buffer.
|
|
|
|
*
|
|
|
|
* If zero, the destination size will be the buffer size. By default, the
|
|
|
|
* destination size is zero.
|
|
|
|
*/
|
|
|
|
void wlr_scene_buffer_set_dest_size(struct wlr_scene_buffer *scene_buffer,
|
|
|
|
int width, int height);
|
|
|
|
|
2021-09-20 18:19:05 +02:00
|
|
|
/**
|
|
|
|
* Set a transform which will be applied to the buffer.
|
|
|
|
*/
|
|
|
|
void wlr_scene_buffer_set_transform(struct wlr_scene_buffer *scene_buffer,
|
|
|
|
enum wl_output_transform transform);
|
|
|
|
|
2021-08-17 12:24:11 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2021-08-17 12:30:17 +02:00
|
|
|
/**
|
|
|
|
* Render and commit an output.
|
|
|
|
*/
|
|
|
|
bool wlr_scene_output_commit(struct wlr_scene_output *scene_output);
|
2021-12-13 17:23:47 +01:00
|
|
|
/**
|
|
|
|
* Call wlr_surface_send_frame_done() on all surfaces in the scene rendered by
|
|
|
|
* wlr_scene_output_commit() for which wlr_scene_surface->primary_output
|
|
|
|
* matches the given scene_output.
|
|
|
|
*/
|
|
|
|
void wlr_scene_output_send_frame_done(struct wlr_scene_output *scene_output,
|
|
|
|
struct timespec *now);
|
2021-10-20 18:16:27 +02:00
|
|
|
/**
|
|
|
|
* Call `iterator` on each surface in the scene-graph visible on the output,
|
|
|
|
* with the surface's position in layout coordinates. The function is called
|
|
|
|
* from root to leaves (in rendering order).
|
|
|
|
*/
|
|
|
|
void wlr_scene_output_for_each_surface(struct wlr_scene_output *scene_output,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data);
|
2021-11-30 20:55:04 +01:00
|
|
|
/**
|
|
|
|
* Get a scene-graph output from a wlr_output.
|
|
|
|
*
|
|
|
|
* If the output hasn't been added to the scene-graph, returns NULL.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_output *wlr_scene_get_scene_output(struct wlr_scene *scene,
|
|
|
|
struct wlr_output *output);
|
2021-10-20 18:16:27 +02:00
|
|
|
|
2021-09-02 12:47:28 +02:00
|
|
|
/**
|
|
|
|
* Attach an output layout to a scene.
|
|
|
|
*
|
|
|
|
* Outputs in the output layout are automatically added to the scene. Any
|
|
|
|
* change to the output layout is mirrored to the scene-graph outputs.
|
|
|
|
*/
|
|
|
|
bool wlr_scene_attach_output_layout(struct wlr_scene *scene,
|
|
|
|
struct wlr_output_layout *output_layout);
|
|
|
|
|
2021-08-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* Add a node displaying a surface and all of its sub-surfaces to the
|
|
|
|
* scene-graph.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_node *wlr_scene_subsurface_tree_create(
|
|
|
|
struct wlr_scene_node *parent, struct wlr_surface *surface);
|
|
|
|
|
2021-10-25 18:29:24 +02:00
|
|
|
/**
|
|
|
|
* Add a node displaying an xdg_surface and all of its sub-surfaces to the
|
|
|
|
* scene-graph.
|
|
|
|
*
|
|
|
|
* The origin of the returned scene-graph node will match the top-left corner
|
|
|
|
* of the xdg_surface window geometry.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_node *wlr_scene_xdg_surface_create(
|
|
|
|
struct wlr_scene_node *parent, struct wlr_xdg_surface *xdg_surface);
|
|
|
|
|
2022-01-09 23:48:24 +01:00
|
|
|
/**
|
|
|
|
* Add a node displaying a layer_surface_v1 and all of its sub-surfaces to the
|
|
|
|
* scene-graph.
|
|
|
|
*
|
|
|
|
* The origin of the returned scene-graph node will match the top-left corner
|
|
|
|
* of the layer surface.
|
|
|
|
*/
|
|
|
|
struct wlr_scene_layer_surface_v1 *wlr_scene_layer_surface_v1_create(
|
|
|
|
struct wlr_scene_node *parent, struct wlr_layer_surface_v1 *layer_surface);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure a layer_surface_v1, position its scene node in accordance to its
|
|
|
|
* current state, and update the remaining usable area.
|
|
|
|
*
|
|
|
|
* full_area represents the entire area that may be used by the layer surface
|
|
|
|
* if its exclusive_zone is -1, and is usually the output dimensions.
|
|
|
|
* usable_area represents what remains of full_area that can be used if
|
|
|
|
* exclusive_zone is >= 0. usable_area is updated if the surface has a positive
|
|
|
|
* exclusive_zone, so that it can be used for the next layer surface.
|
|
|
|
*/
|
|
|
|
void wlr_scene_layer_surface_v1_configure(
|
|
|
|
struct wlr_scene_layer_surface_v1 *scene_layer_surface,
|
|
|
|
const struct wlr_box *full_area, struct wlr_box *usable_area);
|
|
|
|
|
2019-12-25 18:53:58 +01:00
|
|
|
#endif
|