cogl/auto/texture_pixmap_x11.rs
1#![allow(
2 clippy::too_many_arguments,
3 clippy::let_and_return,
4 clippy::from_over_into
5)]
6
7use crate::{Context, Object, TexturePixmapX11ReportLevel};
8
9use glib::translate::*;
10use std::{fmt, ptr};
11
12glib_wrapper! {
13 pub struct TexturePixmapX11(Object<ffi::CoglTexturePixmapX11, TexturePixmapX11Class>) @extends Object;
14
15 match fn {
16 get_type => || ffi::cogl_texture_pixmap_x11_get_gtype(),
17 }
18}
19
20impl TexturePixmapX11 {
21 /// Creates a texture that contains the contents of `pixmap`. If
22 /// `automatic_updates` is `true` then Cogl will attempt to listen for
23 /// damage events on the pixmap and automatically update the texture
24 /// when it changes.
25 /// ## `context`
26 /// A `Context`
27 /// ## `pixmap`
28 /// A X11 pixmap ID
29 /// ## `automatic_updates`
30 /// Whether to automatically copy the contents of
31 /// the pixmap to the texture.
32 ///
33 /// # Returns
34 ///
35 /// a new `TexturePixmapX11` instance
36 pub fn new(
37 context: &Context,
38 pixmap: u32,
39 automatic_updates: bool,
40 ) -> Result<TexturePixmapX11, glib::Error> {
41 unsafe {
42 let mut error = ptr::null_mut();
43 let ret = ffi::cogl_texture_pixmap_x11_new(
44 context.to_glib_none().0,
45 pixmap,
46 automatic_updates as i32,
47 &mut error,
48 );
49 if error.is_null() {
50 Ok(from_glib_full(ret))
51 } else {
52 Err(from_glib_full(error))
53 }
54 }
55 }
56
57 /// Creates one of a pair of textures to contain the contents of `pixmap`,
58 /// which has stereo content. (Different images for the right and left eyes.)
59 /// The left image is drawn using this texture; the right image is drawn
60 /// using a texture created by calling
61 /// `TexturePixmapX11::new_right` and passing in this texture as an
62 /// argument.
63 ///
64 /// In general, you should not use this function unless you have
65 /// queried the `GLX_STEREO_TREE_EXT` attribute of the corresponding
66 /// window using glXQueryDrawable() and determined that the window is
67 /// stereo. Note that this attribute can change over time and
68 /// notification is also provided through events defined in the
69 /// EXT_stereo_tree GLX extension. As long as the system has support for
70 /// stereo content, drawing using the left and right pixmaps will not
71 /// produce an error even if the window doesn't have stereo
72 /// content any more, but drawing with the right pixmap will produce
73 /// undefined output, so you need to listen for these events and
74 /// re-render to avoid race conditions. (Recreating a non-stereo
75 /// pixmap is not necessary, but may save resources.)
76 /// ## `context`
77 /// A `Context`
78 /// ## `pixmap`
79 /// A X11 pixmap ID
80 /// ## `automatic_updates`
81 /// Whether to automatically copy the contents of
82 /// the pixmap to the texture.
83 ///
84 /// # Returns
85 ///
86 /// a new `TexturePixmapX11` instance
87 pub fn new_left(
88 context: &Context,
89 pixmap: u32,
90 automatic_updates: bool,
91 ) -> Result<TexturePixmapX11, glib::Error> {
92 unsafe {
93 let mut error = ptr::null_mut();
94 let ret = ffi::cogl_texture_pixmap_x11_new_left(
95 context.to_glib_none().0,
96 pixmap,
97 automatic_updates as i32,
98 &mut error,
99 );
100 if error.is_null() {
101 Ok(from_glib_full(ret))
102 } else {
103 Err(from_glib_full(error))
104 }
105 }
106 }
107
108 /// Checks whether the given `self` is using the
109 /// GLX_EXT_texture_from_pixmap or similar extension to copy the
110 /// contents of the pixmap to the texture. This extension is usually
111 /// implemented as zero-copy operation so it implies the updates are
112 /// working efficiently.
113 ///
114 /// # Returns
115 ///
116 /// `true` if the texture is using an efficient extension
117 /// and `false` otherwise
118 pub fn is_using_tfp_extension(&self) -> bool {
119 unsafe {
120 ffi::cogl_texture_pixmap_x11_is_using_tfp_extension(self.to_glib_none().0)
121 == crate::TRUE
122 }
123 }
124
125 /// Creates a texture object that corresponds to the right-eye image
126 /// of a pixmap with stereo content. `self` must have been
127 /// created using `TexturePixmapX11::new_left`.
128 ///
129 /// # Returns
130 ///
131 /// a new `TexturePixmapX11` instance
132 pub fn new_right(&self) -> Option<TexturePixmapX11> {
133 unsafe {
134 from_glib_none(ffi::cogl_texture_pixmap_x11_new_right(
135 self.to_glib_none().0,
136 ))
137 }
138 }
139
140 /// Sets the damage object that will be used to track automatic updates
141 /// to the `self`. Damage tracking can be disabled by passing 0 for
142 /// `damage`. Otherwise this damage will replace the one used if `true`
143 /// was passed for automatic_updates to `TexturePixmapX11::new`.
144 ///
145 /// Note that Cogl will subtract from the damage region as it processes
146 /// damage events.
147 /// ## `damage`
148 /// A X11 Damage object or 0
149 /// ## `report_level`
150 /// The report level which describes how to interpret
151 /// the damage events. This should match the level that the damage
152 /// object was created with.
153 pub fn set_damage_object(&self, damage: u32, report_level: TexturePixmapX11ReportLevel) {
154 unsafe {
155 ffi::cogl_texture_pixmap_x11_set_damage_object(
156 self.to_glib_none().0,
157 damage,
158 report_level.to_glib(),
159 );
160 }
161 }
162
163 /// Forces an update of the given `self` so that it is refreshed with
164 /// the contents of the pixmap that was given to
165 /// `TexturePixmapX11::new`.
166 /// ## `x`
167 /// x coordinate of the area to update
168 /// ## `y`
169 /// y coordinate of the area to update
170 /// ## `width`
171 /// width of the area to update
172 /// ## `height`
173 /// height of the area to update
174 pub fn update_area(&self, x: i32, y: i32, width: i32, height: i32) {
175 unsafe {
176 ffi::cogl_texture_pixmap_x11_update_area(self.to_glib_none().0, x, y, width, height);
177 }
178 }
179
180 pub fn error_quark() -> u32 {
181 unsafe { ffi::cogl_texture_pixmap_x11_error_quark() }
182 }
183}
184
185impl fmt::Display for TexturePixmapX11 {
186 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
187 write!(f, "TexturePixmapX11")
188 }
189}