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