plat/apple_mac_gpu.rs (Apple)#
Source: lib/plat/apple_mac_gpu.rs
apple_mac_gpu -- the GPU's layer in a window on macOS (AP6, docs/APPLE.md): a CAMetalLayer as a
sublayer of the view's layer, above the picture the CPU path puts into that layer (win_present).
lib/gpu's Metal swapchain draws into it; the counterpart of the child window on Windows and the
SurfaceView on Android.
win_native(w) the window's GPU layer, shown (a program that draws the window with the
GPU alone: gputest)
win_gpu_child(w) the same layer for the UI's output, hidden until win_gpu_child_show:
the CPU's picture stays visible below it until the GPU's first frame
win_gpu_child_show show or hide it (hiding brings the CPU path's picture back at once:
it is the view layer's contents under the sublayer)
The layer follows the view's bounds (autoresizing), its contentsScale follows the window's
backingScaleFactor (size_changed); the drawable size in pixels is lib/gpu's. Main thread only,
as all of AppKit; lib/gpu may use the layer on its own thread (nextDrawable, drawableSize).
struct NativeWindowa window's GPU layer (a CAMetalLayer, retained: released when this goes) and the window's size in pixels when it was taken (lib/gpu builds swapchains on a worker, where plat's state is out of reach)layer: usizesize: (i32, i32)
fn win_native(w: i32) -> Option<NativeWindow>(gpu) the window's GPU layer, shown: the GPU draws the whole window (do not call win_present for it; the view layer's own picture stays below, hidden)fn win_gpu_child(w: i32) -> Option<NativeWindow>(gpu) the UI output's layer of window w, hidden until win_gpu_child_showfn win_gpu_child_show(w: i32, on: bool)(gpu) show or hide the UI output's layer of window wfn win_gpu_child_later(_w: i32) -> bool(gpu) the layer comes at once (Android: the surface comes later)fn win_gpu_child_alone(_w: i32) -> bool(gpu) nothing else is composed over the window's layer (popups are windows of their own)fn win_display_adapter(_w: i32) -> Option<(u32, u32)>(gpu) the PCI ids of the GPU that shows the window: none on a Mac (one GPU per screen at most)fn gpu_thread_spawn(stack: usize, f: alloc::boxed::Box<dyn FnOnce() + Send>) -> Option<crate::Thread>(gpu) a thread for the GPU output's job (a plain plat thread)fn win_release_kept(w: i32)(gpu) the view layer's own picture is not needed while the GPU shows the window: it goes (the way back draws one first, win_present)fn gpu_wait(deadline_us: u64)(gpu) the UI output waits a little for a free image: the window's events go on meanwhilefn gpu_out_state(_state: u32)(gpu) how the output came up (GPU_STATE_*): Android keeps it across runsfn win_in_sizemove() -> bool(gpu) no live resize loop holds the program's own loop on macOS (AppKit's live resize runs inside the event loop, the frames are CPU frames)fn win_remote_session() -> bool(gpu) a remote session: Screen Sharing shows what the window server composes, the GPU worksfn win_test_image(_w: i32) -> Option<(i32, i32, Vec<u8>)>(tests) what the window system holds for window w: the view layer's picture is ours (the CPU path) and the GPU layer's is not readable from here: Nonefn win_test_composed(_w: i32) -> Option<(i32, i32, Vec<u8>)>(tests) window w as the system composes it: Windows only (PrintWindow): Nonefn win_test_screen(_x: i32, _y: i32, _w: i32, _h: i32) -> Option<Vec<u8>>(tests) a part of the screen: macOS asks the user for that (screen recording): Nonefn win_test_send(_w: i32, _msg: u32, _wp: usize, _lp: isize) -> isize(tests) nothing to send to: Windows' messagesfn gpu_test_presented() -> Vec<(u64, u64)>(bench: Wayland's presentation feedback) nothing here