use llimphi_hal::{Frame, Hal};
pub use vello;
pub use vello::kurbo;
pub use vello::peniko;
#[cfg(feature = "hybrid")]
pub use vello_hybrid;
pub mod gpu;
pub use gpu::{GpuBatch, GpuPipelines};
#[derive(Debug)]
pub enum RasterError {
Init(String),
Render(String),
}
impl std::fmt::Display for RasterError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Init(s) => write!(f, "vello init: {s}"),
Self::Render(s) => write!(f, "vello render: {s}"),
}
}
}
impl std::error::Error for RasterError {}
pub struct Renderer {
inner: vello::Renderer,
}
impl Renderer {
pub fn new(hal: &Hal) -> Result<Self, RasterError> {
let inner = vello::Renderer::new(
&hal.device,
vello::RendererOptions {
use_cpu: false,
antialiasing_support: vello::AaSupport {
area: true,
msaa8: false,
msaa16: false,
},
num_init_threads: None,
pipeline_cache: None,
},
)
.map_err(|e| RasterError::Init(e.to_string()))?;
Ok(Self { inner })
}
pub fn render(
&mut self,
hal: &Hal,
scene: &vello::Scene,
frame: &Frame,
base_color: peniko::Color,
) -> Result<(), RasterError> {
let (width, height) = frame.size();
self.render_to_view(hal, scene, frame.view(), width, height, base_color)
}
pub fn render_to_view(
&mut self,
hal: &Hal,
scene: &vello::Scene,
view: &llimphi_hal::wgpu::TextureView,
width: u32,
height: u32,
base_color: peniko::Color,
) -> Result<(), RasterError> {
self.inner
.render_to_texture(
&hal.device,
&hal.queue,
scene,
view,
&vello::RenderParams {
base_color,
width,
height,
antialiasing_method: vello::AaConfig::Area,
},
)
.map_err(|e| RasterError::Render(e.to_string()))
}
}