diff options
author | Erik Reider <[email protected]> | 2023-12-30 11:25:16 +0100 |
---|---|---|
committer | Erik Reider <[email protected]> | 2024-01-02 11:21:58 +0100 |
commit | 0b52aa9d137b03017313e028accc92dc5d536440 (patch) | |
tree | 06649993526e0a339fff34f0ae8b4c8ec2fa4d13 /include | |
parent | b929a2bbadf467864796ad4ec90882ce86cfebff (diff) |
Initial rebase without effects
Diffstat (limited to 'include')
-rw-r--r-- | include/render/fx_renderer/matrix.h | 8 | ||||
-rw-r--r-- | include/render/pixel_format.h | 56 | ||||
-rw-r--r-- | include/types/wlr_buffer.h | 69 | ||||
-rw-r--r-- | include/types/wlr_output.h | 10 | ||||
-rw-r--r-- | include/types/wlr_scene.h | 2 | ||||
-rw-r--r-- | include/util/env.h | 14 | ||||
-rw-r--r-- | include/util/time.h | 8 | ||||
-rw-r--r-- | include/wlr/types/wlr_scene.h | 152 |
8 files changed, 219 insertions, 100 deletions
diff --git a/include/render/fx_renderer/matrix.h b/include/render/fx_renderer/matrix.h index 6931e8d..c3bae42 100644 --- a/include/render/fx_renderer/matrix.h +++ b/include/render/fx_renderer/matrix.h @@ -3,7 +3,13 @@ #include <wlr/types/wlr_output.h> +/** + * Writes a 2D orthographic projection matrix to mat of (width, height) with a + * specified wl_output_transform. + * + * Equivalent to glOrtho(0, width, 0, height, 1, -1) with the transform applied. + */ void matrix_projection(float mat[static 9], int width, int height, - enum wl_output_transform transform); + enum wl_output_transform transform); #endif diff --git a/include/render/pixel_format.h b/include/render/pixel_format.h index d045b6a..a024ff9 100644 --- a/include/render/pixel_format.h +++ b/include/render/pixel_format.h @@ -3,24 +3,62 @@ #include <wayland-server-protocol.h> +/** + * Information about a pixel format. + * + * A pixel format is identified via its DRM four character code (see <drm_fourcc.h>). + * + * Simple formats have a block size of 1×1 pixels and bytes_per_block contains + * the number of bytes per pixel (including padding). + * + * Tiled formats (e.g. sub-sampled YCbCr) are described with a block size + * greater than 1×1 pixels. A block is a rectangle of pixels which are stored + * next to each other in a byte-aligned memory region. + */ struct wlr_pixel_format_info { - uint32_t drm_format; + uint32_t drm_format; - /* Equivalent of the format if it has an alpha channel, - * DRM_FORMAT_INVALID (0) if NA - */ - uint32_t opaque_substitute; + /* Equivalent of the format if it has an alpha channel, + * DRM_FORMAT_INVALID (0) if NA + */ + uint32_t opaque_substitute; - /* Bits per pixels */ - uint32_t bpp; + /* Bytes per block (including padding) */ + uint32_t bytes_per_block; + /* Size of a block in pixels (zero for 1×1) */ + uint32_t block_width, block_height; - /* True if the format has an alpha channel */ - bool has_alpha; + /* True if the format has an alpha channel */ + bool has_alpha; }; +/** + * Get pixel format information from a DRM FourCC. + * + * NULL is returned if the pixel format is unknown. + */ const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt); +/** + * Get the number of pixels per block for a pixel format. + */ +uint32_t pixel_format_info_pixels_per_block(const struct wlr_pixel_format_info *info); +/** + * Get the minimum stride for a given pixel format and width. + */ +int32_t pixel_format_info_min_stride(const struct wlr_pixel_format_info *info, int32_t width); +/** + * Check whether a stride is large enough for a given pixel format and width. + */ +bool pixel_format_info_check_stride(const struct wlr_pixel_format_info *info, + int32_t stride, int32_t width); +/** + * Convert an enum wl_shm_format to a DRM FourCC. + */ uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt); +/** + * Convert a DRM FourCC to an enum wl_shm_format. + */ enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt); #endif diff --git a/include/types/wlr_buffer.h b/include/types/wlr_buffer.h index 59d78e9..016cae8 100644 --- a/include/types/wlr_buffer.h +++ b/include/types/wlr_buffer.h @@ -3,75 +3,6 @@ #include <wlr/types/wlr_buffer.h> -struct wlr_shm_client_buffer { - struct wlr_buffer base; - - uint32_t format; - size_t stride; - - // The following fields are NULL if the client has destroyed the wl_buffer - struct wl_resource *resource; - struct wl_shm_buffer *shm_buffer; - - // This is used to keep the backing storage alive after the client has - // destroyed the wl_buffer - struct wl_shm_pool *saved_shm_pool; - void *saved_data; - - struct wl_listener resource_destroy; - struct wl_listener release; -}; - -struct wlr_shm_client_buffer *shm_client_buffer_get_or_create( - struct wl_resource *resource); - -/** - * A read-only buffer that holds a data pointer. - * - * This is suitable for passing raw pixel data to a function that accepts a - * wlr_buffer. - */ -struct wlr_readonly_data_buffer { - struct wlr_buffer base; - - const void *data; - uint32_t format; - size_t stride; - - void *saved_data; -}; - -/** - * Wraps a read-only data pointer into a wlr_buffer. The data pointer may be - * accessed until readonly_data_buffer_drop() is called. - */ -struct wlr_readonly_data_buffer *readonly_data_buffer_create(uint32_t format, - size_t stride, uint32_t width, uint32_t height, const void *data); -/** - * Drops ownership of the buffer (see wlr_buffer_drop() for more details) and - * perform a copy of the data pointer if a consumer still has the buffer locked. - */ -bool readonly_data_buffer_drop(struct wlr_readonly_data_buffer *buffer); - -struct wlr_dmabuf_buffer { - struct wlr_buffer base; - struct wlr_dmabuf_attributes dmabuf; - bool saved; -}; - -/** - * Wraps a DMA-BUF into a wlr_buffer. The DMA-BUF may be accessed until - * dmabuf_buffer_drop() is called. - */ -struct wlr_dmabuf_buffer *dmabuf_buffer_create( - struct wlr_dmabuf_attributes *dmabuf); -/** - * Drops ownership of the buffer (see wlr_buffer_drop() for more details) and - * takes a reference to the DMA-BUF (by dup'ing its file descriptors) if a - * consumer still has the buffer locked. - */ -bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer); - /** * Check whether a buffer is fully opaque. * diff --git a/include/types/wlr_output.h b/include/types/wlr_output.h new file mode 100644 index 0000000..b239b6a --- /dev/null +++ b/include/types/wlr_output.h @@ -0,0 +1,10 @@ +#ifndef TYPES_WLR_OUTPUT_H +#define TYPES_WLR_OUTPUT_H + +#include <wlr/render/drm_format_set.h> +#include <wlr/types/wlr_output.h> + +void output_pending_resolution(struct wlr_output *output, + const struct wlr_output_state *state, int *width, int *height); + +#endif diff --git a/include/types/wlr_scene.h b/include/types/wlr_scene.h index 64c11bc..80dcfd1 100644 --- a/include/types/wlr_scene.h +++ b/include/types/wlr_scene.h @@ -5,4 +5,6 @@ struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node); +void scene_surface_set_clip(struct wlr_scene_surface *surface, struct wlr_box *clip); + #endif diff --git a/include/util/env.h b/include/util/env.h index 6720fa8..e271f4b 100644 --- a/include/util/env.h +++ b/include/util/env.h @@ -4,8 +4,20 @@ #include <stdbool.h> #include <unistd.h> +/** + * Parse a bool from an environment variable. + * + * On success, the parsed value is returned. On error, false is returned. + */ bool env_parse_bool(const char *option); -ssize_t env_parse_switch(const char *option, const char **switches); +/** + * Pick a choice from an environment variable. + * + * On success, the choice index is returned. On error, zero is returned. + * + * switches is a NULL-terminated array. + */ +size_t env_parse_switch(const char *option, const char **switches); #endif diff --git a/include/util/time.h b/include/util/time.h index 287698d..3f76aa4 100644 --- a/include/util/time.h +++ b/include/util/time.h @@ -1,12 +1,13 @@ #ifndef UTIL_TIME_H #define UTIL_TIME_H +#include <stdint.h> #include <time.h> /** * Get the current time, in milliseconds. */ -uint32_t get_current_time_msec(void); +int64_t get_current_time_msec(void); /** * Convert a timespec to milliseconds. @@ -14,6 +15,11 @@ uint32_t get_current_time_msec(void); int64_t timespec_to_msec(const struct timespec *a); /** + * Convert a timespec to nanoseconds. + */ +int64_t timespec_to_nsec(const struct timespec *a); + +/** * Convert nanoseconds to a timespec. */ void timespec_from_nsec(struct timespec *r, int64_t nsec); diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index 7b4c002..f52e167 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -20,21 +20,33 @@ */ #include <pixman.h> +#include <time.h> #include <wayland-server-core.h> -#include <wlr/types/wlr_compositor.h> +#include <wlr/render/wlr_renderer.h> #include <wlr/types/wlr_damage_ring.h> #include "types/fx/shadow_data.h" +#include <wlr/types/wlr_linux_dmabuf_v1.h> +#include <wlr/util/addon.h> +#include <wlr/util/box.h> struct wlr_output; struct wlr_output_layout; +struct wlr_output_layout_output; struct wlr_xdg_surface; struct wlr_layer_surface_v1; +struct wlr_drag_icon; +struct wlr_surface; struct wlr_scene_node; struct wlr_scene_buffer; +struct wlr_scene_output_layout; + +struct wlr_presentation; +struct wlr_linux_dmabuf_v1; +struct wlr_output_state; typedef bool (*wlr_scene_buffer_point_accepts_input_func_t)( - struct wlr_scene_buffer *buffer, int sx, int sy); + struct wlr_scene_buffer *buffer, double *sx, double *sy); typedef void (*wlr_scene_buffer_iterator_func_t)( struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data); @@ -89,10 +101,12 @@ struct wlr_scene { // May be NULL struct wlr_presentation *presentation; + struct wlr_linux_dmabuf_v1 *linux_dmabuf_v1; // private state struct wl_listener presentation_destroy; + struct wl_listener linux_dmabuf_v1_destroy; enum wlr_scene_debug_damage_option debug_damage_option; bool direct_scanout; @@ -106,11 +120,14 @@ struct wlr_scene_surface { // private state + struct wlr_box clip; + struct wlr_addon addon; + struct wl_listener outputs_update; struct wl_listener output_enter; struct wl_listener output_leave; - struct wl_listener output_present; + struct wl_listener output_sample; struct wl_listener frame_done; struct wl_listener surface_destroy; struct wl_listener surface_commit; @@ -123,6 +140,16 @@ struct wlr_scene_rect { float color[4]; }; +struct wlr_scene_outputs_update_event { + struct wlr_scene_output **active; + size_t size; +}; + +struct wlr_scene_output_sample_event { + struct wlr_scene_output *output; + bool direct_scanout; +}; + /** A scene-graph node displaying a buffer */ struct wlr_scene_buffer { struct wlr_scene_node node; @@ -131,9 +158,10 @@ struct wlr_scene_buffer { struct wlr_buffer *buffer; struct { + struct wl_signal outputs_update; // struct wlr_scene_outputs_update_event struct wl_signal output_enter; // struct wlr_scene_output struct wl_signal output_leave; // struct wlr_scene_output - struct wl_signal output_present; // struct wlr_scene_output + struct wl_signal output_sample; // struct wlr_scene_output_sample_event struct wl_signal frame_done; // struct timespec } events; @@ -148,18 +176,20 @@ struct wlr_scene_buffer { */ struct wlr_scene_output *primary_output; - // private state - float opacity; int corner_radius; struct shadow_data shadow_data; - - uint64_t active_outputs; - struct wlr_texture *texture; + enum wlr_scale_filter_mode filter_mode; struct wlr_fbox src_box; int dst_width, dst_height; enum wl_output_transform transform; pixman_region32_t opaque_region; + + // private state + + uint64_t active_outputs; + struct wlr_texture *texture; + struct wlr_linux_dmabuf_feedback_v1_init_options prev_feedback_options; }; /** A viewport for an output in the scene-graph */ @@ -183,7 +213,6 @@ struct wlr_scene_output { bool prev_scanout; struct wl_listener output_commit; - struct wl_listener output_mode; struct wl_listener output_damage; struct wl_listener output_needs_frame; @@ -192,6 +221,11 @@ struct wlr_scene_output { struct wl_array render_list; }; +struct wlr_scene_timer { + int64_t pre_render_duration; + struct wlr_render_timer *render_timer; +}; + /** A layer shell scene helper */ struct wlr_scene_layer_surface_v1 { struct wlr_scene_tree *tree; @@ -269,6 +303,7 @@ struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node, * Create a new scene-graph. */ struct wlr_scene *wlr_scene_create(void); + /** * Handle presentation feedback for all surfaces in the scene, assuming that * scene outputs and the scene rendering functions are used. @@ -279,6 +314,15 @@ void wlr_scene_set_presentation(struct wlr_scene *scene, struct wlr_presentation *presentation); /** + * Handles linux_dmabuf_v1 feedback for all surfaces in the scene. + * + * Asserts that a struct wlr_linux_dmabuf_v1 hasn't already been set for the scene. + */ +void wlr_scene_set_linux_dmabuf_v1(struct wlr_scene *scene, + struct wlr_linux_dmabuf_v1 *linux_dmabuf_v1); + + +/** * Add a node displaying nothing but its children. */ struct wlr_scene_tree *wlr_scene_tree_create(struct wlr_scene_tree *parent); @@ -295,13 +339,29 @@ struct wlr_scene_tree *wlr_scene_tree_create(struct wlr_scene_tree *parent); struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_tree *parent, struct wlr_surface *surface); +/** + * If this node represents a wlr_scene_buffer, that buffer will be returned. It + * is not legal to feed a node that does not represent a wlr_scene_buffer. + */ struct wlr_scene_buffer *wlr_scene_buffer_from_node(struct wlr_scene_node *node); /** + * If this node represents a wlr_scene_tree, that tree will be returned. It + * is not legal to feed a node that does not represent a wlr_scene_tree. + */ +struct wlr_scene_tree *wlr_scene_tree_from_node(struct wlr_scene_node *node); + +/** + * If this node represents a wlr_scene_rect, that rect will be returned. It + * is not legal to feed a node that does not represent a wlr_scene_rect. + */ +struct wlr_scene_rect *wlr_scene_rect_from_node(struct wlr_scene_node *node); + +/** * If this buffer is backed by a surface, then the struct wlr_scene_surface is * returned. If not, NULL will be returned. */ -struct wlr_scene_surface *wlr_scene_surface_from_buffer( +struct wlr_scene_surface *wlr_scene_surface_try_from_buffer( struct wlr_scene_buffer *scene_buffer); /** @@ -343,14 +403,14 @@ void wlr_scene_buffer_set_buffer(struct wlr_scene_buffer *scene_buffer, * the whole buffer node will be damaged. */ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buffer, - struct wlr_buffer *buffer, pixman_region32_t *region); + struct wlr_buffer *buffer, const pixman_region32_t *region); /** * Sets the buffer's opaque region. This is an optimization hint used to * determine if buffers which reside under this one need to be rendered or not. */ void wlr_scene_buffer_set_opaque_region(struct wlr_scene_buffer *scene_buffer, - pixman_region32_t *region); + const pixman_region32_t *region); /** * Set the source rectangle describing the region of the buffer which will be @@ -384,6 +444,12 @@ void wlr_scene_buffer_set_opacity(struct wlr_scene_buffer *scene_buffer, float opacity); /** +* Sets the filter mode to use when scaling the buffer +*/ +void wlr_scene_buffer_set_filter_mode(struct wlr_scene_buffer *scene_buffer, + enum wlr_scale_filter_mode filter_mode); + +/** * Sets the corner radius of this buffer */ void wlr_scene_buffer_set_corner_radius(struct wlr_scene_buffer *scene_buffer, @@ -417,10 +483,32 @@ void wlr_scene_output_destroy(struct wlr_scene_output *scene_output); */ void wlr_scene_output_set_position(struct wlr_scene_output *scene_output, int lx, int ly); + +struct wlr_scene_output_state_options { + struct wlr_scene_timer *timer; +}; + /** * Render and commit an output. */ -bool wlr_scene_output_commit(struct wlr_scene_output *scene_output); +bool wlr_scene_output_commit(struct wlr_scene_output *scene_output, + const struct wlr_scene_output_state_options *options); + +/** + * Render and populate given output state. + */ +bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, + struct wlr_output_state *state, const struct wlr_scene_output_state_options *options); + +/** + * Retrieve the duration in nanoseconds between the last wlr_scene_output_commit() call and the end + * of its operations, including those on the GPU that may have finished after the call returned. + * + * Returns -1 if the duration is unavailable. + */ +int64_t wlr_scene_timer_get_duration_ns(struct wlr_scene_timer *timer); +void wlr_scene_timer_finish(struct wlr_scene_timer *timer); + /** * 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 @@ -446,15 +534,24 @@ struct wlr_scene_output *wlr_scene_get_scene_output(struct wlr_scene *scene, /** * Attach an output layout to a scene. * - * Adding, removing, or repositioning an output in the output layout - * will respectively add, remove or reposition a corresponding - * scene-graph output. When the output layout is destroyed, scene-graph - * outputs which were created by this helper will be destroyed. + * The resulting scene output layout allows to synchronize the positions of scene + * outputs with the positions of corresponding layout outputs. + * + * It is automatically destroyed when the scene or the output layout is destroyed. */ -bool wlr_scene_attach_output_layout(struct wlr_scene *scene, +struct wlr_scene_output_layout *wlr_scene_attach_output_layout(struct wlr_scene *scene, struct wlr_output_layout *output_layout); /** + * Add an output to the scene output layout. + * + * When the layout output is repositioned, the scene output will be repositioned + * accordingly. + */ +void wlr_scene_output_layout_add_output(struct wlr_scene_output_layout *sol, + struct wlr_output_layout_output *lo, struct wlr_scene_output *so); + +/** * Add a node displaying a surface and all of its sub-surfaces to the * scene-graph. */ @@ -462,6 +559,16 @@ struct wlr_scene_tree *wlr_scene_subsurface_tree_create( struct wlr_scene_tree *parent, struct wlr_surface *surface); /** + * Sets a cropping region for any subsurface trees that are children of this + * scene node. The clip coordinate space will be that of the root surface of + * the subsurface tree. + * + * A NULL or empty clip will disable clipping + */ +void wlr_scene_subsurface_tree_set_clip(struct wlr_scene_node *node, + struct wlr_box *clip); + +/** * Add a node displaying an xdg_surface and all of its sub-surfaces to the * scene-graph. * @@ -495,4 +602,11 @@ 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); +/** + * Add a node displaying a drag icon and all its sub-surfaces to the + * scene-graph. + */ +struct wlr_scene_tree *wlr_scene_drag_icon_create( + struct wlr_scene_tree *parent, struct wlr_drag_icon *drag_icon); + #endif |