1848b8605Smrg#ifndef WAYLAND_DRM_H
2848b8605Smrg#define WAYLAND_DRM_H
3848b8605Smrg
4848b8605Smrg#include <wayland-server.h>
5848b8605Smrg
6b8e80941Smrgstruct wl_display;
7b8e80941Smrgstruct wl_resource;
8b8e80941Smrgstruct wl_drm_buffer;
9b8e80941Smrg
10b8e80941Smrgstruct wayland_drm_callbacks {
11b8e80941Smrg	int (*authenticate)(void *user_data, uint32_t id);
12b8e80941Smrg
13b8e80941Smrg	void (*reference_buffer)(void *user_data, uint32_t name, int fd,
14b8e80941Smrg                                 struct wl_drm_buffer *buffer);
15b8e80941Smrg
16b8e80941Smrg	void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
17b8e80941Smrg
18b8e80941Smrg	bool (*is_format_supported)(void *user_data, uint32_t format);
19848b8605Smrg};
20848b8605Smrg
21b8e80941Smrg
22b8e80941Smrgstruct wl_drm {
23b8e80941Smrg	struct wl_display *display;
24b8e80941Smrg	struct wl_global *wl_drm_global;
25b8e80941Smrg
26b8e80941Smrg	void *user_data;
27b8e80941Smrg	char *device_name;
28b8e80941Smrg	uint32_t flags;
29b8e80941Smrg
30b8e80941Smrg	struct wayland_drm_callbacks callbacks;
31b8e80941Smrg
32b8e80941Smrg	struct wl_buffer_interface buffer_interface;
33b8e80941Smrg};
34848b8605Smrg
35848b8605Smrgstruct wl_drm_buffer {
36848b8605Smrg	struct wl_resource *resource;
37848b8605Smrg	struct wl_drm *drm;
38848b8605Smrg	int32_t width, height;
39848b8605Smrg	uint32_t format;
40848b8605Smrg        const void *driver_format;
41848b8605Smrg        int32_t offset[3];
42848b8605Smrg        int32_t stride[3];
43848b8605Smrg	void *driver_buffer;
44848b8605Smrg};
45848b8605Smrg
46848b8605Smrgenum { WAYLAND_DRM_PRIME = 0x01 };
47848b8605Smrg
48b8e80941Smrgstatic inline struct wl_drm_buffer *
49b8e80941Smrgwayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource)
50b8e80941Smrg{
51b8e80941Smrg	if (resource == NULL)
52b8e80941Smrg		return NULL;
53b8e80941Smrg
54b8e80941Smrg	if (wl_resource_instance_of(resource, &wl_buffer_interface,
55b8e80941Smrg	                            &drm->buffer_interface))
56b8e80941Smrg		return wl_resource_get_user_data(resource);
57b8e80941Smrg	else
58b8e80941Smrg		return NULL;
59b8e80941Smrg}
60848b8605Smrg
61848b8605Smrgstruct wl_drm *
62848b8605Smrgwayland_drm_init(struct wl_display *display, char *device_name,
63b8e80941Smrg		 const struct wayland_drm_callbacks *callbacks, void *user_data,
64848b8605Smrg                 uint32_t flags);
65848b8605Smrg
66848b8605Smrgvoid
67848b8605Smrgwayland_drm_uninit(struct wl_drm *drm);
68848b8605Smrg
69848b8605Smrg#endif
70