| 1 | /* gdkdmabufformats.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 <glib-object.h> |
| 22 | #include "gdkdmabufformatsprivate.h"cxx . . $ `<file>/gdk/gdkdmabufformatsprivate.h`/ |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * GdkDmabufFormats: |
| 27 | * |
| 28 | * Provides information about supported DMA buffer formats. |
| 29 | * |
| 30 | * You can query whether a given format is supported with |
| 31 | * [[email protected]] and you can iterate |
| 32 | * over the list of all supported formats with |
| 33 | * [[email protected]_n_formats] and |
| 34 | * [[email protected]_format]. |
| 35 | * |
| 36 | * The list of supported formats is sorted by preference, |
| 37 | * with the best formats coming first. |
| 38 | * |
| 39 | * The list may contains (format, modifier) pairs where the modifier |
| 40 | * is `DMA_FORMAT_MOD_INVALID`, indicating that **_implicit modifiers_** |
| 41 | * may be used with this format. |
| 42 | * |
| 43 | * See [[email protected]] for more information |
| 44 | * about DMA buffers. |
| 45 | * |
| 46 | * Note that DMA buffers only exist on Linux. |
| 47 | * |
| 48 | * Since: 4.14 |
| 49 | */ |
| 50 | |
| 51 | struct _GdkDmabufFormatscxx . . $ _GdkDmabufFormats# |
| 52 | { |
| 53 | int ref_countcxx . . $ _GdkDmabufFormats#ref_count.; |
| 54 | |
| 55 | gsizecxx . . $ gsize# n_formatscxx . . $ _GdkDmabufFormats#n_formats.; |
| 56 | GdkDmabufFormatcxx . . $ GdkDmabufFormat# *formatscxx . . $ _GdkDmabufFormats#formats.; |
| 57 | }; |
| 58 | |
| 59 | G_DEFINE_BOXED_TYPEcxx . . $ `<external>/9567554376676449156/gtype.h:2440:9`! (GdkDmabufFormats, gdk_dmabuf_formats, gdk_dmabuf_formats_ref, gdk_dmabuf_formats_unref) |
| 60 | |
| 61 | /** |
| 62 | * gdk_dmabuf_formats_ref: |
| 63 | * @formats: a `GdkDmabufFormats` |
| 64 | * |
| 65 | * Increases the reference count of @formats. |
| 66 | * |
| 67 | * Returns: the passed-in object |
| 68 | * |
| 69 | * Since: 4.14 |
| 70 | */ |
| 71 | GdkDmabufFormatscxx . . $ GdkDmabufFormats# * |
| 72 | gdk_dmabuf_formats_refcxx . . $ gdk_dmabuf_formats_ref(e26c09808f9c9930). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats) |
| 73 | { |
| 74 | formats->ref_countcxx . . $ _GdkDmabufFormats#ref_count.++; |
| 75 | |
| 76 | return formats; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * gdk_dmabuf_formats_unref: |
| 81 | * @formats: a `GdkDmabufFormats` |
| 82 | * |
| 83 | * Decreases the reference count of @formats. |
| 84 | * |
| 85 | * When the reference count reaches zero, |
| 86 | * the object is freed. |
| 87 | * |
| 88 | * Since: 4.14 |
| 89 | */ |
| 90 | void |
| 91 | gdk_dmabuf_formats_unrefcxx . . $ gdk_dmabuf_formats_unref(9314220732227fc7). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats) |
| 92 | { |
| 93 | formats->ref_countcxx . . $ _GdkDmabufFormats#ref_count.--; |
| 94 | |
| 95 | if (formats->ref_countcxx . . $ _GdkDmabufFormats#ref_count. > 0) |
| 96 | return; |
| 97 | |
| 98 | g_freecxx . . $ g_free(5d22bdacc48458e8). (formats->formatscxx . . $ _GdkDmabufFormats#formats.); |
| 99 | g_freecxx . . $ g_free(5d22bdacc48458e8). (formats); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * gdk_dmabuf_formats_get_n_formats: |
| 104 | * @formats: a `GdkDmabufFormats` |
| 105 | * |
| 106 | * Returns the number of formats that the @formats object |
| 107 | * contains. |
| 108 | * |
| 109 | * Note that DMA buffers are a Linux concept, so on other |
| 110 | * platforms, [[email protected]_n_formats] will |
| 111 | * always return zero. |
| 112 | * |
| 113 | * Returns: the number of formats |
| 114 | * |
| 115 | * Since: 4.14 |
| 116 | */ |
| 117 | gsizecxx . . $ gsize# |
| 118 | gdk_dmabuf_formats_get_n_formatscxx . . $ gdk_dmabuf_formats_get_n_formats(2319d58d26e70cff). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats) |
| 119 | { |
| 120 | return formats->n_formatscxx . . $ _GdkDmabufFormats#n_formats.; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * gdk_dmabuf_formats_get_format: |
| 125 | * @formats: a `GdkDmabufFormats` |
| 126 | * @idx: the index of the format to return |
| 127 | * @fourcc: (out): return location for the format code |
| 128 | * @modifier: (out): return location for the format modifier |
| 129 | * |
| 130 | * Gets the fourcc code and modifier for a format |
| 131 | * that is contained in @formats. |
| 132 | * |
| 133 | * Since: 4.14 |
| 134 | */ |
| 135 | void |
| 136 | gdk_dmabuf_formats_get_formatcxx . . $ gdk_dmabuf_formats_get_format(7f2948b68c87b446). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats, |
| 137 | gsizecxx . . $ gsize# idx, |
| 138 | guint32cxx . . $ guint32# *fourcc, |
| 139 | guint64cxx . . $ guint64# *modifier) |
| 140 | { |
| 141 | GdkDmabufFormatcxx . . $ GdkDmabufFormat# *format; |
| 142 | |
| 143 | g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (idx < formats->n_formats); |
| 144 | g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (fourcc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 145 | g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (modifier != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 146 | |
| 147 | format = &formats->formatscxx . . $ _GdkDmabufFormats#formats.[idx]; |
| 148 | |
| 149 | *fourcc = format->fourcccxx . . $ _GdkDmabufFormat#fourcc.; |
| 150 | *modifier = format->modifiercxx . . $ _GdkDmabufFormat#modifier.; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * gdk_dmabuf_formats_contains: |
| 155 | * @formats: a `GdkDmabufFormats` |
| 156 | * @fourcc: a format code |
| 157 | * @modifier: a format modifier |
| 158 | * |
| 159 | * Returns whether a given format is contained in @formats. |
| 160 | * |
| 161 | * Returns: `TRUE` if the format specified by the arguments |
| 162 | * is part of @formats |
| 163 | * |
| 164 | * Since: 4.14 |
| 165 | */ |
| 166 | gbooleancxx . . $ gboolean# |
| 167 | gdk_dmabuf_formats_containscxx . . $ gdk_dmabuf_formats_contains(5431d246084b67b8). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats, |
| 168 | guint32cxx . . $ guint32# fourcc, |
| 169 | guint64cxx . . $ guint64# modifier) |
| 170 | { |
| 171 | for (gsizecxx . . $ gsize# i = 0; i < formats->n_formatscxx . . $ _GdkDmabufFormats#n_formats.; i++) |
| 172 | { |
| 173 | GdkDmabufFormatcxx . . $ GdkDmabufFormat# *format = &formats->formatscxx . . $ _GdkDmabufFormats#formats.[i]; |
| 174 | |
| 175 | if (format->fourcccxx . . $ _GdkDmabufFormat#fourcc. == fourcc && format->modifiercxx . . $ _GdkDmabufFormat#modifier. == modifier) |
| 176 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 177 | } |
| 178 | |
| 179 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 180 | } |
| 181 | |
| 182 | /*< private > |
| 183 | * gdk_dmabuf_formats_new: |
| 184 | * @formats: the formats |
| 185 | * @n_formats: the length of @formats |
| 186 | * |
| 187 | * Creates a new `GdkDmabufFormats struct for |
| 188 | * the given formats. |
| 189 | * |
| 190 | * The @formats array is expected to be sorted |
| 191 | * by preference. |
| 192 | * |
| 193 | * Returns: (transfer full): the new `GdkDmabufFormats` |
| 194 | * |
| 195 | * Since: 4.14 |
| 196 | */ |
| 197 | GdkDmabufFormatscxx . . $ GdkDmabufFormats# * |
| 198 | gdk_dmabuf_formats_newcxx . . $ gdk_dmabuf_formats_new(845eb4edd0da14ff). (GdkDmabufFormatcxx . . $ GdkDmabufFormat# *formats, |
| 199 | gsizecxx . . $ gsize# n_formats) |
| 200 | { |
| 201 | GdkDmabufFormatscxx . . $ GdkDmabufFormats# *self; |
| 202 | |
| 203 | self = g_new0cxx . . $ `<external>/1123956534522462559/gmem.h:335:9`! (GdkDmabufFormats, 1); |
| 204 | |
| 205 | self->ref_countcxx . . $ _GdkDmabufFormats#ref_count. = 1; |
| 206 | self->n_formatscxx . . $ _GdkDmabufFormats#n_formats. = n_formats; |
| 207 | self->formatscxx . . $ _GdkDmabufFormats#formats. = g_newcxx . . $ `<external>/1123956534522462559/gmem.h:318:9`! (GdkDmabufFormat, n_formats); |
| 208 | |
| 209 | if (n_formats != 0) |
| 210 | memcpycxx . . $ memcpy(cc817cb175f282d). (self->formatscxx . . $ _GdkDmabufFormats#formats., formats, n_formats * sizeof (GdkDmabufFormatcxx . . $ GdkDmabufFormat#)); |
| 211 | |
| 212 | return self; |
| 213 | } |
| 214 | |
| 215 | const GdkDmabufFormatcxx . . $ GdkDmabufFormat# * |
| 216 | gdk_dmabuf_formats_peek_formatscxx . . $ gdk_dmabuf_formats_peek_formats(d379bd87968b594f). (GdkDmabufFormatscxx . . $ GdkDmabufFormats# *self) |
| 217 | { |
| 218 | return self->formatscxx . . $ _GdkDmabufFormats#formats.; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * gdk_dmabuf_formats_equal: |
| 223 | * @formats1: (nullable): a `GdkDmabufFormats` |
| 224 | * @formats2: (nullable): another `GdkDmabufFormats` |
| 225 | * |
| 226 | * Returns whether @formats1 and @formats2 contain the |
| 227 | * same dmabuf formats, in the same order. |
| 228 | * |
| 229 | * Returns: `TRUE` if @formats1 and @formats2 are equal |
| 230 | * |
| 231 | * Since: 4.14 |
| 232 | */ |
| 233 | gbooleancxx . . $ gboolean# |
| 234 | gdk_dmabuf_formats_equalcxx . . $ gdk_dmabuf_formats_equal(3ac285fbd0e224f3). (const GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats1, |
| 235 | const GdkDmabufFormatscxx . . $ GdkDmabufFormats# *formats2) |
| 236 | { |
| 237 | if (formats1 == formats2) |
| 238 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 239 | |
| 240 | if (formats1 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || formats2 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 241 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 242 | |
| 243 | if (formats1->n_formatscxx . . $ _GdkDmabufFormats#n_formats. != formats2->n_formatscxx . . $ _GdkDmabufFormats#n_formats.) |
| 244 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 245 | |
| 246 | for (gsizecxx . . $ gsize# i = 0; i < formats1->n_formatscxx . . $ _GdkDmabufFormats#n_formats.; i++) |
| 247 | { |
| 248 | GdkDmabufFormatcxx . . $ GdkDmabufFormat# *f1 = &formats1->formatscxx . . $ _GdkDmabufFormats#formats.[i]; |
| 249 | GdkDmabufFormatcxx . . $ GdkDmabufFormat# *f2 = &formats2->formatscxx . . $ _GdkDmabufFormats#formats.[i]; |
| 250 | |
| 251 | if (f1->fourcccxx . . $ _GdkDmabufFormat#fourcc. != f2->fourcccxx . . $ _GdkDmabufFormat#fourcc. || |
| 252 | f1->modifiercxx . . $ _GdkDmabufFormat#modifier. != f2->modifiercxx . . $ _GdkDmabufFormat#modifier.) |
| 253 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 254 | } |
| 255 | |
| 256 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 257 | } |