use raw_window_handle::{DisplayHandle, WindowHandle};
#[cfg(feature = "perf_profile")]
use crate::app::profile_types::RenderProfile;
use crate::layout::render_list::RenderList;
#[cfg(feature = "screenshot")]
pub struct CapturedFrame {
pub width: u32,
pub height: u32,
pub rgba: Vec<u8>,
}
#[cfg(feature = "screenshot")]
#[derive(Clone)]
pub enum RenderCaptureTarget {
Path(std::path::PathBuf),
Bytes(std::sync::Arc<dyn Fn(Result<CapturedFrame, String>) + Send + Sync>),
}
#[cfg(feature = "screenshot")]
impl RenderCaptureTarget {
pub fn describe(&self) -> String {
match self {
Self::Path(path) => path.display().to_string(),
Self::Bytes(_) => "<in-memory capture>".to_owned(),
}
}
pub fn fail(&self, reason: impl Into<String>) {
let reason = reason.into();
match self {
Self::Path(path) => {
tracing::warn!("dropped frame capture to {}: {reason}", path.display());
}
Self::Bytes(callback) => callback(Err(reason)),
}
}
}
#[cfg(feature = "screenshot")]
#[derive(Clone)]
pub struct RenderFrameCapture {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
pub target: RenderCaptureTarget,
pub window_clip: Option<RenderFrameCaptureWindowClip>,
}
#[cfg(feature = "screenshot")]
#[derive(Clone, Copy)]
pub struct RenderFrameCaptureWindowClip {
pub width: f32,
pub height: f32,
pub radii: [f32; 4],
}
pub trait RenderEngine {
fn profile_backend(&self) -> &'static str {
"custom"
}
#[cfg(feature = "perf_profile")]
fn set_profile_context(&mut self, _context: crate::app::profiler::ProfileContext) {}
fn resize(&mut self, width: u32, height: u32);
fn set_scale_factor(&mut self, _scale_factor: f32) {}
fn draws_tooling(&mut self) {}
#[cfg(feature = "canvas")]
fn prepare_canvases(&mut self, canvases: &[crate::canvas::CanvasHandle]) {
for canvas in canvases {
canvas.unsupported();
}
}
fn render(&mut self, list: &RenderList, window: WindowHandle<'_>, display: DisplayHandle<'_>) -> bool;
#[cfg(feature = "screenshot")]
fn supports_frame_capture(&self) -> bool {
false
}
#[cfg(feature = "screenshot")]
fn render_with_capture(
&mut self,
list: &RenderList,
window: WindowHandle<'_>,
display: DisplayHandle<'_>,
_capture: Option<RenderFrameCapture>,
) -> bool {
self.render(list, window, display)
}
fn release_window_surface(&mut self) {}
fn lost(&self) -> bool {
false
}
fn wants_redraw(&self) -> bool {
false
}
#[cfg(feature = "perf_profile")]
fn last_profile(&self) -> Option<RenderProfile> {
None
}
#[cfg(feature = "perf_profile")]
fn layer_profile(&self) -> Option<crate::app::profile_types::LayerProfile> {
None
}
}
pub type RenderEngineFactory = std::sync::Arc<dyn Fn() -> Box<dyn RenderEngine>>;