1 // This file contains generated code. Do not edit directly.
2 // To regenerate this, run 'make'.
3 
4 //! Bindings to the `DRI3` X11 extension.
5 
6 #![allow(clippy::too_many_arguments)]
7 
8 #[allow(unused_imports)]
9 use std::borrow::Cow;
10 use std::convert::TryFrom;
11 #[allow(unused_imports)]
12 use std::convert::TryInto;
13 use std::io::IoSlice;
14 #[allow(unused_imports)]
15 use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
16 #[allow(unused_imports)]
17 use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize};
18 use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection};
19 #[allow(unused_imports)]
20 use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
21 use crate::errors::{ConnectionError, ParseError};
22 use super::xproto;
23 
24 /// The X11 name of the extension for QueryExtension
25 pub const X11_EXTENSION_NAME: &str = "DRI3";
26 
27 /// The version number of this extension that this client library supports.
28 ///
29 /// This constant contains the version number of this extension that is supported
30 /// by this build of x11rb. For most things, it does not make sense to use this
31 /// information. If you need to send a `QueryVersion`, it is recommended to instead
32 /// send the maximum version of the extension that you need.
33 pub const X11_XML_VERSION: (u32, u32) = (1, 2);
34 
35 /// Opcode for the QueryVersion request
36 pub const QUERY_VERSION_REQUEST: u8 = 0;
37 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
38 pub struct QueryVersionRequest {
39     pub major_version: u32,
40     pub minor_version: u32,
41 }
42 impl QueryVersionRequest {
43     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,44     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
45     where
46         Conn: RequestConnection + ?Sized,
47     {
48         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
49             .ok_or(ConnectionError::UnsupportedExtension)?;
50         let length_so_far = 0;
51         let major_version_bytes = self.major_version.serialize();
52         let minor_version_bytes = self.minor_version.serialize();
53         let mut request0 = vec![
54             extension_information.major_opcode,
55             QUERY_VERSION_REQUEST,
56             0,
57             0,
58             major_version_bytes[0],
59             major_version_bytes[1],
60             major_version_bytes[2],
61             major_version_bytes[3],
62             minor_version_bytes[0],
63             minor_version_bytes[1],
64             minor_version_bytes[2],
65             minor_version_bytes[3],
66         ];
67         let length_so_far = length_so_far + request0.len();
68         assert_eq!(length_so_far % 4, 0);
69         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
70         request0[2..4].copy_from_slice(&length.to_ne_bytes());
71         Ok((vec![request0.into()], vec![]))
72     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,73     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
74     where
75         Conn: RequestConnection + ?Sized,
76     {
77         let (bytes, fds) = self.serialize(conn)?;
78         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
79         conn.send_request_with_reply(&slices, fds)
80     }
81     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>82     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
83         if header.minor_opcode != QUERY_VERSION_REQUEST {
84             return Err(ParseError::InvalidValue);
85         }
86         let (major_version, remaining) = u32::try_parse(value)?;
87         let (minor_version, remaining) = u32::try_parse(remaining)?;
88         let _ = remaining;
89         Ok(QueryVersionRequest {
90             major_version,
91             minor_version,
92         })
93     }
94 }
95 impl Request for QueryVersionRequest {
96     type Reply = QueryVersionReply;
97 }
query_version<Conn>(conn: &Conn, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,98 pub fn query_version<Conn>(conn: &Conn, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
99 where
100     Conn: RequestConnection + ?Sized,
101 {
102     let request0 = QueryVersionRequest {
103         major_version,
104         minor_version,
105     };
106     request0.send(conn)
107 }
108 
109 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
110 pub struct QueryVersionReply {
111     pub sequence: u16,
112     pub length: u32,
113     pub major_version: u32,
114     pub minor_version: u32,
115 }
116 impl TryParse for QueryVersionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>117     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
118         let remaining = initial_value;
119         let (response_type, remaining) = u8::try_parse(remaining)?;
120         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
121         let (sequence, remaining) = u16::try_parse(remaining)?;
122         let (length, remaining) = u32::try_parse(remaining)?;
123         let (major_version, remaining) = u32::try_parse(remaining)?;
124         let (minor_version, remaining) = u32::try_parse(remaining)?;
125         if response_type != 1 {
126             return Err(ParseError::InvalidValue);
127         }
128         let result = QueryVersionReply { sequence, length, major_version, minor_version };
129         let _ = remaining;
130         let remaining = initial_value.get(32 + length as usize * 4..)
131             .ok_or(ParseError::InsufficientData)?;
132         Ok((result, remaining))
133     }
134 }
135 
136 /// Opcode for the Open request
137 pub const OPEN_REQUEST: u8 = 1;
138 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
139 pub struct OpenRequest {
140     pub drawable: xproto::Drawable,
141     pub provider: u32,
142 }
143 impl OpenRequest {
144     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,145     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
146     where
147         Conn: RequestConnection + ?Sized,
148     {
149         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
150             .ok_or(ConnectionError::UnsupportedExtension)?;
151         let length_so_far = 0;
152         let drawable_bytes = self.drawable.serialize();
153         let provider_bytes = self.provider.serialize();
154         let mut request0 = vec![
155             extension_information.major_opcode,
156             OPEN_REQUEST,
157             0,
158             0,
159             drawable_bytes[0],
160             drawable_bytes[1],
161             drawable_bytes[2],
162             drawable_bytes[3],
163             provider_bytes[0],
164             provider_bytes[1],
165             provider_bytes[2],
166             provider_bytes[3],
167         ];
168         let length_so_far = length_so_far + request0.len();
169         assert_eq!(length_so_far % 4, 0);
170         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
171         request0[2..4].copy_from_slice(&length.to_ne_bytes());
172         Ok((vec![request0.into()], vec![]))
173     }
send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, OpenReply>, ConnectionError> where Conn: RequestConnection + ?Sized,174     pub fn send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, OpenReply>, ConnectionError>
175     where
176         Conn: RequestConnection + ?Sized,
177     {
178         let (bytes, fds) = self.serialize(conn)?;
179         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
180         conn.send_request_with_reply_with_fds(&slices, fds)
181     }
182     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>183     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
184         if header.minor_opcode != OPEN_REQUEST {
185             return Err(ParseError::InvalidValue);
186         }
187         let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
188         let (provider, remaining) = u32::try_parse(remaining)?;
189         let _ = remaining;
190         Ok(OpenRequest {
191             drawable,
192             provider,
193         })
194     }
195 }
196 impl Request for OpenRequest {
197     type Reply = OpenReply;
198 }
open<Conn>(conn: &Conn, drawable: xproto::Drawable, provider: u32) -> Result<CookieWithFds<'_, Conn, OpenReply>, ConnectionError> where Conn: RequestConnection + ?Sized,199 pub fn open<Conn>(conn: &Conn, drawable: xproto::Drawable, provider: u32) -> Result<CookieWithFds<'_, Conn, OpenReply>, ConnectionError>
200 where
201     Conn: RequestConnection + ?Sized,
202 {
203     let request0 = OpenRequest {
204         drawable,
205         provider,
206     };
207     request0.send(conn)
208 }
209 
210 #[derive(Debug, PartialEq, Eq)]
211 pub struct OpenReply {
212     pub nfd: u8,
213     pub sequence: u16,
214     pub length: u32,
215     pub device_fd: RawFdContainer,
216 }
217 impl TryParseFd for OpenReply {
try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError>218     fn try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError> {
219         let remaining = initial_value;
220         let (response_type, remaining) = u8::try_parse(remaining)?;
221         let (nfd, remaining) = u8::try_parse(remaining)?;
222         let (sequence, remaining) = u16::try_parse(remaining)?;
223         let (length, remaining) = u32::try_parse(remaining)?;
224         if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
225         let device_fd = fds.remove(0);
226         let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?;
227         if response_type != 1 {
228             return Err(ParseError::InvalidValue);
229         }
230         let result = OpenReply { nfd, sequence, length, device_fd };
231         let _ = remaining;
232         let remaining = initial_value.get(32 + length as usize * 4..)
233             .ok_or(ParseError::InsufficientData)?;
234         Ok((result, remaining))
235     }
236 }
237 
238 /// Opcode for the PixmapFromBuffer request
239 pub const PIXMAP_FROM_BUFFER_REQUEST: u8 = 2;
240 #[derive(Debug, PartialEq, Eq)]
241 pub struct PixmapFromBufferRequest {
242     pub pixmap: xproto::Pixmap,
243     pub drawable: xproto::Drawable,
244     pub size: u32,
245     pub width: u16,
246     pub height: u16,
247     pub stride: u16,
248     pub depth: u8,
249     pub bpp: u8,
250     pub pixmap_fd: RawFdContainer,
251 }
252 impl PixmapFromBufferRequest {
253     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,254     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
255     where
256         Conn: RequestConnection + ?Sized,
257     {
258         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
259             .ok_or(ConnectionError::UnsupportedExtension)?;
260         let length_so_far = 0;
261         let pixmap_bytes = self.pixmap.serialize();
262         let drawable_bytes = self.drawable.serialize();
263         let size_bytes = self.size.serialize();
264         let width_bytes = self.width.serialize();
265         let height_bytes = self.height.serialize();
266         let stride_bytes = self.stride.serialize();
267         let depth_bytes = self.depth.serialize();
268         let bpp_bytes = self.bpp.serialize();
269         let mut request0 = vec![
270             extension_information.major_opcode,
271             PIXMAP_FROM_BUFFER_REQUEST,
272             0,
273             0,
274             pixmap_bytes[0],
275             pixmap_bytes[1],
276             pixmap_bytes[2],
277             pixmap_bytes[3],
278             drawable_bytes[0],
279             drawable_bytes[1],
280             drawable_bytes[2],
281             drawable_bytes[3],
282             size_bytes[0],
283             size_bytes[1],
284             size_bytes[2],
285             size_bytes[3],
286             width_bytes[0],
287             width_bytes[1],
288             height_bytes[0],
289             height_bytes[1],
290             stride_bytes[0],
291             stride_bytes[1],
292             depth_bytes[0],
293             bpp_bytes[0],
294         ];
295         let length_so_far = length_so_far + request0.len();
296         assert_eq!(length_so_far % 4, 0);
297         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
298         request0[2..4].copy_from_slice(&length.to_ne_bytes());
299         Ok((vec![request0.into()], vec![self.pixmap_fd]))
300     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,301     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
302     where
303         Conn: RequestConnection + ?Sized,
304     {
305         let (bytes, fds) = self.serialize(conn)?;
306         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
307         conn.send_request_without_reply(&slices, fds)
308     }
309     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError>310     pub fn try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError> {
311         if header.minor_opcode != PIXMAP_FROM_BUFFER_REQUEST {
312             return Err(ParseError::InvalidValue);
313         }
314         let (pixmap, remaining) = xproto::Pixmap::try_parse(value)?;
315         let (drawable, remaining) = xproto::Drawable::try_parse(remaining)?;
316         let (size, remaining) = u32::try_parse(remaining)?;
317         let (width, remaining) = u16::try_parse(remaining)?;
318         let (height, remaining) = u16::try_parse(remaining)?;
319         let (stride, remaining) = u16::try_parse(remaining)?;
320         let (depth, remaining) = u8::try_parse(remaining)?;
321         let (bpp, remaining) = u8::try_parse(remaining)?;
322         if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
323         let pixmap_fd = fds.remove(0);
324         let _ = remaining;
325         Ok(PixmapFromBufferRequest {
326             pixmap,
327             drawable,
328             size,
329             width,
330             height,
331             stride,
332             depth,
333             bpp,
334             pixmap_fd,
335         })
336     }
337 }
338 impl Request for PixmapFromBufferRequest {
339     type Reply = ();
340 }
pixmap_from_buffer<Conn, A>(conn: &Conn, pixmap: xproto::Pixmap, drawable: xproto::Drawable, size: u32, width: u16, height: u16, stride: u16, depth: u8, bpp: u8, pixmap_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<RawFdContainer>,341 pub fn pixmap_from_buffer<Conn, A>(conn: &Conn, pixmap: xproto::Pixmap, drawable: xproto::Drawable, size: u32, width: u16, height: u16, stride: u16, depth: u8, bpp: u8, pixmap_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError>
342 where
343     Conn: RequestConnection + ?Sized,
344     A: Into<RawFdContainer>,
345 {
346     let pixmap_fd: RawFdContainer = pixmap_fd.into();
347     let request0 = PixmapFromBufferRequest {
348         pixmap,
349         drawable,
350         size,
351         width,
352         height,
353         stride,
354         depth,
355         bpp,
356         pixmap_fd,
357     };
358     request0.send(conn)
359 }
360 
361 /// Opcode for the BufferFromPixmap request
362 pub const BUFFER_FROM_PIXMAP_REQUEST: u8 = 3;
363 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
364 pub struct BufferFromPixmapRequest {
365     pub pixmap: xproto::Pixmap,
366 }
367 impl BufferFromPixmapRequest {
368     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,369     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
370     where
371         Conn: RequestConnection + ?Sized,
372     {
373         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
374             .ok_or(ConnectionError::UnsupportedExtension)?;
375         let length_so_far = 0;
376         let pixmap_bytes = self.pixmap.serialize();
377         let mut request0 = vec![
378             extension_information.major_opcode,
379             BUFFER_FROM_PIXMAP_REQUEST,
380             0,
381             0,
382             pixmap_bytes[0],
383             pixmap_bytes[1],
384             pixmap_bytes[2],
385             pixmap_bytes[3],
386         ];
387         let length_so_far = length_so_far + request0.len();
388         assert_eq!(length_so_far % 4, 0);
389         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
390         request0[2..4].copy_from_slice(&length.to_ne_bytes());
391         Ok((vec![request0.into()], vec![]))
392     }
send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, BufferFromPixmapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,393     pub fn send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, BufferFromPixmapReply>, ConnectionError>
394     where
395         Conn: RequestConnection + ?Sized,
396     {
397         let (bytes, fds) = self.serialize(conn)?;
398         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
399         conn.send_request_with_reply_with_fds(&slices, fds)
400     }
401     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>402     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
403         if header.minor_opcode != BUFFER_FROM_PIXMAP_REQUEST {
404             return Err(ParseError::InvalidValue);
405         }
406         let (pixmap, remaining) = xproto::Pixmap::try_parse(value)?;
407         let _ = remaining;
408         Ok(BufferFromPixmapRequest {
409             pixmap,
410         })
411     }
412 }
413 impl Request for BufferFromPixmapRequest {
414     type Reply = BufferFromPixmapReply;
415 }
buffer_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BufferFromPixmapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,416 pub fn buffer_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BufferFromPixmapReply>, ConnectionError>
417 where
418     Conn: RequestConnection + ?Sized,
419 {
420     let request0 = BufferFromPixmapRequest {
421         pixmap,
422     };
423     request0.send(conn)
424 }
425 
426 #[derive(Debug, PartialEq, Eq)]
427 pub struct BufferFromPixmapReply {
428     pub nfd: u8,
429     pub sequence: u16,
430     pub length: u32,
431     pub size: u32,
432     pub width: u16,
433     pub height: u16,
434     pub stride: u16,
435     pub depth: u8,
436     pub bpp: u8,
437     pub pixmap_fd: RawFdContainer,
438 }
439 impl TryParseFd for BufferFromPixmapReply {
try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError>440     fn try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError> {
441         let remaining = initial_value;
442         let (response_type, remaining) = u8::try_parse(remaining)?;
443         let (nfd, remaining) = u8::try_parse(remaining)?;
444         let (sequence, remaining) = u16::try_parse(remaining)?;
445         let (length, remaining) = u32::try_parse(remaining)?;
446         let (size, remaining) = u32::try_parse(remaining)?;
447         let (width, remaining) = u16::try_parse(remaining)?;
448         let (height, remaining) = u16::try_parse(remaining)?;
449         let (stride, remaining) = u16::try_parse(remaining)?;
450         let (depth, remaining) = u8::try_parse(remaining)?;
451         let (bpp, remaining) = u8::try_parse(remaining)?;
452         if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
453         let pixmap_fd = fds.remove(0);
454         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
455         if response_type != 1 {
456             return Err(ParseError::InvalidValue);
457         }
458         let result = BufferFromPixmapReply { nfd, sequence, length, size, width, height, stride, depth, bpp, pixmap_fd };
459         let _ = remaining;
460         let remaining = initial_value.get(32 + length as usize * 4..)
461             .ok_or(ParseError::InsufficientData)?;
462         Ok((result, remaining))
463     }
464 }
465 
466 /// Opcode for the FenceFromFD request
467 pub const FENCE_FROM_FD_REQUEST: u8 = 4;
468 #[derive(Debug, PartialEq, Eq)]
469 pub struct FenceFromFDRequest {
470     pub drawable: xproto::Drawable,
471     pub fence: u32,
472     pub initially_triggered: bool,
473     pub fence_fd: RawFdContainer,
474 }
475 impl FenceFromFDRequest {
476     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,477     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
478     where
479         Conn: RequestConnection + ?Sized,
480     {
481         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
482             .ok_or(ConnectionError::UnsupportedExtension)?;
483         let length_so_far = 0;
484         let drawable_bytes = self.drawable.serialize();
485         let fence_bytes = self.fence.serialize();
486         let initially_triggered_bytes = self.initially_triggered.serialize();
487         let mut request0 = vec![
488             extension_information.major_opcode,
489             FENCE_FROM_FD_REQUEST,
490             0,
491             0,
492             drawable_bytes[0],
493             drawable_bytes[1],
494             drawable_bytes[2],
495             drawable_bytes[3],
496             fence_bytes[0],
497             fence_bytes[1],
498             fence_bytes[2],
499             fence_bytes[3],
500             initially_triggered_bytes[0],
501             0,
502             0,
503             0,
504         ];
505         let length_so_far = length_so_far + request0.len();
506         assert_eq!(length_so_far % 4, 0);
507         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
508         request0[2..4].copy_from_slice(&length.to_ne_bytes());
509         Ok((vec![request0.into()], vec![self.fence_fd]))
510     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,511     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
512     where
513         Conn: RequestConnection + ?Sized,
514     {
515         let (bytes, fds) = self.serialize(conn)?;
516         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
517         conn.send_request_without_reply(&slices, fds)
518     }
519     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError>520     pub fn try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError> {
521         if header.minor_opcode != FENCE_FROM_FD_REQUEST {
522             return Err(ParseError::InvalidValue);
523         }
524         let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
525         let (fence, remaining) = u32::try_parse(remaining)?;
526         let (initially_triggered, remaining) = bool::try_parse(remaining)?;
527         let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
528         if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
529         let fence_fd = fds.remove(0);
530         let _ = remaining;
531         Ok(FenceFromFDRequest {
532             drawable,
533             fence,
534             initially_triggered,
535             fence_fd,
536         })
537     }
538 }
539 impl Request for FenceFromFDRequest {
540     type Reply = ();
541 }
fence_from_fd<Conn, A>(conn: &Conn, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<RawFdContainer>,542 pub fn fence_from_fd<Conn, A>(conn: &Conn, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError>
543 where
544     Conn: RequestConnection + ?Sized,
545     A: Into<RawFdContainer>,
546 {
547     let fence_fd: RawFdContainer = fence_fd.into();
548     let request0 = FenceFromFDRequest {
549         drawable,
550         fence,
551         initially_triggered,
552         fence_fd,
553     };
554     request0.send(conn)
555 }
556 
557 /// Opcode for the FDFromFence request
558 pub const FD_FROM_FENCE_REQUEST: u8 = 5;
559 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
560 pub struct FDFromFenceRequest {
561     pub drawable: xproto::Drawable,
562     pub fence: u32,
563 }
564 impl FDFromFenceRequest {
565     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,566     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
567     where
568         Conn: RequestConnection + ?Sized,
569     {
570         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
571             .ok_or(ConnectionError::UnsupportedExtension)?;
572         let length_so_far = 0;
573         let drawable_bytes = self.drawable.serialize();
574         let fence_bytes = self.fence.serialize();
575         let mut request0 = vec![
576             extension_information.major_opcode,
577             FD_FROM_FENCE_REQUEST,
578             0,
579             0,
580             drawable_bytes[0],
581             drawable_bytes[1],
582             drawable_bytes[2],
583             drawable_bytes[3],
584             fence_bytes[0],
585             fence_bytes[1],
586             fence_bytes[2],
587             fence_bytes[3],
588         ];
589         let length_so_far = length_so_far + request0.len();
590         assert_eq!(length_so_far % 4, 0);
591         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
592         request0[2..4].copy_from_slice(&length.to_ne_bytes());
593         Ok((vec![request0.into()], vec![]))
594     }
send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, FDFromFenceReply>, ConnectionError> where Conn: RequestConnection + ?Sized,595     pub fn send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, FDFromFenceReply>, ConnectionError>
596     where
597         Conn: RequestConnection + ?Sized,
598     {
599         let (bytes, fds) = self.serialize(conn)?;
600         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
601         conn.send_request_with_reply_with_fds(&slices, fds)
602     }
603     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>604     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
605         if header.minor_opcode != FD_FROM_FENCE_REQUEST {
606             return Err(ParseError::InvalidValue);
607         }
608         let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
609         let (fence, remaining) = u32::try_parse(remaining)?;
610         let _ = remaining;
611         Ok(FDFromFenceRequest {
612             drawable,
613             fence,
614         })
615     }
616 }
617 impl Request for FDFromFenceRequest {
618     type Reply = FDFromFenceReply;
619 }
fd_from_fence<Conn>(conn: &Conn, drawable: xproto::Drawable, fence: u32) -> Result<CookieWithFds<'_, Conn, FDFromFenceReply>, ConnectionError> where Conn: RequestConnection + ?Sized,620 pub fn fd_from_fence<Conn>(conn: &Conn, drawable: xproto::Drawable, fence: u32) -> Result<CookieWithFds<'_, Conn, FDFromFenceReply>, ConnectionError>
621 where
622     Conn: RequestConnection + ?Sized,
623 {
624     let request0 = FDFromFenceRequest {
625         drawable,
626         fence,
627     };
628     request0.send(conn)
629 }
630 
631 #[derive(Debug, PartialEq, Eq)]
632 pub struct FDFromFenceReply {
633     pub nfd: u8,
634     pub sequence: u16,
635     pub length: u32,
636     pub fence_fd: RawFdContainer,
637 }
638 impl TryParseFd for FDFromFenceReply {
try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError>639     fn try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError> {
640         let remaining = initial_value;
641         let (response_type, remaining) = u8::try_parse(remaining)?;
642         let (nfd, remaining) = u8::try_parse(remaining)?;
643         let (sequence, remaining) = u16::try_parse(remaining)?;
644         let (length, remaining) = u32::try_parse(remaining)?;
645         if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
646         let fence_fd = fds.remove(0);
647         let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?;
648         if response_type != 1 {
649             return Err(ParseError::InvalidValue);
650         }
651         let result = FDFromFenceReply { nfd, sequence, length, fence_fd };
652         let _ = remaining;
653         let remaining = initial_value.get(32 + length as usize * 4..)
654             .ok_or(ParseError::InsufficientData)?;
655         Ok((result, remaining))
656     }
657 }
658 
659 /// Opcode for the GetSupportedModifiers request
660 pub const GET_SUPPORTED_MODIFIERS_REQUEST: u8 = 6;
661 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
662 pub struct GetSupportedModifiersRequest {
663     pub window: u32,
664     pub depth: u8,
665     pub bpp: u8,
666 }
667 impl GetSupportedModifiersRequest {
668     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,669     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
670     where
671         Conn: RequestConnection + ?Sized,
672     {
673         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
674             .ok_or(ConnectionError::UnsupportedExtension)?;
675         let length_so_far = 0;
676         let window_bytes = self.window.serialize();
677         let depth_bytes = self.depth.serialize();
678         let bpp_bytes = self.bpp.serialize();
679         let mut request0 = vec![
680             extension_information.major_opcode,
681             GET_SUPPORTED_MODIFIERS_REQUEST,
682             0,
683             0,
684             window_bytes[0],
685             window_bytes[1],
686             window_bytes[2],
687             window_bytes[3],
688             depth_bytes[0],
689             bpp_bytes[0],
690             0,
691             0,
692         ];
693         let length_so_far = length_so_far + request0.len();
694         assert_eq!(length_so_far % 4, 0);
695         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
696         request0[2..4].copy_from_slice(&length.to_ne_bytes());
697         Ok((vec![request0.into()], vec![]))
698     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetSupportedModifiersReply>, ConnectionError> where Conn: RequestConnection + ?Sized,699     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetSupportedModifiersReply>, ConnectionError>
700     where
701         Conn: RequestConnection + ?Sized,
702     {
703         let (bytes, fds) = self.serialize(conn)?;
704         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
705         conn.send_request_with_reply(&slices, fds)
706     }
707     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>708     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
709         if header.minor_opcode != GET_SUPPORTED_MODIFIERS_REQUEST {
710             return Err(ParseError::InvalidValue);
711         }
712         let (window, remaining) = u32::try_parse(value)?;
713         let (depth, remaining) = u8::try_parse(remaining)?;
714         let (bpp, remaining) = u8::try_parse(remaining)?;
715         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
716         let _ = remaining;
717         Ok(GetSupportedModifiersRequest {
718             window,
719             depth,
720             bpp,
721         })
722     }
723 }
724 impl Request for GetSupportedModifiersRequest {
725     type Reply = GetSupportedModifiersReply;
726 }
get_supported_modifiers<Conn>(conn: &Conn, window: u32, depth: u8, bpp: u8) -> Result<Cookie<'_, Conn, GetSupportedModifiersReply>, ConnectionError> where Conn: RequestConnection + ?Sized,727 pub fn get_supported_modifiers<Conn>(conn: &Conn, window: u32, depth: u8, bpp: u8) -> Result<Cookie<'_, Conn, GetSupportedModifiersReply>, ConnectionError>
728 where
729     Conn: RequestConnection + ?Sized,
730 {
731     let request0 = GetSupportedModifiersRequest {
732         window,
733         depth,
734         bpp,
735     };
736     request0.send(conn)
737 }
738 
739 #[derive(Debug, Clone, PartialEq, Eq)]
740 pub struct GetSupportedModifiersReply {
741     pub sequence: u16,
742     pub length: u32,
743     pub window_modifiers: Vec<u64>,
744     pub screen_modifiers: Vec<u64>,
745 }
746 impl TryParse for GetSupportedModifiersReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>747     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
748         let remaining = initial_value;
749         let (response_type, remaining) = u8::try_parse(remaining)?;
750         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
751         let (sequence, remaining) = u16::try_parse(remaining)?;
752         let (length, remaining) = u32::try_parse(remaining)?;
753         let (num_window_modifiers, remaining) = u32::try_parse(remaining)?;
754         let (num_screen_modifiers, remaining) = u32::try_parse(remaining)?;
755         let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
756         let (window_modifiers, remaining) = crate::x11_utils::parse_list::<u64>(remaining, num_window_modifiers.try_to_usize()?)?;
757         let (screen_modifiers, remaining) = crate::x11_utils::parse_list::<u64>(remaining, num_screen_modifiers.try_to_usize()?)?;
758         if response_type != 1 {
759             return Err(ParseError::InvalidValue);
760         }
761         let result = GetSupportedModifiersReply { sequence, length, window_modifiers, screen_modifiers };
762         let _ = remaining;
763         let remaining = initial_value.get(32 + length as usize * 4..)
764             .ok_or(ParseError::InsufficientData)?;
765         Ok((result, remaining))
766     }
767 }
768 impl GetSupportedModifiersReply {
769     /// Get the value of the `num_window_modifiers` field.
770     ///
771     /// The `num_window_modifiers` field is used as the length field of the `window_modifiers` field.
772     /// This function computes the field's value again based on the length of the list.
773     ///
774     /// # Panics
775     ///
776     /// Panics if the value cannot be represented in the target type. This
777     /// cannot happen with values of the struct received from the X11 server.
num_window_modifiers(&self) -> u32778     pub fn num_window_modifiers(&self) -> u32 {
779         self.window_modifiers.len()
780             .try_into().unwrap()
781     }
782     /// Get the value of the `num_screen_modifiers` field.
783     ///
784     /// The `num_screen_modifiers` field is used as the length field of the `screen_modifiers` field.
785     /// This function computes the field's value again based on the length of the list.
786     ///
787     /// # Panics
788     ///
789     /// Panics if the value cannot be represented in the target type. This
790     /// cannot happen with values of the struct received from the X11 server.
num_screen_modifiers(&self) -> u32791     pub fn num_screen_modifiers(&self) -> u32 {
792         self.screen_modifiers.len()
793             .try_into().unwrap()
794     }
795 }
796 
797 /// Opcode for the PixmapFromBuffers request
798 pub const PIXMAP_FROM_BUFFERS_REQUEST: u8 = 7;
799 #[derive(Debug, PartialEq, Eq)]
800 pub struct PixmapFromBuffersRequest {
801     pub pixmap: xproto::Pixmap,
802     pub window: xproto::Window,
803     pub width: u16,
804     pub height: u16,
805     pub stride0: u32,
806     pub offset0: u32,
807     pub stride1: u32,
808     pub offset1: u32,
809     pub stride2: u32,
810     pub offset2: u32,
811     pub stride3: u32,
812     pub offset3: u32,
813     pub depth: u8,
814     pub bpp: u8,
815     pub modifier: u64,
816     pub buffers: Vec<RawFdContainer>,
817 }
818 impl PixmapFromBuffersRequest {
819     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,820     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
821     where
822         Conn: RequestConnection + ?Sized,
823     {
824         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
825             .ok_or(ConnectionError::UnsupportedExtension)?;
826         let length_so_far = 0;
827         let pixmap_bytes = self.pixmap.serialize();
828         let window_bytes = self.window.serialize();
829         let num_buffers = u8::try_from(self.buffers.len()).expect("`buffers` has too many elements");
830         let num_buffers_bytes = num_buffers.serialize();
831         let width_bytes = self.width.serialize();
832         let height_bytes = self.height.serialize();
833         let stride0_bytes = self.stride0.serialize();
834         let offset0_bytes = self.offset0.serialize();
835         let stride1_bytes = self.stride1.serialize();
836         let offset1_bytes = self.offset1.serialize();
837         let stride2_bytes = self.stride2.serialize();
838         let offset2_bytes = self.offset2.serialize();
839         let stride3_bytes = self.stride3.serialize();
840         let offset3_bytes = self.offset3.serialize();
841         let depth_bytes = self.depth.serialize();
842         let bpp_bytes = self.bpp.serialize();
843         let modifier_bytes = self.modifier.serialize();
844         let mut request0 = vec![
845             extension_information.major_opcode,
846             PIXMAP_FROM_BUFFERS_REQUEST,
847             0,
848             0,
849             pixmap_bytes[0],
850             pixmap_bytes[1],
851             pixmap_bytes[2],
852             pixmap_bytes[3],
853             window_bytes[0],
854             window_bytes[1],
855             window_bytes[2],
856             window_bytes[3],
857             num_buffers_bytes[0],
858             0,
859             0,
860             0,
861             width_bytes[0],
862             width_bytes[1],
863             height_bytes[0],
864             height_bytes[1],
865             stride0_bytes[0],
866             stride0_bytes[1],
867             stride0_bytes[2],
868             stride0_bytes[3],
869             offset0_bytes[0],
870             offset0_bytes[1],
871             offset0_bytes[2],
872             offset0_bytes[3],
873             stride1_bytes[0],
874             stride1_bytes[1],
875             stride1_bytes[2],
876             stride1_bytes[3],
877             offset1_bytes[0],
878             offset1_bytes[1],
879             offset1_bytes[2],
880             offset1_bytes[3],
881             stride2_bytes[0],
882             stride2_bytes[1],
883             stride2_bytes[2],
884             stride2_bytes[3],
885             offset2_bytes[0],
886             offset2_bytes[1],
887             offset2_bytes[2],
888             offset2_bytes[3],
889             stride3_bytes[0],
890             stride3_bytes[1],
891             stride3_bytes[2],
892             stride3_bytes[3],
893             offset3_bytes[0],
894             offset3_bytes[1],
895             offset3_bytes[2],
896             offset3_bytes[3],
897             depth_bytes[0],
898             bpp_bytes[0],
899             0,
900             0,
901             modifier_bytes[0],
902             modifier_bytes[1],
903             modifier_bytes[2],
904             modifier_bytes[3],
905             modifier_bytes[4],
906             modifier_bytes[5],
907             modifier_bytes[6],
908             modifier_bytes[7],
909         ];
910         let length_so_far = length_so_far + request0.len();
911         assert_eq!(length_so_far % 4, 0);
912         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
913         request0[2..4].copy_from_slice(&length.to_ne_bytes());
914         Ok((vec![request0.into()], self.buffers))
915     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,916     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
917     where
918         Conn: RequestConnection + ?Sized,
919     {
920         let (bytes, fds) = self.serialize(conn)?;
921         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
922         conn.send_request_without_reply(&slices, fds)
923     }
924     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError>925     pub fn try_parse_request_fd(header: RequestHeader, value: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<Self, ParseError> {
926         if header.minor_opcode != PIXMAP_FROM_BUFFERS_REQUEST {
927             return Err(ParseError::InvalidValue);
928         }
929         let (pixmap, remaining) = xproto::Pixmap::try_parse(value)?;
930         let (window, remaining) = xproto::Window::try_parse(remaining)?;
931         let (num_buffers, remaining) = u8::try_parse(remaining)?;
932         let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
933         let (width, remaining) = u16::try_parse(remaining)?;
934         let (height, remaining) = u16::try_parse(remaining)?;
935         let (stride0, remaining) = u32::try_parse(remaining)?;
936         let (offset0, remaining) = u32::try_parse(remaining)?;
937         let (stride1, remaining) = u32::try_parse(remaining)?;
938         let (offset1, remaining) = u32::try_parse(remaining)?;
939         let (stride2, remaining) = u32::try_parse(remaining)?;
940         let (offset2, remaining) = u32::try_parse(remaining)?;
941         let (stride3, remaining) = u32::try_parse(remaining)?;
942         let (offset3, remaining) = u32::try_parse(remaining)?;
943         let (depth, remaining) = u8::try_parse(remaining)?;
944         let (bpp, remaining) = u8::try_parse(remaining)?;
945         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
946         let (modifier, remaining) = u64::try_parse(remaining)?;
947         let fds_len = num_buffers.try_to_usize()?;
948         if fds.len() < fds_len { return Err(ParseError::MissingFileDescriptors) }
949         let mut buffers = fds.split_off(fds_len);
950         std::mem::swap(fds, &mut buffers);
951         let _ = remaining;
952         Ok(PixmapFromBuffersRequest {
953             pixmap,
954             window,
955             width,
956             height,
957             stride0,
958             offset0,
959             stride1,
960             offset1,
961             stride2,
962             offset2,
963             stride3,
964             offset3,
965             depth,
966             bpp,
967             modifier,
968             buffers,
969         })
970     }
971 }
972 impl Request for PixmapFromBuffersRequest {
973     type Reply = ();
974 }
pixmap_from_buffers<Conn>(conn: &Conn, pixmap: xproto::Pixmap, window: xproto::Window, width: u16, height: u16, stride0: u32, offset0: u32, stride1: u32, offset1: u32, stride2: u32, offset2: u32, stride3: u32, offset3: u32, depth: u8, bpp: u8, modifier: u64, buffers: Vec<RawFdContainer>) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,975 pub fn pixmap_from_buffers<Conn>(conn: &Conn, pixmap: xproto::Pixmap, window: xproto::Window, width: u16, height: u16, stride0: u32, offset0: u32, stride1: u32, offset1: u32, stride2: u32, offset2: u32, stride3: u32, offset3: u32, depth: u8, bpp: u8, modifier: u64, buffers: Vec<RawFdContainer>) -> Result<VoidCookie<'_, Conn>, ConnectionError>
976 where
977     Conn: RequestConnection + ?Sized,
978 {
979     let request0 = PixmapFromBuffersRequest {
980         pixmap,
981         window,
982         width,
983         height,
984         stride0,
985         offset0,
986         stride1,
987         offset1,
988         stride2,
989         offset2,
990         stride3,
991         offset3,
992         depth,
993         bpp,
994         modifier,
995         buffers,
996     };
997     request0.send(conn)
998 }
999 
1000 /// Opcode for the BuffersFromPixmap request
1001 pub const BUFFERS_FROM_PIXMAP_REQUEST: u8 = 8;
1002 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1003 pub struct BuffersFromPixmapRequest {
1004     pub pixmap: xproto::Pixmap,
1005 }
1006 impl BuffersFromPixmapRequest {
1007     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1008     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1009     where
1010         Conn: RequestConnection + ?Sized,
1011     {
1012         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1013             .ok_or(ConnectionError::UnsupportedExtension)?;
1014         let length_so_far = 0;
1015         let pixmap_bytes = self.pixmap.serialize();
1016         let mut request0 = vec![
1017             extension_information.major_opcode,
1018             BUFFERS_FROM_PIXMAP_REQUEST,
1019             0,
1020             0,
1021             pixmap_bytes[0],
1022             pixmap_bytes[1],
1023             pixmap_bytes[2],
1024             pixmap_bytes[3],
1025         ];
1026         let length_so_far = length_so_far + request0.len();
1027         assert_eq!(length_so_far % 4, 0);
1028         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1029         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1030         Ok((vec![request0.into()], vec![]))
1031     }
send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, BuffersFromPixmapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,1032     pub fn send<Conn>(self, conn: &Conn) -> Result<CookieWithFds<'_, Conn, BuffersFromPixmapReply>, ConnectionError>
1033     where
1034         Conn: RequestConnection + ?Sized,
1035     {
1036         let (bytes, fds) = self.serialize(conn)?;
1037         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1038         conn.send_request_with_reply_with_fds(&slices, fds)
1039     }
1040     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>1041     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1042         if header.minor_opcode != BUFFERS_FROM_PIXMAP_REQUEST {
1043             return Err(ParseError::InvalidValue);
1044         }
1045         let (pixmap, remaining) = xproto::Pixmap::try_parse(value)?;
1046         let _ = remaining;
1047         Ok(BuffersFromPixmapRequest {
1048             pixmap,
1049         })
1050     }
1051 }
1052 impl Request for BuffersFromPixmapRequest {
1053     type Reply = BuffersFromPixmapReply;
1054 }
buffers_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BuffersFromPixmapReply>, ConnectionError> where Conn: RequestConnection + ?Sized,1055 pub fn buffers_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BuffersFromPixmapReply>, ConnectionError>
1056 where
1057     Conn: RequestConnection + ?Sized,
1058 {
1059     let request0 = BuffersFromPixmapRequest {
1060         pixmap,
1061     };
1062     request0.send(conn)
1063 }
1064 
1065 #[derive(Debug, PartialEq, Eq)]
1066 pub struct BuffersFromPixmapReply {
1067     pub sequence: u16,
1068     pub length: u32,
1069     pub width: u16,
1070     pub height: u16,
1071     pub modifier: u64,
1072     pub depth: u8,
1073     pub bpp: u8,
1074     pub strides: Vec<u32>,
1075     pub offsets: Vec<u32>,
1076     pub buffers: Vec<RawFdContainer>,
1077 }
1078 impl TryParseFd for BuffersFromPixmapReply {
try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError>1079     fn try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError> {
1080         let remaining = initial_value;
1081         let (response_type, remaining) = u8::try_parse(remaining)?;
1082         let (nfd, remaining) = u8::try_parse(remaining)?;
1083         let (sequence, remaining) = u16::try_parse(remaining)?;
1084         let (length, remaining) = u32::try_parse(remaining)?;
1085         let (width, remaining) = u16::try_parse(remaining)?;
1086         let (height, remaining) = u16::try_parse(remaining)?;
1087         let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
1088         let (modifier, remaining) = u64::try_parse(remaining)?;
1089         let (depth, remaining) = u8::try_parse(remaining)?;
1090         let (bpp, remaining) = u8::try_parse(remaining)?;
1091         let remaining = remaining.get(6..).ok_or(ParseError::InsufficientData)?;
1092         let (strides, remaining) = crate::x11_utils::parse_list::<u32>(remaining, nfd.try_to_usize()?)?;
1093         let (offsets, remaining) = crate::x11_utils::parse_list::<u32>(remaining, nfd.try_to_usize()?)?;
1094         let fds_len = nfd.try_to_usize()?;
1095         if fds.len() < fds_len { return Err(ParseError::MissingFileDescriptors) }
1096         let mut buffers = fds.split_off(fds_len);
1097         std::mem::swap(fds, &mut buffers);
1098         if response_type != 1 {
1099             return Err(ParseError::InvalidValue);
1100         }
1101         let result = BuffersFromPixmapReply { sequence, length, width, height, modifier, depth, bpp, strides, offsets, buffers };
1102         let _ = remaining;
1103         let remaining = initial_value.get(32 + length as usize * 4..)
1104             .ok_or(ParseError::InsufficientData)?;
1105         Ok((result, remaining))
1106     }
1107 }
1108 impl BuffersFromPixmapReply {
1109     /// Get the value of the `nfd` field.
1110     ///
1111     /// The `nfd` field is used as the length field of the `strides` field.
1112     /// This function computes the field's value again based on the length of the list.
1113     ///
1114     /// # Panics
1115     ///
1116     /// Panics if the value cannot be represented in the target type. This
1117     /// cannot happen with values of the struct received from the X11 server.
nfd(&self) -> u81118     pub fn nfd(&self) -> u8 {
1119         self.strides.len()
1120             .try_into().unwrap()
1121     }
1122 }
1123 
1124 /// Extension trait defining the requests of this extension.
1125 pub trait ConnectionExt: RequestConnection {
dri3_query_version(&self, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>1126     fn dri3_query_version(&self, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>
1127     {
1128         query_version(self, major_version, minor_version)
1129     }
dri3_open(&self, drawable: xproto::Drawable, provider: u32) -> Result<CookieWithFds<'_, Self, OpenReply>, ConnectionError>1130     fn dri3_open(&self, drawable: xproto::Drawable, provider: u32) -> Result<CookieWithFds<'_, Self, OpenReply>, ConnectionError>
1131     {
1132         open(self, drawable, provider)
1133     }
dri3_pixmap_from_buffer<A>(&self, pixmap: xproto::Pixmap, drawable: xproto::Drawable, size: u32, width: u16, height: u16, stride: u16, depth: u8, bpp: u8, pixmap_fd: A) -> Result<VoidCookie<'_, Self>, ConnectionError> where A: Into<RawFdContainer>,1134     fn dri3_pixmap_from_buffer<A>(&self, pixmap: xproto::Pixmap, drawable: xproto::Drawable, size: u32, width: u16, height: u16, stride: u16, depth: u8, bpp: u8, pixmap_fd: A) -> Result<VoidCookie<'_, Self>, ConnectionError>
1135     where
1136         A: Into<RawFdContainer>,
1137     {
1138         pixmap_from_buffer(self, pixmap, drawable, size, width, height, stride, depth, bpp, pixmap_fd)
1139     }
dri3_buffer_from_pixmap(&self, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Self, BufferFromPixmapReply>, ConnectionError>1140     fn dri3_buffer_from_pixmap(&self, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Self, BufferFromPixmapReply>, ConnectionError>
1141     {
1142         buffer_from_pixmap(self, pixmap)
1143     }
dri3_fence_from_fd<A>(&self, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Result<VoidCookie<'_, Self>, ConnectionError> where A: Into<RawFdContainer>,1144     fn dri3_fence_from_fd<A>(&self, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Result<VoidCookie<'_, Self>, ConnectionError>
1145     where
1146         A: Into<RawFdContainer>,
1147     {
1148         fence_from_fd(self, drawable, fence, initially_triggered, fence_fd)
1149     }
dri3_fd_from_fence(&self, drawable: xproto::Drawable, fence: u32) -> Result<CookieWithFds<'_, Self, FDFromFenceReply>, ConnectionError>1150     fn dri3_fd_from_fence(&self, drawable: xproto::Drawable, fence: u32) -> Result<CookieWithFds<'_, Self, FDFromFenceReply>, ConnectionError>
1151     {
1152         fd_from_fence(self, drawable, fence)
1153     }
dri3_get_supported_modifiers(&self, window: u32, depth: u8, bpp: u8) -> Result<Cookie<'_, Self, GetSupportedModifiersReply>, ConnectionError>1154     fn dri3_get_supported_modifiers(&self, window: u32, depth: u8, bpp: u8) -> Result<Cookie<'_, Self, GetSupportedModifiersReply>, ConnectionError>
1155     {
1156         get_supported_modifiers(self, window, depth, bpp)
1157     }
dri3_pixmap_from_buffers(&self, pixmap: xproto::Pixmap, window: xproto::Window, width: u16, height: u16, stride0: u32, offset0: u32, stride1: u32, offset1: u32, stride2: u32, offset2: u32, stride3: u32, offset3: u32, depth: u8, bpp: u8, modifier: u64, buffers: Vec<RawFdContainer>) -> Result<VoidCookie<'_, Self>, ConnectionError>1158     fn dri3_pixmap_from_buffers(&self, pixmap: xproto::Pixmap, window: xproto::Window, width: u16, height: u16, stride0: u32, offset0: u32, stride1: u32, offset1: u32, stride2: u32, offset2: u32, stride3: u32, offset3: u32, depth: u8, bpp: u8, modifier: u64, buffers: Vec<RawFdContainer>) -> Result<VoidCookie<'_, Self>, ConnectionError>
1159     {
1160         pixmap_from_buffers(self, pixmap, window, width, height, stride0, offset0, stride1, offset1, stride2, offset2, stride3, offset3, depth, bpp, modifier, buffers)
1161     }
dri3_buffers_from_pixmap(&self, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Self, BuffersFromPixmapReply>, ConnectionError>1162     fn dri3_buffers_from_pixmap(&self, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Self, BuffersFromPixmapReply>, ConnectionError>
1163     {
1164         buffers_from_pixmap(self, pixmap)
1165     }
1166 }
1167 
1168 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
1169