From 3af70a965db408352eafa7d7fbec2c533415bdab Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Fri, 6 Jun 2025 14:58:13 +0200 Subject: [PATCH] WIP --- frontend/src/app/render_wasm/api.cljs | 9 ++++--- render-wasm/src/main.rs | 6 ++--- render-wasm/src/render.rs | 35 +++++++++++++++++++++------ render-wasm/src/render/options.rs | 4 +-- render-wasm/src/state.rs | 3 ++- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 0bf4096577..a18cd180a6 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -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)) diff --git a/render-wasm/src/main.rs b/render-wasm/src/main.rs index 522f71966c..6891614390 100644 --- a/render-wasm/src/main.rs +++ b/render-wasm/src/main.rs @@ -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"); }); } diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index ae25a366b4..c30f2fa4d5 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -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, // 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, pub current_tile: Option, @@ -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>, scale_content: &HashMap, 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, structure: &HashMap>, scale_content: &HashMap, - 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, + modifiers: &HashMap, + structure: &HashMap>, + scale_content: &HashMap, + 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, diff --git a/render-wasm/src/render/options.rs b/render-wasm/src/render/options.rs index 74fb1cf70c..665609188e 100644 --- a/render-wasm/src/render/options.rs +++ b/render-wasm/src/render/options.rs @@ -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, } -impl RenderOptions { +impl RenderStateOptions { pub fn is_debug_visible(&self) -> bool { self.flags & options::DEBUG_VISIBLE == options::DEBUG_VISIBLE } diff --git a/render-wasm/src/state.rs b/render-wasm/src/state.rs index 72d08f0ba8..b104ab972f 100644 --- a/render-wasm/src/state.rs +++ b/render-wasm/src/state.rs @@ -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(()) }