gdk4/auto/
memory_texture_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, ColorState, MemoryFormat, Texture};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// [`MemoryTextureBuilder`][crate::MemoryTextureBuilder] is a builder used to construct [`Texture`][crate::Texture] objects
    /// from system memory provided via [`glib::Bytes`][crate::glib::Bytes].
    ///
    /// The operation is quite simple: Create a texture builder, set all the necessary
    /// properties - keep in mind that the properties [`bytes`][struct@crate::MemoryTextureBuilder#bytes],
    /// [`stride`][struct@crate::MemoryTextureBuilder#stride], [`width`][struct@crate::MemoryTextureBuilder#width],
    /// and [`height`][struct@crate::MemoryTextureBuilder#height] are mandatory - and then call
    /// [`build()`][Self::build()] to create the new texture.
    ///
    /// [`MemoryTextureBuilder`][crate::MemoryTextureBuilder] can be used for quick one-shot construction of
    /// textures as well as kept around and reused to construct multiple textures.
    ///
    /// ## Properties
    ///
    ///
    /// #### `bytes`
    ///  The bytes holding the data.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `color-state`
    ///  The colorstate describing the data.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `format`
    ///  The format of the data.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `height`
    ///  The height of the texture.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `stride`
    ///  The rowstride of the texture.
    ///
    /// The rowstride is the number of bytes between the first pixel
    /// in a row of image data, and the first pixel in the next row.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `update-region`
    ///  The update region for [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture].
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `update-texture`
    ///  The texture [`update-region`][struct@crate::MemoryTextureBuilder#update-region] is an update for.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `width`
    ///  The width of the texture.
    ///
    /// Readable | Writeable
    #[doc(alias = "GdkMemoryTextureBuilder")]
    pub struct MemoryTextureBuilder(Object<ffi::GdkMemoryTextureBuilder, ffi::GdkMemoryTextureBuilderClass>);

    match fn {
        type_ => || ffi::gdk_memory_texture_builder_get_type(),
    }
}

impl MemoryTextureBuilder {
    /// Creates a new texture builder.
    ///
    /// # Returns
    ///
    /// the new `GdkTextureBuilder`
    #[doc(alias = "gdk_memory_texture_builder_new")]
    pub fn new() -> MemoryTextureBuilder {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gdk_memory_texture_builder_new()) }
    }

    /// Builds a new [`Texture`][crate::Texture] with the values set up in the builder.
    ///
    /// Note that it is a programming error to call this function if any mandatory
    /// property has not been set.
    ///
    /// It is possible to call this function multiple times to create multiple textures,
    /// possibly with changing properties in between.
    ///
    /// # Returns
    ///
    /// a newly built [`Texture`][crate::Texture]
    #[doc(alias = "gdk_memory_texture_builder_build")]
    pub fn build(&self) -> Texture {
        unsafe { from_glib_full(ffi::gdk_memory_texture_builder_build(self.to_glib_none().0)) }
    }

    /// Gets the bytes previously set via gdk_memory_texture_builder_set_bytes()
    /// or [`None`] if none was set.
    ///
    /// # Returns
    ///
    /// The bytes
    #[doc(alias = "gdk_memory_texture_builder_get_bytes")]
    #[doc(alias = "get_bytes")]
    pub fn bytes(&self) -> Option<glib::Bytes> {
        unsafe {
            from_glib_none(ffi::gdk_memory_texture_builder_get_bytes(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the colorstate previously set via gdk_memory_texture_builder_set_color_state().
    ///
    /// # Returns
    ///
    /// The colorstate
    #[doc(alias = "gdk_memory_texture_builder_get_color_state")]
    #[doc(alias = "get_color_state")]
    #[doc(alias = "color-state")]
    pub fn color_state(&self) -> ColorState {
        unsafe {
            from_glib_none(ffi::gdk_memory_texture_builder_get_color_state(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the format previously set via gdk_memory_texture_builder_set_format().
    ///
    /// # Returns
    ///
    /// The format
    #[doc(alias = "gdk_memory_texture_builder_get_format")]
    #[doc(alias = "get_format")]
    pub fn format(&self) -> MemoryFormat {
        unsafe {
            from_glib(ffi::gdk_memory_texture_builder_get_format(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the height previously set via gdk_memory_texture_builder_set_height()
    /// or 0 if the height wasn't set.
    ///
    /// # Returns
    ///
    /// The height
    #[doc(alias = "gdk_memory_texture_builder_get_height")]
    #[doc(alias = "get_height")]
    pub fn height(&self) -> i32 {
        unsafe { ffi::gdk_memory_texture_builder_get_height(self.to_glib_none().0) }
    }

    /// Gets the stride previously set via gdk_memory_texture_builder_set_stride().
    ///
    /// # Returns
    ///
    /// the stride
    #[doc(alias = "gdk_memory_texture_builder_get_stride")]
    #[doc(alias = "get_stride")]
    pub fn stride(&self) -> usize {
        unsafe { ffi::gdk_memory_texture_builder_get_stride(self.to_glib_none().0) }
    }

    /// Gets the region previously set via gdk_memory_texture_builder_set_update_region()
    /// or [`None`] if none was set.
    ///
    /// # Returns
    ///
    /// The update region
    #[doc(alias = "gdk_memory_texture_builder_get_update_region")]
    #[doc(alias = "get_update_region")]
    #[doc(alias = "update-region")]
    pub fn update_region(&self) -> Option<cairo::Region> {
        unsafe {
            from_glib_none(ffi::gdk_memory_texture_builder_get_update_region(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the texture previously set via gdk_memory_texture_builder_set_update_texture()
    /// or [`None`] if none was set.
    ///
    /// # Returns
    ///
    /// The update texture
    #[doc(alias = "gdk_memory_texture_builder_get_update_texture")]
    #[doc(alias = "get_update_texture")]
    #[doc(alias = "update-texture")]
    pub fn update_texture(&self) -> Option<Texture> {
        unsafe {
            from_glib_none(ffi::gdk_memory_texture_builder_get_update_texture(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the width previously set via gdk_memory_texture_builder_set_width()
    /// or 0 if the width wasn't set.
    ///
    /// # Returns
    ///
    /// The width
    #[doc(alias = "gdk_memory_texture_builder_get_width")]
    #[doc(alias = "get_width")]
    pub fn width(&self) -> i32 {
        unsafe { ffi::gdk_memory_texture_builder_get_width(self.to_glib_none().0) }
    }

    /// Sets the data to be shown but the texture.
    ///
    /// The bytes must be set before calling [`build()`][Self::build()].
    /// ## `bytes`
    /// The bytes the texture shows or [`None`] to unset
    #[doc(alias = "gdk_memory_texture_builder_set_bytes")]
    #[doc(alias = "bytes")]
    pub fn set_bytes(&self, bytes: Option<&glib::Bytes>) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_bytes(
                self.to_glib_none().0,
                bytes.to_glib_none().0,
            );
        }
    }

    /// Sets the colorstate describing the data.
    ///
    /// By default, the sRGB colorstate is used. If you don't know
    /// what colorstates are, this is probably the right thing.
    /// ## `color_state`
    /// The colorstate describing the data
    #[doc(alias = "gdk_memory_texture_builder_set_color_state")]
    #[doc(alias = "color-state")]
    pub fn set_color_state(&self, color_state: Option<&ColorState>) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_color_state(
                self.to_glib_none().0,
                color_state.to_glib_none().0,
            );
        }
    }

    /// Sets the format of the bytes.
    ///
    /// The default is `GDK_MEMORY_R8G8B8A8_PREMULTIPLIED`.
    /// ## `format`
    /// The texture's format
    #[doc(alias = "gdk_memory_texture_builder_set_format")]
    #[doc(alias = "format")]
    pub fn set_format(&self, format: MemoryFormat) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib());
        }
    }

    /// Sets the height of the texture.
    ///
    /// The height must be set before calling [`build()`][Self::build()].
    /// ## `height`
    /// The texture's height or 0 to unset
    #[doc(alias = "gdk_memory_texture_builder_set_height")]
    #[doc(alias = "height")]
    pub fn set_height(&self, height: i32) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height);
        }
    }

    /// Sets the rowstride of the bytes used.
    ///
    /// The rowstride must be set before calling [`build()`][Self::build()].
    /// ## `stride`
    /// the stride or 0 to unset
    #[doc(alias = "gdk_memory_texture_builder_set_stride")]
    #[doc(alias = "stride")]
    pub fn set_stride(&self, stride: usize) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride);
        }
    }

    /// Sets the region to be updated by this texture.
    ///
    /// Together with [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture],
    /// this describes an update of a previous texture.
    ///
    /// When rendering animations of large textures, it is possible that
    /// consecutive textures are only updating contents in parts of the texture.
    /// It is then possible to describe this update via these two properties,
    /// so that GTK can avoid rerendering parts that did not change.
    ///
    /// An example would be a screen recording where only the mouse pointer moves.
    /// ## `region`
    /// the region to update
    #[doc(alias = "gdk_memory_texture_builder_set_update_region")]
    #[doc(alias = "update-region")]
    pub fn set_update_region(&self, region: Option<&cairo::Region>) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_update_region(
                self.to_glib_none().0,
                mut_override(region.to_glib_none().0),
            );
        }
    }

    /// Sets the texture to be updated by this texture.
    ///
    /// See [`set_update_region()`][Self::set_update_region()] for an explanation.
    /// ## `texture`
    /// the texture to update
    #[doc(alias = "gdk_memory_texture_builder_set_update_texture")]
    #[doc(alias = "update-texture")]
    pub fn set_update_texture(&self, texture: Option<&impl IsA<Texture>>) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_update_texture(
                self.to_glib_none().0,
                texture.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    /// Sets the width of the texture.
    ///
    /// The width must be set before calling [`build()`][Self::build()].
    /// ## `width`
    /// The texture's width or 0 to unset
    #[doc(alias = "gdk_memory_texture_builder_set_width")]
    #[doc(alias = "width")]
    pub fn set_width(&self, width: i32) {
        unsafe {
            ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width);
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "bytes")]
    pub fn connect_bytes_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_bytes_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::bytes\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_bytes_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "color-state")]
    pub fn connect_color_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_color_state_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::color-state\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_color_state_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "format")]
    pub fn connect_format_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_format_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::format\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_format_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "height")]
    pub fn connect_height_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_height_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::height\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_height_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "stride")]
    pub fn connect_stride_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_stride_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::stride\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_stride_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "update-region")]
    pub fn connect_update_region_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_update_region_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::update-region\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_update_region_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "update-texture")]
    pub fn connect_update_texture_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_update_texture_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::update-texture\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_update_texture_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
    #[doc(alias = "width")]
    pub fn connect_width_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_width_trampoline<
            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
        >(
            this: *mut ffi::GdkMemoryTextureBuilder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::width\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_width_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

#[cfg(feature = "v4_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
impl Default for MemoryTextureBuilder {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for MemoryTextureBuilder {}
unsafe impl Sync for MemoryTextureBuilder {}