Debian Codegraph @

gdk/gdkdmabuftexture.c

raw symbols SCIP
1 /* gdkdmabuftexture.c
2 *
3 * Copyright 2023 Red Hat, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "config.h"cxx . . $ `<file>/build/config.h`/
20
21 #include "gdkdmabuftextureprivate.h"cxx . . $ `<file>/gdk/gdkdmabuftextureprivate.h`/
22
23 #include "gdkcolorstateprivate.h"cxx . . $ `<file>/gdk/gdkcolorstateprivate.h`/
24 #include "gdkdisplayprivate.h"cxx . . $ `<file>/gdk/gdkdisplayprivate.h`/
25 #include "gdkdmabufdownloaderprivate.h"cxx . . $ `<file>/gdk/gdkdmabufdownloaderprivate.h`/
26 #include "gdkdmabufformatsbuilderprivate.h"cxx . . $ `<file>/gdk/gdkdmabufformatsbuilderprivate.h`/
27 #include "gdkdmabuffourccprivate.h"cxx . . $ `<file>/gdk/gdkdmabuffourccprivate.h`/
28 #include "gdkdmabufprivate.h"cxx . . $ `<file>/gdk/gdkdmabufprivate.h`/
29 #include "gdkdmabuftexturebuilderprivate.h"cxx . . $ `<file>/gdk/gdkdmabuftexturebuilderprivate.h`/
30 #include "gdktextureprivate.h"cxx . . $ `<file>/gdk/gdktextureprivate.h`/
31 #include <gdk/gdkglcontext.h>cxx . . $ `<file>/gdk/gdkglcontext.h`/
32 #include <gdk/gdkgltexturebuilder.h>cxx . . $ `<file>/gdk/gdkgltexturebuilder.h`/
33 #include <gdk/gdktexturedownloader.h>cxx . . $ `<file>/gdk/gdktexturedownloader.h`/
34
35 /**
36 * GdkDmabufTexture:
37 *
38 * A `GdkTexture` representing a DMA buffer.
39 *
40 * To create a `GdkDmabufTexture`, use the auxiliary
41 * [[email protected]] object.
42 *
43 * Dma-buf textures can only be created on Linux.
44 *
45 * Since: 4.14
46 */
47
48 struct _GdkDmabufTexturecxx . . $ _GdkDmabufTexture#
49 {
50 GdkTexturecxx . . $ GdkTexture# parent_instancecxx . . $ _GdkDmabufTexture#parent_instance.;
51
52 GdkDisplaycxx . . $ GdkDisplay# *displaycxx . . $ _GdkDmabufTexture#display.;
53
54 GdkDmabufcxx . . $ GdkDmabuf# dmabufcxx . . $ _GdkDmabufTexture#dmabuf.;
55
56 GDestroyNotifycxx . . $ GDestroyNotify# destroycxx . . $ _GdkDmabufTexture#destroy.;
57 gpointercxx . . $ gpointer# datacxx . . $ _GdkDmabufTexture#data.;
58 };
59
60 struct _GdkDmabufTextureClasscxx . . $ _GdkDmabufTextureClass#
61 {
62 GdkTextureClasscxx . . $ GdkTextureClass# parent_classcxx . . $ _GdkDmabufTextureClass#parent_class.;
63 };
64
65 /**
66 * gdk_dmabuf_error_quark:
67 *
68 * Registers an error quark for [[email protected]] errors.
69 *
70 * Returns: the error quark
71 **/
72 G_DEFINE_QUARKcxx . . $ `<external>/1742745020260712427/gquark.h:51:9`! (gdk-dmabuf-error-quark, gdk_dmabuf_error)
73
74 G_DEFINE_TYPEcxx . . $ `<external>/9567554376676449156/gtype.h:1834:9`! (GdkDmabufTexture, gdk_dmabuf_texture, GDK_TYPE_TEXTUREcxx . . $ `gdk/gdktexture.h:30:9`!)
75
76 static void
77 gdk_dmabuf_texture_disposecxx . . $ gdk_dmabuf_texture_dispose(6087475fa43034d3). (GObjectcxx . . $ GObject# *object)
78 {
79 GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self = GDK_DMABUF_TEXTUREcxx . . $ `gdk/gdkdmabuftexture.h:32:9`! (object);
80
81 if (self->destroycxx . . $ _GdkDmabufTexture#destroy.)
82 {
83 self->destroycxx . . $ _GdkDmabufTexture#destroy. (self->datacxx . . $ _GdkDmabufTexture#data.);
84 self->destroycxx . . $ _GdkDmabufTexture#destroy. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
85 }
86
87 g_clear_objectcxx . . $ `<external>/1341695927569185362/gobject.h:695:9`! (&self->display);
88
89 G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (gdk_dmabuf_texture_parent_class)->disposecxx . . $ _GObjectClass#dispose. (object);
90 }
91
92 typedef struct _Downloadcxx . . $ _Download# Downloadcxx . . $ Download#;
93
94 struct _Downloadcxx . . $ _Download#
95 {
96 GdkDmabufTexturecxx . . $ GdkDmabufTexture# *texturecxx . . $ _Download#texture.;
97 gucharcxx . . $ guchar# *datacxx . . $ _Download#data.;
98 GdkMemoryLayoutcxx . . $ GdkMemoryLayout# layoutcxx . . $ _Download#layout.;
99 GdkColorStatecxx . . $ GdkColorState# *color_statecxx . . $ _Download#color_state.;
100 volatile int spinlockcxx . . $ _Download#spinlock.;
101 };
102
103 static gbooleancxx . . $ gboolean#
104 gdk_dmabuf_texture_invoke_callbackcxx . . $ gdk_dmabuf_texture_invoke_callback(dedf1e9b1c614a07). (gpointercxx . . $ gpointer# data)
105 {
106 Downloadcxx . . $ Download# *download = data;
107 GdkDisplaycxx . . $ GdkDisplay# *display = download->texturecxx . . $ _Download#texture.->displaycxx . . $ _GdkDmabufTexture#display.;
108
109 if (display->egl_downloadercxx . . $ _GdkDisplay#egl_downloader. &&
110 gdk_dmabuf_downloader_downloadcxx . . $ gdk_dmabuf_downloader_download(d8a7d8083eea8cd9). (display->egl_downloadercxx . . $ _GdkDisplay#egl_downloader.,
111 download->texturecxx . . $ _Download#texture.,
112 download->datacxx . . $ _Download#data.,
113 &download->layoutcxx . . $ _Download#layout.,
114 download->color_statecxx . . $ _Download#color_state.))
115 {
116 /* Successfully downloaded using EGL */
117 }
118 else if (display->vk_downloadercxx . . $ _GdkDisplay#vk_downloader. &&
119 gdk_dmabuf_downloader_downloadcxx . . $ gdk_dmabuf_downloader_download(d8a7d8083eea8cd9). (display->vk_downloadercxx . . $ _GdkDisplay#vk_downloader.,
120 download->texturecxx . . $ _Download#texture.,
121 download->datacxx . . $ _Download#data.,
122 &download->layoutcxx . . $ _Download#layout.,
123 download->color_statecxx . . $ _Download#color_state.))
124 {
125 /* Successfully downloaded using Vulkan */
126 }
127 #ifdef HAVE_DMABUFcxx . . $ `build/config.h:34:9`!
128 else if (gdk_dmabuf_download_mmapcxx . . $ gdk_dmabuf_download_mmap(7c838bbf0607daba). (GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (download->texture),
129 download->datacxx . . $ _Download#data.,
130 &download->layoutcxx . . $ _Download#layout.,
131 download->color_statecxx . . $ _Download#color_state.))
132 {
133 /* Successfully downloaded using mmap */
134 }
135 #endif
136 else
137 {
138 const GdkDmabufcxx . . $ GdkDmabuf# *dmabuf = gdk_dmabuf_texture_get_dmabufcxx . . $ gdk_dmabuf_texture_get_dmabuf(3c587bc73e930c2e). (download->texturecxx . . $ _Download#texture.);
139
140 g_criticalcxx . . $ `<external>/5169755362661750954/gmessages.h:337:9`! ("Failed to download %dx%d dmabuf texture (format %.4s:%#" G_GINT64_MODIFIERcxx . . $ `<external>/10505296616216143549/glibconfig.h:72:9`! "x)",
141 gdk_texture_get_width (GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (download->texture)),
142 gdk_texture_get_height (GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (download->texture)),
143 (char *)&(dmabuf->fourcc), dmabuf->modifier);
144 }
145
146 g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`! (&download->spinlock, 1);
147 return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
148 }
149
150 static void
151 gdk_dmabuf_texture_downloadcxx . . $ gdk_dmabuf_texture_download(7a1a0b00792c79fe). (GdkTexturecxx . . $ GdkTexture# *texture,
152 gucharcxx . . $ guchar# *data,
153 const GdkMemoryLayoutcxx . . $ GdkMemoryLayout# *layout,
154 GdkColorStatecxx . . $ GdkColorState# *color_state)
155 {
156 GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self = GDK_DMABUF_TEXTUREcxx . . $ `gdk/gdkdmabuftexture.h:32:9`! (texture);
157 Downloadcxx . . $ Download# download = { self, data, *layout, color_state, 0 };
158
159 g_main_context_invokecxx . . $ g_main_context_invoke(48f1df92a3f30c61). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, gdk_dmabuf_texture_invoke_callbackcxx . . $ gdk_dmabuf_texture_invoke_callback(dedf1e9b1c614a07)., &download);
160
161 while (g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`! (&download.spinlock) == 0);
162 }
163
164 static void
165 gdk_dmabuf_texture_class_initcxx . . $ gdk_dmabuf_texture_class_init(1fddaafd7b24ab92). (GdkDmabufTextureClasscxx . . $ GdkDmabufTextureClass# *klass)
166 {
167 GdkTextureClasscxx . . $ GdkTextureClass# *texture_class = GDK_TEXTURE_CLASScxx . . $ `gdk/gdktextureprivate.h:18:9`! (klass);
168 GObjectClasscxx . . $ GObjectClass# *gobject_class = G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (klass);
169
170 texture_class->downloadcxx . . $ _GdkTextureClass#download. = gdk_dmabuf_texture_downloadcxx . . $ gdk_dmabuf_texture_download(7a1a0b00792c79fe).;
171
172 gobject_class->disposecxx . . $ _GObjectClass#dispose. = gdk_dmabuf_texture_disposecxx . . $ gdk_dmabuf_texture_dispose(6087475fa43034d3).;
173 }
174
175 static void
176 gdk_dmabuf_texture_initcxx . . $ gdk_dmabuf_texture_init(16859b17c102605f). (GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self)
177 {
178 }
179
180 GdkDisplaycxx . . $ GdkDisplay# *
181 gdk_dmabuf_texture_get_displaycxx . . $ gdk_dmabuf_texture_get_display(8a4e457edd27b2fb). (GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self)
182 {
183 return self->displaycxx . . $ _GdkDmabufTexture#display.;
184 }
185
186 const GdkDmabufcxx . . $ GdkDmabuf# *
187 gdk_dmabuf_texture_get_dmabufcxx . . $ gdk_dmabuf_texture_get_dmabuf(3c587bc73e930c2e). (GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self)
188 {
189 return &self->dmabufcxx . . $ _GdkDmabufTexture#dmabuf.;
190 }
191
192 GdkTexturecxx . . $ GdkTexture# *
193 gdk_dmabuf_texture_new_from_buildercxx . . $ gdk_dmabuf_texture_new_from_builder(351b6e640d4c3b36). (GdkDmabufTextureBuildercxx . . $ GdkDmabufTextureBuilder# *builder,
194 GDestroyNotifycxx . . $ GDestroyNotify# destroy,
195 gpointercxx . . $ gpointer# data,
196 GErrorcxx . . $ GError# **error)
197 {
198 #ifdef HAVE_DMABUFcxx . . $ `build/config.h:34:9`!
199 GdkDmabufTexturecxx . . $ GdkDmabufTexture# *self;
200 GdkTexturecxx . . $ GdkTexture# *update_texture;
201 GdkDisplaycxx . . $ GdkDisplay# *display;
202 GdkDmabufcxx . . $ GdkDmabuf# dmabuf;
203 GdkColorStatecxx . . $ GdkColorState# *color_state;
204 int width, height;
205 gbooleancxx . . $ gboolean# premultiplied;
206 GdkMemoryFormatcxx . . $ GdkMemoryFormat# format;
207 gbooleancxx . . $ gboolean# is_yuv;
208
209 display = gdk_dmabuf_texture_builder_get_displaycxx . . $ gdk_dmabuf_texture_builder_get_display(a68863dd4044995e). (builder);
210 width = gdk_dmabuf_texture_builder_get_widthcxx . . $ gdk_dmabuf_texture_builder_get_width(7f7d4b5309c8d42e). (builder);
211 height = gdk_dmabuf_texture_builder_get_heightcxx . . $ gdk_dmabuf_texture_builder_get_height(7f7d4b5309c8d42e). (builder);
212 premultiplied = gdk_dmabuf_texture_builder_get_premultipliedcxx . . $ gdk_dmabuf_texture_builder_get_premultiplied(4fa9c084f5dbe9d9). (builder);
213
214 if (!gdk_dmabuf_sanitizecxx . . $ gdk_dmabuf_sanitize(21d303446d3a96ee). (&dmabuf,
215 width,
216 height,
217 gdk_dmabuf_texture_builder_get_dmabufcxx . . $ gdk_dmabuf_texture_builder_get_dmabuf(f4439d1f5b4c0a3c). (builder),
218 error))
219 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
220
221 if (gdk_memory_format_find_by_dmabuf_fourcccxx . . $ gdk_memory_format_find_by_dmabuf_fourcc(99557810107d2563). (dmabuf.fourcccxx . . $ _GdkDmabuf#fourcc., premultiplied, &format, &is_yuv))
222 {
223 if (!gdk_memory_format_is_block_boundarycxx . . $ gdk_memory_format_is_block_boundary(839ab6e09e2f5b4). (format, width, height))
224 {
225 g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error,
226 GDK_DMABUF_ERRORcxx . . $ `gdk/gdkdmabuftexture.h:35:9`!, GDK_DMABUF_ERROR_UNSUPPORTED_FORMATcxx . . $ GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT.,
227 "Size of %dx%d is not valid for dmabuf format %.4s, must be multiple of %zux%zu",
228 width, height,
229 (char *) &dmabuf.fourcccxx . . $ _GdkDmabuf#fourcc.,
230 gdk_memory_format_get_block_widthcxx . . $ gdk_memory_format_get_block_width(297990571baf5d1d). (format),
231 gdk_memory_format_get_block_heightcxx . . $ gdk_memory_format_get_block_height(297990571baf5d1d). (format));
232 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
233 }
234 }
235 else
236 {
237 g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error,
238 GDK_DMABUF_ERRORcxx . . $ `gdk/gdkdmabuftexture.h:35:9`!, GDK_DMABUF_ERROR_UNSUPPORTED_FORMATcxx . . $ GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT.,
239 "Unsupported dmabuf format %.4s",
240 (char *) &dmabuf.fourcccxx . . $ _GdkDmabuf#fourcc.);
241 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
242 }
243
244 gdk_display_init_dmabufcxx . . $ gdk_display_init_dmabuf(2f702f82283e587b). (display);
245
246 if (!gdk_dmabuf_formats_containscxx . . $ gdk_dmabuf_formats_contains(5431d246084b67b8). (display->dmabuf_formatscxx . . $ _GdkDisplay#dmabuf_formats., dmabuf.fourcccxx . . $ _GdkDmabuf#fourcc., dmabuf.modifiercxx . . $ _GdkDmabuf#modifier.))
247 {
248 g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error,
249 GDK_DMABUF_ERRORcxx . . $ `gdk/gdkdmabuftexture.h:35:9`!, GDK_DMABUF_ERROR_UNSUPPORTED_FORMATcxx . . $ GDK_DMABUF_ERROR_UNSUPPORTED_FORMAT.,
250 "Unsupported dmabuf format: %.4s:%#" G_GINT64_MODIFIERcxx . . $ `<external>/10505296616216143549/glibconfig.h:72:9`! "x",
251 (char *) &dmabuf.fourcccxx . . $ _GdkDmabuf#fourcc., dmabuf.modifiercxx . . $ _GdkDmabuf#modifier.);
252 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
253 }
254
255 color_state = gdk_dmabuf_texture_builder_get_color_statecxx . . $ gdk_dmabuf_texture_builder_get_color_state(2e2dacc62f6bebcd). (builder);
256 if (color_state == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
257 {
258 if (is_yuv)
259 color_state = GDK_COLOR_STATE_YUVcxx . . $ `gdk/gdkcolorstateprivate.h:93:9`!;
260 else
261 color_state = GDK_COLOR_STATE_SRGBcxx . . $ `gdk/gdkcolorstateprivate.h:87:9`!;
262 }
263
264 self = g_object_newcxx . . $ g_object_new(8485fe61b4be4c78). (GDK_TYPE_DMABUF_TEXTUREcxx . . $ `gdk/gdkdmabuftexture.h:30:9`!,
265 "width", width,
266 "height", height,
267 "color-state", color_state,
268 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
269
270 g_set_objectcxx . . $ `<external>/1341695927569185362/gobject.h:762:9`! (&self->display, display);
271 GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (self)->formatcxx . . $ _GdkTexture#format. = format;
272 self->dmabufcxx . . $ _GdkDmabufTexture#dmabuf. = dmabuf;
273
274 GDK_DISPLAY_DEBUGcxx . . $ `gdk/gdkdebugprivate.h:133:9`! (display, DMABUF,
275 "Creating dmabuf texture, format %.4s:%#" G_GINT64_MODIFIERcxx . . $ `<external>/10505296616216143549/glibconfig.h:72:9`! "x, %s%u planes, memory format %s",
276 (char *) &dmabuf.fourcc, dmabuf.modifier,
277 gdk_dmabuf_texture_builder_get_premultiplied (builder) ? " premultiplied, " : "",
278 dmabuf.n_planes,
279 gdk_memory_format_get_name (GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (self)->format));
280
281 /* Set this only once we know that the texture will be created.
282 * Otherwise dispose() will run the callback */
283 self->destroycxx . . $ _GdkDmabufTexture#destroy. = destroy;
284 self->datacxx . . $ _GdkDmabufTexture#data. = data;
285
286 update_texture = gdk_dmabuf_texture_builder_get_update_texturecxx . . $ gdk_dmabuf_texture_builder_get_update_texture(7639d8071d0be98e). (builder);
287 if (update_texture)
288 {
289 cairo_region_tcxx . . $ cairo_region_t# *update_region = gdk_dmabuf_texture_builder_get_update_regioncxx . . $ gdk_dmabuf_texture_builder_get_update_region(fbcaa0266a1d64d). (builder);
290 if (update_region)
291 {
292 update_region = cairo_region_copycxx . . $ cairo_region_copy(dc882fa877beddfa). (update_region);
293 cairo_region_intersect_rectanglecxx . . $ cairo_region_intersect_rectangle(725a66f827e69750). (update_region,
294 &(cairo_rectangle_int_tcxx . . $ cairo_rectangle_int_t#) {
295 0, 0,
296 update_texture->widthcxx . . $ _GdkTexture#width., update_texture->heightcxx . . $ _GdkTexture#height.
297 });
298 gdk_texture_set_diffcxx . . $ gdk_texture_set_diff(332bc387a01bbacc). (GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (self), update_texture, update_region);
299 }
300 }
301
302 return GDK_TEXTUREcxx . . $ `gdk/gdktexture.h:32:9`! (self);
303
304 #else /* !HAVE_DMABUF */
305 g_set_error_literal (error, GDK_DMABUF_ERROR, GDK_DMABUF_ERROR_NOT_AVAILABLE,
306 "dmabuf support disabled at compile-time.");
307 return NULL;
308 #endif
309 }
310