blob: f4ab52cbd2f7a9ae0e404917c9640af911e5c613 [file] [log] [blame]
Pekka Paalanen230f3b12014-09-29 14:18:40 -04001/*
2 * Copyright © 2014, 2015 Collabora, Ltd.
3 *
Yong Bakos53361532017-01-23 06:17:44 -08004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Pekka Paalanen230f3b12014-09-29 14:18:40 -040011 *
Yong Bakos53361532017-01-23 06:17:44 -080012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Pekka Paalanen230f3b12014-09-29 14:18:40 -040024 */
25
26#ifndef WESTON_LINUX_DMABUF_H
27#define WESTON_LINUX_DMABUF_H
28
29#include <stdint.h>
30
31#define MAX_DMABUF_PLANES 4
Varad Gautam41b4b8f2017-04-26 19:17:17 +053032#ifndef DRM_FORMAT_MOD_INVALID
33#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
34#endif
Pekka Paalanen230f3b12014-09-29 14:18:40 -040035
36struct linux_dmabuf_buffer;
37typedef void (*dmabuf_user_data_destroy_func)(
38 struct linux_dmabuf_buffer *buffer);
39
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000040struct dmabuf_attributes {
Pekka Paalanen230f3b12014-09-29 14:18:40 -040041 int32_t width;
42 int32_t height;
43 uint32_t format;
44 uint32_t flags; /* enum zlinux_buffer_params_flags */
45 int n_planes;
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000046 int fd[MAX_DMABUF_PLANES];
Pekka Paalanen230f3b12014-09-29 14:18:40 -040047 uint32_t offset[MAX_DMABUF_PLANES];
48 uint32_t stride[MAX_DMABUF_PLANES];
49 uint64_t modifier[MAX_DMABUF_PLANES];
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000050};
51
52struct linux_dmabuf_buffer {
53 struct wl_resource *buffer_resource;
54 struct wl_resource *params_resource;
55 struct weston_compositor *compositor;
56 struct dmabuf_attributes attributes;
Pekka Paalanen230f3b12014-09-29 14:18:40 -040057
58 void *user_data;
59 dmabuf_user_data_destroy_func user_data_destroy_func;
60
61 /* XXX:
62 *
63 * Add backend private data. This would be for the backend
64 * to do all additional imports it might ever use in advance.
65 * The basic principle, even if not implemented in drivers today,
66 * is that dmabufs are first attached, but the actual allocation
67 * is deferred to first use. This would allow the exporter and all
68 * attachers to agree on how to allocate.
69 *
70 * The DRM backend would use this to create drmFBs for each
71 * dmabuf_buffer, just in case at some point it would become
72 * feasible to scan it out directly. This would improve the
73 * possibilities to successfully scan out, avoiding compositing.
74 */
75};
76
77int
78linux_dmabuf_setup(struct weston_compositor *compositor);
79
80struct linux_dmabuf_buffer *
81linux_dmabuf_buffer_get(struct wl_resource *resource);
82
83void
84linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
85 void *data,
86 dmabuf_user_data_destroy_func func);
87void *
88linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer);
89
90void
91linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
92 const char *msg);
93
94#endif /* WESTON_LINUX_DMABUF_H */