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_camera_pos`.
445    #[get(type(copy))]
446    pub(crate) sky3d_cam_loc: i32,
447    /// Cached 3D sky uniform `u_sun_color_ambient`.
448    #[get(type(copy))]
449    pub(crate) sky3d_sun_loc: i32,
450    /// Cached 3D sky uniform `u_sky_horizon_tod`.
451    #[get(type(copy))]
452    pub(crate) sky3d_hor_loc: i32,
453    /// Cached 3D sky uniform `u_sky_zenith_aspect`.
454    #[get(type(copy))]
455    pub(crate) sky3d_zen_loc: i32,
456    /// Compiled instanced 3D PBR open-world program ID.
457    #[get(type(copy))]
458    pub(crate) mesh3d_program: u32,
459    /// Instanced 3D mesh vertex array object handle.
460    #[get(type(copy))]
461    pub(crate) mesh3d_vao: u32,
462    /// Static 3D mesh vertex buffer handle.
463    #[get(type(copy))]
464    pub(crate) mesh3d_vert_vbo: u32,
465    /// Allocated byte capacity of `mesh3d_vert_vbo`.
466    #[get(type(copy))]
467    pub(crate) mesh3d_vert_cap: usize,
468    /// Uploaded mesh vertex buffer revision.
469    #[get(type(copy))]
470    pub(crate) mesh3d_vert_rev: u64,
471    /// Streaming 3D instance buffer handle.
472    #[get(type(copy))]
473    pub(crate) mesh3d_inst_vbo: u32,
474    /// Allocated byte capacity of `mesh3d_inst_vbo`.
475    #[get(type(copy))]
476    pub(crate) mesh3d_inst_cap: usize,
477    /// Cached 3D mesh uniform `u_view_proj`.
478    #[get(type(copy))]
479    pub(crate) mesh3d_vp_loc: i32,
480    /// Cached 3D mesh uniform `u_camera_pos`.
481    #[get(type(copy))]
482    pub(crate) mesh3d_cam_loc: i32,
483    /// Cached 3D mesh uniform `u_sun_dir_fog`.
484    #[get(type(copy))]
485    pub(crate) mesh3d_sun_fog_loc: i32,
486    /// Cached 3D mesh uniform `u_sun_color_ambient`.
487    #[get(type(copy))]
488    pub(crate) mesh3d_sun_col_loc: i32,
489    /// Cached 3D mesh uniform `u_sky_horizon_tod`.
490    #[get(type(copy))]
491    pub(crate) mesh3d_hor_loc: i32,
492    /// Cached 3D mesh uniform `u_sky_zenith_aspect`.
493    #[get(type(copy))]
494    pub(crate) mesh3d_zen_loc: i32,
495}
496
497/// Live dynamic EGL + GLES3 instanced uber-shader presentation surface over Wayland (`wl_egl_window`) or X11 (`Window`).
498#[derive(Data, Debug)]
499pub(crate) struct LinuxEglGlesSurface {
500    /// Active `EGLDisplay` handle stored as `usize`.
501    #[get(type(copy))]
502    pub(crate) egl_display: usize,
503    /// Active `EGLContext` handle stored as `usize`.
504    #[get(type(copy))]
505    pub(crate) egl_context: usize,
506    /// Active `EGLSurface` handle stored as `usize`.
507    #[get(type(copy))]
508    pub(crate) egl_surface: usize,
509    /// Active `wl_egl_window*` pointer (`0` on X11).
510    #[get(type(copy))]
511    pub(crate) wl_egl_window: usize,
512    /// Compiled GLES3 instanced UI uber-shader program ID.
513    #[get(type(copy))]
514    pub(crate) program: u32,
515    /// Vertex array object binding quad + instanced attribute descriptors.
516    #[get(type(copy))]
517    pub(crate) vao: u32,
518    /// Static 6-vertex unit quad buffer bound at attribute location `0`.
519    #[get(type(copy))]
520    pub(crate) quad_vbo: u32,
521    /// Streaming 64-byte `GpuPrimitiveInstance` VBO.
522    #[get(type(copy))]
523    pub(crate) instance_vbo: u32,
524    /// Allocated byte capacity of `instance_vbo`.
525    #[get(type(copy))]
526    pub(crate) instance_vbo_cap: usize,
527    /// Persistent `GL_R8` glyph atlas texture ID.
528    #[get(type(copy))]
529    pub(crate) glyph_r8_tex: u32,
530    /// Width of `glyph_r8_tex` in texels.
531    #[get(type(copy))]
532    pub(crate) glyph_r8_w: u32,
533    /// Height of `glyph_r8_tex` in texels.
534    #[get(type(copy))]
535    pub(crate) glyph_r8_h: u32,
536    /// Uploaded revision of `glyph_r8_tex`.
537    #[get(type(copy))]
538    pub(crate) glyph_r8_rev: u64,
539    /// Color `GL_RGBA8` glyph texture ID.
540    #[get(type(copy))]
541    pub(crate) glyph_rgba8_tex: u32,
542    /// Persistent `GL_RGBA8` image atlas texture ID.
543    #[get(type(copy))]
544    pub(crate) image_tex: u32,
545    /// Width of `image_tex` in texels.
546    #[get(type(copy))]
547    pub(crate) image_w: u32,
548    /// Height of `image_tex` in texels.
549    #[get(type(copy))]
550    pub(crate) image_h: u32,
551    /// Uploaded revision of `image_tex`.
552    #[get(type(copy))]
553    pub(crate) image_rev: u64,
554    /// External/video `GL_RGBA8` texture ID.
555    #[get(type(copy))]
556    pub(crate) external_tex: u32,
557    /// Cached uniform location for `u_viewport`.
558    #[get(type(copy))]
559    pub(crate) viewport_loc: i32,
560    /// Cached uniform location for `u_scroll_offset`.
561    #[get(type(copy))]
562    pub(crate) scroll_loc: i32,
563    /// Active surface width in physical pixels.
564    #[get(type(copy))]
565    pub(crate) width: u32,
566    /// Active surface height in physical pixels.
567    #[get(type(copy))]
568    pub(crate) height: u32,
569    /// True when backed by `wl_egl_window`; false when backed by X11 `Window`.
570    #[get(type(copy))]
571    pub(crate) is_wayland: bool,
572    /// Maximum supported GLES3 texture dimension queried via `GL_MAX_TEXTURE_SIZE`.
573    #[get(type(copy))]
574    pub(crate) max_tex_dim: u32,
575    /// Lazily initialized offscreen GLES3 scene pass pipeline (`OceanFluid` + `World3d`).
576    #[get(skip)]
577    #[get_mut(skip)]
578    #[set(skip)]
579    pub(crate) scene: Option<LinuxEglScenePipeline>,
580    /// Reusable flat primitive staging buffer avoiding per-frame allocations on direct submission.
581    #[get(skip)]
582    #[get_mut(skip)]
583    #[set(skip)]
584    pub(crate) scratch_prims: Vec<GpuPrimitiveInstance>,
585    /// Reusable draw-range metadata buffer paired with `scratch_prims`.
586    #[get(skip)]
587    #[get_mut(skip)]
588    #[set(skip)]
589    pub(crate) scratch_ranges: Vec<(usize, usize, Rect, [f32; 2])>,
590    /// Heap-stable atomic VSync latch cleared by `wl_surface.frame` callback on Wayland.
591    #[get(skip)]
592    #[get_mut(skip)]
593    #[set(skip)]
594    pub(crate) vsync_pending: Box<AtomicBool>,
595}
596
597/// Raw `wl_registry_listener` ABI table registered during Wayland global discovery.
598#[repr(C)]
599#[derive(Clone, Copy)]
600pub(crate) struct WlRegistryListener {
601    /// Callback invoked for each advertised Wayland global `(data, registry, name, interface, version)`.
602    pub(crate) global: unsafe extern "C" fn(*mut c_void, *mut c_void, u32, *const c_char, u32),
603    /// Callback invoked when a Wayland global is removed `(data, registry, name)`.
604    pub(crate) global_remove: unsafe extern "C" fn(*mut c_void, *mut c_void, u32),
605}
606
607/// Raw `wl_buffer_listener` ABI table tracking compositor buffer release notifications.
608#[repr(C)]
609#[derive(Clone, Copy)]
610pub(crate) struct WlBufferListener {
611    /// Callback invoked when the compositor finishes reading a `wl_buffer` (`(data, buffer)`).
612    pub(crate) release: unsafe extern "C" fn(*mut c_void, *mut c_void),
613}
614
615/// Mutable state populated by `WL_REGISTRY_LISTENER` during initial `wl_display_roundtrip`.
616#[repr(C)]
617#[derive(Clone, Copy, Debug, Default)]
618pub(crate) struct WlRegistryBindState {
619    /// Bound `wl_compositor*` proxy handle.
620    pub(crate) compositor: usize,
621    /// Negotiated `wl_compositor` protocol version.
622    pub(crate) compositor_version: u32,
623    /// Bound `wl_shm*` proxy handle.
624    pub(crate) shm: usize,
625}
626
627/// Descriptor carrying POSIX shared-memory FD, geometry, format, and release flag pointer for `WaylandShmCommitOps`.
628#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
629pub struct WaylandShmBufferDescriptor {
630    /// Open shared-memory file descriptor (`memfd_create` or `/dev/shm`).
631    #[get(type(copy))]
632    pub(crate) fd: i32,
633    /// Total mapped buffer byte size.
634    #[get(type(copy))]
635    pub(crate) size: i32,
636    /// Physical buffer width in pixels.
637    #[get(type(copy))]
638    pub(crate) width: i32,
639    /// Physical buffer height in pixels.
640    #[get(type(copy))]
641    pub(crate) height: i32,
642    /// Row stride in bytes (`width * 4`).
643    #[get(type(copy))]
644    pub(crate) stride: i32,
645    /// Wayland shm pixel format (`WL_SHM_FORMAT_ARGB8888` or `WL_SHM_FORMAT_XRGB8888`).
646    #[get(type(copy))]
647    pub(crate) format: u32,
648    /// Raw pointer to the slot's release `AtomicBool` userdata registered on `wl_buffer.release`.
649    #[get(type(copy))]
650    pub(crate) release_flag_ptr: usize,
651}
652
653/// Single double-buffered Wayland `wl_shm` memory mapping and protocol buffer slot.
654#[derive(Debug)]
655pub struct WaylandShmBufferSlot {
656    /// Open POSIX shared-memory file descriptor (`-1` when unallocated).
657    pub(crate) fd: i32,
658    /// Base pointer returned by `mmap(..., MAP_SHARED, fd, 0)` (`0` when unmapped).
659    pub(crate) mapped_ptr: usize,
660    /// Mapped byte capacity of this shared-memory region.
661    pub(crate) mapped_len: usize,
662    /// Current allocated buffer width in physical pixels.
663    pub(crate) width: u32,
664    /// Current allocated buffer height in physical pixels.
665    pub(crate) height: u32,
666    /// Row stride in bytes (`width * 4`).
667    pub(crate) stride: u32,
668    /// Bound Wayland shm pixel format (`WL_SHM_FORMAT_ARGB8888` or `WL_SHM_FORMAT_XRGB8888`).
669    pub(crate) format: u32,
670    /// Associated `wl_shm_pool*` proxy handle (`0` when detached).
671    pub(crate) wl_pool: usize,
672    /// Associated `wl_buffer*` proxy handle (`0` when detached).
673    pub(crate) wl_buffer: usize,
674    /// Atomic busy flag cleared asynchronously by `wl_buffer.release` (`true` while held by compositor).
675    pub(crate) busy: Box<AtomicBool>,
676    /// True once this slot has received a complete full-frame pixel copy for its current dimensions.
677    pub(crate) has_full_copy: bool,
678}
679
680/// Double-buffered Wayland `wl_shm` software swapchain owning two POSIX shm mappings and dirty-rect tracking.
681#[derive(Debug)]
682pub struct WaylandShmSwapchain {
683    /// Two ping-pong shared-memory slots enabling tear-free double-buffered Wayland commits.
684    pub(crate) slots: [WaylandShmBufferSlot; WL_SHM_SLOT_COUNT],
685    /// Wayland shm pixel format (`WL_SHM_FORMAT_XRGB8888` or `WL_SHM_FORMAT_ARGB8888`).
686    pub(crate) pixel_format: u32,
687    /// Dirty rectangles from the immediately preceding submitted frame so double-buffered back slots stay coherent.
688    pub(crate) previous_dirty_rects: Vec<(u32, u32, u32, u32)>,
689    /// Index (`0` or `1`) of the most recently committed buffer slot.
690    pub(crate) last_committed_slot: u8,
691    /// Cumulative count of successfully committed Wayland shm frames.
692    pub(crate) submitted_frames: u64,
693    /// Cumulative count of unchanged frames skipped without commit.
694    pub(crate) skipped_unchanged_frames: u64,
695    /// Cumulative count of failed presentation attempts.
696    pub(crate) failed_frames: u64,
697}
698
699/// Native `libwayland-client.so.0` transport invoking `wl_shm_pool`, `wl_buffer`, `wl_surface`, and `wl_display_flush`.
700#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
701pub struct NativeWaylandShmTransport {
702    /// Live `wl_display*` connection pointer.
703    #[get(type(copy))]
704    pub(crate) display: usize,
705    /// Live `wl_surface*` proxy pointer.
706    #[get(type(copy))]
707    pub(crate) surface: usize,
708    /// Live `wl_shm*` global proxy pointer.
709    #[get(type(copy))]
710    pub(crate) wl_shm: usize,
711    /// Negotiated `wl_surface` interface version (`>= 4` uses `damage_buffer`, `< 4` uses `damage`).
712    #[get(type(copy))]
713    pub(crate) surface_version: u32,
714    /// Integer `wl_surface.set_buffer_scale` divisor applied prior to commit (`<= 0` defaults to `1`).
715    #[new(skip)]
716    #[get(type(copy))]
717    pub(crate) buffer_scale: i32,
718}
719
720/// Explicit per-frame Linux presentation telemetry separating direct GPU vs Wayland shm vs X11 software blits.
721#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
722pub struct LinuxPresentTelemetry {
723    /// Active presentation transport (`GpuDirect`, `WaylandShmSoftware`, or `X11Software`).
724    #[get(type(copy))]
725    pub(crate) mode: LinuxPresentationMode,
726    /// Explicit frame outcome (`Submitted`, `SkippedUnchanged`, or `Failed`).
727    #[get(type(copy))]
728    pub(crate) outcome: LinuxPresentOutcome,
729    /// True whenever a CPU software framebuffer mirror is active (`false` for `GpuDirect`).
730    #[get(type(copy))]
731    pub(crate) cpu_mirror_active: bool,
732    /// Exact pixel bytes copied into Wayland shm or uploaded via X11 `XPutImage` (`0` for `GpuDirect` or skip).
733    #[get(type(copy))]
734    pub(crate) upload_bytes: u64,
735    /// Number of dirty rectangles damaged or uploaded during this frame.
736    #[get(type(copy))]
737    pub(crate) dirty_rect_count: u32,
738    /// Double-buffered Wayland shm slot index (`0` or `1`) committed on this frame.
739    #[get(type(copy))]
740    pub(crate) committed_buffer_slot: u8,
741    /// Cumulative submitted frames recorded on this window.
742    #[get(type(copy))]
743    pub(crate) submitted_frames: u64,
744    /// Cumulative unchanged frames skipped on this window.
745    #[get(type(copy))]
746    pub(crate) skipped_unchanged_frames: u64,
747    /// Cumulative failed frames recorded on this window.
748    #[get(type(copy))]
749    pub(crate) failed_frames: u64,
750}
751
752/// Raw 192-byte X11 `XEvent` union storage aligned for 64-bit Linux LP64 ABI.
753#[repr(C)]
754#[derive(Clone, Copy)]
755pub(crate) struct X11EventRaw {
756    /// Raw union payload words.
757    pub(crate) pad: [isize; 24],
758}
759
760/// X11 `XKeyEvent` / `XButtonEvent` ABI layout on LP64 Linux.
761#[repr(C)]
762#[derive(Clone, Copy)]
763pub(crate) struct X11KeyOrButtonEvent {
764    /// Event discriminant (`KeyPress`, `KeyRelease`, `ButtonPress`, `ButtonRelease`).
765    pub(crate) event_type: i32,
766    /// X server serial number.
767    pub(crate) serial: usize,
768    /// Non-zero when generated by `SendEvent`.
769    pub(crate) send_event: i32,
770    /// Connection `Display*`.
771    pub(crate) display: *mut c_void,
772    /// Target `Window` XID.
773    pub(crate) window: u64,
774    /// Root window XID.
775    pub(crate) root: u64,
776    /// Subwindow XID.
777    pub(crate) subwindow: u64,
778    /// Event timestamp in milliseconds.
779    pub(crate) time: u64,
780    /// Pointer X coordinate relative to window.
781    pub(crate) x: i32,
782    /// Pointer Y coordinate relative to window.
783    pub(crate) y: i32,
784    /// Pointer X relative to root window.
785    pub(crate) x_root: i32,
786    /// Pointer Y relative to root window.
787    pub(crate) y_root: i32,
788    /// Modifier key / button mask.
789    pub(crate) state: u32,
790    /// Hardware keycode or mouse button number.
791    pub(crate) detail: u32,
792    /// Same-screen flag.
793    pub(crate) same_screen: i32,
794}
795
796/// X11 `XMotionEvent` ABI layout on LP64 Linux.
797#[repr(C)]
798#[derive(Clone, Copy)]
799pub(crate) struct X11MotionEvent {
800    /// Event discriminant (`MotionNotify`).
801    pub(crate) event_type: i32,
802    /// X server serial number.
803    pub(crate) serial: usize,
804    /// Send-event flag.
805    pub(crate) send_event: i32,
806    /// Connection `Display*`.
807    pub(crate) display: *mut c_void,
808    /// Target `Window` XID.
809    pub(crate) window: u64,
810    /// Root window XID.
811    pub(crate) root: u64,
812    /// Subwindow XID.
813    pub(crate) subwindow: u64,
814    /// Timestamp in milliseconds.
815    pub(crate) time: u64,
816    /// Pointer X coordinate relative to window.
817    pub(crate) x: i32,
818    /// Pointer Y coordinate relative to window.
819    pub(crate) y: i32,
820    /// Pointer X relative to root window.
821    pub(crate) x_root: i32,
822    /// Pointer Y relative to root window.
823    pub(crate) y_root: i32,
824    /// Active modifier mask.
825    pub(crate) state: u32,
826    /// Motion hint byte.
827    pub(crate) is_hint: c_char,
828    /// Same-screen flag.
829    pub(crate) same_screen: i32,
830}
831
832/// X11 `XConfigureEvent` ABI layout on LP64 Linux.
833#[repr(C)]
834#[derive(Clone, Copy)]
835pub(crate) struct X11ConfigureEvent {
836    /// Event discriminant (`ConfigureNotify`).
837    pub(crate) event_type: i32,
838    /// X server serial number.
839    pub(crate) serial: usize,
840    /// Send-event flag.
841    pub(crate) send_event: i32,
842    /// Connection `Display*`.
843    pub(crate) display: *mut c_void,
844    /// Event-delivery window XID.
845    pub(crate) event_window: u64,
846    /// Reconfigured target window XID.
847    pub(crate) window: u64,
848    /// New window X position.
849    pub(crate) x: i32,
850    /// New window Y position.
851    pub(crate) y: i32,
852    /// New window client width in physical pixels.
853    pub(crate) width: i32,
854    /// New window client height in physical pixels.
855    pub(crate) height: i32,
856}
857
858/// X11 `XClientMessageEvent` ABI layout on LP64 Linux.
859#[repr(C)]
860#[derive(Clone, Copy)]
861pub(crate) struct X11ClientMessageEvent {
862    /// Event discriminant (`ClientMessage`).
863    pub(crate) event_type: i32,
864    /// X server serial number.
865    pub(crate) serial: usize,
866    /// Send-event flag.
867    pub(crate) send_event: i32,
868    /// Connection `Display*`.
869    pub(crate) display: *mut c_void,
870    /// Target `Window` XID.
871    pub(crate) window: u64,
872    /// Message type atom (`WM_PROTOCOLS`).
873    pub(crate) message_type: u64,
874    /// Data format (`8`, `16`, or `32`).
875    pub(crate) format: i32,
876    /// 32-bit protocol data payload (`l[0]` holds `WM_DELETE_WINDOW`).
877    pub(crate) data: [u64; 5],
878}
879
880/// Bundle returned when opening a native Linux X11 or Wayland window.
881#[derive(Clone, Copy, Data, Debug)]
882pub(crate) struct LinuxNativeWindowHandle {
883    /// Dynamically loaded `libX11` or `libwayland-client` handle.
884    #[get(type(copy))]
885    pub(crate) lib: usize,
886    /// True when backed by Wayland; false when backed by X11.
887    #[get(type(copy))]
888    pub(crate) is_wayland: bool,
889    /// Raw `Display*` or `wl_display*`.
890    #[get(type(copy))]
891    pub(crate) display: usize,
892    /// Native X11 `Window` XID or Wayland surface pointer.
893    #[get(type(copy))]
894    pub(crate) window: u64,
895    /// Cached X11 `GC` handle for `XPutImage`.
896    #[get(type(copy))]
897    pub(crate) gc: usize,
898    /// Cached X11 `Visual*` pointer for `XCreateImage`.
899    #[get(type(copy))]
900    pub(crate) visual: usize,
901    /// X11 default visual color depth (e.g., `24` or `32`).
902    #[get(type(copy))]
903    pub(crate) depth: u32,
904    /// Interned `WM_DELETE_WINDOW` atom for graceful window closing.
905    #[get(type(copy))]
906    pub(crate) wm_delete_atom: u64,
907    /// Probed display DPI scale factor (`1.0..=4.0`).
908    #[get(type(copy))]
909    pub(crate) scale_factor: f32,
910    /// True when X11 MIT-SHM (`XShmQueryExtension`) is supported on this display.
911    #[get(type(copy))]
912    pub(crate) mit_shm_available: bool,
913    /// True when Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is available.
914    #[get(type(copy))]
915    pub(crate) wayland_vulkan_wsi: bool,
916    /// True when X11 Vulkan WSI (`VK_KHR_xlib_surface`) is available.
917    #[get(type(copy))]
918    pub(crate) xlib_vulkan_wsi: bool,
919    /// Bound Wayland `wl_compositor*` proxy pointer (`0` on X11 or unavailable).
920    #[get(type(copy))]
921    pub(crate) wl_compositor: usize,
922    /// Bound Wayland `wl_shm*` proxy pointer (`0` on X11 or unavailable).
923    #[get(type(copy))]
924    pub(crate) wl_shm: usize,
925    /// Negotiated Wayland `wl_surface` interface version (`0` on X11).
926    #[get(type(copy))]
927    pub(crate) wl_surface_version: u32,
928}
929
930/// Native Linux X11 / Wayland window record.
931#[derive(Clone, Data, Debug)]
932pub struct LinuxWindowRecord {
933    /// Window configuration.
934    pub(crate) config: WindowConfig,
935    /// Live window state.
936    #[get(type(copy))]
937    pub(crate) state: WindowState,
938    /// True when backed by Wayland; false when backed by X11 Xlib.
939    #[get(type(copy))]
940    pub(crate) is_wayland: bool,
941    /// Raw display handle (`Display*` or `wl_display*`).
942    #[get(type(copy))]
943    pub(crate) display: usize,
944    /// Raw window or surface identifier (`Window` or `wl_surface*`).
945    #[get(type(copy))]
946    pub(crate) window: u64,
947    /// Cached X11 `GC` handle used by `XPutImage`.
948    #[get(type(copy))]
949    pub(crate) gc: usize,
950    /// Cached X11 `Visual*` pointer used by `XCreateImage`.
951    #[get(type(copy))]
952    pub(crate) visual: usize,
953    /// X11 visual depth in bits (`24` or `32`).
954    #[get(type(copy))]
955    pub(crate) depth: u32,
956    /// Interned `WM_DELETE_WINDOW` protocol atom.
957    #[get(type(copy))]
958    pub(crate) wm_delete_atom: u64,
959    /// Whether `XMapWindow` has been issued after Frame 1 presentation (eliminates unmapped flash).
960    #[get(type(copy))]
961    pub(crate) revealed: bool,
962    /// Whether X11 MIT-SHM shared-memory image transport is supported by the X server.
963    #[get(type(copy))]
964    pub(crate) mit_shm_available: bool,
965    /// Whether Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is ready on this display.
966    #[get(type(copy))]
967    pub(crate) wayland_vulkan_wsi: bool,
968    /// Whether X11 Vulkan WSI (`VK_KHR_xlib_surface`) is ready on this display.
969    #[get(type(copy))]
970    pub(crate) xlib_vulkan_wsi: bool,
971    /// Bound Wayland `wl_compositor*` proxy pointer (`0` on X11).
972    #[get(type(copy))]
973    pub(crate) wl_compositor: usize,
974    /// Bound Wayland `wl_shm*` proxy pointer (`0` on X11).
975    #[get(type(copy))]
976    pub(crate) wl_shm: usize,
977    /// Negotiated Wayland `wl_surface` interface version (`>= 4` supports `damage_buffer`).
978    #[get(type(copy))]
979    pub(crate) wl_surface_version: u32,
980    /// Reported `wl_output.mode` refresh rate in millihertz (e.g. `240000` for `240Hz`, `0` if unset).
981    #[get(type(copy))]
982    pub(crate) wayland_output_refresh_milli_hz: u32,
983    /// Latest `wp_presentation` feedback timestamp in nanoseconds (`0` before first presentation).
984    #[get(type(copy))]
985    pub(crate) wayland_presentation_time_ns: u64,
986    /// Whether a `wl_surface::frame` callback is currently armed awaiting compositor VSync.
987    #[get(type(copy))]
988    pub(crate) wayland_frame_callback_pending: bool,
989    /// Active Linux presentation mode (`GpuDirect`, `WaylandShmSoftware`, or `X11Software`).
990    #[get(type(copy))]
991    pub(crate) presentation_mode: LinuxPresentationMode,
992    /// Explicit CPU-mirror telemetry flag (`true` on Wayland shm / X11 software; `false` on direct GPU).
993    #[get(type(copy))]
994    pub(crate) cpu_mirror_active: bool,
995    /// Most recent per-frame Linux presentation telemetry snapshot.
996    #[get(type(copy))]
997    pub(crate) last_telemetry: LinuxPresentTelemetry,
998    /// Double-buffered Wayland `wl_shm` software swapchain attached to this window when Wayland is active.
999    #[get(skip)]
1000    #[get_mut(skip)]
1001    #[set(skip)]
1002    pub(crate) wayland_shm: Option<Arc<Mutex<WaylandShmSwapchain>>>,
1003    /// Optional dynamically loaded EGL + GLES3 instanced direct-GPU surface over Wayland or X11.
1004    #[get(skip)]
1005    #[get_mut(skip)]
1006    #[set(skip)]
1007    pub(crate) egl_gles: Option<Arc<Mutex<LinuxEglGlesSurface>>>,
1008}
1009
1010/// Direct Linux X11 / Wayland (`dlopen`-loaded) + Vulkan platform backend.
1011#[derive(Clone, Data, Debug)]
1012pub struct LinuxPlatform {
1013    /// Monotonic window handle generator.
1014    #[get(pub(crate), type(copy))]
1015    #[get_mut(pub(crate))]
1016    #[set(pub(crate))]
1017    pub(crate) next_id: u64,
1018    /// Dynamically loaded `libX11` handle if present.
1019    #[get(pub(crate), type(copy))]
1020    #[get_mut(pub(crate))]
1021    #[set(pub(crate))]
1022    pub(crate) x11_lib: usize,
1023    /// Active native Linux windows.
1024    pub(crate) windows: HashMap<WindowId, LinuxWindowRecord>,
1025    /// Queued window and input events.
1026    pub(crate) pending_events: Vec<WindowEvent>,
1027    /// Clipboard text cache.
1028    #[get(skip)]
1029    pub(crate) clipboard_cache: Option<String>,
1030    /// Whether the Linux X11/Wayland frame pump is paused for background freeze.
1031    #[get(pub(crate), type(copy))]
1032    #[set(pub(crate))]
1033    pub(crate) pump_paused: bool,
1034    /// Non-blocking wakeup pipe read end passed to `poll(display_fd, wakeup_pipe)` (`-1` when unavailable).
1035    #[get(pub(crate), type(copy))]
1036    #[set(pub(crate))]
1037    pub(crate) wake_read_fd: i32,
1038    /// Non-blocking wakeup pipe write end signaled by `wake_event_loop()` (`-1` when unavailable).
1039    #[get(pub(crate), type(copy))]
1040    #[set(pub(crate))]
1041    pub(crate) wake_write_fd: i32,
1042}