JFLib

plat/android_gpu.rs#

Source: lib/plat/android_gpu.rs

android_gpu -- what the GPU layer and the UI's output through the GPU need of Android
(lib/gpu vk_load.rs, vk_swap.rs; lib/ui/gpu_out.rs; docs/GPU.md "Ausgabe unter Android")

  dl_open(name) / dl_sym(handle, name) / dl_close(handle)   libvulkan.so at run time: no
                                     DT_NEEDED, the program starts on a phone without it
  gpu_thread_spawn(stack, f)         a thread for the output's jobs: thread_spawn's
                                     (android_thread.rs, Bionic's pthreads)
  win_gpu_child(w)                   the surface of the SurfaceView (ANativeWindow), the analogue
                                     of Windows' child window; only for window 0 while nothing
                                     else shows on the canvas (tool windows and popups are
                                     composed on the CPU, below the surface)
  win_gpu_child_later(w)             no surface now, a frame or the host brings it: not a reason
                                     to give up, and nothing to poll for
  win_gpu_child_show(w, show)        show: the frame is on the surface, the canvas path rests;
                                     hide: the frame is on its way to the Bitmap, the host takes
                                     the SurfaceView away (the surface goes with it)
  win_release_kept(w)                the canvas's copy of the window goes

The surface comes and goes with the system (GalleryActivity's SurfaceHolder.Callback, bridge.c):
jfgui_gpu_surface(window) on the UI thread.  bridge.c owns the ANativeWindow reference; the
VkSurfaceKHR takes its own, so a worker still building on a surface that went away gets errors,
not a dangling pointer.
  • fn dl_open(name: &str) -> Option<usize> open a shared library (a name as the linker searches it, or a path) -> its handle

  • unsafe fn dl_sym(handle: usize, name: &[u8]) -> usize a symbol of the library (name NUL-terminated) -> its address, 0 when missing

    Safety#

    handle came from dl_open and has not been closed: the dynamic linker reads its structures before it could tell a wrong handle.

  • unsafe fn dl_close(handle: usize) give the library back

    Safety#

    handle came from dl_open and is closed once; nothing uses what dl_sym found in it any more (the library may be unloaded).

  • fn gpu_thread_spawn(stack: usize, f: Box<dyn FnOnce() + Send>) -> Option<super::Thread> a thread with stack bytes of stack (the output's jobs) -> its handle

  • struct NativeWindow a target for swapchains: the ANativeWindow of the SurfaceView, with a reference of its own (a worker may get to it after the surface went)

    • window: usize
  • extern "C" fn jfgui_gpu_surface(window: usize) -> u32 (bridge.c) the surface came (an ANativeWindow) or went (0; nothing uses it when this returns) -> 1: the frame waits to go to the canvas, the host renders once more

  • fn gpu_out_state(state: u32) how the output came up: the host keeps it across runs, the program's resolution follows

  • fn win_gpu_child(w: i32) -> Option<NativeWindow> the surface for window w; None: see win_gpu_child_later

  • fn win_gpu_child_later(w: i32) -> bool no surface for window w now, but it may come: the host or the next frame wakes the loop

  • fn win_gpu_child_alone(w: i32) -> bool the window still shows on its surface alone: nothing else came on the canvas

  • fn win_gpu_child_show(w: i32, show: bool) show: the window shows on the surface; hide: on the canvas, the surface goes

  • fn win_release_kept(w: i32) the frame is on the surface: the canvas's copy of the window goes (it comes back whole)

  • fn win_in_sizemove() -> bool no modal size loop here

  • fn win_display_adapter(_w: i32) -> Option<(u32, u32)> one GPU, which drives the display

  • fn win_remote_session() -> bool no remote sessions here

// the script command `gpu` (a script's real windows) has nothing to work with here: scripts run on
// the desktop, this target has its own test (apps/androidGallery/tests/android_gpu.py)
WT_NOANIM: u32 = 0
WT_FROM_POINT: u32 = 0
  • fn win_test(_op: u32, _w: i32, _a: [i32; 4]) -> i64

  • fn win_test_image(_w: i32) -> Option<(i32, i32, alloc::vec::Vec<u8>)>

  • fn win_test_composed(_w: i32) -> Option<(i32, i32, alloc::vec::Vec<u8>)>

  • fn win_test_screen(_x: i32, _y: i32, _w: i32, _h: i32) -> Option<alloc::vec::Vec<u8>>

  • fn gpu_wait(_deadline_us: u64)

Source: docs/API.md in the JFLib repository.