Skip to main content

euv_core/platform/linux/
struct.rs

1use super::*;
2
3/// Cached `libX11.so.6` function pointer table resolved once per process.
4#[derive(Clone, Copy, Debug, Default)]
5pub(crate) struct LinuxX11Syms {
6    /// Handle returned by `dlopen("libX11.so.6")`.
7    pub(crate) lib: usize,
8    /// `XOpenDisplay` symbol address.
9    pub(crate) open_display: usize,
10    /// `XDefaultScreen` symbol address.
11    pub(crate) default_screen: usize,
12    /// `XRootWindow` symbol address.
13    pub(crate) root_window: usize,
14    /// `XCreateSimpleWindow` symbol address.
15    pub(crate) create_simple_window: usize,
16    /// `XStoreName` symbol address.
17    pub(crate) store_name: usize,
18    /// `XMapWindow` symbol address.
19    pub(crate) map_window: usize,
20    /// `XResizeWindow` symbol address.
21    pub(crate) resize_window: usize,
22    /// `XDestroyWindow` symbol address.
23    pub(crate) destroy_window: usize,
24    /// `XFlush` symbol address.
25    pub(crate) flush: usize,
26    /// `XDefaultGC` symbol address.
27    pub(crate) default_gc: usize,
28    /// `XDefaultVisual` symbol address.
29    pub(crate) default_visual: usize,
30    /// `XDefaultDepth` symbol address.
31    pub(crate) default_depth: usize,
32    /// `XCreateImage` symbol address.
33    pub(crate) create_image: usize,
34    /// `XPutImage` symbol address.
35    pub(crate) put_image: usize,
36    /// `XFree` symbol address.
37    pub(crate) free: usize,
38    /// `XSelectInput` symbol address.
39    pub(crate) select_input: usize,
40    /// `XInternAtom` symbol address.
41    pub(crate) intern_atom: usize,
42    /// `XSetWMProtocols` symbol address.
43    pub(crate) set_wm_protocols: usize,
44    /// `XPending` symbol address.
45    pub(crate) pending: usize,
46    /// `XNextEvent` symbol address.
47    pub(crate) next_event: usize,
48    /// `XLookupString` symbol address.
49    pub(crate) lookup_string: usize,
50    /// `XResourceManagerString` symbol address.
51    pub(crate) resource_manager_string: usize,
52    /// `XConnectionNumber` symbol address returning the display socket fd for `poll()`.
53    pub(crate) connection_number: usize,
54}
55
56/// Cached `libXrandr.so.2` function pointer table resolved once per process.
57#[derive(Clone, Copy, Debug, Default)]
58pub(crate) struct LinuxXRandrSyms {
59    /// `XRRGetScreenInfo` symbol address.
60    pub(crate) get_screen_info: usize,
61    /// `XRRConfigCurrentRate` symbol address.
62    pub(crate) config_current_rate: usize,
63    /// `XRRFreeScreenConfigInfo` symbol address.
64    pub(crate) free_screen_config_info: usize,
65}
66
67/// Cached `libXext.so.6` MIT-SHM function pointer table resolved once per process.
68#[derive(Clone, Copy, Debug, Default)]
69pub(crate) struct LinuxXShmSyms {
70    /// `XShmQueryExtension` symbol address.
71    pub(crate) query_extension: usize,
72    /// `XShmCreateImage` symbol address.
73    pub(crate) create_image: usize,
74    /// `XShmAttach` symbol address.
75    pub(crate) attach: usize,
76    /// `XShmDetach` symbol address.
77    pub(crate) detach: usize,
78    /// `XShmPutImage` symbol address.
79    pub(crate) put_image: usize,
80}
81
82/// Cached `libwayland-client.so.0` + Vulkan WSI symbol table resolved once per process.
83#[derive(Clone, Copy, Debug, Default)]
84pub(crate) struct LinuxWaylandSyms {
85    /// Handle returned by `dlopen("libwayland-client.so.0")`.
86    pub(crate) lib: usize,
87    /// `wl_display_connect` symbol address.
88    pub(crate) display_connect: usize,
89    /// `wl_display_disconnect` symbol address.
90    pub(crate) display_disconnect: usize,
91    /// `wl_display_dispatch_pending` symbol address.
92    pub(crate) display_dispatch_pending: usize,
93    /// `wl_display_dispatch` symbol address.
94    pub(crate) display_dispatch: usize,
95    /// `wl_display_flush` symbol address.
96    pub(crate) display_flush: usize,
97    /// `wl_display_roundtrip` symbol address.
98    pub(crate) display_roundtrip: usize,
99    /// `wl_display_get_error` symbol address.
100    pub(crate) display_get_error: usize,
101    /// `wl_display_get_fd` symbol address for blocking `poll()`.
102    pub(crate) display_get_fd: usize,
103    /// `wl_display_prepare_read` symbol address for race-free Wayland `poll()`.
104    pub(crate) display_prepare_read: usize,
105    /// `wl_display_read_events` symbol address for draining events after `poll()`.
106    pub(crate) display_read_events: usize,
107    /// `wl_display_cancel_read` symbol address canceling a prepared read on wakeup pipe signal.
108    pub(crate) display_cancel_read: usize,
109    /// `wl_proxy_marshal_flags` symbol address.
110    pub(crate) proxy_marshal_flags: usize,
111    /// `wl_proxy_add_listener` symbol address.
112    pub(crate) proxy_add_listener: usize,
113    /// `wl_proxy_destroy` symbol address.
114    pub(crate) proxy_destroy: usize,
115    /// `wl_proxy_get_version` symbol address.
116    pub(crate) proxy_get_version: usize,
117    /// Exported `wl_registry_interface` pointer address.
118    pub(crate) registry_interface: usize,
119    /// Exported `wl_compositor_interface` pointer address.
120    pub(crate) compositor_interface: usize,
121    /// Exported `wl_surface_interface` pointer address.
122    pub(crate) surface_interface: usize,
123    /// Exported `wl_shm_interface` pointer address.
124    pub(crate) shm_interface: usize,
125    /// Exported `wl_shm_pool_interface` pointer address.
126    pub(crate) shm_pool_interface: usize,
127    /// Exported `wl_buffer_interface` pointer address.
128    pub(crate) buffer_interface: usize,
129    /// Exported `wl_callback_interface` pointer address for `wl_surface.frame` VSync pacing.
130    pub(crate) callback_interface: usize,
131    /// True when `vkCreateWaylandSurfaceKHR` is available in `libvulkan.so.1`.
132    pub(crate) vulkan_wsi_available: bool,
133    /// True when `vkCreateXlibSurfaceKHR` is available in `libvulkan.so.1`.
134    pub(crate) xlib_vulkan_wsi_available: bool,
135}
136
137/// POSIX `struct pollfd` ABI layout for blocking `poll(display_fd, wakeup_pipe)`.
138#[repr(C)]
139#[derive(Clone, Copy, Debug, Default)]
140pub(crate) struct LinuxPollFd {
141    /// Target file descriptor.
142    pub(crate) fd: i32,
143    /// Requested event bitmask (`LINUX_POLLIN`).
144    pub(crate) events: i16,
145    /// Returned event bitmask populated by kernel `poll()`.
146    pub(crate) revents: i16,
147}
148
149/// Raw `wl_callback_listener` ABI table tracking `wl_surface.frame` VSync completion.
150#[repr(C)]
151#[derive(Clone, Copy)]
152pub(crate) struct WlCallbackListener {
153    /// Callback invoked on compositor VBlank (`(data, callback, callback_data)`).
154    pub(crate) done: unsafe extern "C" fn(*mut c_void, *mut c_void, u32),
155}
156
157/// Cached `libEGL.so.1`, `libGLESv2.so.2`, and `libwayland-egl.so.1` symbol table resolved once per process.
158#[derive(Clone, Copy, Data, Debug, Default)]
159pub(crate) struct LinuxEglGlesSyms {
160    /// True when core EGL and GLES3 instanced symbols resolved cleanly.
161    #[get(type(copy))]
162    pub(crate) ready: bool,
163    /// True when `libwayland-egl.so.1` resolved cleanly.
164    #[get(type(copy))]
165    pub(crate) wayland_egl_ready: bool,
166    /// `eglGetDisplay` address.
167    #[get(type(copy))]
168    pub(crate) egl_get_display: usize,
169    /// `eglInitialize` address.
170    #[get(type(copy))]
171    pub(crate) egl_initialize: usize,
172    /// `eglBindAPI` address.
173    #[get(type(copy))]
174    pub(crate) egl_bind_api: usize,
175    /// `eglChooseConfig` address.
176    #[get(type(copy))]
177    pub(crate) egl_choose_config: usize,
178    /// `eglCreateContext` address.
179    #[get(type(copy))]
180    pub(crate) egl_create_context: usize,
181    /// `eglCreateWindowSurface` address.
182    #[get(type(copy))]
183    pub(crate) egl_create_window_surface: usize,
184    /// `eglMakeCurrent` address.
185    #[get(type(copy))]
186    pub(crate) egl_make_current: usize,
187    /// `eglSwapInterval` address.
188    #[get(type(copy))]
189    pub(crate) egl_swap_interval: usize,
190    /// `eglSwapBuffers` address.
191    #[get(type(copy))]
192    pub(crate) egl_swap_buffers: usize,
193    /// `eglDestroySurface` address.
194    #[get(type(copy))]
195    pub(crate) egl_destroy_surface: usize,
196    /// `eglDestroyContext` address.
197    #[get(type(copy))]
198    pub(crate) egl_destroy_context: usize,
199    /// `eglTerminate` address.
200    #[get(type(copy))]
201    pub(crate) egl_terminate: usize,
202    /// `wl_egl_window_create` address.
203    #[get(type(copy))]
204    pub(crate) wl_egl_window_create: usize,
205    /// `wl_egl_window_resize` address.
206    #[get(type(copy))]
207    pub(crate) wl_egl_window_resize: usize,
208    /// `wl_egl_window_destroy` address.
209    #[get(type(copy))]
210    pub(crate) wl_egl_window_destroy: usize,
211    /// `glCreateShader` address.
212    #[get(type(copy))]
213    pub(crate) gl_create_shader: usize,
214    /// `glShaderSource` address.
215    #[get(type(copy))]
216    pub(crate) gl_shader_source: usize,
217    /// `glCompileShader` address.
218    #[get(type(copy))]
219    pub(crate) gl_compile_shader: usize,
220    /// `glGetShaderiv` address.
221    #[get(type(copy))]
222    pub(crate) gl_get_shaderiv: usize,
223    /// `glDeleteShader` address.
224    #[get(type(copy))]
225    pub(crate) gl_delete_shader: usize,
226    /// `glCreateProgram` address.
227    #[get(type(copy))]
228    pub(crate) gl_create_program: usize,
229    /// `glAttachShader` address.
230    #[get(type(copy))]
231    pub(crate) gl_attach_shader: usize,
232    /// `glLinkProgram` address.
233    #[get(type(copy))]
234    pub(crate) gl_link_program: usize,
235    /// `glGetProgramiv` address.
236    #[get(type(copy))]
237    pub(crate) gl_get_programiv: usize,
238    /// `glDeleteProgram` address.
239    #[get(type(copy))]
240    pub(crate) gl_delete_program: usize,
241    /// `glUseProgram` address.
242    #[get(type(copy))]
243    pub(crate) gl_use_program: usize,
244    /// `glGetUniformLocation` address.
245    #[get(type(copy))]
246    pub(crate) gl_get_uniform_location: usize,
247    /// `glUniform1i` address.
248    #[get(type(copy))]
249    pub(crate) gl_uniform1i: usize,
250    /// `glUniform2f` address.
251    #[get(type(copy))]
252    pub(crate) gl_uniform2f: usize,
253    /// `glGenVertexArrays` address.
254    #[get(type(copy))]
255    pub(crate) gl_gen_vertex_arrays: usize,
256    /// `glBindVertexArray` address.
257    #[get(type(copy))]
258    pub(crate) gl_bind_vertex_array: usize,
259    /// `glDeleteVertexArrays` address.
260    #[get(type(copy))]
261    pub(crate) gl_delete_vertex_arrays: usize,
262    /// `glGenBuffers` address.
263    #[get(type(copy))]
264    pub(crate) gl_gen_buffers: usize,
265    /// `glBindBuffer` address.
266    #[get(type(copy))]
267    pub(crate) gl_bind_buffer: usize,
268    /// `glBufferData` address.
269    #[get(type(copy))]
270    pub(crate) gl_buffer_data: usize,
271    /// `glBufferSubData` address.
272    #[get(type(copy))]
273    pub(crate) gl_buffer_sub_data: usize,
274    /// `glDeleteBuffers` address.
275    #[get(type(copy))]
276    pub(crate) gl_delete_buffers: usize,
277    /// `glEnableVertexAttribArray` address.
278    #[get(type(copy))]
279    pub(crate) gl_enable_vertex_attrib_array: usize,
280    /// `glVertexAttribPointer` address.
281    #[get(type(copy))]
282    pub(crate) gl_vertex_attrib_pointer: usize,
283    /// `glVertexAttribIPointer` address.
284    #[get(type(copy))]
285    pub(crate) gl_vertex_attrib_ipointer: usize,
286    /// `glVertexAttribDivisor` address.
287    #[get(type(copy))]
288    pub(crate) gl_vertex_attrib_divisor: usize,
289    /// `glGenTextures` address.
290    #[get(type(copy))]
291    pub(crate) gl_gen_textures: usize,
292    /// `glBindTexture` address.
293    #[get(type(copy))]
294    pub(crate) gl_bind_texture: usize,
295    /// `glTexParameteri` address.
296    #[get(type(copy))]
297    pub(crate) gl_tex_parameteri: usize,
298    /// `glTexStorage2D` address.
299    #[get(type(copy))]
300    pub(crate) gl_tex_storage_2d: usize,
301    /// `glTexImage2D` address.
302    #[get(type(copy))]
303    pub(crate) gl_tex_image_2d: usize,
304    /// `glTexSubImage2D` address.
305    #[get(type(copy))]
306    pub(crate) gl_tex_sub_image_2d: usize,
307    /// `glDeleteTextures` address.
308    #[get(type(copy))]
309    pub(crate) gl_delete_textures: usize,
310    /// `glActiveTexture` address.
311    #[get(type(copy))]
312    pub(crate) gl_active_texture: usize,
313    /// `glPixelStorei` address.
314    #[get(type(copy))]
315    pub(crate) gl_pixel_storei: usize,
316    /// `glViewport` address.
317    #[get(type(copy))]
318    pub(crate) gl_viewport: usize,
319    /// `glEnable` address.
320    #[get(type(copy))]
321    pub(crate) gl_enable: usize,
322    /// `glDisable` address.
323    #[get(type(copy))]
324    pub(crate) gl_disable: usize,
325    /// `glBlendFuncSeparate` address.
326    #[get(type(copy))]
327    pub(crate) gl_blend_func_separate: usize,
328    /// `glScissor` address.
329    #[get(type(copy))]
330    pub(crate) gl_scissor: usize,
331    /// `glClearColor` address.
332    #[get(type(copy))]
333    pub(crate) gl_clear_color: usize,
334    /// `glClear` address.
335    #[get(type(copy))]
336    pub(crate) gl_clear: usize,
337    /// `glDrawArraysInstanced` address.
338    #[get(type(copy))]
339    pub(crate) gl_draw_arrays_instanced: usize,
340    /// `glDrawArrays` address.
341    #[get(type(copy))]
342    pub(crate) gl_draw_arrays: usize,
343    /// `glUniform4f` address.
344    #[get(type(copy))]
345    pub(crate) gl_uniform4f: usize,
346    /// `glUniformMatrix4fv` address.
347    #[get(type(copy))]
348    pub(crate) gl_uniform_matrix4fv: usize,
349    /// `glGetIntegerv` address.
350    #[get(type(copy))]
351    pub(crate) gl_get_integerv: usize,
352    /// `glGenFramebuffers` address.
353    #[get(type(copy))]
354    pub(crate) gl_gen_framebuffers: usize,
355    /// `glBindFramebuffer` address.
356    #[get(type(copy))]
357    pub(crate) gl_bind_framebuffer: usize,
358    /// `glFramebufferTexture2D` address.
359    #[get(type(copy))]
360    pub(crate) gl_framebuffer_texture_2d: usize,
361    /// `glDeleteFramebuffers` address.
362    #[get(type(copy))]
363    pub(crate) gl_delete_framebuffers: usize,
364    /// `glGenRenderbuffers` address.
365    #[get(type(copy))]
366    pub(crate) gl_gen_renderbuffers: usize,
367    /// `glBindRenderbuffer` address.
368    #[get(type(copy))]
369    pub(crate) gl_bind_renderbuffer: usize,
370    /// `glRenderbufferStorage` address.
371    #[get(type(copy))]
372    pub(crate) gl_renderbuffer_storage: usize,
373    /// `glFramebufferRenderbuffer` address.
374    #[get(type(copy))]
375    pub(crate) gl_framebuffer_renderbuffer: usize,
376    /// `glDeleteRenderbuffers` address.
377    #[get(type(copy))]
378    pub(crate) gl_delete_renderbuffers: usize,
379    /// `glDepthMask` address.
380    #[get(type(copy))]
381    pub(crate) gl_depth_mask: usize,
382    /// `glDepthFunc` address.
383    #[get(type(copy))]
384    pub(crate) gl_depth_func: usize,
385    /// `glClearDepthf` address.
386    #[get(type(copy))]
387    pub(crate) gl_clear_depthf: usize,
388}
389
390/// Retained Linux GLES 3.0 offscreen GPU scene pipeline executing `DirectGpuScenePass` (`OceanFluid` + `World3d`).
391#[derive(Data, Debug, Default)]
392pub(crate) struct LinuxEglScenePipeline {
393    /// Offscreen scene framebuffer handle.
394    #[get(type(copy))]
395    pub(crate) scene_fbo: u32,
396    /// Offscreen RGBA8 scene color texture bound to `GL_TEXTURE3` (`u_external_tex`).
397    #[get(type(copy))]
398    pub(crate) scene_color_tex: u32,
399    /// Offscreen 24-bit depth renderbuffer handle for 3D Z-buffered rendering.
400    #[get(type(copy))]
401    pub(crate) scene_depth_rbo: u32,
402    /// Active offscreen scene width in pixels.
403    #[get(type(copy))]
404    pub(crate) scene_w: u32,
405    /// Active offscreen scene height in pixels.
406    #[get(type(copy))]
407    pub(crate) scene_h: u32,
408    /// Resident PBF interactive wake RGBA8 texture handle.
409    #[get(type(copy))]
410    pub(crate) wake_tex: u32,
411    /// Active wake texture width in texels.
412    #[get(type(copy))]
413    pub(crate) wake_w: u32,
414    /// Active wake texture height in texels.
415    #[get(type(copy))]
416    pub(crate) wake_h: u32,
417    /// Compiled Gerstner ocean + storm sky program ID.
418    #[get(type(copy))]
419    pub(crate) ocean_program: u32,
420    /// Cached ocean uniform `u_time_agit_hor_aspect`.
421    #[get(type(copy))]
422    pub(crate) ocean_time_loc: i32,
423    /// Cached ocean uniform `u_roll_boat_uv`.
424    #[get(type(copy))]
425    pub(crate) ocean_roll_loc: i32,
426    /// Cached ocean uniform `u_sun_dir_wake`.
427    #[get(type(copy))]
428    pub(crate) ocean_sun_loc: i32,
429    /// Compiled origami paper boat overlay program ID.
430    #[get(type(copy))]
431    pub(crate) boat_program: u32,
432    /// Boat vertex array object handle.
433    #[get(type(copy))]
434    pub(crate) boat_vao: u32,
435    /// Streaming boat vertex buffer handle.
436    #[get(type(copy))]
437    pub(crate) boat_vbo: u32,
438    /// Allocated byte capacity of `boat_vbo`.
439    #[get(type(copy))]
440    pub(crate) boat_vbo_cap: usize,
441    /// Compiled 3D atmospheric sky program ID.
442    #[get(type(copy))]
443    pub(crate) sky3d_program: u32,
444    /// Cached 3D sky uniform `u_view_proj`.
445    #[get(type(copy))]
446    pub(crate) sky3d_vp_loc: i32,
447    /// Cached 3D sky uniform `u_camera_pos`.
448    #[get(type(copy))]
449    pub(crate) sky3d_cam_loc: i32,
450    /// Cached 3D sky uniform `u_sun_dir_fog`.
451    #[get(type(copy))]
452    pub(crate) sky3d_sun_dir_loc: i32,
453    /// Cached 3D sky uniform `u_sun_color_ambient`.
454    #[get(type(copy))]
455    pub(crate) sky3d_sun_loc: i32,
456    /// Cached 3D sky uniform `u_sky_horizon_tod`.
457    #[get(type(copy))]
458    pub(crate) sky3d_hor_loc: i32,
459    /// Cached 3D sky uniform `u_sky_zenith_aspect`.
460    #[get(type(copy))]
461    pub(crate) sky3d_zen_loc: i32,
462    /// Compiled instanced 3D PBR open-world program ID.
463    #[get(type(copy))]
464    pub(crate) mesh3d_program: u32,
465    /// Instanced 3D mesh vertex array object handle.
466    #[get(type(copy))]
467    pub(crate) mesh3d_vao: u32,
468    /// Static 3D mesh vertex buffer handle.
469    #[get(type(copy))]
470    pub(crate) mesh3d_vert_vbo: u32,
471    /// Allocated byte capacity of `mesh3d_vert_vbo`.
472    #[get(type(copy))]
473    pub(crate) mesh3d_vert_cap: usize,
474    /// Uploaded mesh vertex buffer revision.
475    #[get(type(copy))]
476    pub(crate) mesh3d_vert_rev: u64,
477    /// Streaming 3D instance buffer handle.
478    #[get(type(copy))]
479    pub(crate) mesh3d_inst_vbo: u32,
480    /// Allocated byte capacity of `mesh3d_inst_vbo`.
481    #[get(type(copy))]
482    pub(crate) mesh3d_inst_cap: usize,
483    /// Cached 3D mesh uniform `u_view_proj`.
484    #[get(type(copy))]
485    pub(crate) mesh3d_vp_loc: i32,
486    /// Cached 3D mesh uniform `u_camera_pos`.
487    #[get(type(copy))]
488    pub(crate) mesh3d_cam_loc: i32,
489    /// Cached 3D mesh uniform `u_sun_dir_fog`.
490    #[get(type(copy))]
491    pub(crate) mesh3d_sun_fog_loc: i32,
492    /// Cached 3D mesh uniform `u_sun_color_ambient`.
493    #[get(type(copy))]
494    pub(crate) mesh3d_sun_col_loc: i32,
495    /// Cached 3D mesh uniform `u_sky_horizon_tod`.
496    #[get(type(copy))]
497    pub(crate) mesh3d_hor_loc: i32,
498    /// Cached 3D mesh uniform `u_sky_zenith_aspect`.
499    #[get(type(copy))]
500    pub(crate) mesh3d_zen_loc: i32,
501}
502
503/// Live dynamic EGL + GLES3 instanced uber-shader presentation surface over Wayland (`wl_egl_window`) or X11 (`Window`).
504#[derive(Data, Debug)]
505pub(crate) struct LinuxEglGlesSurface {
506    /// Active `EGLDisplay` handle stored as `usize`.
507    #[get(type(copy))]
508    pub(crate) egl_display: usize,
509    /// Active `EGLContext` handle stored as `usize`.
510    #[get(type(copy))]
511    pub(crate) egl_context: usize,
512    /// Active `EGLSurface` handle stored as `usize`.
513    #[get(type(copy))]
514    pub(crate) egl_surface: usize,
515    /// Active `wl_egl_window*` pointer (`0` on X11).
516    #[get(type(copy))]
517    pub(crate) wl_egl_window: usize,
518    /// Compiled GLES3 instanced UI uber-shader program ID.
519    #[get(type(copy))]
520    pub(crate) program: u32,
521    /// Vertex array object binding quad + instanced attribute descriptors.
522    #[get(type(copy))]
523    pub(crate) vao: u32,
524    /// Static 6-vertex unit quad buffer bound at attribute location `0`.
525    #[get(type(copy))]
526    pub(crate) quad_vbo: u32,
527    /// Streaming 64-byte `GpuPrimitiveInstance` VBO.
528    #[get(type(copy))]
529    pub(crate) instance_vbo: u32,
530    /// Allocated byte capacity of `instance_vbo`.
531    #[get(type(copy))]
532    pub(crate) instance_vbo_cap: usize,
533    /// Persistent `GL_R8` glyph atlas texture ID.
534    #[get(type(copy))]
535    pub(crate) glyph_r8_tex: u32,
536    /// Width of `glyph_r8_tex` in texels.
537    #[get(type(copy))]
538    pub(crate) glyph_r8_w: u32,
539    /// Height of `glyph_r8_tex` in texels.
540    #[get(type(copy))]
541    pub(crate) glyph_r8_h: u32,
542    /// Uploaded revision of `glyph_r8_tex`.
543    #[get(type(copy))]
544    pub(crate) glyph_r8_rev: u64,
545    /// Color `GL_RGBA8` glyph texture ID.
546    #[get(type(copy))]
547    pub(crate) glyph_rgba8_tex: u32,
548    /// Persistent `GL_RGBA8` image atlas texture ID.
549    #[get(type(copy))]
550    pub(crate) image_tex: u32,
551    /// Width of `image_tex` in texels.
552    #[get(type(copy))]
553    pub(crate) image_w: u32,
554    /// Height of `image_tex` in texels.
555    #[get(type(copy))]
556    pub(crate) image_h: u32,
557    /// Uploaded revision of `image_tex`.
558    #[get(type(copy))]
559    pub(crate) image_rev: u64,
560    /// External/video `GL_RGBA8` texture ID.
561    #[get(type(copy))]
562    pub(crate) external_tex: u32,
563    /// Cached uniform location for `u_viewport`.
564    #[get(type(copy))]
565    pub(crate) viewport_loc: i32,
566    /// Cached uniform location for `u_scroll_offset`.
567    #[get(type(copy))]
568    pub(crate) scroll_loc: i32,
569    /// Active surface width in physical pixels.
570    #[get(type(copy))]
571    pub(crate) width: u32,
572    /// Active surface height in physical pixels.
573    #[get(type(copy))]
574    pub(crate) height: u32,
575    /// True when backed by `wl_egl_window`; false when backed by X11 `Window`.
576    #[get(type(copy))]
577    pub(crate) is_wayland: bool,
578    /// Maximum supported GLES3 texture dimension queried via `GL_MAX_TEXTURE_SIZE`.
579    #[get(type(copy))]
580    pub(crate) max_tex_dim: u32,
581    /// Lazily initialized offscreen GLES3 scene pass pipeline (`OceanFluid` + `World3d`).
582    #[get(skip)]
583    #[get_mut(skip)]
584    #[set(skip)]
585    pub(crate) scene: Option<LinuxEglScenePipeline>,
586    /// Reusable flat primitive staging buffer avoiding per-frame allocations on direct submission.
587    #[get(skip)]
588    #[get_mut(skip)]
589    #[set(skip)]
590    pub(crate) scratch_prims: Vec<GpuPrimitiveInstance>,
591    /// Reusable draw-range metadata buffer paired with `scratch_prims`.
592    #[get(skip)]
593    #[get_mut(skip)]
594    #[set(skip)]
595    pub(crate) scratch_ranges: Vec<(usize, usize, Rect, [f32; 2])>,
596    /// Heap-stable atomic VSync latch cleared by `wl_surface.frame` callback on Wayland.
597    #[get(skip)]
598    #[get_mut(skip)]
599    #[set(skip)]
600    pub(crate) vsync_pending: Box<AtomicBool>,
601}
602
603/// Raw `wl_registry_listener` ABI table registered during Wayland global discovery.
604#[repr(C)]
605#[derive(Clone, Copy)]
606pub(crate) struct WlRegistryListener {
607    /// Callback invoked for each advertised Wayland global `(data, registry, name, interface, version)`.
608    pub(crate) global: unsafe extern "C" fn(*mut c_void, *mut c_void, u32, *const c_char, u32),
609    /// Callback invoked when a Wayland global is removed `(data, registry, name)`.
610    pub(crate) global_remove: unsafe extern "C" fn(*mut c_void, *mut c_void, u32),
611}
612
613/// Raw `wl_buffer_listener` ABI table tracking compositor buffer release notifications.
614#[repr(C)]
615#[derive(Clone, Copy)]
616pub(crate) struct WlBufferListener {
617    /// Callback invoked when the compositor finishes reading a `wl_buffer` (`(data, buffer)`).
618    pub(crate) release: unsafe extern "C" fn(*mut c_void, *mut c_void),
619}
620
621/// Mutable state populated by `WL_REGISTRY_LISTENER` during initial `wl_display_roundtrip`.
622#[repr(C)]
623#[derive(Clone, Copy, Debug, Default)]
624pub(crate) struct WlRegistryBindState {
625    /// Bound `wl_compositor*` proxy handle.
626    pub(crate) compositor: usize,
627    /// Negotiated `wl_compositor` protocol version.
628    pub(crate) compositor_version: u32,
629    /// Bound `wl_shm*` proxy handle.
630    pub(crate) shm: usize,
631}
632
633/// Descriptor carrying POSIX shared-memory FD, geometry, format, and release flag pointer for `WaylandShmCommitOps`.
634#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
635pub struct WaylandShmBufferDescriptor {
636    /// Open shared-memory file descriptor (`memfd_create` or `/dev/shm`).
637    #[get(type(copy))]
638    pub(crate) fd: i32,
639    /// Total mapped buffer byte size.
640    #[get(type(copy))]
641    pub(crate) size: i32,
642    /// Physical buffer width in pixels.
643    #[get(type(copy))]
644    pub(crate) width: i32,
645    /// Physical buffer height in pixels.
646    #[get(type(copy))]
647    pub(crate) height: i32,
648    /// Row stride in bytes (`width * 4`).
649    #[get(type(copy))]
650    pub(crate) stride: i32,
651    /// Wayland shm pixel format (`WL_SHM_FORMAT_ARGB8888` or `WL_SHM_FORMAT_XRGB8888`).
652    #[get(type(copy))]
653    pub(crate) format: u32,
654    /// Raw pointer to the slot's release `AtomicBool` userdata registered on `wl_buffer.release`.
655    #[get(type(copy))]
656    pub(crate) release_flag_ptr: usize,
657}
658
659/// Single double-buffered Wayland `wl_shm` memory mapping and protocol buffer slot.
660#[derive(Debug)]
661pub struct WaylandShmBufferSlot {
662    /// Open POSIX shared-memory file descriptor (`-1` when unallocated).
663    pub(crate) fd: i32,
664    /// Base pointer returned by `mmap(..., MAP_SHARED, fd, 0)` (`0` when unmapped).
665    pub(crate) mapped_ptr: usize,
666    /// Mapped byte capacity of this shared-memory region.
667    pub(crate) mapped_len: usize,
668    /// Current allocated buffer width in physical pixels.
669    pub(crate) width: u32,
670    /// Current allocated buffer height in physical pixels.
671    pub(crate) height: u32,
672    /// Row stride in bytes (`width * 4`).
673    pub(crate) stride: u32,
674    /// Bound Wayland shm pixel format (`WL_SHM_FORMAT_ARGB8888` or `WL_SHM_FORMAT_XRGB8888`).
675    pub(crate) format: u32,
676    /// Associated `wl_shm_pool*` proxy handle (`0` when detached).
677    pub(crate) wl_pool: usize,
678    /// Associated `wl_buffer*` proxy handle (`0` when detached).
679    pub(crate) wl_buffer: usize,
680    /// Atomic busy flag cleared asynchronously by `wl_buffer.release` (`true` while held by compositor).
681    pub(crate) busy: Box<AtomicBool>,
682    /// True once this slot has received a complete full-frame pixel copy for its current dimensions.
683    pub(crate) has_full_copy: bool,
684}
685
686/// Double-buffered Wayland `wl_shm` software swapchain owning two POSIX shm mappings and dirty-rect tracking.
687#[derive(Debug)]
688pub struct WaylandShmSwapchain {
689    /// Two ping-pong shared-memory slots enabling tear-free double-buffered Wayland commits.
690    pub(crate) slots: [WaylandShmBufferSlot; WL_SHM_SLOT_COUNT],
691    /// Wayland shm pixel format (`WL_SHM_FORMAT_XRGB8888` or `WL_SHM_FORMAT_ARGB8888`).
692    pub(crate) pixel_format: u32,
693    /// Dirty rectangles from the immediately preceding submitted frame so double-buffered back slots stay coherent.
694    pub(crate) previous_dirty_rects: Vec<(u32, u32, u32, u32)>,
695    /// Index (`0` or `1`) of the most recently committed buffer slot.
696    pub(crate) last_committed_slot: u8,
697    /// Cumulative count of successfully committed Wayland shm frames.
698    pub(crate) submitted_frames: u64,
699    /// Cumulative count of unchanged frames skipped without commit.
700    pub(crate) skipped_unchanged_frames: u64,
701    /// Cumulative count of failed presentation attempts.
702    pub(crate) failed_frames: u64,
703}
704
705/// Native `libwayland-client.so.0` transport invoking `wl_shm_pool`, `wl_buffer`, `wl_surface`, and `wl_display_flush`.
706#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
707pub struct NativeWaylandShmTransport {
708    /// Live `wl_display*` connection pointer.
709    #[get(type(copy))]
710    pub(crate) display: usize,
711    /// Live `wl_surface*` proxy pointer.
712    #[get(type(copy))]
713    pub(crate) surface: usize,
714    /// Live `wl_shm*` global proxy pointer.
715    #[get(type(copy))]
716    pub(crate) wl_shm: usize,
717    /// Negotiated `wl_surface` interface version (`>= 4` uses `damage_buffer`, `< 4` uses `damage`).
718    #[get(type(copy))]
719    pub(crate) surface_version: u32,
720    /// Integer `wl_surface.set_buffer_scale` divisor applied prior to commit (`<= 0` defaults to `1`).
721    #[new(skip)]
722    #[get(type(copy))]
723    pub(crate) buffer_scale: i32,
724}
725
726/// Explicit per-frame Linux presentation telemetry separating direct GPU vs Wayland shm vs X11 software blits.
727#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
728pub struct LinuxPresentTelemetry {
729    /// Active presentation transport (`GpuDirect`, `WaylandShmSoftware`, or `X11Software`).
730    #[get(type(copy))]
731    pub(crate) mode: LinuxPresentationMode,
732    /// Explicit frame outcome (`Submitted`, `SkippedUnchanged`, or `Failed`).
733    #[get(type(copy))]
734    pub(crate) outcome: LinuxPresentOutcome,
735    /// True whenever a CPU software framebuffer mirror is active (`false` for `GpuDirect`).
736    #[get(type(copy))]
737    pub(crate) cpu_mirror_active: bool,
738    /// Exact pixel bytes copied into Wayland shm or uploaded via X11 `XPutImage` (`0` for `GpuDirect` or skip).
739    #[get(type(copy))]
740    pub(crate) upload_bytes: u64,
741    /// Number of dirty rectangles damaged or uploaded during this frame.
742    #[get(type(copy))]
743    pub(crate) dirty_rect_count: u32,
744    /// Double-buffered Wayland shm slot index (`0` or `1`) committed on this frame.
745    #[get(type(copy))]
746    pub(crate) committed_buffer_slot: u8,
747    /// Cumulative submitted frames recorded on this window.
748    #[get(type(copy))]
749    pub(crate) submitted_frames: u64,
750    /// Cumulative unchanged frames skipped on this window.
751    #[get(type(copy))]
752    pub(crate) skipped_unchanged_frames: u64,
753    /// Cumulative failed frames recorded on this window.
754    #[get(type(copy))]
755    pub(crate) failed_frames: u64,
756}
757
758/// Raw 192-byte X11 `XEvent` union storage aligned for 64-bit Linux LP64 ABI.
759#[repr(C)]
760#[derive(Clone, Copy)]
761pub(crate) struct X11EventRaw {
762    /// Raw union payload words.
763    pub(crate) pad: [isize; 24],
764}
765
766/// X11 `XKeyEvent` / `XButtonEvent` ABI layout on LP64 Linux.
767#[repr(C)]
768#[derive(Clone, Copy)]
769pub(crate) struct X11KeyOrButtonEvent {
770    /// Event discriminant (`KeyPress`, `KeyRelease`, `ButtonPress`, `ButtonRelease`).
771    pub(crate) event_type: i32,
772    /// X server serial number.
773    pub(crate) serial: usize,
774    /// Non-zero when generated by `SendEvent`.
775    pub(crate) send_event: i32,
776    /// Connection `Display*`.
777    pub(crate) display: *mut c_void,
778    /// Target `Window` XID.
779    pub(crate) window: u64,
780    /// Root window XID.
781    pub(crate) root: u64,
782    /// Subwindow XID.
783    pub(crate) subwindow: u64,
784    /// Event timestamp in milliseconds.
785    pub(crate) time: u64,
786    /// Pointer X coordinate relative to window.
787    pub(crate) x: i32,
788    /// Pointer Y coordinate relative to window.
789    pub(crate) y: i32,
790    /// Pointer X relative to root window.
791    pub(crate) x_root: i32,
792    /// Pointer Y relative to root window.
793    pub(crate) y_root: i32,
794    /// Modifier key / button mask.
795    pub(crate) state: u32,
796    /// Hardware keycode or mouse button number.
797    pub(crate) detail: u32,
798    /// Same-screen flag.
799    pub(crate) same_screen: i32,
800}
801
802/// X11 `XMotionEvent` ABI layout on LP64 Linux.
803#[repr(C)]
804#[derive(Clone, Copy)]
805pub(crate) struct X11MotionEvent {
806    /// Event discriminant (`MotionNotify`).
807    pub(crate) event_type: i32,
808    /// X server serial number.
809    pub(crate) serial: usize,
810    /// Send-event flag.
811    pub(crate) send_event: i32,
812    /// Connection `Display*`.
813    pub(crate) display: *mut c_void,
814    /// Target `Window` XID.
815    pub(crate) window: u64,
816    /// Root window XID.
817    pub(crate) root: u64,
818    /// Subwindow XID.
819    pub(crate) subwindow: u64,
820    /// Timestamp in milliseconds.
821    pub(crate) time: u64,
822    /// Pointer X coordinate relative to window.
823    pub(crate) x: i32,
824    /// Pointer Y coordinate relative to window.
825    pub(crate) y: i32,
826    /// Pointer X relative to root window.
827    pub(crate) x_root: i32,
828    /// Pointer Y relative to root window.
829    pub(crate) y_root: i32,
830    /// Active modifier mask.
831    pub(crate) state: u32,
832    /// Motion hint byte.
833    pub(crate) is_hint: c_char,
834    /// Same-screen flag.
835    pub(crate) same_screen: i32,
836}
837
838/// X11 `XConfigureEvent` ABI layout on LP64 Linux.
839#[repr(C)]
840#[derive(Clone, Copy)]
841pub(crate) struct X11ConfigureEvent {
842    /// Event discriminant (`ConfigureNotify`).
843    pub(crate) event_type: i32,
844    /// X server serial number.
845    pub(crate) serial: usize,
846    /// Send-event flag.
847    pub(crate) send_event: i32,
848    /// Connection `Display*`.
849    pub(crate) display: *mut c_void,
850    /// Event-delivery window XID.
851    pub(crate) event_window: u64,
852    /// Reconfigured target window XID.
853    pub(crate) window: u64,
854    /// New window X position.
855    pub(crate) x: i32,
856    /// New window Y position.
857    pub(crate) y: i32,
858    /// New window client width in physical pixels.
859    pub(crate) width: i32,
860    /// New window client height in physical pixels.
861    pub(crate) height: i32,
862}
863
864/// X11 `XClientMessageEvent` ABI layout on LP64 Linux.
865#[repr(C)]
866#[derive(Clone, Copy)]
867pub(crate) struct X11ClientMessageEvent {
868    /// Event discriminant (`ClientMessage`).
869    pub(crate) event_type: i32,
870    /// X server serial number.
871    pub(crate) serial: usize,
872    /// Send-event flag.
873    pub(crate) send_event: i32,
874    /// Connection `Display*`.
875    pub(crate) display: *mut c_void,
876    /// Target `Window` XID.
877    pub(crate) window: u64,
878    /// Message type atom (`WM_PROTOCOLS`).
879    pub(crate) message_type: u64,
880    /// Data format (`8`, `16`, or `32`).
881    pub(crate) format: i32,
882    /// 32-bit protocol data payload (`l[0]` holds `WM_DELETE_WINDOW`).
883    pub(crate) data: [u64; 5],
884}
885
886/// Bundle returned when opening a native Linux X11 or Wayland window.
887#[derive(Clone, Copy, Data, Debug)]
888pub(crate) struct LinuxNativeWindowHandle {
889    /// Dynamically loaded `libX11` or `libwayland-client` handle.
890    #[get(type(copy))]
891    pub(crate) lib: usize,
892    /// True when backed by Wayland; false when backed by X11.
893    #[get(type(copy))]
894    pub(crate) is_wayland: bool,
895    /// Raw `Display*` or `wl_display*`.
896    #[get(type(copy))]
897    pub(crate) display: usize,
898    /// Native X11 `Window` XID or Wayland surface pointer.
899    #[get(type(copy))]
900    pub(crate) window: u64,
901    /// Cached X11 `GC` handle for `XPutImage`.
902    #[get(type(copy))]
903    pub(crate) gc: usize,
904    /// Cached X11 `Visual*` pointer for `XCreateImage`.
905    #[get(type(copy))]
906    pub(crate) visual: usize,
907    /// X11 default visual color depth (e.g., `24` or `32`).
908    #[get(type(copy))]
909    pub(crate) depth: u32,
910    /// Interned `WM_DELETE_WINDOW` atom for graceful window closing.
911    #[get(type(copy))]
912    pub(crate) wm_delete_atom: u64,
913    /// Probed display DPI scale factor (`1.0..=4.0`).
914    #[get(type(copy))]
915    pub(crate) scale_factor: f32,
916    /// True when X11 MIT-SHM (`XShmQueryExtension`) is supported on this display.
917    #[get(type(copy))]
918    pub(crate) mit_shm_available: bool,
919    /// True when Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is available.
920    #[get(type(copy))]
921    pub(crate) wayland_vulkan_wsi: bool,
922    /// True when X11 Vulkan WSI (`VK_KHR_xlib_surface`) is available.
923    #[get(type(copy))]
924    pub(crate) xlib_vulkan_wsi: bool,
925    /// Bound Wayland `wl_compositor*` proxy pointer (`0` on X11 or unavailable).
926    #[get(type(copy))]
927    pub(crate) wl_compositor: usize,
928    /// Bound Wayland `wl_shm*` proxy pointer (`0` on X11 or unavailable).
929    #[get(type(copy))]
930    pub(crate) wl_shm: usize,
931    /// Negotiated Wayland `wl_surface` interface version (`0` on X11).
932    #[get(type(copy))]
933    pub(crate) wl_surface_version: u32,
934}
935
936/// Native Linux X11 / Wayland window record.
937#[derive(Clone, Data, Debug)]
938pub struct LinuxWindowRecord {
939    /// Window configuration.
940    pub(crate) config: WindowConfig,
941    /// Live window state.
942    #[get(type(copy))]
943    pub(crate) state: WindowState,
944    /// True when backed by Wayland; false when backed by X11 Xlib.
945    #[get(type(copy))]
946    pub(crate) is_wayland: bool,
947    /// Raw display handle (`Display*` or `wl_display*`).
948    #[get(type(copy))]
949    pub(crate) display: usize,
950    /// Raw window or surface identifier (`Window` or `wl_surface*`).
951    #[get(type(copy))]
952    pub(crate) window: u64,
953    /// Cached X11 `GC` handle used by `XPutImage`.
954    #[get(type(copy))]
955    pub(crate) gc: usize,
956    /// Cached X11 `Visual*` pointer used by `XCreateImage`.
957    #[get(type(copy))]
958    pub(crate) visual: usize,
959    /// X11 visual depth in bits (`24` or `32`).
960    #[get(type(copy))]
961    pub(crate) depth: u32,
962    /// Interned `WM_DELETE_WINDOW` protocol atom.
963    #[get(type(copy))]
964    pub(crate) wm_delete_atom: u64,
965    /// Whether `XMapWindow` has been issued after Frame 1 presentation (eliminates unmapped flash).
966    #[get(type(copy))]
967    pub(crate) revealed: bool,
968    /// Whether X11 MIT-SHM shared-memory image transport is supported by the X server.
969    #[get(type(copy))]
970    pub(crate) mit_shm_available: bool,
971    /// Whether Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is ready on this display.
972    #[get(type(copy))]
973    pub(crate) wayland_vulkan_wsi: bool,
974    /// Whether X11 Vulkan WSI (`VK_KHR_xlib_surface`) is ready on this display.
975    #[get(type(copy))]
976    pub(crate) xlib_vulkan_wsi: bool,
977    /// Bound Wayland `wl_compositor*` proxy pointer (`0` on X11).
978    #[get(type(copy))]
979    pub(crate) wl_compositor: usize,
980    /// Bound Wayland `wl_shm*` proxy pointer (`0` on X11).
981    #[get(type(copy))]
982    pub(crate) wl_shm: usize,
983    /// Negotiated Wayland `wl_surface` interface version (`>= 4` supports `damage_buffer`).
984    #[get(type(copy))]
985    pub(crate) wl_surface_version: u32,
986    /// Reported `wl_output.mode` refresh rate in millihertz (e.g. `240000` for `240Hz`, `0` if unset).
987    #[get(type(copy))]
988    pub(crate) wayland_output_refresh_milli_hz: u32,
989    /// Latest `wp_presentation` feedback timestamp in nanoseconds (`0` before first presentation).
990    #[get(type(copy))]
991    pub(crate) wayland_presentation_time_ns: u64,
992    /// Whether a `wl_surface::frame` callback is currently armed awaiting compositor VSync.
993    #[get(type(copy))]
994    pub(crate) wayland_frame_callback_pending: bool,
995    /// Active Linux presentation mode (`GpuDirect`, `WaylandShmSoftware`, or `X11Software`).
996    #[get(type(copy))]
997    pub(crate) presentation_mode: LinuxPresentationMode,
998    /// Explicit CPU-mirror telemetry flag (`true` on Wayland shm / X11 software; `false` on direct GPU).
999    #[get(type(copy))]
1000    pub(crate) cpu_mirror_active: bool,
1001    /// Most recent per-frame Linux presentation telemetry snapshot.
1002    #[get(type(copy))]
1003    pub(crate) last_telemetry: LinuxPresentTelemetry,
1004    /// Double-buffered Wayland `wl_shm` software swapchain attached to this window when Wayland is active.
1005    #[get(skip)]
1006    #[get_mut(skip)]
1007    #[set(skip)]
1008    pub(crate) wayland_shm: Option<Arc<Mutex<WaylandShmSwapchain>>>,
1009    /// Optional dynamically loaded EGL + GLES3 instanced direct-GPU surface over Wayland or X11.
1010    #[get(skip)]
1011    #[get_mut(skip)]
1012    #[set(skip)]
1013    pub(crate) egl_gles: Option<Arc<Mutex<LinuxEglGlesSurface>>>,
1014}
1015
1016/// Direct Linux X11 / Wayland (`dlopen`-loaded) + Vulkan platform backend.
1017#[derive(Clone, Data, Debug)]
1018pub struct LinuxPlatform {
1019    /// Monotonic window handle generator.
1020    #[get(pub(crate), type(copy))]
1021    #[get_mut(pub(crate))]
1022    #[set(pub(crate))]
1023    pub(crate) next_id: u64,
1024    /// Dynamically loaded `libX11` handle if present.
1025    #[get(pub(crate), type(copy))]
1026    #[get_mut(pub(crate))]
1027    #[set(pub(crate))]
1028    pub(crate) x11_lib: usize,
1029    /// Active native Linux windows.
1030    pub(crate) windows: HashMap<WindowId, LinuxWindowRecord>,
1031    /// Queued window and input events.
1032    pub(crate) pending_events: Vec<WindowEvent>,
1033    /// Clipboard text cache.
1034    #[get(skip)]
1035    pub(crate) clipboard_cache: Option<String>,
1036    /// Whether the Linux X11/Wayland frame pump is paused for background freeze.
1037    #[get(pub(crate), type(copy))]
1038    #[set(pub(crate))]
1039    pub(crate) pump_paused: bool,
1040    /// Non-blocking wakeup pipe read end passed to `poll(display_fd, wakeup_pipe)` (`-1` when unavailable).
1041    #[get(pub(crate), type(copy))]
1042    #[set(pub(crate))]
1043    pub(crate) wake_read_fd: i32,
1044    /// Non-blocking wakeup pipe write end signaled by `wake_event_loop()` (`-1` when unavailable).
1045    #[get(pub(crate), type(copy))]
1046    #[set(pub(crate))]
1047    pub(crate) wake_write_fd: i32,
1048}