1use crate::graphics::{Antialiasing, Shell};
2use crate::primitive;
3use crate::quad;
4use crate::text;
5use crate::triangle;
6
7use std::sync::{Arc, RwLock};
8
9#[derive(Clone)]
10pub struct Engine {
11 pub(crate) device: wgpu::Device,
12 pub(crate) queue: wgpu::Queue,
13 pub(crate) format: wgpu::TextureFormat,
14
15 pub(crate) quad_pipeline: quad::Pipeline,
16 pub(crate) text_pipeline: text::Pipeline,
17 pub(crate) triangle_pipeline: triangle::Pipeline,
18 #[cfg(any(feature = "image", feature = "svg"))]
19 pub(crate) image_pipeline: crate::image::Pipeline,
20 pub(crate) primitive_storage: Arc<RwLock<primitive::Storage>>,
21 _shell: Shell,
22}
23
24impl Engine {
25 pub fn new(
26 _adapter: &wgpu::Adapter,
27 device: wgpu::Device,
28 queue: wgpu::Queue,
29 format: wgpu::TextureFormat,
30 antialiasing: Option<Antialiasing>, shell: Shell,
32 ) -> Self {
33 Self {
34 format,
35
36 quad_pipeline: quad::Pipeline::new(&device, format),
37 text_pipeline: text::Pipeline::new(&device, &queue, format),
38 triangle_pipeline: triangle::Pipeline::new(
39 &device,
40 format,
41 antialiasing,
42 ),
43
44 #[cfg(any(feature = "image", feature = "svg"))]
45 image_pipeline: {
46 let backend = _adapter.get_info().backend;
47
48 crate::image::Pipeline::new(&device, format, backend)
49 },
50
51 primitive_storage: Arc::new(RwLock::new(
52 primitive::Storage::default(),
53 )),
54
55 device,
56 queue,
57 _shell: shell,
58 }
59 }
60
61 #[cfg(any(feature = "image", feature = "svg"))]
62 pub fn create_image_cache(&self) -> crate::image::Cache {
63 self.image_pipeline.create_cache(
64 &self.device,
65 &self.queue,
66 &self._shell,
67 )
68 }
69}