This commit is contained in:
Aitor Moreno 2025-06-06 14:58:13 +02:00
parent 9a6989d2ca
commit 3af70a965d
5 changed files with 41 additions and 16 deletions

View File

@ -98,9 +98,12 @@
;; This should never be called from the outside.
(defn- render
[timestamp]
(h/call wasm/internal-module "_render" timestamp)
(set! wasm/internal-frame-id nil))
([timestamp]
(render timestamp false))
([timestamp full]
(h/call wasm/internal-module "_render" timestamp full)
(set! wasm/internal-frame-id nil)))
(def debounce-render (fns/debounce render 100))

View File

@ -119,10 +119,10 @@ pub extern "C" fn set_canvas_background(raw_color: u32) {
}
#[no_mangle]
pub extern "C" fn render(_: i32) {
with_state_mut!(state, {
pub extern "C" fn render(_: i32, full: bool) {
with_state!(state, {
state
.start_render_loop(performance::get_time())
.start_render_loop(performance::get_time(), full)
.expect("Error rendering");
});
}

View File

@ -17,7 +17,7 @@ use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use gpu_state::GpuState;
use options::RenderOptions;
use options::RenderStateOptions;
use surfaces::{SurfaceId, Surfaces};
use crate::performance;
@ -151,7 +151,7 @@ impl FocusMode {
pub(crate) struct RenderState {
gpu_state: GpuState,
pub options: RenderOptions,
pub options: RenderStateOptions,
pub surfaces: Surfaces,
pub fonts: FontStore,
pub viewbox: Viewbox,
@ -163,6 +163,7 @@ pub(crate) struct RenderState {
pub render_request_id: Option<i32>,
// Indicates whether the rendering process has pending frames.
pub render_in_progress: bool,
pub render_is_full: bool,
// Stack of nodes pending to be rendered.
pending_nodes: Vec<NodeRenderState>,
pub current_tile: Option<tiles::Tile>,
@ -220,18 +221,21 @@ impl RenderState {
let viewbox = Viewbox::new(width as f32, height as f32);
let tiles = tiles::TileHashMap::new();
let context = gpu_state.context.clone();
RenderState {
gpu_state: gpu_state.clone(),
options: RenderOptions::default(),
gpu_state,
options: RenderStateOptions::default(),
surfaces,
fonts,
viewbox,
cached_viewbox: Viewbox::new(0., 0.),
cached_target_snapshot: None,
images: ImageStore::new(gpu_state.context.clone()),
images: ImageStore::new(context),
background_color: skia::Color::TRANSPARENT,
render_request_id: None,
render_in_progress: false,
render_is_full: false,
pending_nodes: vec![],
current_tile: None,
sampling_options,
@ -624,6 +628,7 @@ impl RenderState {
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
timestamp: i32,
full: bool,
) -> Result<(), String> {
let scale = self.get_scale();
self.tile_viewbox.update(self.viewbox, scale);
@ -666,6 +671,7 @@ impl RenderState {
// reorder by distance to the center.
self.current_tile = None;
self.render_in_progress = true;
self.render_is_full = full;
self.apply_drawing_to_render_canvas(None);
self.process_animation_frame(tree, modifiers, structure, scale_content, timestamp)?;
performance::end_measure!("start_render_loop");
@ -678,11 +684,15 @@ impl RenderState {
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
timestamp: i32,
timestamp: i32
) -> Result<(), String> {
performance::begin_measure!("process_animation_frame");
if self.render_in_progress {
self.render_shape_tree_partial(tree, modifiers, structure, scale_content, timestamp)?;
if self.render_is_full {
self.render_shape_tree_full(tree, modifiers, structure, scale_content, timestamp)?;
} else {
self.render_shape_tree_partial(tree, modifiers, structure, scale_content, timestamp)?;
}
self.flush_and_submit();
if self.render_in_progress {
@ -868,6 +878,17 @@ impl RenderState {
)
}
pub fn render_shape_tree_full(
&mut self,
tree: &mut HashMap<Uuid, &mut Shape>,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
timestamp: i32,
) -> Result<(bool, bool), String> {
self.render_shape_tree_partial_uncached(tree, modifiers, structure, scale_content, timestamp)
}
pub fn render_shape_tree_partial_uncached(
&mut self,
tree: &ShapesPool,

View File

@ -1,12 +1,12 @@
use crate::options;
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct RenderOptions {
pub struct RenderStateOptions {
pub flags: u32,
pub dpr: Option<f32>,
}
impl RenderOptions {
impl RenderStateOptions {
pub fn is_debug_visible(&self) -> bool {
self.flags & options::DEBUG_VISIBLE == options::DEBUG_VISIBLE
}

View File

@ -55,13 +55,14 @@ impl State {
.render_from_cache(&self.shapes, &self.modifiers, &self.structure);
}
pub fn start_render_loop(&mut self, timestamp: i32) -> Result<(), String> {
pub fn start_render_loop(&mut self, timestamp: i32, full: bool) -> Result<(), String> {
self.render_state.start_render_loop(
&self.shapes,
&self.modifiers,
&self.structure,
&self.scale_content,
timestamp,
full
)?;
Ok(())
}