1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! GPU memory the system's compositor shows, as a host hands it to the app: on Apple platforms an
//! `IOSurface`, Android's `HardwareBuffer`, a dmabuf behind Wayland's `wl_buffer`, a shared D3D
//! texture. Not a dart:ui type: Flutter's engine keeps its buffers to itself. They follow
//! `wasdk:platform/hardware-buffers` one to one.
//!
//! A hardware buffer is memory the app holds: one it allocates
//! ([`HardwareBufferAllocator::allocate`]), as `IOSurfaceCreate` and `AHardwareBuffer_allocate`
//! make one, and an image the system's hardware codecs decode
//! ([`HardwareImageCodecs`](crate::image_codecs::HardwareImageCodecs)), which no system pool waits
//! for. A video's frame is apart, lent with its slot in a decoder's pool
//! ([`VideoFrame`](crate::VideoFrame)), and its memory is one of these too, which keeps the frame
//! while it is held. The app draws into a buffer and samples it through a texture it imports on
//! its own device ([`Platform::import_texture`](crate::Platform::import_texture)), shows it on a
//! composition layer ([`CompositionLayer::present`](crate::CompositionLayer::present)), and has
//! the hardware codecs encode it; its pixels come back to the app's memory only through
//! [`HardwareBuffer::read_pixels`]. A buffer knows only its own facts, its size and what it was
//! allocated for, and names no GPU API: the host, which knows both the buffer and the device,
//! imports it, as each system's GPU API imports such memory.
//!
//! Each host implements [`HardwareBuffer`] over its system's buffers. Platform code reaches the
//! system's own buffer by downcasting through `Any` to the type of the host that handed it out: on
//! Apple platforms `waft-embedder-winit`'s `SurfaceBuffer`, whose `surface` is the `IOSurface`.
//!
//! The invariant a host keeps: a texture imported of a buffer holds the buffer, and the frame it
//! is the memory of, until the GPU is done with it.
use Any;
use Arc;
use crate;
/// What makes the app's hardware buffers: the role of Android's graphics allocator (gralloc's
/// `IAllocator`), Fuchsia's sysmem `Allocator` and a GBM device on Linux. `None` from
/// [`Platform::hardware_buffer_allocator`](crate::Platform::hardware_buffer_allocator) where the
/// system allocates none. It may be called from any thread, as a producer allocates a buffer where
/// it draws.
/// What a buffer is allocated for, named after its users, as Android's `AHardwareBuffer` usage
/// is: so far what the GPU does with it, which a texture imported of it allows
/// ([`Platform::import_texture`](crate::Platform::import_texture)). The CPU, the system's
/// compositor and a video encoder join as they are needed.
/// One block of pixels in memory the GPU, the system's compositor and other processes all reach.
/// Every method may be called from any thread.