blob: 64f43e5977e880e8e4365948228ff9200f4d49a0 [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
32
33struct linux_dmabuf_buffer;
34typedef void (*dmabuf_user_data_destroy_func)(
35 struct linux_dmabuf_buffer *buffer);
36
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000037struct dmabuf_attributes {
Pekka Paalanen230f3b12014-09-29 14:18:40 -040038 int32_t width;
39 int32_t height;
40 uint32_t format;
41 uint32_t flags; /* enum zlinux_buffer_params_flags */
42 int n_planes;
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000043 int fd[MAX_DMABUF_PLANES];
Pekka Paalanen230f3b12014-09-29 14:18:40 -040044 uint32_t offset[MAX_DMABUF_PLANES];
45 uint32_t stride[MAX_DMABUF_PLANES];
46 uint64_t modifier[MAX_DMABUF_PLANES];
Emmanuel Gil Peyrotc3996922015-11-24 19:28:24 +000047};
48
49struct linux_dmabuf_buffer {
50 struct wl_resource *buffer_resource;
51 struct wl_resource *params_resource;
52 struct weston_compositor *compositor;
53 struct dmabuf_attributes attributes;
Pekka Paalanen230f3b12014-09-29 14:18:40 -040054
55 void *user_data;
56 dmabuf_user_data_destroy_func user_data_destroy_func;
57
58 /* XXX:
59 *
60 * Add backend private data. This would be for the backend
61 * to do all additional imports it might ever use in advance.
62 * The basic principle, even if not implemented in drivers today,
63 * is that dmabufs are first attached, but the actual allocation
64 * is deferred to first use. This would allow the exporter and all
65 * attachers to agree on how to allocate.
66 *
67 * The DRM backend would use this to create drmFBs for each
68 * dmabuf_buffer, just in case at some point it would become
69 * feasible to scan it out directly. This would improve the
70 * possibilities to successfully scan out, avoiding compositing.
71 */
72};
73
74int
75linux_dmabuf_setup(struct weston_compositor *compositor);
76
77struct linux_dmabuf_buffer *
78linux_dmabuf_buffer_get(struct wl_resource *resource);
79
80void
81linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
82 void *data,
83 dmabuf_user_data_destroy_func func);
84void *
85linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer);
86
87void
88linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
89 const char *msg);
90
91#endif /* WESTON_LINUX_DMABUF_H */