xref: /openbmc/qemu/ui/dmabuf.c (revision 6e6ae491)
1*6e6ae491SDongwon Kim /*
2*6e6ae491SDongwon Kim  * SPDX-License-Identifier: GPL-2.0-or-later
3*6e6ae491SDongwon Kim  *
4*6e6ae491SDongwon Kim  * QemuDmaBuf struct and helpers used for accessing its data
5*6e6ae491SDongwon Kim  *
6*6e6ae491SDongwon Kim  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7*6e6ae491SDongwon Kim  * See the COPYING file in the top-level directory.
8*6e6ae491SDongwon Kim  */
9*6e6ae491SDongwon Kim 
10*6e6ae491SDongwon Kim #include "qemu/osdep.h"
11*6e6ae491SDongwon Kim #include "ui/dmabuf.h"
12*6e6ae491SDongwon Kim 
13*6e6ae491SDongwon Kim QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height,
14*6e6ae491SDongwon Kim                             uint32_t stride, uint32_t x,
15*6e6ae491SDongwon Kim                             uint32_t y, uint32_t backing_width,
16*6e6ae491SDongwon Kim                             uint32_t backing_height, uint32_t fourcc,
17*6e6ae491SDongwon Kim                             uint64_t modifier, int32_t dmabuf_fd,
18*6e6ae491SDongwon Kim                             bool allow_fences, bool y0_top) {
19*6e6ae491SDongwon Kim     QemuDmaBuf *dmabuf;
20*6e6ae491SDongwon Kim 
21*6e6ae491SDongwon Kim     dmabuf = g_new0(QemuDmaBuf, 1);
22*6e6ae491SDongwon Kim 
23*6e6ae491SDongwon Kim     dmabuf->width = width;
24*6e6ae491SDongwon Kim     dmabuf->height = height;
25*6e6ae491SDongwon Kim     dmabuf->stride = stride;
26*6e6ae491SDongwon Kim     dmabuf->x = x;
27*6e6ae491SDongwon Kim     dmabuf->y = y;
28*6e6ae491SDongwon Kim     dmabuf->backing_width = backing_width;
29*6e6ae491SDongwon Kim     dmabuf->backing_height = backing_height;
30*6e6ae491SDongwon Kim     dmabuf->fourcc = fourcc;
31*6e6ae491SDongwon Kim     dmabuf->modifier = modifier;
32*6e6ae491SDongwon Kim     dmabuf->fd = dmabuf_fd;
33*6e6ae491SDongwon Kim     dmabuf->allow_fences = allow_fences;
34*6e6ae491SDongwon Kim     dmabuf->y0_top = y0_top;
35*6e6ae491SDongwon Kim     dmabuf->fence_fd = -1;
36*6e6ae491SDongwon Kim 
37*6e6ae491SDongwon Kim     return dmabuf;
38*6e6ae491SDongwon Kim }
39*6e6ae491SDongwon Kim 
40*6e6ae491SDongwon Kim void qemu_dmabuf_free(QemuDmaBuf *dmabuf)
41*6e6ae491SDongwon Kim {
42*6e6ae491SDongwon Kim     if (dmabuf == NULL) {
43*6e6ae491SDongwon Kim         return;
44*6e6ae491SDongwon Kim     }
45*6e6ae491SDongwon Kim 
46*6e6ae491SDongwon Kim     g_free(dmabuf);
47*6e6ae491SDongwon Kim }
48*6e6ae491SDongwon Kim 
49*6e6ae491SDongwon Kim int qemu_dmabuf_get_fd(QemuDmaBuf *dmabuf)
50*6e6ae491SDongwon Kim {
51*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
52*6e6ae491SDongwon Kim 
53*6e6ae491SDongwon Kim     return dmabuf->fd;
54*6e6ae491SDongwon Kim }
55*6e6ae491SDongwon Kim 
56*6e6ae491SDongwon Kim int qemu_dmabuf_dup_fd(QemuDmaBuf *dmabuf)
57*6e6ae491SDongwon Kim {
58*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
59*6e6ae491SDongwon Kim 
60*6e6ae491SDongwon Kim     if (dmabuf->fd >= 0) {
61*6e6ae491SDongwon Kim         return dup(dmabuf->fd);
62*6e6ae491SDongwon Kim     } else {
63*6e6ae491SDongwon Kim         return -1;
64*6e6ae491SDongwon Kim     }
65*6e6ae491SDongwon Kim }
66*6e6ae491SDongwon Kim 
67*6e6ae491SDongwon Kim void qemu_dmabuf_close(QemuDmaBuf *dmabuf)
68*6e6ae491SDongwon Kim {
69*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
70*6e6ae491SDongwon Kim 
71*6e6ae491SDongwon Kim     if (dmabuf->fd >= 0) {
72*6e6ae491SDongwon Kim         close(dmabuf->fd);
73*6e6ae491SDongwon Kim         dmabuf->fd = -1;
74*6e6ae491SDongwon Kim     }
75*6e6ae491SDongwon Kim }
76*6e6ae491SDongwon Kim 
77*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf)
78*6e6ae491SDongwon Kim {
79*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
80*6e6ae491SDongwon Kim 
81*6e6ae491SDongwon Kim     return dmabuf->width;
82*6e6ae491SDongwon Kim }
83*6e6ae491SDongwon Kim 
84*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf)
85*6e6ae491SDongwon Kim {
86*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
87*6e6ae491SDongwon Kim 
88*6e6ae491SDongwon Kim     return dmabuf->height;
89*6e6ae491SDongwon Kim }
90*6e6ae491SDongwon Kim 
91*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_stride(QemuDmaBuf *dmabuf)
92*6e6ae491SDongwon Kim {
93*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
94*6e6ae491SDongwon Kim 
95*6e6ae491SDongwon Kim     return dmabuf->stride;
96*6e6ae491SDongwon Kim }
97*6e6ae491SDongwon Kim 
98*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_fourcc(QemuDmaBuf *dmabuf)
99*6e6ae491SDongwon Kim {
100*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
101*6e6ae491SDongwon Kim 
102*6e6ae491SDongwon Kim     return dmabuf->fourcc;
103*6e6ae491SDongwon Kim }
104*6e6ae491SDongwon Kim 
105*6e6ae491SDongwon Kim uint64_t qemu_dmabuf_get_modifier(QemuDmaBuf *dmabuf)
106*6e6ae491SDongwon Kim {
107*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
108*6e6ae491SDongwon Kim 
109*6e6ae491SDongwon Kim     return dmabuf->modifier;
110*6e6ae491SDongwon Kim }
111*6e6ae491SDongwon Kim 
112*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_texture(QemuDmaBuf *dmabuf)
113*6e6ae491SDongwon Kim {
114*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
115*6e6ae491SDongwon Kim 
116*6e6ae491SDongwon Kim     return dmabuf->texture;
117*6e6ae491SDongwon Kim }
118*6e6ae491SDongwon Kim 
119*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_x(QemuDmaBuf *dmabuf)
120*6e6ae491SDongwon Kim {
121*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
122*6e6ae491SDongwon Kim 
123*6e6ae491SDongwon Kim     return dmabuf->x;
124*6e6ae491SDongwon Kim }
125*6e6ae491SDongwon Kim 
126*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf)
127*6e6ae491SDongwon Kim {
128*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
129*6e6ae491SDongwon Kim 
130*6e6ae491SDongwon Kim     return dmabuf->y;
131*6e6ae491SDongwon Kim }
132*6e6ae491SDongwon Kim 
133*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf)
134*6e6ae491SDongwon Kim {
135*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
136*6e6ae491SDongwon Kim 
137*6e6ae491SDongwon Kim     return dmabuf->backing_width;
138*6e6ae491SDongwon Kim }
139*6e6ae491SDongwon Kim 
140*6e6ae491SDongwon Kim uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf)
141*6e6ae491SDongwon Kim {
142*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
143*6e6ae491SDongwon Kim 
144*6e6ae491SDongwon Kim     return dmabuf->backing_height;
145*6e6ae491SDongwon Kim }
146*6e6ae491SDongwon Kim 
147*6e6ae491SDongwon Kim bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf)
148*6e6ae491SDongwon Kim {
149*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
150*6e6ae491SDongwon Kim 
151*6e6ae491SDongwon Kim     return dmabuf->y0_top;
152*6e6ae491SDongwon Kim }
153*6e6ae491SDongwon Kim 
154*6e6ae491SDongwon Kim void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf)
155*6e6ae491SDongwon Kim {
156*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
157*6e6ae491SDongwon Kim 
158*6e6ae491SDongwon Kim     return dmabuf->sync;
159*6e6ae491SDongwon Kim }
160*6e6ae491SDongwon Kim 
161*6e6ae491SDongwon Kim int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf)
162*6e6ae491SDongwon Kim {
163*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
164*6e6ae491SDongwon Kim 
165*6e6ae491SDongwon Kim     return dmabuf->fence_fd;
166*6e6ae491SDongwon Kim }
167*6e6ae491SDongwon Kim 
168*6e6ae491SDongwon Kim bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf)
169*6e6ae491SDongwon Kim {
170*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
171*6e6ae491SDongwon Kim 
172*6e6ae491SDongwon Kim     return dmabuf->allow_fences;
173*6e6ae491SDongwon Kim }
174*6e6ae491SDongwon Kim 
175*6e6ae491SDongwon Kim bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf)
176*6e6ae491SDongwon Kim {
177*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
178*6e6ae491SDongwon Kim 
179*6e6ae491SDongwon Kim     return dmabuf->draw_submitted;
180*6e6ae491SDongwon Kim }
181*6e6ae491SDongwon Kim 
182*6e6ae491SDongwon Kim void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture)
183*6e6ae491SDongwon Kim {
184*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
185*6e6ae491SDongwon Kim     dmabuf->texture = texture;
186*6e6ae491SDongwon Kim }
187*6e6ae491SDongwon Kim 
188*6e6ae491SDongwon Kim void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd)
189*6e6ae491SDongwon Kim {
190*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
191*6e6ae491SDongwon Kim     dmabuf->fence_fd = fence_fd;
192*6e6ae491SDongwon Kim }
193*6e6ae491SDongwon Kim 
194*6e6ae491SDongwon Kim void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync)
195*6e6ae491SDongwon Kim {
196*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
197*6e6ae491SDongwon Kim     dmabuf->sync = sync;
198*6e6ae491SDongwon Kim }
199*6e6ae491SDongwon Kim 
200*6e6ae491SDongwon Kim void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitted)
201*6e6ae491SDongwon Kim {
202*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
203*6e6ae491SDongwon Kim     dmabuf->draw_submitted = draw_submitted;
204*6e6ae491SDongwon Kim }
205*6e6ae491SDongwon Kim 
206*6e6ae491SDongwon Kim void qemu_dmabuf_set_fd(QemuDmaBuf *dmabuf, int32_t fd)
207*6e6ae491SDongwon Kim {
208*6e6ae491SDongwon Kim     assert(dmabuf != NULL);
209*6e6ae491SDongwon Kim     dmabuf->fd = fd;
210*6e6ae491SDongwon Kim }
211