1use std::{
6 rc::Rc,
7 sync::atomic::{AtomicU16, Ordering},
8};
9
10use cranpose_core::{NodeId, RecordId, RecordRef, SceneUpdate, StoreId};
11use cranpose_ui::{GraphicsLayer, Rect};
12use cranpose_ui_graphics::CommandRecording;
13
14use super::{
15 ChildOrder, Facts, GeoRecord, HashCache, Item, ItemKind, ItemLists, Journal, JournalEntry,
16 JournalRead, LayerProps, LayerRef, NodeRecords, Reach, RecordEvent, RecordEvents, RecordFlags,
17 RecordKind, RecordNode, ShapeChunks, ShapeRun, Slab, Span, SpanPool, TreeRecord, WarmRecord,
18 recordings::Recordings,
19};
20#[cfg(feature = "window-damage")]
21use super::{ReachState, own_marks};
22#[cfg(feature = "layer-tree")]
23use crate::graph::LayerNode;
24use crate::graph::{
25 DrawCommandId, DrawPrimitiveNode, DrawRunNode, ProjectiveTransform, TextPrimitiveNode,
26};
27
28pub struct SceneStore {
30 id: StoreId,
32 pub(super) tree: Vec<TreeRecord>,
33 pub(super) geo: Vec<GeoRecord>,
34 pub(super) warm: Vec<WarmRecord>,
35 pub(super) generations: Vec<u32>,
36 pub(super) generation_floor: u32,
39 pub(super) free_rows: Vec<u32>,
40 pub(super) items: SpanPool<Item>,
41 #[cfg(feature = "window-damage")]
42 pub(super) marks: own_marks::Marks,
43 pub(super) props: Slab<LayerProps>,
44 pub(super) graphics_layers: Slab<GraphicsLayer>,
45 pub(super) transforms: Slab<ProjectiveTransform>,
46 pub(super) draws: Slab<DrawPrimitiveNode>,
47 pub(super) texts: Slab<TextPrimitiveNode>,
48 pub(super) runs: Slab<DrawRunNode>,
49 pub(super) shape_runs: Slab<ShapeRun>,
50 pub(super) shape_chunks: ShapeChunks,
51 pub(super) hashes: HashCache,
52 pub(super) facts: Facts,
53 pub(super) node_records: NodeRecords,
54 pub(crate) lists: ItemLists,
55 root: Option<RecordId>,
56 update: SceneUpdate,
57 pub(super) journal: Journal,
58 pub(super) order: ChildOrder,
59 pub(crate) recordings: Recordings,
60}
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
64pub struct SceneVersion {
65 store: StoreId,
66 update: SceneUpdate,
67}
68
69impl SceneVersion {
70 pub fn update(self) -> SceneUpdate {
72 self.update
73 }
74}
75
76#[derive(Clone, Copy, Debug)]
78pub struct RecordSeed {
79 pub kind: RecordKind,
81 pub node: Option<NodeId>,
84 pub parent: Option<RecordId>,
86}
87
88fn next_store_id() -> StoreId {
89 static NEXT: AtomicU16 = AtomicU16::new(1);
90 loop {
91 if let Some(id) = StoreId::new(NEXT.fetch_add(1, Ordering::Relaxed)) {
92 return id;
93 }
94 }
95}
96
97impl Default for SceneStore {
98 fn default() -> Self {
99 Self::new()
100 }
101}
102
103impl SceneStore {
104 pub fn new() -> Self {
106 Self {
107 id: next_store_id(),
108 tree: Vec::new(),
109 geo: Vec::new(),
110 warm: Vec::new(),
111 generations: Vec::new(),
112 generation_floor: 0,
113 free_rows: Vec::new(),
114 items: SpanPool::default(),
115 #[cfg(feature = "window-damage")]
116 marks: own_marks::Marks::default(),
117 props: Slab::default(),
118 graphics_layers: Slab::default(),
119 transforms: Slab::default(),
120 draws: Slab::default(),
121 texts: Slab::default(),
122 runs: Slab::default(),
123 shape_runs: Slab::default(),
124 shape_chunks: ShapeChunks::default(),
125 hashes: HashCache::default(),
126 facts: Facts::default(),
127 node_records: NodeRecords::default(),
128 lists: ItemLists::default(),
129 root: None,
130 update: SceneUpdate::default(),
131 journal: Journal::default(),
132 order: ChildOrder::default(),
133 recordings: Recordings::default(),
134 }
135 }
136
137 #[inline]
139 pub fn id(&self) -> StoreId {
140 self.id
141 }
142
143 pub fn version(&self) -> SceneVersion {
145 SceneVersion {
146 store: self.id,
147 update: self.update,
148 }
149 }
150
151 pub fn root(&self) -> Option<RecordId> {
153 self.root
154 }
155
156 pub fn update(&self) -> SceneUpdate {
158 self.update
159 }
160
161 pub fn begin_update(&mut self) -> SceneUpdate {
163 self.recordings.begin_update();
164 self.update = self.update.next();
165 self.journal.begin(self.update, self.tree.len());
166 self.update
167 }
168
169 #[inline]
171 pub fn changed_within(&self, id: RecordId, updates: u32) -> bool {
172 let row = &self.tree[id.index()];
173 self.update.since(row.content_rev) < updates || self.update.since(row.place_rev) < updates
174 }
175
176 #[inline]
179 fn touch(&mut self, index: usize) {
180 let tree = &self.tree[index];
181 if self.journal.follows_stamps()
182 && tree.content_rev != self.update
183 && tree.place_rev != self.update
184 {
185 self.journal.stamp(RecordRef {
186 id: RecordId::from_index(index).expect("a row is a record"),
187 generation: self.generations[index],
188 });
189 }
190 }
191
192 pub fn follow(&mut self, events: RecordEvents) {
195 if self.journal.followed() != events {
196 self.journal.follow(events);
197 self.mark_for_redraws();
198 }
199 }
200
201 #[cfg(feature = "window-damage")]
203 #[inline]
204 pub(super) fn follows_redrawn_reach(&self) -> bool {
205 self.journal.wants_redrawn_reach(self.update)
206 }
207
208 #[cfg(feature = "window-damage")]
211 fn mark_for_redraws(&mut self) {
212 if self.follows_redrawn_reach() {
213 own_marks::refresh_lost(self);
214 }
215 }
216
217 #[cfg(not(feature = "window-damage"))]
218 #[inline]
219 fn mark_for_redraws(&mut self) {}
220
221 pub fn changes_since(&self, read: Option<SceneVersion>) -> JournalRead<'_> {
225 match read {
226 Some(read) if read.store == self.id => self.journal.since(read.update, self.update),
227 _ => JournalRead::Lost,
228 }
229 }
230
231 pub fn stamps_since(&self, read: Option<SceneVersion>) -> Option<&[RecordRef]> {
237 let read = read.filter(|read| read.store == self.id)?;
238 self.journal.stamps_since(read.update, self.update)
239 }
240
241 pub fn changed_since(&self, read: Option<SceneVersion>) -> bool {
245 match read {
246 Some(read) if read.store == self.id => self.journal.changed_since(read.update),
247 _ => true,
248 }
249 }
250
251 #[inline]
254 pub(super) fn log(&mut self, event: RecordEvent, id: RecordId) {
255 self.journal.note_change(self.update);
256 if self.journal.wants(event, self.update) {
257 self.log_entry(event, id);
258 }
259 }
260
261 fn log_entry(&mut self, event: RecordEvent, id: RecordId) {
262 let index = id.index();
263 self.journal.log(JournalEntry {
264 update: self.update,
265 event,
266 record: RecordRef {
267 id,
268 generation: self.generations[index],
269 },
270 parent: self.tree[index].parent.map(|parent| RecordRef {
271 id: parent,
272 generation: self.generations[parent.index()],
273 }),
274 node: self.warm[index].node.map(RecordNode::id),
275 });
276 }
277
278 pub fn finish_update(&mut self) {
282 super::child_order::settle(self);
283 #[cfg(feature = "window-damage")]
284 own_marks::settle(self);
285 }
286
287 pub fn trim(&mut self) -> bool {
294 super::growth_slack::trim(self)
295 }
296
297 #[expect(
301 clippy::inline_always,
302 reason = "the collect walk and the update call it for every record; out of line the gauntlet frame took 2% more instructions"
303 )]
304 #[inline(always)]
305 #[cfg(feature = "window-damage")]
306 pub(super) fn redraw_pending(&mut self, index: usize) {
307 if !self.follows_redrawn_reach() {
308 own_marks::lose(self, index);
309 return;
310 }
311 let flags = &mut self.tree[index].flags;
312 if !flags.contains(RecordFlags::REDRAW_PENDING) {
313 *flags = flags.with(RecordFlags::REDRAW_PENDING);
314 self.marks.redrawn.push(RecordRef {
315 id: RecordId::from_index(index).expect("a row is a record"),
316 generation: self.generations[index],
317 });
318 }
319 }
320
321 #[cfg(not(feature = "window-damage"))]
324 #[inline]
325 pub(super) fn redraw_pending(&mut self, index: usize) {
326 self.log(
327 RecordEvent::Redrawn(Reach::Unknown),
328 RecordId::from_index(index).expect("a row is a record"),
329 );
330 }
331
332 #[cfg(feature = "window-damage")]
333 pub(super) fn reach(&self, index: usize) -> Reach {
334 match self.tree[index].reach_state {
335 ReachState::Empty => Reach::Empty,
336 ReachState::Finite => Reach::Finite(self.geo[index].reach),
337 ReachState::Unknown => Reach::Unknown,
338 }
339 }
340
341 #[cfg(feature = "window-damage")]
342 pub(super) fn set_reach(&mut self, index: usize, reach: Reach) {
343 let (state, rect) = match reach {
344 Reach::Empty => (ReachState::Empty, Rect::default()),
345 Reach::Finite(rect) => (ReachState::Finite, rect),
346 Reach::Unknown => (ReachState::Unknown, Rect::default()),
347 };
348 self.tree[index].reach_state = state;
349 self.geo[index].reach = rect;
350 }
351
352 #[cfg(feature = "window-damage")]
356 #[inline]
357 pub(super) fn stale(&mut self, index: usize) {
358 if !self.tree[index].flags.contains(RecordFlags::REACH_STALE)
359 || super::facts::keeps_contained(self, index)
360 {
361 self.stale_climb(index);
362 }
363 }
364
365 #[cfg(not(feature = "window-damage"))]
367 #[inline]
368 pub(super) fn stale(&mut self, _index: usize) {}
369
370 #[cfg(feature = "window-damage")]
371 #[inline(never)]
372 fn stale_climb(&mut self, index: usize) {
373 super::facts::forget_contained(self, index);
374 self.reach_stale(index);
375 }
376
377 #[cfg(feature = "window-damage")]
380 fn reach_stale(&mut self, index: usize) {
381 let mut current = Some(index);
382 while let Some(index) = current {
383 let flags = &mut self.tree[index].flags;
384 if flags.contains(RecordFlags::REACH_STALE) {
385 break;
386 }
387 *flags = flags.with(RecordFlags::REACH_STALE);
388 current = self.tree[index].parent.map(RecordId::index);
389 }
390 }
391
392 #[cfg(feature = "window-damage")]
395 pub fn refresh_reach(&mut self) {
396 own_marks::refresh_lost(self);
397 if let Some(root) = self.root {
398 super::reach::refresh(self, root);
399 }
400 }
401
402 #[inline]
405 pub(super) fn stale_with_parent(&mut self, index: usize) {
406 self.stale(index);
407 if let Some(parent) = self.tree[index].parent {
408 self.stale(parent.index());
409 }
410 }
411
412 #[cfg(feature = "layer-tree")]
414 pub fn from_layer(root: &LayerNode) -> Self {
415 let mut store = Self::new();
416 store.describe(root);
417 store
418 }
419
420 #[cfg(feature = "layer-tree")]
424 pub fn describe(&mut self, root: &LayerNode) {
425 self.begin_update();
426 super::spec::write_root(self, root);
427 self.finish_update();
428 }
429
430 #[inline]
432 pub fn layer(&self, id: RecordId) -> LayerRef<'_> {
433 LayerRef::new(self, id)
434 }
435
436 pub fn root_layer(&self) -> Option<LayerRef<'_>> {
438 self.root.map(|root| self.layer(root))
439 }
440
441 pub fn heap_bytes(&self) -> usize {
443 super::heap_bytes::store_heap_bytes(self)
444 }
445
446 pub fn node_count(&self) -> usize {
449 self.record_count()
450 + self.draws.values().count()
451 + self.texts.values().count()
452 + self.runs.values().map(DrawRunNode::len).sum::<usize>()
453 + self.shape_item_count()
454 }
455
456 pub fn record_count(&self) -> usize {
458 self.tree.len() - self.free_rows.len()
459 }
460
461 pub fn clear(&mut self) {
463 self.tree.clear();
464 self.geo.clear();
465 self.warm.clear();
466 if let Some(&last) = self.generations.iter().max() {
470 self.generation_floor = self.generation_floor.max(last.wrapping_add(1));
471 }
472 self.generations.clear();
473 self.free_rows = Vec::new();
474 self.items.clear();
475 #[cfg(feature = "window-damage")]
476 self.marks.clear();
477 self.props.clear();
478 self.graphics_layers.clear();
479 self.transforms.clear();
480 self.draws.clear();
481 self.texts.clear();
482 self.runs.clear();
483 self.clear_shapes();
484 self.hashes.clear();
485 self.facts.clear();
486 self.node_records.clear();
487 self.root = None;
488 self.update = self.update.next();
491 self.journal.clear(self.update);
492 }
493
494 pub(crate) fn reserve_records(&mut self, records: usize) {
498 let more = records.saturating_sub(self.free_rows.len());
499 self.tree.reserve_exact(more);
500 self.geo.reserve_exact(more);
501 self.warm.reserve_exact(more);
502 self.generations.reserve_exact(more);
503 self.facts.reserve_rows(self.tree.len() + more);
504 self.node_records.reserve(more);
505 }
506
507 pub fn insert(&mut self, seed: RecordSeed) -> RecordId {
512 let update = self.update;
513 let tree = TreeRecord {
514 parent: seed.parent,
515 items: Span::default(),
516 kind: seed.kind,
517 #[cfg(feature = "window-damage")]
518 reach_state: ReachState::Empty,
519 flags: RecordFlags::default(),
520 content_rev: update,
521 place_rev: update,
522 subtree_rev: update,
523 transform: None,
524 };
525 let warm = WarmRecord {
526 node: seed.node.map(RecordNode::of),
527 props: None,
528 graphics_layer: None,
529 content_offset: [0.0; 2],
530 #[cfg(feature = "window-damage")]
531 own_marks: Span::default(),
532 };
533 let id = match self.free_rows.pop() {
534 Some(row) => {
535 let index = row as usize;
536 self.tree[index] = tree;
537 self.geo[index] = GeoRecord::default();
538 self.warm[index] = warm;
539 RecordId::from_index(index).expect("a freed row was a record")
540 }
541 None => {
542 self.tree.push(tree);
543 self.geo.push(GeoRecord::default());
544 self.warm.push(warm);
545 self.generations.push(self.generation_floor);
546 RecordId::from_index(self.tree.len() - 1).expect("fewer than 2^32 records")
547 }
548 };
549 self.facts.open_row(id.index());
550 self.node_records.claim(id, seed.kind, seed.node);
551 match seed.parent {
552 Some(parent) => self.note_subtree_change(Some(parent)),
553 None => self.root = Some(id),
554 }
555 self.stale_with_parent(id.index());
556 #[cfg(feature = "window-damage")]
557 own_marks::pend_inserted(self, id.index());
558 self.log(RecordEvent::Inserted, id);
559 if self.journal.follows_stamps() {
560 self.journal.stamp(self.record_ref(id));
561 }
562 id
563 }
564
565 #[inline(never)]
569 pub fn remove_subtree(&mut self, id: RecordId) {
570 self.log(RecordEvent::Removed, id);
571 let index = id.index();
572 self.node_records
573 .release(id, self.tree[index].kind, self.node(id));
574 if let Some(parent) = self.tree[index].parent {
575 self.stale(parent.index());
576 }
577 let span = self.tree[index].items;
578 for position in 0..span.len() {
579 let item = self.items.span(span)[position];
580 self.remove_item(item);
581 }
582 self.items.free_span(span);
584 self.tree[index].items = Span::default();
585 #[cfg(feature = "window-damage")]
586 self.marks
587 .pool
588 .free_span(std::mem::take(&mut self.warm[index].own_marks));
589 self.hashes.remove(index);
590 self.drop_props(index);
591 if let Some(transform) = self.tree[index].transform.take() {
592 self.transforms.remove(transform.index());
593 }
594 self.generations[index] = self.generations[index].wrapping_add(1);
595 self.free_rows
596 .push(u32::try_from(index).expect("fewer than 2^32 records"));
597 if self.root == Some(id) {
598 self.root = None;
599 }
600 }
601
602 pub fn remove_item(&mut self, item: Item) {
604 match item.kind() {
605 ItemKind::Child => {
606 if let Some(child) = item.as_child() {
607 self.remove_subtree(child);
608 }
609 }
610 ItemKind::Draw => {
611 self.draws.remove(item.index());
612 }
613 ItemKind::Text => {
614 self.texts.remove(item.index());
615 }
616 ItemKind::Run => {
617 if let Some(run) = self.runs.take(item.index()) {
618 self.keep_released(run.command, &run.recording);
619 }
620 }
621 ItemKind::Shape => self.remove_shapes(item.index()),
622 }
623 }
624
625 #[inline]
628 pub fn record_ref(&self, id: RecordId) -> RecordRef {
629 RecordRef {
630 id,
631 generation: self.generations[id.index()],
632 }
633 }
634
635 #[inline]
637 pub fn resolve(&self, held: RecordRef) -> Option<RecordId> {
638 (self.generations.get(held.id.index()) == Some(&held.generation)).then_some(held.id)
639 }
640
641 #[inline]
643 pub fn items(&self, id: RecordId) -> &[Item] {
644 self.items.span(self.tree[id.index()].items)
645 }
646
647 pub(crate) fn write_items(&mut self, id: RecordId, items: &[Item]) {
650 self.replace_items(id, items);
651 self.stale(id.index());
652 }
653
654 pub(super) fn replace_items(&mut self, id: RecordId, items: &[Item]) -> bool {
658 let index = id.index();
659 let old = self.items.span(self.tree[index].items);
660 if old == items {
663 return false;
664 }
665 if !super::facts::same_children(old, items) {
666 super::facts::forget_children(self, index);
667 }
668 super::facts::forget_own(self, index);
669 let noted = self.journal.follows(RecordEvent::Changed);
670 if noted {
671 let record = self.record_ref(id);
672 self.order.note(record, old);
673 }
674 self.tree[index].items = self.items.write(self.tree[index].items, items);
675 self.touch(index);
676 if !noted {
680 self.journal.note_change(self.update);
681 }
682 true
683 }
684
685 pub fn add_draw(&mut self, draw: DrawPrimitiveNode) -> Item {
687 Item::new(ItemKind::Draw, self.draws.insert(draw))
688 }
689
690 pub fn add_text(&mut self, text: TextPrimitiveNode) -> Item {
692 Item::new(ItemKind::Text, self.texts.insert(text))
693 }
694
695 pub fn add_run(&mut self, run: DrawRunNode) -> Item {
697 Item::new(ItemKind::Run, self.runs.insert(run))
698 }
699
700 #[inline]
702 pub fn draw(&self, item: Item) -> &DrawPrimitiveNode {
703 &self.draws[item.index()]
704 }
705
706 #[inline]
708 pub fn text(&self, item: Item) -> &TextPrimitiveNode {
709 &self.texts[item.index()]
710 }
711
712 pub(crate) fn text_mut(&mut self, item: Item) -> &mut TextPrimitiveNode {
715 &mut self.texts[item.index()]
716 }
717
718 #[inline]
720 pub fn run(&self, item: Item) -> &DrawRunNode {
721 &self.runs[item.index()]
722 }
723
724 #[inline]
726 pub(crate) fn run_mut(&mut self, item: Item) -> &mut DrawRunNode {
727 &mut self.runs[item.index()]
728 }
729
730 pub(crate) fn swap_run_recording(&mut self, item: Item, recording: Rc<CommandRecording>) {
732 let run = &mut self.runs[item.index()];
733 if Rc::ptr_eq(&run.recording, &recording) {
735 return;
736 }
737 let command = run.command;
738 let old = std::mem::replace(&mut run.recording, recording);
739 self.keep_released(command, &old);
740 }
741
742 fn keep_released(&mut self, command: Option<DrawCommandId>, recording: &Rc<CommandRecording>) {
745 if let Some(id) = command {
746 self.recordings.keep(id, recording);
747 }
748 }
749
750 #[inline]
752 pub fn kind(&self, id: RecordId) -> RecordKind {
753 self.tree[id.index()].kind
754 }
755
756 #[inline]
758 pub fn node(&self, id: RecordId) -> Option<NodeId> {
759 self.warm[id.index()].node.map(RecordNode::id)
760 }
761
762 #[inline]
764 pub fn parent(&self, id: RecordId) -> Option<RecordId> {
765 self.tree[id.index()].parent
766 }
767
768 pub(crate) fn record_of(&self, node: NodeId) -> Option<RecordId> {
770 self.node_records.get(node)
771 }
772
773 pub(crate) fn drawn_parent(&self, node: NodeId) -> Option<NodeId> {
777 let mut record = self.record_of(node)?;
778 loop {
779 record = self.parent(record)?;
780 if let Some(parent) = self.node(record)
781 && parent != node
782 {
783 return Some(parent);
784 }
785 }
786 }
787
788 #[inline]
790 pub fn flags(&self, id: RecordId) -> RecordFlags {
791 self.tree[id.index()].flags
792 }
793
794 pub(crate) fn write_flags(&mut self, id: RecordId, flags: RecordFlags) -> bool {
797 let changed = self.write_flag_row(id.index(), flags);
798 if changed {
799 self.stale_with_parent(id.index());
800 }
801 changed
802 }
803
804 #[inline]
806 pub fn node_rect(&self, id: RecordId) -> Rect {
807 self.geo[id.index()].node_rect()
808 }
809
810 #[inline]
813 pub(crate) fn write_size(&mut self, id: RecordId, width: f32, height: f32) -> bool {
814 let index = id.index();
815 let size = [width, height];
816 if super::records::same_pair(self.geo[index].size, size) {
817 return false;
818 }
819 self.geo[index].size = size;
820 self.stale_with_parent(index);
821 true
822 }
823
824 #[inline]
828 pub fn set_kind(&mut self, id: RecordId, kind: RecordKind, node: Option<NodeId>) -> bool {
829 let index = id.index();
830 let changed =
831 self.tree[index].kind != kind || self.warm[index].node != node.map(RecordNode::of);
832 if changed {
833 self.change_kind(id, kind, node);
834 }
835 changed
836 }
837
838 #[inline(never)]
839 fn change_kind(&mut self, id: RecordId, kind: RecordKind, node: Option<NodeId>) {
840 let index = id.index();
841 self.log(RecordEvent::Released, id);
842 self.node_records
843 .release(id, self.tree[index].kind, self.node(id));
844 self.node_records.claim(id, kind, node);
845 self.tree[index].kind = kind;
846 self.warm[index].node = node.map(RecordNode::of);
847 self.stale_with_parent(index);
848 self.log(RecordEvent::Claimed, id);
849 self.touch(index);
850 }
851
852 pub(crate) fn drop_items(&mut self, id: RecordId) {
855 let index = id.index();
856 let span = self.tree[index].items;
857 if !super::facts::same_children(self.items.span(span), &[]) {
858 super::facts::forget_children(self, index);
859 }
860 for position in 0..span.len() {
861 let item = self.items.span(span)[position];
862 self.remove_item(item);
863 }
864 self.items.free_span(span);
865 self.tree[index].items = Span::default();
866 super::facts::forget_own(self, index);
867 self.stale(index);
868 if span.len() != 0 {
869 self.touch(index);
870 }
871 }
872
873 pub fn note_content_change(&mut self, id: RecordId) {
877 let update = self.update;
878 let index = id.index();
879 self.redraw_pending(index);
880 self.stale(index);
881 super::facts::forget_own(self, index);
882 self.touch(index);
883 let tree = &mut self.tree[index];
884 tree.content_rev = update;
885 let raise = tree.subtree_rev != update;
886 self.note_content_run(index);
887 if raise {
888 self.raise_subtree_revs(id);
889 }
890 }
891
892 pub fn note_property_change(&mut self, id: RecordId) {
896 let update = self.update;
897 let index = id.index();
898 if self.tree[index].content_rev != update {
899 self.log(RecordEvent::Changed, id);
900 }
901 self.touch(index);
902 let tree = &mut self.tree[index];
903 tree.content_rev = update;
904 tree.subtree_rev = update;
905 let parent = tree.parent;
906 self.note_subtree_change(parent);
907 }
908
909 #[inline]
912 pub(super) fn moved(&mut self, index: usize) {
913 if self.tree[index].place_rev != self.update {
914 self.touch(index);
915 self.tree[index].place_rev = self.update;
916 self.log(
917 RecordEvent::Moved,
918 RecordId::from_index(index).expect("a row is a record"),
919 );
920 self.note_subtree_change(self.tree[index].parent);
921 }
922 }
923
924 #[inline]
928 pub(super) fn note_subtree_change(&mut self, from: Option<RecordId>) {
929 if let Some(record) = from
930 && self.tree[record.index()].subtree_rev != self.update
931 {
932 self.raise_subtree_revs(record);
933 }
934 }
935
936 #[inline(never)]
937 fn raise_subtree_revs(&mut self, from: RecordId) {
938 let update = self.update;
939 let mut current = Some(from);
940 while let Some(record) = current {
941 let index = record.index();
942 let tree = &mut self.tree[index];
943 if tree.subtree_rev == update {
944 break;
945 }
946 tree.subtree_rev = update;
947 current = tree.parent;
948 self.note_content_run(index);
949 }
950 }
951
952 #[cfg(feature = "window-damage")]
955 #[inline]
956 fn note_content_run(&mut self, index: usize) {
957 if self.tree[index].flags.contains(RecordFlags::HAS_PROPS)
958 && let Some(props) = self.warm[index].props
959 {
960 self.props[props.index()].content_run.note(self.update);
961 }
962 }
963
964 #[cfg(not(feature = "window-damage"))]
966 #[inline]
967 fn note_content_run(&mut self, _index: usize) {}
968
969 pub fn content_rev(&self, id: RecordId) -> SceneUpdate {
971 self.tree[id.index()].content_rev
972 }
973}