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
use crate::{Error, Handle};

/// A [Handle] to the G2d API which doesn't require a window.
#[derive(Debug)]
pub struct WindowlessHandle {
    wgpu_device: wgpu::Device,
    wgpu_queue: wgpu::Queue,
}

impl WindowlessHandle {
    /// Attempts to create a [WindowlessHandle].
    pub async fn new() -> Result<Self, Error> {
        let wgpu_instance = super::create_wgpu_instance();
        let wgpu_adapter = super::request_wgpu_adapter(&wgpu_instance, None).await?;
        let (wgpu_device, wgpu_queue) = super::request_wgpu_device(&wgpu_adapter).await?;

        Ok(Self {
            wgpu_device,
            wgpu_queue,
        })
    }
}

impl Handle for WindowlessHandle {
    fn wgpu_device(&self) -> &wgpu::Device {
        &self.wgpu_device
    }

    fn wgpu_queue(&self) -> &wgpu::Queue {
        &self.wgpu_queue
    }
}