🐛 Fix rendering order

This commit is contained in:
Aitor Moreno 2025-04-22 17:45:57 +02:00 committed by Andrey Antukh
parent 53dcd94f0d
commit 38a708e12b

View file

@ -1,7 +1,7 @@
use skia_safe::{self as skia, Matrix, RRect, Rect}; use skia_safe::{self as skia, Matrix, RRect, Rect};
use crate::uuid::Uuid; use crate::uuid::Uuid;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet, VecDeque};
use crate::performance; use crate::performance;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -90,7 +90,7 @@ pub(crate) struct RenderState {
// Indicates whether the rendering process has pending frames. // Indicates whether the rendering process has pending frames.
pub render_in_progress: bool, pub render_in_progress: bool,
// Stack of nodes pending to be rendered. // Stack of nodes pending to be rendered.
pub pending_nodes: Vec<NodeRenderState>, pub pending_nodes: VecDeque<NodeRenderState>,
pub current_tile: Option<tiles::Tile>, pub current_tile: Option<tiles::Tile>,
pub sampling_options: skia::SamplingOptions, pub sampling_options: skia::SamplingOptions,
pub render_area: Rect, pub render_area: Rect,
@ -128,7 +128,7 @@ impl RenderState {
background_color: skia::Color::TRANSPARENT, background_color: skia::Color::TRANSPARENT,
render_request_id: None, render_request_id: None,
render_in_progress: false, render_in_progress: false,
pending_nodes: vec![], pending_nodes: VecDeque::new(),
current_tile: None, current_tile: None,
sampling_options, sampling_options,
render_area: Rect::new_empty(), render_area: Rect::new_empty(),
@ -480,7 +480,7 @@ impl RenderState {
} }
performance::end_measure!("tile_cache"); performance::end_measure!("tile_cache");
self.pending_nodes = vec![]; self.pending_nodes = VecDeque::new();
// reorder by distance to the center. // reorder by distance to the center.
self.pending_tiles.sort_by(|a, b| b.2.cmp(&a.2)); self.pending_tiles.sort_by(|a, b| b.2.cmp(&a.2));
self.current_tile = None; self.current_tile = None;
@ -625,7 +625,7 @@ impl RenderState {
performance::begin_measure!("render_shape_tree::uncached"); performance::begin_measure!("render_shape_tree::uncached");
let mut i = 0; let mut i = 0;
let mut is_empty = true; let mut is_empty = true;
while let Some(node_render_state) = self.pending_nodes.pop() { while let Some(node_render_state) = self.pending_nodes.pop_front() {
let NodeRenderState { let NodeRenderState {
id: node_id, id: node_id,
visited_children, visited_children,
@ -650,7 +650,7 @@ impl RenderState {
// the blend mode 'destination-in') the content // the blend mode 'destination-in') the content
// of the group and the mask. // of the group and the mask.
if group.masked { if group.masked {
self.pending_nodes.push(NodeRenderState { self.pending_nodes.push_back(NodeRenderState {
id: node_id, id: node_id,
visited_children: true, visited_children: true,
clip_bounds: None, clip_bounds: None,
@ -658,7 +658,7 @@ impl RenderState {
mask: false, mask: false,
}); });
if let Some(&mask_id) = element.mask_id() { if let Some(&mask_id) = element.mask_id() {
self.pending_nodes.push(NodeRenderState { self.pending_nodes.push_back(NodeRenderState {
id: mask_id, id: mask_id,
visited_children: false, visited_children: false,
clip_bounds: None, clip_bounds: None,
@ -700,7 +700,7 @@ impl RenderState {
} }
// Set the node as visited_children before processing children // Set the node as visited_children before processing children
self.pending_nodes.push(NodeRenderState { self.pending_nodes.push_back(NodeRenderState {
id: node_id, id: node_id,
visited_children: true, visited_children: true,
clip_bounds: None, clip_bounds: None,
@ -725,7 +725,7 @@ impl RenderState {
} }
for child_id in children_ids.iter().rev() { for child_id in children_ids.iter().rev() {
self.pending_nodes.push(NodeRenderState { self.pending_nodes.push_back(NodeRenderState {
id: *child_id, id: *child_id,
visited_children: false, visited_children: false,
clip_bounds: children_clip_bounds, clip_bounds: children_clip_bounds,