mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
🎉 Replace run_script tiles-complete dispatch with wapi extern binding
This commit is contained in:
parent
88dbfe7602
commit
bc9496deaa
@ -12,5 +12,13 @@ addToLibrary({
|
||||
} else {
|
||||
return window.cancelAnimationFrame(frameId);
|
||||
}
|
||||
},
|
||||
wapi_notifyTilesRenderComplete: function wapi_notifyTilesRenderComplete() {
|
||||
// The corresponding listener lives on `document` (main thread), so in a
|
||||
// worker context we simply skip the dispatch instead of crashing.
|
||||
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
|
||||
return;
|
||||
}
|
||||
document.dispatchEvent(new CustomEvent('penpot:wasm:tiles-complete'));
|
||||
}
|
||||
});
|
||||
|
||||
@ -44,12 +44,6 @@ const VIEWPORT_INTEREST_AREA_THRESHOLD: i32 = 3;
|
||||
const MAX_BLOCKING_TIME_MS: i32 = 32;
|
||||
const NODE_BATCH_THRESHOLD: i32 = 3;
|
||||
|
||||
/// Dispatches `penpot:wasm:tiles-complete` on `document` so the UI can react when a full
|
||||
/// tile pass has finished (e.g. remove page-transition blur).
|
||||
fn notify_tiles_render_complete() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
crate::run_script!("document.dispatchEvent(new CustomEvent('penpot:wasm:tiles-complete'))");
|
||||
}
|
||||
const BLUR_DOWNSCALE_THRESHOLD: f32 = 8.0;
|
||||
|
||||
type ClipStack = Vec<(Rect, Option<Corners>, Matrix)>;
|
||||
@ -1763,7 +1757,7 @@ impl RenderState {
|
||||
self.cancel_animation_frame();
|
||||
self.render_request_id = Some(wapi::request_animation_frame!());
|
||||
} else {
|
||||
notify_tiles_render_complete();
|
||||
wapi::notify_tiles_render_complete!();
|
||||
performance::end_measure!("render");
|
||||
}
|
||||
}
|
||||
@ -1781,6 +1775,8 @@ impl RenderState {
|
||||
self.render_shape_tree_partial(base_object, tree, timestamp, false)?;
|
||||
}
|
||||
self.flush_and_submit();
|
||||
wapi::notify_tiles_render_complete!();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@ -35,5 +35,21 @@ macro_rules! cancel_animation_frame {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! notify_tiles_render_complete {
|
||||
() => {{
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
unsafe extern "C" {
|
||||
pub fn wapi_notifyTilesRenderComplete();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
unsafe {
|
||||
wapi_notifyTilesRenderComplete()
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
pub use cancel_animation_frame;
|
||||
pub use notify_tiles_render_complete;
|
||||
pub use request_animation_frame;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user