|
| 1 | +// Copyright 2018 the Vello Authors and The Pathfinder Project Developers |
| 2 | +// SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | + |
| 4 | +use image::RgbaImage; |
| 5 | + |
| 6 | +#[cfg(feature = "enable-winit")] |
| 7 | +use winit::window::Window; |
| 8 | + |
| 9 | +use crate::Rect; |
| 10 | +use crate::{Connection, ConnectionError, LayerContainerInfo}; |
| 11 | +use crate::{LayerGeometryInfo, LayerId, LayerMap, LayerSurfaceInfo, LayerTreeInfo, Promise}; |
| 12 | + |
| 13 | +// Backend definition |
| 14 | + |
| 15 | +pub trait Backend: Sized { |
| 16 | + type NativeConnection; |
| 17 | + type Host; |
| 18 | + |
| 19 | + // Constructor |
| 20 | + fn new(connection: Connection<Self::NativeConnection>) -> Result<Self, ConnectionError>; |
| 21 | + |
| 22 | + // Transactions |
| 23 | + fn begin_transaction(&self); |
| 24 | + fn end_transaction( |
| 25 | + &mut self, |
| 26 | + promise: &Promise<()>, |
| 27 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 28 | + container_component: &LayerMap<LayerContainerInfo>, |
| 29 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 30 | + surface_component: &LayerMap<LayerSurfaceInfo>, |
| 31 | + ); |
| 32 | + |
| 33 | + // Layer creation and destruction |
| 34 | + fn add_container_layer(&mut self, new_layer: LayerId); |
| 35 | + fn add_surface_layer(&mut self, new_layer: LayerId); |
| 36 | + fn delete_layer(&mut self, layer: LayerId); |
| 37 | + |
| 38 | + // Layer tree management |
| 39 | + fn insert_before( |
| 40 | + &mut self, |
| 41 | + parent: LayerId, |
| 42 | + new_child: LayerId, |
| 43 | + reference: Option<LayerId>, |
| 44 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 45 | + container_component: &LayerMap<LayerContainerInfo>, |
| 46 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 47 | + ); |
| 48 | + fn remove_from_superlayer( |
| 49 | + &mut self, |
| 50 | + layer: LayerId, |
| 51 | + parent: LayerId, |
| 52 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 53 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 54 | + ); |
| 55 | + |
| 56 | + // Native hosting |
| 57 | + unsafe fn host_layer( |
| 58 | + &mut self, |
| 59 | + layer: LayerId, |
| 60 | + host: Self::Host, |
| 61 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 62 | + container_component: &LayerMap<LayerContainerInfo>, |
| 63 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 64 | + ); |
| 65 | + fn unhost_layer(&mut self, layer: LayerId); |
| 66 | + |
| 67 | + // Geometry |
| 68 | + fn set_layer_bounds( |
| 69 | + &mut self, |
| 70 | + layer: LayerId, |
| 71 | + old_bounds: &Rect<f32>, |
| 72 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 73 | + container_component: &LayerMap<LayerContainerInfo>, |
| 74 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 75 | + ); |
| 76 | + |
| 77 | + // Miscellaneous layer flags |
| 78 | + fn set_layer_surface_options( |
| 79 | + &mut self, |
| 80 | + layer: LayerId, |
| 81 | + surface_component: &LayerMap<LayerSurfaceInfo>, |
| 82 | + ); |
| 83 | + |
| 84 | + // Screenshots |
| 85 | + fn screenshot_hosted_layer( |
| 86 | + &mut self, |
| 87 | + layer: LayerId, |
| 88 | + transaction_promise: &Promise<()>, |
| 89 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 90 | + container_component: &LayerMap<LayerContainerInfo>, |
| 91 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 92 | + surface_component: &LayerMap<LayerSurfaceInfo>, |
| 93 | + ) -> Promise<RgbaImage>; |
| 94 | + |
| 95 | + // `winit` integration |
| 96 | + #[cfg(feature = "enable-winit")] |
| 97 | + fn window(&self) -> Option<&Window>; |
| 98 | + #[cfg(feature = "enable-winit")] |
| 99 | + fn host_layer_in_window( |
| 100 | + &mut self, |
| 101 | + layer: LayerId, |
| 102 | + tree_component: &LayerMap<LayerTreeInfo>, |
| 103 | + container_component: &LayerMap<LayerContainerInfo>, |
| 104 | + geometry_component: &LayerMap<LayerGeometryInfo>, |
| 105 | + ) -> Result<(), ()>; |
| 106 | +} |
0 commit comments