♻️ Refactor wasm shapes state management

This commit is contained in:
alonso.torres 2025-07-03 15:59:56 +02:00 committed by Aitor Moreno
parent 747427daa4
commit 69135ef8c7
10 changed files with 200 additions and 171 deletions

View file

@ -21,7 +21,8 @@ use options::RenderOptions;
use surfaces::{SurfaceId, Surfaces};
use crate::performance;
use crate::shapes::{Corners, Fill, Shape, SolidColor, StructureEntry, Type};
use crate::shapes::{Corners, Fill, Shape, StructureEntry, Type};
use crate::state::ShapesPool;
use crate::tiles::{self, PendingTiles, TileRect};
use crate::uuid::Uuid;
use crate::view::Viewbox;
@ -558,7 +559,7 @@ impl RenderState {
pub fn render_from_cache(
&mut self,
shapes: &HashMap<Uuid, &mut Shape>,
shapes: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) {
@ -599,7 +600,7 @@ impl RenderState {
pub fn start_render_loop(
&mut self,
tree: &HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
@ -654,7 +655,7 @@ impl RenderState {
pub fn process_animation_frame(
&mut self,
tree: &HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
@ -850,7 +851,7 @@ impl RenderState {
pub fn render_shape_tree_partial_uncached(
&mut self,
tree: &HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
@ -967,7 +968,7 @@ impl RenderState {
pub fn render_shape_tree_partial(
&mut self,
tree: &HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
scale_content: &HashMap<Uuid, f32>,
@ -1109,7 +1110,7 @@ impl RenderState {
pub fn rebuild_tiles_shallow(
&mut self,
tree: &mut HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) {
@ -1118,7 +1119,7 @@ impl RenderState {
self.surfaces.remove_cached_tiles();
let mut nodes = vec![Uuid::nil()];
while let Some(shape_id) = nodes.pop() {
if let Some(shape) = tree.get_mut(&shape_id) {
if let Some(shape) = tree.get(&shape_id) {
let mut shape: Cow<Shape> = Cow::Borrowed(shape);
if shape_id != Uuid::nil() {
if let Some(modifier) = modifiers.get(&shape_id) {
@ -1139,7 +1140,7 @@ impl RenderState {
pub fn rebuild_tiles(
&mut self,
tree: &mut HashMap<Uuid, &mut Shape>,
tree: &ShapesPool,
modifiers: &HashMap<Uuid, Matrix>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) {
@ -1148,7 +1149,7 @@ impl RenderState {
self.surfaces.remove_cached_tiles();
let mut nodes = vec![Uuid::nil()];
while let Some(shape_id) = nodes.pop() {
if let Some(shape) = tree.get_mut(&shape_id) {
if let Some(shape) = tree.get(&shape_id) {
let mut shape: Cow<Shape> = Cow::Borrowed(shape);
if shape_id != Uuid::nil() {
if let Some(modifier) = modifiers.get(&shape_id) {
@ -1166,13 +1167,9 @@ impl RenderState {
performance::end_measure!("rebuild_tiles");
}
pub fn rebuild_modifier_tiles(
&mut self,
tree: &mut HashMap<Uuid, &mut Shape>,
modifiers: &HashMap<Uuid, Matrix>,
) {
pub fn rebuild_modifier_tiles(&mut self, tree: &ShapesPool, modifiers: &HashMap<Uuid, Matrix>) {
for (uuid, matrix) in modifiers {
if let Some(shape) = tree.get_mut(uuid) {
if let Some(shape) = tree.get(uuid) {
let mut shape: Cow<Shape> = Cow::Borrowed(shape);
shape.to_mut().apply_transform(matrix);
self.update_tile_for(&shape);