diff options
Diffstat (limited to 'include/wlr/render')
-rw-r--r-- | include/wlr/render/dmabuf.h | 48 | ||||
-rw-r--r-- | include/wlr/render/egl.h | 118 | ||||
-rw-r--r-- | include/wlr/render/gles2.h | 27 | ||||
-rw-r--r-- | include/wlr/render/interface.h | 87 | ||||
-rw-r--r-- | include/wlr/render/meson.build | 9 | ||||
-rw-r--r-- | include/wlr/render/wlr_renderer.h | 121 | ||||
-rw-r--r-- | include/wlr/render/wlr_texture.h | 73 |
7 files changed, 483 insertions, 0 deletions
diff --git a/include/wlr/render/dmabuf.h b/include/wlr/render/dmabuf.h new file mode 100644 index 00000000..32cfe874 --- /dev/null +++ b/include/wlr/render/dmabuf.h @@ -0,0 +1,48 @@ +/* + * 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_RENDER_DMABUF_H +#define WLR_RENDER_DMABUF_H + +#include <stdint.h> + +// So we don't have to pull in linux specific drm headers +#ifndef DRM_FORMAT_MOD_INVALID +#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1) +#endif + +#ifndef DRM_FORMAT_MOD_LINEAR +#define DRM_FORMAT_MOD_LINEAR 0 +#endif + +#define WLR_DMABUF_MAX_PLANES 4 + +enum wlr_dmabuf_attributes_flags { + WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT = 1, + WLR_DMABUF_ATTRIBUTES_FLAGS_INTERLACED = 2, + WLR_DMABUF_ATTRIBUTES_FLAGS_BOTTOM_FIRST = 4, +}; + +struct wlr_dmabuf_attributes { + int32_t width, height; + uint32_t format; + uint32_t flags; // enum wlr_dmabuf_attributes_flags + uint64_t modifier; + + int n_planes; + uint32_t offset[WLR_DMABUF_MAX_PLANES]; + uint32_t stride[WLR_DMABUF_MAX_PLANES]; + int fd[WLR_DMABUF_MAX_PLANES]; +}; + +/** + * Closes all file descriptors in the DMA-BUF attributes. + */ +void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs); + +#endif diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h new file mode 100644 index 00000000..269af7e2 --- /dev/null +++ b/include/wlr/render/egl.h @@ -0,0 +1,118 @@ +/* + * 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_RENDER_EGL_H +#define WLR_RENDER_EGL_H + +#include <wlr/config.h> + +#if !WLR_HAS_X11_BACKEND && !WLR_HAS_XWAYLAND && !defined MESA_EGL_NO_X11_HEADERS +#define MESA_EGL_NO_X11_HEADERS +#endif + +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <pixman.h> +#include <stdbool.h> +#include <wayland-server.h> +#include <wlr/render/dmabuf.h> + +struct wlr_egl { + EGLenum platform; + EGLDisplay display; + EGLConfig config; + EGLContext context; + + const char *exts_str; + + struct { + bool bind_wayland_display_wl; + bool buffer_age_ext; + bool image_base_khr; + bool image_dma_buf_export_mesa; + bool image_dmabuf_import_ext; + bool image_dmabuf_import_modifiers_ext; + bool swap_buffers_with_damage_ext; + bool swap_buffers_with_damage_khr; + } exts; + + struct wl_display *wl_display; +}; + +// TODO: Allocate and return a wlr_egl +/** + * Initializes an EGL context for the given platform and remote display. + * Will attempt to load all possibly required api functions. + */ +bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, + EGLint *config_attribs, EGLint visual_id); + +/** + * Frees all related EGL resources, makes the context not-current and + * unbinds a bound wayland display. + */ +void wlr_egl_finish(struct wlr_egl *egl); + +/** + * Binds the given display to the EGL instance. + * This will allow clients to create EGL surfaces from wayland ones and render + * to it. + */ +bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display); + +/** + * Returns a surface for the given native window + * The window must match the remote display the wlr_egl was created with. + */ +EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window); + +/** + * Creates an EGL image from the given wl_drm buffer resource. + */ +EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data, EGLint *fmt, int *width, int *height, + bool *inverted_y); + +/** + * Creates an EGL image from the given dmabuf attributes. Check usability + * of the dmabuf with wlr_egl_check_import_dmabuf once first. + */ +EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, + struct wlr_dmabuf_attributes *attributes); + +/** + * Get the available dmabuf formats + */ +int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int **formats); + +/** + * Get the available dmabuf modifiers for a given format + */ +int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl, int format, + uint64_t **modifiers); + +bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image, + int32_t width, int32_t height, uint32_t flags, + struct wlr_dmabuf_attributes *attribs); + +/** + * Destroys an EGL image created with the given wlr_egl. + */ +bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); + +bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, + int *buffer_age); + +bool wlr_egl_is_current(struct wlr_egl *egl); + +bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, + pixman_region32_t *damage); + +bool wlr_egl_destroy_surface(struct wlr_egl *egl, EGLSurface surface); + +#endif diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h new file mode 100644 index 00000000..fca11ab8 --- /dev/null +++ b/include/wlr/render/gles2.h @@ -0,0 +1,27 @@ +/* + * 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_RENDER_GLES2_H +#define WLR_RENDER_GLES2_H + +#include <wlr/backend.h> +#include <wlr/render/wlr_renderer.h> + +struct wlr_egl; + +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); + +struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); +struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data); +struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, + struct wlr_dmabuf_attributes *attribs); + +#endif diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h new file mode 100644 index 00000000..c98a7cda --- /dev/null +++ b/include/wlr/render/interface.h @@ -0,0 +1,87 @@ +/* + * 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_RENDER_INTERFACE_H +#define WLR_RENDER_INTERFACE_H + +#include <wlr/config.h> + +#if !WLR_HAS_X11_BACKEND && !WLR_HAS_XWAYLAND && !defined MESA_EGL_NO_X11_HEADERS +#define MESA_EGL_NO_X11_HEADERS +#endif + +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <stdbool.h> +#include <wayland-server-protocol.h> +#include <wlr/render/wlr_renderer.h> +#include <wlr/render/wlr_texture.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_output.h> +#include <wlr/render/dmabuf.h> + +struct wlr_renderer_impl { + void (*begin)(struct wlr_renderer *renderer, uint32_t width, + uint32_t height); + void (*end)(struct wlr_renderer *renderer); + void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); + void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); + bool (*render_texture_with_matrix)(struct wlr_renderer *renderer, + struct wlr_texture *texture, const float matrix[static 9], + float alpha); + void (*render_quad_with_matrix)(struct wlr_renderer *renderer, + const float color[static 4], const float matrix[static 9]); + void (*render_ellipse_with_matrix)(struct wlr_renderer *renderer, + const float color[static 4], const float matrix[static 9]); + const enum wl_shm_format *(*formats)( + struct wlr_renderer *renderer, size_t *len); + bool (*format_supported)(struct wlr_renderer *renderer, + enum wl_shm_format fmt); + bool (*resource_is_wl_drm_buffer)(struct wlr_renderer *renderer, + struct wl_resource *resource); + void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer, + struct wl_resource *buffer, int *width, int *height); + int (*get_dmabuf_formats)(struct wlr_renderer *renderer, int **formats); + int (*get_dmabuf_modifiers)(struct wlr_renderer *renderer, int format, + uint64_t **modifiers); + enum wl_shm_format (*preferred_read_format)(struct wlr_renderer *renderer); + bool (*read_pixels)(struct wlr_renderer *renderer, enum wl_shm_format fmt, + uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + void *data); + struct wlr_texture *(*texture_from_pixels)(struct wlr_renderer *renderer, + enum wl_shm_format fmt, uint32_t stride, uint32_t width, + uint32_t height, const void *data); + struct wlr_texture *(*texture_from_wl_drm)(struct wlr_renderer *renderer, + struct wl_resource *data); + struct wlr_texture *(*texture_from_dmabuf)(struct wlr_renderer *renderer, + struct wlr_dmabuf_attributes *attribs); + void (*destroy)(struct wlr_renderer *renderer); + void (*init_wl_display)(struct wlr_renderer *renderer, + struct wl_display *wl_display); +}; + +void wlr_renderer_init(struct wlr_renderer *renderer, + const struct wlr_renderer_impl *impl); + +struct wlr_texture_impl { + void (*get_size)(struct wlr_texture *texture, int *width, int *height); + bool (*is_opaque)(struct wlr_texture *texture); + bool (*write_pixels)(struct wlr_texture *texture, + uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + const void *data); + bool (*to_dmabuf)(struct wlr_texture *texture, + struct wlr_dmabuf_attributes *attribs); + void (*destroy)(struct wlr_texture *texture); +}; + +void wlr_texture_init(struct wlr_texture *texture, + const struct wlr_texture_impl *impl); + +#endif diff --git a/include/wlr/render/meson.build b/include/wlr/render/meson.build new file mode 100644 index 00000000..05127bb7 --- /dev/null +++ b/include/wlr/render/meson.build @@ -0,0 +1,9 @@ +install_headers( + 'dmabuf.h', + 'egl.h', + 'gles2.h', + 'interface.h', + 'wlr_renderer.h', + 'wlr_texture.h', + subdir: 'wlr/render' +) diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h new file mode 100644 index 00000000..9c031b7f --- /dev/null +++ b/include/wlr/render/wlr_renderer.h @@ -0,0 +1,121 @@ +/* + * 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_RENDER_WLR_RENDERER_H +#define WLR_RENDER_WLR_RENDERER_H + +#include <stdint.h> +#include <wayland-server-protocol.h> +#include <wlr/render/egl.h> +#include <wlr/render/wlr_texture.h> +#include <wlr/types/wlr_box.h> + +enum wlr_renderer_read_pixels_flags { + WLR_RENDERER_READ_PIXELS_Y_INVERT = 1, +}; + +struct wlr_renderer_impl; + +struct wlr_renderer { + const struct wlr_renderer_impl *impl; + + struct { + struct wl_signal destroy; + } events; +}; + +struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl, EGLenum platform, + void *remote_display, EGLint *config_attribs, EGLint visual_id); + +void wlr_renderer_begin(struct wlr_renderer *r, int width, int height); +void wlr_renderer_end(struct wlr_renderer *r); +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); +/** + * Defines a scissor box. Only pixels that lie within the scissor box can be + * modified by drawing functions. Providing a NULL `box` disables the scissor + * box. + */ +void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); +/** + * Renders the requested texture. + */ +bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, + const float projection[static 9], int x, int y, float alpha); +/** + * Renders the requested texture using the provided matrix. + */ +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha); +/** + * Renders a solid rectangle in the specified color. + */ +void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]); +/** + * Renders a solid quadrangle in the specified color with the specified matrix. + */ +void wlr_render_quad_with_matrix(struct wlr_renderer *r, + const float color[static 4], const float matrix[static 9]); +/** + * Renders a solid ellipse in the specified color. + */ +void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]); +/** + * Renders a solid ellipse in the specified color with the specified matrix. + */ +void wlr_render_ellipse_with_matrix(struct wlr_renderer *r, + const float color[static 4], const float matrix[static 9]); +/** + * Returns a list of pixel formats supported by this renderer. + */ +const enum wl_shm_format *wlr_renderer_get_formats(struct wlr_renderer *r, + size_t *len); +/** + * Returns true if this wl_buffer is a wl_drm buffer. + */ +bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *renderer, + struct wl_resource *buffer); +/** + * Gets the width and height of a wl_drm buffer. + */ +void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *renderer, + struct wl_resource *buffer, int *width, int *height); +/** + * Get the available dmabuf formats + */ +int wlr_renderer_get_dmabuf_formats(struct wlr_renderer *renderer, + int **formats); +/** + * Get the available dmabuf modifiers for a given format + */ +int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *renderer, int format, + uint64_t **modifiers); +/** + * Reads out of pixels of the currently bound surface into data. `stride` is in + * bytes. + * + * If `flags` is not NULl, the caller indicates that it accepts frame flags + * defined in `enum wlr_renderer_read_pixels_flags`. + */ +bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt, + uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data); +/** + * Checks if a format is supported. + */ +bool wlr_renderer_format_supported(struct wlr_renderer *r, + enum wl_shm_format fmt); +void wlr_renderer_init_wl_display(struct wlr_renderer *r, + struct wl_display *wl_display); +/** + * Destroys this wlr_renderer. Textures must be destroyed separately. + */ +void wlr_renderer_destroy(struct wlr_renderer *renderer); + +#endif diff --git a/include/wlr/render/wlr_texture.h b/include/wlr/render/wlr_texture.h new file mode 100644 index 00000000..f210717a --- /dev/null +++ b/include/wlr/render/wlr_texture.h @@ -0,0 +1,73 @@ +/* + * 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_RENDER_WLR_TEXTURE_H +#define WLR_RENDER_WLR_TEXTURE_H + +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <stdint.h> +#include <wayland-server-protocol.h> +#include <wlr/render/dmabuf.h> + +struct wlr_renderer; +struct wlr_texture_impl; + +struct wlr_texture { + const struct wlr_texture_impl *impl; +}; + +/** + * Create a new texture from raw pixel data. `stride` is in bytes. The returned + * texture is mutable. + */ +struct wlr_texture *wlr_texture_from_pixels(struct wlr_renderer *renderer, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); + +/** + * Create a new texture from a wl_drm resource. The returned texture is + * immutable. + */ +struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer, + struct wl_resource *data); + +/** + * Create a new texture from a DMA-BUF. The returned texture is immutable. + */ +struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer, + struct wlr_dmabuf_attributes *attribs); + +/** + * Get the texture width and height. + */ +void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height); + +/** + * Returns true if this texture is using a fully opaque format. + */ +bool wlr_texture_is_opaque(struct wlr_texture *texture); + +/** + * Update a texture with raw pixels. The texture must be mutable, and the input + * data must have the same pixel format that the texture was created with. + */ +bool wlr_texture_write_pixels(struct wlr_texture *texture, + uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + const void *data); + +bool wlr_texture_to_dmabuf(struct wlr_texture *texture, + struct wlr_dmabuf_attributes *attribs); + +/** + * Destroys this wlr_texture. + */ +void wlr_texture_destroy(struct wlr_texture *texture); + +#endif |