2018-07-13 14:40:56 +02: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
|
|
|
|
|
2018-03-19 23:16:29 +01:00
|
|
|
#ifndef WLR_RENDER_WLR_RENDERER_H
|
|
|
|
#define WLR_RENDER_WLR_RENDERER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <wayland-server-protocol.h>
|
2021-01-14 04:49:07 +01:00
|
|
|
#include <wlr/backend.h>
|
2018-03-19 23:16:29 +01:00
|
|
|
#include <wlr/render/wlr_texture.h>
|
|
|
|
#include <wlr/types/wlr_box.h>
|
|
|
|
|
2018-06-23 15:02:43 +02:00
|
|
|
enum wlr_renderer_read_pixels_flags {
|
|
|
|
WLR_RENDERER_READ_PIXELS_Y_INVERT = 1,
|
|
|
|
};
|
|
|
|
|
2018-04-26 01:11:36 +02:00
|
|
|
struct wlr_renderer_impl;
|
2019-04-01 18:17:23 +02:00
|
|
|
struct wlr_drm_format_set;
|
2020-07-28 16:56:18 +02:00
|
|
|
struct wlr_buffer;
|
2018-03-19 23:16:29 +01:00
|
|
|
|
2018-04-26 01:11:36 +02:00
|
|
|
struct wlr_renderer {
|
|
|
|
const struct wlr_renderer_impl *impl;
|
|
|
|
|
2019-12-28 11:53:11 +01:00
|
|
|
bool rendering;
|
|
|
|
|
2018-04-26 01:11:36 +02:00
|
|
|
struct {
|
|
|
|
struct wl_signal destroy;
|
|
|
|
} events;
|
|
|
|
};
|
2018-03-19 23:16:29 +01:00
|
|
|
|
2021-01-14 04:49:07 +01:00
|
|
|
struct wlr_renderer *wlr_renderer_autocreate(struct wlr_backend *backend);
|
2018-05-25 12:14:35 +02:00
|
|
|
|
2020-10-11 16:06:26 +02:00
|
|
|
void wlr_renderer_begin(struct wlr_renderer *r, uint32_t width, uint32_t height);
|
2018-03-19 23:16:29 +01:00
|
|
|
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);
|
2020-04-27 12:27:01 +02:00
|
|
|
/**
|
|
|
|
* Renders the requested texture using the provided matrix, after cropping it
|
|
|
|
* to the provided rectangle.
|
|
|
|
*/
|
|
|
|
bool wlr_render_subtexture_with_matrix(struct wlr_renderer *r,
|
|
|
|
struct wlr_texture *texture, const struct wlr_fbox *box,
|
|
|
|
const float matrix[static 9], float alpha);
|
2018-03-19 23:16:29 +01:00
|
|
|
/**
|
2018-03-26 18:41:51 +02:00
|
|
|
* Renders a solid rectangle in the specified color.
|
2018-03-19 23:16:29 +01:00
|
|
|
*/
|
2018-03-26 18:41:51 +02:00
|
|
|
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,
|
2018-03-19 23:16:29 +01:00
|
|
|
const float color[static 4], const float matrix[static 9]);
|
|
|
|
/**
|
|
|
|
* Renders a solid ellipse in the specified color.
|
|
|
|
*/
|
2018-03-26 18:41:51 +02:00
|
|
|
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,
|
2018-03-19 23:16:29 +01:00
|
|
|
const float color[static 4], const float matrix[static 9]);
|
|
|
|
/**
|
2020-11-18 13:40:08 +01:00
|
|
|
* Get the shared-memory formats supporting import usage. Buffers allocated
|
|
|
|
* with a format from this list may be imported via wlr_texture_from_pixels.
|
2018-03-19 23:16:29 +01:00
|
|
|
*/
|
2020-11-18 14:57:53 +01:00
|
|
|
const enum wl_shm_format *wlr_renderer_get_shm_texture_formats(
|
|
|
|
struct wlr_renderer *r, size_t *len);
|
2018-03-19 23:16:29 +01:00
|
|
|
/**
|
2018-03-24 23:30:28 +01:00
|
|
|
* Returns true if this wl_buffer is a wl_drm buffer.
|
2018-03-19 23:16:29 +01:00
|
|
|
*/
|
2018-03-24 23:30:28 +01:00
|
|
|
bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *renderer,
|
2018-03-19 23:16:29 +01:00
|
|
|
struct wl_resource *buffer);
|
2018-03-24 23:30:28 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
2018-04-08 17:00:56 +02:00
|
|
|
/**
|
2020-11-18 13:40:08 +01:00
|
|
|
* Get the DMA-BUF formats supporting sampling usage. Buffers allocated with
|
|
|
|
* a format from this list may be imported via wlr_texture_from_dmabuf.
|
2018-04-08 17:00:56 +02:00
|
|
|
*/
|
2020-11-18 14:53:13 +01:00
|
|
|
const struct wlr_drm_format_set *wlr_renderer_get_dmabuf_texture_formats(
|
2019-04-01 18:17:23 +02:00
|
|
|
struct wlr_renderer *renderer);
|
2018-03-19 23:16:29 +01:00
|
|
|
/**
|
|
|
|
* Reads out of pixels of the currently bound surface into data. `stride` is in
|
|
|
|
* bytes.
|
2018-06-23 15:02:43 +02:00
|
|
|
*
|
|
|
|
* If `flags` is not NULl, the caller indicates that it accepts frame flags
|
|
|
|
* defined in `enum wlr_renderer_read_pixels_flags`.
|
2018-03-19 23:16:29 +01:00
|
|
|
*/
|
|
|
|
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
2018-06-23 15:02:43 +02:00
|
|
|
uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height,
|
2018-03-19 23:16:29 +01:00
|
|
|
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data);
|
2020-04-23 01:23:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Blits the dmabuf in src onto the one in dst.
|
|
|
|
*/
|
|
|
|
bool wlr_renderer_blit_dmabuf(struct wlr_renderer *r,
|
|
|
|
struct wlr_dmabuf_attributes *dst, struct wlr_dmabuf_attributes *src);
|
2020-03-23 14:32:27 +01:00
|
|
|
/**
|
|
|
|
* Creates necessary shm and invokes the initialization of the implementation.
|
|
|
|
*
|
|
|
|
* Returns false on failure.
|
|
|
|
*/
|
|
|
|
bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
|
2018-05-21 20:07:08 +02:00
|
|
|
struct wl_display *wl_display);
|
2019-11-07 19:38:45 +01:00
|
|
|
|
2020-06-10 14:47:12 +02:00
|
|
|
/**
|
|
|
|
* Obtains the FD of the DRM device used for rendering, or -1 if unavailable.
|
|
|
|
*
|
|
|
|
* The caller doesn't have ownership of the FD, it must not close it.
|
|
|
|
*/
|
|
|
|
int wlr_renderer_get_drm_fd(struct wlr_renderer *r);
|
|
|
|
|
2018-03-19 23:16:29 +01:00
|
|
|
/**
|
|
|
|
* Destroys this wlr_renderer. Textures must be destroyed separately.
|
|
|
|
*/
|
|
|
|
void wlr_renderer_destroy(struct wlr_renderer *renderer);
|
|
|
|
|
|
|
|
#endif
|