Debian Codegraph @

gst-libs/gst/wayland/gstwloutput.c

raw
1 /* GStreamer Wayland Library
2 *
3 * Copyright (C) 2025 Collabora Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library 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 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include "gstwloutput.h"
26 #include "gstwloutput-private.h"
27
28 struct _GstWlOutput
29 {
30 GObject parent;
31
32 struct wl_output *output;
33 guint32 global_id;
34
35 gchar *name;
36 gchar *description;
37
38 gint scale_factor;
39
40 struct
41 {
42 gint x;
43 gint y;
44 gint physical_width;
45 gint physical_height;
46 enum wl_output_subpixel subpixel;
47 gchar *make;
48 gchar *model;
49 enum wl_output_transform transform;
50 } geometry;
51
52 struct
53 {
54 guint flags;
55 gint width;
56 gint height;
57 gint refresh;
58 } mode;
59 };
60
61 G_DEFINE_TYPE (GstWlOutput, gst_wl_output, G_TYPE_OBJECT);
62
63 static void
64 gst_wl_output_finalize (GObject * object)
65 {
66 GstWlOutput *self = GST_WL_OUTPUT (object);
67 g_free (self->name);
68 g_free (self->description);
69 g_free (self->geometry.make);
70 g_free (self->geometry.model);
71
72 wl_output_destroy (self->output);
73
74 G_OBJECT_CLASS (gst_wl_output_parent_class)->finalize (object);
75 }
76
77 static void
78 gst_wl_output_init (GstWlOutput * self)
79 {
80 }
81
82 static void
83 gst_wl_output_class_init (GstWlOutputClass * klass)
84 {
85 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
86 gobject_class->finalize = gst_wl_output_finalize;
87 }
88
89 /**
90 * gst_wl_output_new: (skip):
91 * @output: A wl_output proxy
92 *
93 * Returns: (transfer full): A #GstWlOutput object
94 *
95 * Since: 1.28
96 */
97 GstWlOutput *
98 gst_wl_output_new (struct wl_output *output, guint32 global_id)
99 {
100 GstWlOutput *self = GST_WL_OUTPUT (g_object_new (GST_TYPE_WL_OUTPUT, NULL));
101
102 self->output = output;
103 self->global_id = global_id;
104
105 return self;
106 }
107
108 /**
109 * gst_wl_output_set_name: (skip):
110 * @self: the #GstWlOutput
111 * @name: the name to set
112 *
113 * Saves the name of the #GstWlOutput.
114 *
115 * Since: 1.28
116 */
117 void
118 gst_wl_output_set_name (GstWlOutput * self, const gchar * name)
119 {
120 g_free (self->name);
121 self->name = g_strdup (name);
122 }
123
124 /**
125 * gst_wl_output_set_description: (skip):
126 * @self: the #GstWlOutput
127 * @description: the name to set
128 *
129 * Saves the description of the #GstWlOutput.
130 *
131 * Since: 1.28
132 */
133 void
134 gst_wl_output_set_description (GstWlOutput * self, const gchar * description)
135 {
136 g_free (self->description);
137 self->description = g_strdup (description);
138 }
139
140 /**
141 * gst_wl_output_set_scale: (skip):
142 * @self: the #GstWlOutput
143 * @scale: the name to set
144 *
145 * Saves the scale of the #GstWlOutput.
146 *
147 * Since: 1.28
148 */
149 void
150 gst_wl_output_set_scale (GstWlOutput * self, gint scale_factor)
151 {
152 self->scale_factor = scale_factor;
153 }
154
155 /**
156 * gst_wl_output_set_geometry: (skip):
157 * @self: the #GstWlOutput
158 * @x: the x coordinate
159 * @y: the y coordinate
160 * @physical_width: the width in mm
161 * @physical_height: the height in mm
162 * @subpixel: type of pixels
163 * @make: the brand of the output
164 * @model: the specific model
165 * @transform: the transform used to render to this output
166 *
167 * Saves all the parameters that are part of the geometry callback for the
168 * output.
169 *
170 * Since: 1.28
171 */
172 void
173 gst_wl_output_set_geometry (GstWlOutput * self, gint x, gint y,
174 gint physical_width, gint physical_height,
175 enum wl_output_subpixel subpixel, const gchar * make, const gchar * model,
176 enum wl_output_transform transform)
177 {
178 g_free (self->geometry.make);
179 g_free (self->geometry.model);
180 self->geometry.x = x;
181 self->geometry.y = y;
182 self->geometry.physical_width = physical_width;
183 self->geometry.physical_height = physical_height;
184 self->geometry.subpixel = subpixel;
185 self->geometry.make = g_strdup (make);
186 self->geometry.model = g_strdup (model);
187 self->geometry.transform = transform;
188 }
189
190 /**
191 * gst_wl_output_set_mode: (skip):
192 * @self: A #GstWlOutput
193 * @flags: enum wl_output_mode
194 * @width: the width in pixels
195 * @height: the height in pixels
196 * @refresh: the refresh rate in mHz
197 *
198 * Saves all the paramters that are part of the mode callback for the output. The
199 * compositor may call this multiple times but must send the current mode last.
200 * Only the last mode is kept.
201 *
202 * Since: 1.28
203 */
204 void
205 gst_wl_output_set_mode (GstWlOutput * self, guint flags, gint width,
206 gint height, gint refresh)
207 {
208 self->mode.flags = flags;
209 self->mode.width = width;
210 self->mode.height = height;
211 self->mode.refresh = refresh;
212 }
213
214 /**
215 * gst_wl_output_get_wl_output:
216 * @self: A #GstWlOutput
217 *
218 * Returns: the struct wl_output pointer
219 *
220 * Since: 1.28
221 */
222 struct wl_output *
223 gst_wl_output_get_wl_output (GstWlOutput * self)
224 {
225 return self->output;
226 }
227
228 /**
229 * gst_wl_output_get_id:
230 * @self: A #GstWlOutput
231 *
232 * Returns: the Waylandnd object global id
233 *
234 * Since: 1.28
235 */
236 guint32
237 gst_wl_output_get_id (GstWlOutput * self)
238 {
239 return wl_proxy_get_id ((struct wl_proxy *) self->output);
240 }
241
242 /**
243 * gst_wl_output_get_name:
244 * @self: A #GstWlOutput
245 *
246 * Returns: the output name
247 *
248 * Since: 1.28
249 */
250 const gchar *
251 gst_wl_output_get_name (GstWlOutput * self)
252 {
253 return self->name;
254 }
255
256 /**
257 * gst_wl_output_get_description:
258 * @self: A #GstWlOutput
259 *
260 * Returns: the output description
261 *
262 * Since: 1.28
263 */
264 const gchar *
265 gst_wl_output_get_decscription (GstWlOutput * self)
266 {
267 return self->description;
268 }
269
270 /**
271 * gst_wl_output_get_make:
272 * @self: A #GstWlOutput
273 *
274 * Returns: the output make
275 *
276 * Since: 1.28
277 */
278 const gchar *
279 gst_wl_output_get_make (GstWlOutput * self)
280 {
281 return self->geometry.make;
282 }
283
284 /**
285 * gst_wl_output_get_model:
286 * @self: A #GstWlOutput
287 *
288 * Returns: the output model
289 *
290 * Since: 1.28
291 */
292 const gchar *
293 gst_wl_output_get_model (GstWlOutput * self)
294 {
295 return self->geometry.model;
296 }
297
298 /**
299 * gst_wl_output_get_scale:
300 * @self: A #GstWlOutput
301 *
302 * The output scale from the output protocol is rounded up to the next integer
303 * value. For accurate scaling factor use the fractional scaling protocol, which
304 * is queried per surface rather then per output.
305 *
306 * Returns: the output scale factor
307 *
308 * Since: 1.28
309 */
310 gint
311 gst_wl_output_get_scale (GstWlOutput * self)
312 {
313 return self->scale_factor;
314 }
315
316 /**
317 * gst_wl_output_get_x:
318 * @self: A #GstWlOutput
319 *
320 * Returns: the output virtual x coordinate
321 *
322 * Since: 1.28
323 */
324 gint
325 gst_wl_output_get_x (GstWlOutput * self)
326 {
327 return self->geometry.x;
328 }
329
330 /**
331 * gst_wl_output_get_y:
332 * @self: A #GstWlOutput
333 *
334 * Returns: the output virtual y coordinate
335 *
336 * Since: 1.28
337 */
338 gint
339 gst_wl_output_get_y (GstWlOutput * self)
340 {
341 return self->geometry.y;
342 }
343
344 /**
345 * gst_wl_output_get_physical_width:
346 * @self: A #GstWlOutput
347 *
348 * Returns: the output physical width
349 *
350 * Since: 1.28
351 */
352 gint
353 gst_wl_output_get_physical_width (GstWlOutput * self)
354 {
355 return self->geometry.physical_width;
356 }
357
358 /**
359 * gst_wl_output_get_physical_height:
360 * @self: A #GstWlOutput
361 *
362 * Returns: the output physical height
363 *
364 * Since: 1.28
365 */
366 gint
367 gst_wl_output_get_physical_height (GstWlOutput * self)
368 {
369 return self->geometry.physical_height;
370 }
371
372 /**
373 * gst_wl_output_get_subpixel:
374 * @self: A #GstWlOutput
375 *
376 * Returns: the output subpixel type (see enum wl_output_subpixel)
377 *
378 * Since: 1.28
379 */
380 enum wl_output_subpixel
381 gst_wl_output_get_subpixel (GstWlOutput * self)
382 {
383 return self->geometry.subpixel;
384 }
385
386 /**
387 * gst_wl_output_get_transform:
388 * @self: A #GstWlOutput
389 *
390 * Returns: the output transform (see enum wl_output_transfor)
391 *
392 * Since: 1.28
393 */
394 enum wl_output_transform
395 gst_wl_output_get_transform (GstWlOutput * self)
396 {
397 return self->geometry.transform;
398 }
399
400 /**
401 * gst_wl_output_get_mode_flags:
402 * @self: A #GstWlOutput
403 *
404 * Returns: the output mode flags (see enum wl_output_mode)
405 *
406 * Since: 1.28
407 */
408 guint
409 gst_wl_output_get_mode_flags (GstWlOutput * self)
410 {
411 return self->mode.flags;
412 }
413
414 /**
415 * gst_wl_output_get_width:
416 * @self: A #GstWlOutput
417 *
418 * Returns: the output width in pixels
419 *
420 * Since: 1.28
421 */
422 gint
423 gst_wl_output_get_width (GstWlOutput * self)
424 {
425 return self->mode.width;
426 }
427
428 /**
429 * gst_wl_output_get_height:
430 * @self: A #GstWlOutput
431 *
432 * Returns: the output height in pixels
433 *
434 * Since: 1.28
435 */
436 gint
437 gst_wl_output_get_height (GstWlOutput * self)
438 {
439 return self->mode.height;
440 }
441
442 /**
443 * gst_wl_output_get_refresh:
444 * @self: A #GstWlOutput
445 *
446 * Returns: the output refresh in mHz
447 *
448 * Since: 1.28
449 */
450 gint
451 gst_wl_output_get_refresh (GstWlOutput * self)
452 {
453 return self->mode.refresh;
454 }