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
//! A GPU of the system's, as a host hands it to the app: what the system makes for that GPU, its
//! video decoders and its hardware buffer allocator, as Direct3D makes a video device on one
//! adapter, VA-API and GBM open one render node, and FFmpeg makes a hardware device before a
//! decoder on it. Memory these make opens on that GPU: a picture a decoder writes, or a buffer the
//! allocator makes, is drawn and shown with no copy across GPUs. Software decoders are among a
//! GPU's too, as the GPU their pictures are copied into. Apple's systems and Android name no GPU,
//! their memory opening on any of the machine's, so they hand out one.
//!
//! The invariant a host keeps: what a GPU hands out makes its memory on that GPU, never on another.
use std::rc::Rc;
use std::sync::Arc;
use crate::GpuId;
use crate::HardwareBufferAllocator;
use crate::video_decoders::VideoDecoders;
/// One of the system's GPUs ([`Platform::gpu`](crate::Platform::gpu)).
pub trait SystemGpu {
/// The GPU as its system names it; `None` where the system names none.
fn id(&self) -> Option<GpuId>;
/// Its video decoders, on its video hardware and on the processor, whose pictures are in its
/// memory; `None` where the system decodes no video for the app.
fn video_decoders(&self) -> Option<Rc<dyn VideoDecoders>>;
/// What allocates its hardware buffers, from any thread; `None` where the system allocates
/// none.
fn hardware_buffer_allocator(&self) -> Option<Arc<dyn HardwareBufferAllocator>>;
}
/// A GPU as a host gathers it: its name and what the system made for it, which every host hands
/// out as its [`SystemGpu`].
pub struct HostGpu {
pub id: Option<GpuId>,
pub video_decoders: Option<Rc<dyn VideoDecoders>>,
pub hardware_buffer_allocator: Option<Arc<dyn HardwareBufferAllocator>>,
}
impl SystemGpu for HostGpu {
fn id(&self) -> Option<GpuId> {
self.id
}
fn video_decoders(&self) -> Option<Rc<dyn VideoDecoders>> {
self.video_decoders.clone()
}
fn hardware_buffer_allocator(&self) -> Option<Arc<dyn HardwareBufferAllocator>> {
self.hardware_buffer_allocator.clone()
}
}