1#![allow(clippy::too_many_arguments)]
7
8#[allow(unused_imports)]
9use std::borrow::Cow;
10#[allow(unused_imports)]
11use std::convert::TryInto;
12#[allow(unused_imports)]
13use crate::utils::RawFdContainer;
14#[allow(unused_imports)]
15use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
16use std::io::IoSlice;
17use crate::connection::RequestConnection;
18#[allow(unused_imports)]
19use crate::connection::Connection as X11Connection;
20#[allow(unused_imports)]
21use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
22use crate::errors::ConnectionError;
23#[allow(unused_imports)]
24use crate::errors::ReplyOrIdError;
25use std::future::Future;
26use std::pin::Pin;
27#[allow(unused_imports)]
28use super::xproto;
29
30pub use x11rb_protocol::protocol::dri3::*;
31
32async fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
34 let info = conn.extension_information(X11_EXTENSION_NAME).await?;
35 let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
36 Ok(info.major_opcode)
37}
38
39pub async fn query_version<Conn>(conn: &Conn, major_version: u32, minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
40where
41 Conn: RequestConnection + ?Sized,
42{
43 let request0 = QueryVersionRequest {
44 major_version,
45 minor_version,
46 };
47 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
48 let slices = [IoSlice::new(&bytes[0])];
49 assert_eq!(slices.len(), bytes.len());
50 conn.send_request_with_reply(&slices, fds).await
51}
52pub async fn open<Conn>(conn: &Conn, drawable: xproto::Drawable, provider: u32) -> Result<CookieWithFds<'_, Conn, OpenReply>, ConnectionError>
53where
54 Conn: RequestConnection + ?Sized,
55{
56 let request0 = OpenRequest {
57 drawable,
58 provider,
59 };
60 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
61 let slices = [IoSlice::new(&bytes[0])];
62 assert_eq!(slices.len(), bytes.len());
63 conn.send_request_with_reply_with_fds(&slices, fds).await
64}
65pub async 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>
66where
67 Conn: RequestConnection + ?Sized,
68 A: Into<RawFdContainer> + Send,
69{
70 let pixmap_fd: RawFdContainer = pixmap_fd.into();
71 let request0 = PixmapFromBufferRequest {
72 pixmap,
73 drawable,
74 size,
75 width,
76 height,
77 stride,
78 depth,
79 bpp,
80 pixmap_fd,
81 };
82 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
83 let slices = [IoSlice::new(&bytes[0])];
84 assert_eq!(slices.len(), bytes.len());
85 conn.send_request_without_reply(&slices, fds).await
86}
87pub async fn buffer_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BufferFromPixmapReply>, ConnectionError>
88where
89 Conn: RequestConnection + ?Sized,
90{
91 let request0 = BufferFromPixmapRequest {
92 pixmap,
93 };
94 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
95 let slices = [IoSlice::new(&bytes[0])];
96 assert_eq!(slices.len(), bytes.len());
97 conn.send_request_with_reply_with_fds(&slices, fds).await
98}
99pub async fn fence_from_fd<Conn, A>(conn: &Conn, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError>
100where
101 Conn: RequestConnection + ?Sized,
102 A: Into<RawFdContainer> + Send,
103{
104 let fence_fd: RawFdContainer = fence_fd.into();
105 let request0 = FenceFromFDRequest {
106 drawable,
107 fence,
108 initially_triggered,
109 fence_fd,
110 };
111 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
112 let slices = [IoSlice::new(&bytes[0])];
113 assert_eq!(slices.len(), bytes.len());
114 conn.send_request_without_reply(&slices, fds).await
115}
116pub async fn fd_from_fence<Conn>(conn: &Conn, drawable: xproto::Drawable, fence: u32) -> Result<CookieWithFds<'_, Conn, FDFromFenceReply>, ConnectionError>
117where
118 Conn: RequestConnection + ?Sized,
119{
120 let request0 = FDFromFenceRequest {
121 drawable,
122 fence,
123 };
124 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
125 let slices = [IoSlice::new(&bytes[0])];
126 assert_eq!(slices.len(), bytes.len());
127 conn.send_request_with_reply_with_fds(&slices, fds).await
128}
129pub async fn get_supported_modifiers<Conn>(conn: &Conn, window: u32, depth: u8, bpp: u8) -> Result<Cookie<'_, Conn, GetSupportedModifiersReply>, ConnectionError>
130where
131 Conn: RequestConnection + ?Sized,
132{
133 let request0 = GetSupportedModifiersRequest {
134 window,
135 depth,
136 bpp,
137 };
138 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
139 let slices = [IoSlice::new(&bytes[0])];
140 assert_eq!(slices.len(), bytes.len());
141 conn.send_request_with_reply(&slices, fds).await
142}
143pub async 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>
144where
145 Conn: RequestConnection + ?Sized,
146{
147 let request0 = PixmapFromBuffersRequest {
148 pixmap,
149 window,
150 width,
151 height,
152 stride0,
153 offset0,
154 stride1,
155 offset1,
156 stride2,
157 offset2,
158 stride3,
159 offset3,
160 depth,
161 bpp,
162 modifier,
163 buffers,
164 };
165 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
166 let slices = [IoSlice::new(&bytes[0])];
167 assert_eq!(slices.len(), bytes.len());
168 conn.send_request_without_reply(&slices, fds).await
169}
170pub async fn buffers_from_pixmap<Conn>(conn: &Conn, pixmap: xproto::Pixmap) -> Result<CookieWithFds<'_, Conn, BuffersFromPixmapReply>, ConnectionError>
171where
172 Conn: RequestConnection + ?Sized,
173{
174 let request0 = BuffersFromPixmapRequest {
175 pixmap,
176 };
177 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
178 let slices = [IoSlice::new(&bytes[0])];
179 assert_eq!(slices.len(), bytes.len());
180 conn.send_request_with_reply_with_fds(&slices, fds).await
181}
182pub async fn set_drm_device_in_use<Conn>(conn: &Conn, window: xproto::Window, drm_major: u32, drm_minor: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
183where
184 Conn: RequestConnection + ?Sized,
185{
186 let request0 = SetDRMDeviceInUseRequest {
187 window,
188 drm_major,
189 drm_minor,
190 };
191 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
192 let slices = [IoSlice::new(&bytes[0])];
193 assert_eq!(slices.len(), bytes.len());
194 conn.send_request_without_reply(&slices, fds).await
195}
196pub async fn import_syncobj<Conn, A>(conn: &Conn, syncobj: Syncobj, drawable: xproto::Drawable, syncobj_fd: A) -> Result<VoidCookie<'_, Conn>, ConnectionError>
197where
198 Conn: RequestConnection + ?Sized,
199 A: Into<RawFdContainer> + Send,
200{
201 let syncobj_fd: RawFdContainer = syncobj_fd.into();
202 let request0 = ImportSyncobjRequest {
203 syncobj,
204 drawable,
205 syncobj_fd,
206 };
207 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
208 let slices = [IoSlice::new(&bytes[0])];
209 assert_eq!(slices.len(), bytes.len());
210 conn.send_request_without_reply(&slices, fds).await
211}
212pub async fn free_syncobj<Conn>(conn: &Conn, syncobj: Syncobj) -> Result<VoidCookie<'_, Conn>, ConnectionError>
213where
214 Conn: RequestConnection + ?Sized,
215{
216 let request0 = FreeSyncobjRequest {
217 syncobj,
218 };
219 let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
220 let slices = [IoSlice::new(&bytes[0])];
221 assert_eq!(slices.len(), bytes.len());
222 conn.send_request_without_reply(&slices, fds).await
223}
224pub trait ConnectionExt: RequestConnection {
226 fn dri3_query_version(&self, major_version: u32, minor_version: u32) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>> + Send + '_>>
227 {
228 Box::pin(query_version(self, major_version, minor_version))
229 }
230 fn dri3_open(&self, drawable: xproto::Drawable, provider: u32) -> Pin<Box<dyn Future<Output = Result<CookieWithFds<'_, Self, OpenReply>, ConnectionError>> + Send + '_>>
231 {
232 Box::pin(open(self, drawable, provider))
233 }
234 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) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
235 where
236 A: Into<RawFdContainer> + Send + 'static,
237 {
238 Box::pin(pixmap_from_buffer(self, pixmap, drawable, size, width, height, stride, depth, bpp, pixmap_fd))
239 }
240 fn dri3_buffer_from_pixmap(&self, pixmap: xproto::Pixmap) -> Pin<Box<dyn Future<Output = Result<CookieWithFds<'_, Self, BufferFromPixmapReply>, ConnectionError>> + Send + '_>>
241 {
242 Box::pin(buffer_from_pixmap(self, pixmap))
243 }
244 fn dri3_fence_from_fd<A>(&self, drawable: xproto::Drawable, fence: u32, initially_triggered: bool, fence_fd: A) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
245 where
246 A: Into<RawFdContainer> + Send + 'static,
247 {
248 Box::pin(fence_from_fd(self, drawable, fence, initially_triggered, fence_fd))
249 }
250 fn dri3_fd_from_fence(&self, drawable: xproto::Drawable, fence: u32) -> Pin<Box<dyn Future<Output = Result<CookieWithFds<'_, Self, FDFromFenceReply>, ConnectionError>> + Send + '_>>
251 {
252 Box::pin(fd_from_fence(self, drawable, fence))
253 }
254 fn dri3_get_supported_modifiers(&self, window: u32, depth: u8, bpp: u8) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, GetSupportedModifiersReply>, ConnectionError>> + Send + '_>>
255 {
256 Box::pin(get_supported_modifiers(self, window, depth, bpp))
257 }
258 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>) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
259 {
260 Box::pin(pixmap_from_buffers(self, pixmap, window, width, height, stride0, offset0, stride1, offset1, stride2, offset2, stride3, offset3, depth, bpp, modifier, buffers))
261 }
262 fn dri3_buffers_from_pixmap(&self, pixmap: xproto::Pixmap) -> Pin<Box<dyn Future<Output = Result<CookieWithFds<'_, Self, BuffersFromPixmapReply>, ConnectionError>> + Send + '_>>
263 {
264 Box::pin(buffers_from_pixmap(self, pixmap))
265 }
266 fn dri3_set_drm_device_in_use(&self, window: xproto::Window, drm_major: u32, drm_minor: u32) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
267 {
268 Box::pin(set_drm_device_in_use(self, window, drm_major, drm_minor))
269 }
270 fn dri3_import_syncobj<A>(&self, syncobj: Syncobj, drawable: xproto::Drawable, syncobj_fd: A) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
271 where
272 A: Into<RawFdContainer> + Send + 'static,
273 {
274 Box::pin(import_syncobj(self, syncobj, drawable, syncobj_fd))
275 }
276 fn dri3_free_syncobj(&self, syncobj: Syncobj) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
277 {
278 Box::pin(free_syncobj(self, syncobj))
279 }
280}
281
282impl<C: RequestConnection + ?Sized> ConnectionExt for C {}