JFLib

plat/web_gpu.rs#

Source: lib/plat/web_gpu.rs

web_gpu -- what the UI's output through the GPU needs of the browser (lib/ui/gpu_out.rs, lib/gpu
web_*.rs, web/gpu.js, web/loader.js; docs/GPU.md "Ausgabe im Browser")

  win_gpu_child(w)                   a canvas above the page's #screen as an OffscreenCanvas in this
                                     worker, the analogue of Android's SurfaceView: only for window 0
                                     while nothing else shows on #screen (tool windows and popups are
                                     composed on the CPU, below it).  None: the page was asked, the canvas
                                     is on its way; each surface takes a new one
  win_gpu_child_later(w)             no canvas now, it comes: no reason to give up, nothing to poll for
  win_gpu_child_alone(w)             the window still shows on it alone
  win_gpu_child_show(w, show)        show: the frame is on the canvas, #screen rests with its last frame
                                     under it.  hide: the frame is on its way to #screen, the page
                                     takes the canvas away after it (after_flush): no gap, no wrong frame
  win_release_kept(w)                the copy of the window for #screen goes, and the worker's pooled
                                     pixel buffers with it
  win_gpu_child_blank()              the page found that the canvas shows nothing (once)

A canvas that has shown nothing yet shows nothing: until the first frame reaches the compositor the
page's #screen is seen through it, the same pixels (the switch needs no message and no timing).  A
new period on the GPU takes a new canvas, so it can never show an old frame.  The worker's thread is the
only one that touches any of this: there are no job threads here, in none of the three bundles (the
compute workers of the threads bundle cannot own WebGPU objects); gpu_out.rs runs its jobs on this
thread when the browser has answered.
/// (browser) the output wants a canvas above #screen; the page answers with jfgui_gpu_canvas
REQUEST_GPU_CANVAS: u32 = 28
/// (browser) the canvas above #screen goes (after the frame that replaces it)
REQUEST_GPU_HIDE: u32 = 29
/// (browser) the canvas above #screen shows: the worker's pixel buffers for the page may go
REQUEST_GPU_SHOWN: u32 = 30
  • extern "C" fn jfgui_gpu_canvas(handle: u32) (worker.js) the page's canvas, as a number of web/gpu.js's table

  • extern "C" fn jfgui_gpu_blank() (worker.js) the page's watcher (watchGpuCanvas in loader.js): the canvas shows nothing

  • fn win_gpu_child_blank() -> bool the page found that the canvas shows nothing, though everything computes right; asked once

  • struct NativeWindow a target for swapchains: the OffscreenCanvas of the page's canvas, a number of web/gpu.js's table

impl NativeWindow

  • fn take(self) -> u32 the number, once (lib/gpu's Surface owns it then)

  • fn gpu_out_state(_state: u32) how the output came up: nothing keeps it across runs here

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

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

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

  • fn win_gpu_child_show(w: i32, show: bool) show: the window shows on the canvas above; hide: on #screen, the canvas above goes after that frame

  • fn win_release_kept(w: i32) the frame is on the canvas above: the copy for #screen goes (it comes back whole)

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

  • fn win_display_adapter(_w: i32) -> Option<(u32, u32)> the browser chooses the GPU

  • fn win_remote_session() -> bool no remote sessions to look for 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/gallery/tests/gpu_web.mjs)
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.