vfio/container: Change VFIOContainerBase to use QOM
[qemu/armbru.git] / ui / dmabuf.c
blobdf7a09703fac60ebc50f348f6cd7eaba65782b8e
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * QemuDmaBuf struct and helpers used for accessing its data
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
11 #include "ui/dmabuf.h"
13 struct QemuDmaBuf {
14 int fd;
15 uint32_t width;
16 uint32_t height;
17 uint32_t stride;
18 uint32_t fourcc;
19 uint64_t modifier;
20 uint32_t texture;
21 uint32_t x;
22 uint32_t y;
23 uint32_t backing_width;
24 uint32_t backing_height;
25 bool y0_top;
26 void *sync;
27 int fence_fd;
28 bool allow_fences;
29 bool draw_submitted;
32 QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height,
33 uint32_t stride, uint32_t x,
34 uint32_t y, uint32_t backing_width,
35 uint32_t backing_height, uint32_t fourcc,
36 uint64_t modifier, int32_t dmabuf_fd,
37 bool allow_fences, bool y0_top) {
38 QemuDmaBuf *dmabuf;
40 dmabuf = g_new0(QemuDmaBuf, 1);
42 dmabuf->width = width;
43 dmabuf->height = height;
44 dmabuf->stride = stride;
45 dmabuf->x = x;
46 dmabuf->y = y;
47 dmabuf->backing_width = backing_width;
48 dmabuf->backing_height = backing_height;
49 dmabuf->fourcc = fourcc;
50 dmabuf->modifier = modifier;
51 dmabuf->fd = dmabuf_fd;
52 dmabuf->allow_fences = allow_fences;
53 dmabuf->y0_top = y0_top;
54 dmabuf->fence_fd = -1;
56 return dmabuf;
59 void qemu_dmabuf_free(QemuDmaBuf *dmabuf)
61 if (dmabuf == NULL) {
62 return;
65 g_free(dmabuf);
68 int qemu_dmabuf_get_fd(QemuDmaBuf *dmabuf)
70 assert(dmabuf != NULL);
72 return dmabuf->fd;
75 int qemu_dmabuf_dup_fd(QemuDmaBuf *dmabuf)
77 assert(dmabuf != NULL);
79 if (dmabuf->fd >= 0) {
80 return dup(dmabuf->fd);
81 } else {
82 return -1;
86 void qemu_dmabuf_close(QemuDmaBuf *dmabuf)
88 assert(dmabuf != NULL);
90 if (dmabuf->fd >= 0) {
91 close(dmabuf->fd);
92 dmabuf->fd = -1;
96 uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf)
98 assert(dmabuf != NULL);
100 return dmabuf->width;
103 uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf)
105 assert(dmabuf != NULL);
107 return dmabuf->height;
110 uint32_t qemu_dmabuf_get_stride(QemuDmaBuf *dmabuf)
112 assert(dmabuf != NULL);
114 return dmabuf->stride;
117 uint32_t qemu_dmabuf_get_fourcc(QemuDmaBuf *dmabuf)
119 assert(dmabuf != NULL);
121 return dmabuf->fourcc;
124 uint64_t qemu_dmabuf_get_modifier(QemuDmaBuf *dmabuf)
126 assert(dmabuf != NULL);
128 return dmabuf->modifier;
131 uint32_t qemu_dmabuf_get_texture(QemuDmaBuf *dmabuf)
133 assert(dmabuf != NULL);
135 return dmabuf->texture;
138 uint32_t qemu_dmabuf_get_x(QemuDmaBuf *dmabuf)
140 assert(dmabuf != NULL);
142 return dmabuf->x;
145 uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf)
147 assert(dmabuf != NULL);
149 return dmabuf->y;
152 uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf)
154 assert(dmabuf != NULL);
156 return dmabuf->backing_width;
159 uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf)
161 assert(dmabuf != NULL);
163 return dmabuf->backing_height;
166 bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf)
168 assert(dmabuf != NULL);
170 return dmabuf->y0_top;
173 void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf)
175 assert(dmabuf != NULL);
177 return dmabuf->sync;
180 int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf)
182 assert(dmabuf != NULL);
184 return dmabuf->fence_fd;
187 bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf)
189 assert(dmabuf != NULL);
191 return dmabuf->allow_fences;
194 bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf)
196 assert(dmabuf != NULL);
198 return dmabuf->draw_submitted;
201 void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture)
203 assert(dmabuf != NULL);
204 dmabuf->texture = texture;
207 void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd)
209 assert(dmabuf != NULL);
210 dmabuf->fence_fd = fence_fd;
213 void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync)
215 assert(dmabuf != NULL);
216 dmabuf->sync = sync;
219 void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitted)
221 assert(dmabuf != NULL);
222 dmabuf->draw_submitted = draw_submitted;
225 void qemu_dmabuf_set_fd(QemuDmaBuf *dmabuf, int32_t fd)
227 assert(dmabuf != NULL);
228 dmabuf->fd = fd;