use super::*;
impl HybridRenderer {
#[must_use]
pub fn with_backend(
gpu_backend: GraphicsBackend,
width: u32,
height: u32,
config: RenderConfig,
) -> Self {
Self::with_backend_and_font(
gpu_backend,
width,
height,
config,
NativeSystemFont::deterministic(),
)
}
#[must_use]
pub fn with_backend_and_font(
gpu_backend: GraphicsBackend,
width: u32,
height: u32,
config: RenderConfig,
font_provider: NativeSystemFont,
) -> Self {
let mut compositor: RecordingGpuDriver = RecordingGpuDriver::default();
compositor.set_backend_kind(gpu_backend);
Self {
software: SoftwareRenderer::with_font_provider(width, height, config, font_provider),
compositor,
}
}
pub fn render(
&mut self,
display_list: &DisplayList,
damage: DamageRegion,
) -> Result<(usize, usize), PlatformError> {
let (tiles, pixels): (usize, usize) = self.get_mut_software().render(display_list, damage);
let w: u32 = self.get_software().get_framebuffer().get_width();
let h: u32 = self.get_software().get_framebuffer().get_height();
let full_rect: Rect = Rect::new(0.0, 0.0, w as f32, h as f32);
let composite_quad: GpuQuadInstance = GpuQuadInstance {
rect: [0.0, 0.0, w as f32, h as f32],
clip: [0.0, 0.0, w as f32, h as f32],
color: [1.0, 1.0, 1.0, 1.0],
secondary_color: [0.0; 4],
radii: [0.0; 4],
stroke_or_blur: 0.0,
angle_rad: 0.0,
kind: GpuPrimitiveKind::TexturedQuad as u32,
reserved: tiles as u32,
};
let composite_prim: GpuPrimitiveInstance =
GpuPrimitiveInstance::from_quad_instance(&composite_quad, 0, 0);
let mut batch: GpuBatch = GpuBatch::default();
batch.set_scissor(full_rect);
batch.get_mut_instances().push(composite_quad);
batch.get_mut_primitives().push(composite_prim);
let _: usize =
self.get_mut_compositor()
.submit_batches(w, h, COLOR_TRANSPARENT, &[batch])?;
Ok((tiles.max(1), pixels))
}
}