1 /*
2  * This an unstable interface of wlroots. No guarantees are made regarding the
3  * future consistency of this API.
4  */
5 #ifndef WLR_USE_UNSTABLE
6 #error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
7 #endif
8 
9 #ifndef WLR_RENDER_INTERFACE_H
10 #define WLR_RENDER_INTERFACE_H
11 
12 #ifndef MESA_EGL_NO_X11_HEADERS
13 #define MESA_EGL_NO_X11_HEADERS
14 #endif
15 #ifndef EGL_NO_X11
16 #define EGL_NO_X11
17 #endif
18 #ifndef EGL_NO_PLATFORM_SPECIFIC_TYPES
19 #define EGL_NO_PLATFORM_SPECIFIC_TYPES
20 #endif
21 
22 #include <EGL/egl.h>
23 #include <EGL/eglext.h>
24 #include <stdbool.h>
25 #include <wayland-server-protocol.h>
26 #include <wlr/render/wlr_renderer.h>
27 #include <wlr/render/wlr_texture.h>
28 #include <wlr/types/wlr_box.h>
29 #include <wlr/types/wlr_output.h>
30 #include <wlr/render/dmabuf.h>
31 
32 struct wlr_renderer_impl {
33 	void (*begin)(struct wlr_renderer *renderer, uint32_t width,
34 		uint32_t height);
35 	void (*end)(struct wlr_renderer *renderer);
36 	void (*clear)(struct wlr_renderer *renderer, const float color[static 4]);
37 	void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
38 	bool (*render_subtexture_with_matrix)(struct wlr_renderer *renderer,
39 		struct wlr_texture *texture, const struct wlr_fbox *box,
40 		const float matrix[static 9], float alpha);
41 	void (*render_quad_with_matrix)(struct wlr_renderer *renderer,
42 		const float color[static 4], const float matrix[static 9]);
43 	void (*render_ellipse_with_matrix)(struct wlr_renderer *renderer,
44 		const float color[static 4], const float matrix[static 9]);
45 	const enum wl_shm_format *(*formats)(
46 		struct wlr_renderer *renderer, size_t *len);
47 	bool (*format_supported)(struct wlr_renderer *renderer,
48 		enum wl_shm_format fmt);
49 	bool (*resource_is_wl_drm_buffer)(struct wlr_renderer *renderer,
50 		struct wl_resource *resource);
51 	void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
52 		struct wl_resource *buffer, int *width, int *height);
53 	const struct wlr_drm_format_set *(*get_dmabuf_formats)(
54 		struct wlr_renderer *renderer);
55 	enum wl_shm_format (*preferred_read_format)(struct wlr_renderer *renderer);
56 	bool (*read_pixels)(struct wlr_renderer *renderer, enum wl_shm_format fmt,
57 		uint32_t *flags, uint32_t stride, uint32_t width, uint32_t height,
58 		uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
59 		void *data);
60 	struct wlr_texture *(*texture_from_pixels)(struct wlr_renderer *renderer,
61 		enum wl_shm_format fmt, uint32_t stride, uint32_t width,
62 		uint32_t height, const void *data);
63 	struct wlr_texture *(*texture_from_wl_drm)(struct wlr_renderer *renderer,
64 		struct wl_resource *data);
65 	struct wlr_texture *(*texture_from_dmabuf)(struct wlr_renderer *renderer,
66 		struct wlr_dmabuf_attributes *attribs);
67 	void (*destroy)(struct wlr_renderer *renderer);
68 	bool (*init_wl_display)(struct wlr_renderer *renderer,
69 		struct wl_display *wl_display);
70 	bool (*blit_dmabuf)(struct wlr_renderer *renderer,
71 		struct wlr_dmabuf_attributes *dst,
72 		struct wlr_dmabuf_attributes *src);
73 };
74 
75 void wlr_renderer_init(struct wlr_renderer *renderer,
76 	const struct wlr_renderer_impl *impl);
77 
78 struct wlr_texture_impl {
79 	bool (*is_opaque)(struct wlr_texture *texture);
80 	bool (*write_pixels)(struct wlr_texture *texture,
81 		uint32_t stride, uint32_t width, uint32_t height,
82 		uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
83 		const void *data);
84 	bool (*to_dmabuf)(struct wlr_texture *texture,
85 		struct wlr_dmabuf_attributes *attribs);
86 	void (*destroy)(struct wlr_texture *texture);
87 };
88 
89 void wlr_texture_init(struct wlr_texture *texture,
90 	const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
91 
92 #endif
93