blob: cd30f91c8bf6fcec39eb0f667c7556118d0bd05c [file] [log] [blame]
Pekka Paalanen230f3b12014-09-29 14:18:40 -04001/*
2 * Copyright © 2014, 2015 Collabora, Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifndef WESTON_LINUX_DMABUF_H
24#define WESTON_LINUX_DMABUF_H
25
26#include <stdint.h>
27
28#define MAX_DMABUF_PLANES 4
29
30struct linux_dmabuf_buffer;
31typedef void (*dmabuf_user_data_destroy_func)(
32 struct linux_dmabuf_buffer *buffer);
33
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000034struct dmabuf_attributes {
Pekka Paalanen230f3b12014-09-29 14:18:40 -040035 int32_t width;
36 int32_t height;
37 uint32_t format;
38 uint32_t flags; /* enum zlinux_buffer_params_flags */
39 int n_planes;
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000040 int fd[MAX_DMABUF_PLANES];
Pekka Paalanen230f3b12014-09-29 14:18:40 -040041 uint32_t offset[MAX_DMABUF_PLANES];
42 uint32_t stride[MAX_DMABUF_PLANES];
43 uint64_t modifier[MAX_DMABUF_PLANES];
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000044};
45
46struct linux_dmabuf_buffer {
47 struct wl_resource *buffer_resource;
48 struct wl_resource *params_resource;
49 struct weston_compositor *compositor;
50 struct dmabuf_attributes attributes;
Pekka Paalanen230f3b12014-09-29 14:18:40 -040051
52 void *user_data;
53 dmabuf_user_data_destroy_func user_data_destroy_func;
54
55 /* XXX:
56 *
57 * Add backend private data. This would be for the backend
58 * to do all additional imports it might ever use in advance.
59 * The basic principle, even if not implemented in drivers today,
60 * is that dmabufs are first attached, but the actual allocation
61 * is deferred to first use. This would allow the exporter and all
62 * attachers to agree on how to allocate.
63 *
64 * The DRM backend would use this to create drmFBs for each
65 * dmabuf_buffer, just in case at some point it would become
66 * feasible to scan it out directly. This would improve the
67 * possibilities to successfully scan out, avoiding compositing.
68 */
69};
70
71int
72linux_dmabuf_setup(struct weston_compositor *compositor);
73
74struct linux_dmabuf_buffer *
75linux_dmabuf_buffer_get(struct wl_resource *resource);
76
77void
78linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
79 void *data,
80 dmabuf_user_data_destroy_func func);
81void *
82linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer);
83
84void
85linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
86 const char *msg);
87
88#endif /* WESTON_LINUX_DMABUF_H */