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