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.
10 #include "qemu/osdep.h"
11 #include "ui/dmabuf.h"
23 uint32_t backing_width
;
24 uint32_t backing_height
;
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
) {
40 dmabuf
= g_new0(QemuDmaBuf
, 1);
42 dmabuf
->width
= width
;
43 dmabuf
->height
= height
;
44 dmabuf
->stride
= stride
;
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;
59 void qemu_dmabuf_free(QemuDmaBuf
*dmabuf
)
68 int qemu_dmabuf_get_fd(QemuDmaBuf
*dmabuf
)
70 assert(dmabuf
!= NULL
);
75 int qemu_dmabuf_dup_fd(QemuDmaBuf
*dmabuf
)
77 assert(dmabuf
!= NULL
);
79 if (dmabuf
->fd
>= 0) {
80 return dup(dmabuf
->fd
);
86 void qemu_dmabuf_close(QemuDmaBuf
*dmabuf
)
88 assert(dmabuf
!= NULL
);
90 if (dmabuf
->fd
>= 0) {
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
);
145 uint32_t qemu_dmabuf_get_y(QemuDmaBuf
*dmabuf
)
147 assert(dmabuf
!= NULL
);
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
);
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
);
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
);