1 #ifndef WAYLAND_DRM_H
2 #define WAYLAND_DRM_H
3
4 #include <wayland-server.h>
5
6 struct wl_display;
7 struct wl_resource;
8 struct wl_drm_buffer;
9
10 struct wayland_drm_callbacks {
11 int (*authenticate)(void *user_data, uint32_t id);
12
13 void (*reference_buffer)(void *user_data, uint32_t name, int fd,
14 struct wl_drm_buffer *buffer);
15
16 void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
17
18 bool (*is_format_supported)(void *user_data, uint32_t format);
19 };
20
21 struct wl_drm {
22 struct wl_display *display;
23 struct wl_global *wl_drm_global;
24
25 void *user_data;
26 char *device_name;
27 uint32_t flags;
28
29 struct wayland_drm_callbacks callbacks;
30
31 struct wl_buffer_interface buffer_interface;
32 };
33
34 struct wl_drm_buffer {
35 struct wl_resource *resource;
36 struct wl_drm *drm;
37 int32_t width, height;
38 uint32_t format;
39 const void *driver_format;
40 int32_t offset[3];
41 int32_t stride[3];
42 void *driver_buffer;
43 };
44
45 enum { WAYLAND_DRM_PRIME = 0x01 };
46
47 static inline struct wl_drm_buffer *
wayland_drm_buffer_get(struct wl_drm * drm,struct wl_resource * resource)48 wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource)
49 {
50 if (resource == NULL)
51 return NULL;
52
53 if (wl_resource_instance_of(resource, &wl_buffer_interface,
54 &drm->buffer_interface))
55 return wl_resource_get_user_data(resource);
56 else
57 return NULL;
58 }
59
60 struct wl_drm *
61 wayland_drm_init(struct wl_display *display, char *device_name,
62 const struct wayland_drm_callbacks *callbacks, void *user_data,
63 uint32_t flags);
64
65 void
66 wayland_drm_uninit(struct wl_drm *drm);
67
68 #endif
69