use valo_dl::Paint;
use crate::pipelines::PipelineBlend;
use crate::renderer::RenderStats;
use super::draw_context::DrawContext;
use super::draw_state::DrawState;
use super::emit::StepEmitter;
use super::source::{fill_paint, white_mask, DrawSource, GlyphRun, Shape};
use super::Caches;
pub(super) struct Drawing<'p, 'a> {
pub context: &'p mut DrawContext,
pub emit: &'p mut StepEmitter<'a>,
pub caches: &'p mut Caches,
pub stats: &'p mut RenderStats,
}
impl Drawing<'_, '_> {
pub fn draw(
&mut self,
source: DrawSource<'_>,
paint: &Paint,
at: &DrawState,
blend: PipelineBlend,
) {
match source {
DrawSource::Shape { shape, .. } => self.draw_shape(&shape, paint, at, blend),
DrawSource::Image {
image,
src,
dst,
sampling,
} => self.draw_image(image, &src, &dst, sampling, paint, at, blend),
DrawSource::RRectBlur { rect, radii, blur } => {
self.draw_rrect_blur(&rect, radii, blur, paint, at, blend)
}
DrawSource::Glyphs(run) => self.draw_glyphs(&run, paint, at, blend),
}
}
pub fn draw_alone(&mut self, source: DrawSource<'_>, paint: &Paint, at: &DrawState) {
match source {
DrawSource::Glyphs(run) if paint.shader.is_some() => {
self.draw_shaded_glyphs(&run, paint, at)
}
source => self.draw(source, paint, at, PipelineBlend::SrcOver),
}
}
fn draw_shaded_glyphs(&mut self, run: &GlyphRun<'_>, paint: &Paint, at: &DrawState) {
self.draw_glyphs(run, &white_mask(paint), at, PipelineBlend::SrcOver);
let ink = Shape::Rect(run.content_bounds);
self.draw_shape(&ink, &fill_paint(paint), at, PipelineBlend::SrcIn);
}
}