Truly independent web browser
LibWeb: Take the compositor animation effect state by reference
Andreas Kling72f8a3bce86e
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex 634e10b8804..6c5ef0902ce 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -2826,6 +2826,11 @@ fn main() -> Result<(), Box<dyn Error>> {layout_config.includes.push("LibWeb/Layout/TreeBuilderRustFFI.h".to_string());+ // A compositor animation effect state is opaque to C++, which holds it by pointer.+ layout_config+ .export+ .rename+ .insert("CompositorAnimationEffectState".to_string(), "void".to_string());generate_ffi_header(layout_config,&[diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 27f8231b3a3..11104e80914 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -21,6 +21,7 @@ use crate::painting::paintable_data::*;use crate::painting::paintable_rows::{PaintableRowsRead, with_inline_pieces};use crate::painting::rect_to_viewport_transform::RectToViewportTransform;use crate::painting::svg_filter::SvgFilterPrimitive;+use crate::painting::visual_animation_builder::CompositorAnimationEffectState;use crate::render_state::{DocumentHost, RenderWait};use libcompositing_rust::ffi::tree_from_handle;use libgfx_rust::filter::Filter;@@ -1245,25 +1246,20 @@ pub unsafe extern "C" fn render_state_background_color_animation_keyframe_colors}#[unsafe(no_mangle)]-pub extern "C" fn compositor_animation_effect_state_create() -> *mut c_void {- Box::into_raw(Box::new(- crate::painting::visual_animation_builder::CompositorAnimationEffectState::default(),- ))- .cast()+pub extern "C" fn compositor_animation_effect_state_create() -> *mut CompositorAnimationEffectState {+ Box::into_raw(Box::new(CompositorAnimationEffectState::default()))}/// # Safety////// `state` must be a handle from `compositor_animation_effect_state_create` that is given up here.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_state_destroy(state: *mut c_void) {+pub unsafe extern "C" fn compositor_animation_effect_state_destroy(state: *mut CompositorAnimationEffectState) {if state.is_null() {return;}// SAFETY: The caller gives up the handle it created.- drop(unsafe {- Box::from_raw(state.cast::<crate::painting::visual_animation_builder::CompositorAnimationEffectState>())- });+ drop(unsafe { Box::from_raw(state) });}/// Builds the animation of the request's target kind for the effect and keeps it pending with the@@ -1271,17 +1267,17 @@ pub unsafe extern "C" fn compositor_animation_effect_state_destroy(state: *mut c////// # Safety///-/// `state` must be a live effect state handle, `document_host` a live document host on its document's thread, and the request and host, with every range they address, live-/// for the call. The host's callbacks run synchronously and may not touch the arena.+/// `document_host` must be a live document host on its document's thread, and the request and host, with every range+/// they address, live for the call. The host's callbacks run synchronously and may not touch the arena.#[unsafe(no_mangle)]pub unsafe extern "C" fn compositor_animation_effect_build(- state: *mut c_void,+ state: &mut CompositorAnimationEffectState,document_host: &DocumentHost,request: *const crate::painting::host::FfiCompositorAnimationRequest,host: &crate::painting::host::FfiCompositorAnimationHost,) -> crate::painting::host::FfiCompositorAnimationBuildOutcome {- use crate::painting::visual_animation_builder::{Host, Request, effect_state_from_handle};- let state = unsafe { effect_state_from_handle(state) };+ use crate::painting::visual_animation_builder::{Host, Request};+ // SAFETY: Guaranteed by the caller.let request = unsafe { Request::new(&*request) };let host = Host::new(host);let layout_node = request.layout_node();@@ -1298,55 +1294,37 @@ pub unsafe extern "C" fn compositor_animation_effect_build(})}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_discard_pending(- state: *mut c_void,+pub extern "C" fn compositor_animation_effect_discard_pending(+ state: &mut CompositorAnimationEffectState,kind: crate::painting::host::FfiVisualAnimationTargetKind,) {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.discard_pending(kind);+ state.discard_pending(kind);}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_has_pending(state: *mut c_void) -> bool {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.has_pending()+pub extern "C" fn compositor_animation_effect_has_pending(state: &CompositorAnimationEffectState) -> bool {+ state.has_pending()}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_clear_pending(state: *mut c_void) {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.clear_pending();+pub extern "C" fn compositor_animation_effect_clear_pending(state: &mut CompositorAnimationEffectState) {+ state.clear_pending();}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_has_retained(state: *mut c_void) -> bool {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.has_retained()+pub extern "C" fn compositor_animation_effect_has_retained(state: &CompositorAnimationEffectState) -> bool {+ state.has_retained()}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_clear_retained(state: *mut c_void) {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.clear_retained();+pub extern "C" fn compositor_animation_effect_clear_retained(state: &mut CompositorAnimationEffectState) {+ state.clear_retained();}-/// # Safety-///-/// `state` must be a live effect state handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_reset(state: *mut c_void) {- unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }.reset();+pub extern "C" fn compositor_animation_effect_reset(state: &mut CompositorAnimationEffectState) {+ state.reset();}/// # Safetydiff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 2f8c72fa41f..f9eb32897c9 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -353,18 +353,13 @@ pub extern "C" fn render_state_begin_compositor_animation_update(host: &crate::r/// Publishes the effect's pending animations: they become the ones it retains, and copies join the compositor/// animations of the current update pass of `host`'s document.///-/// # Safety-///-/// `state` must be a live effect state handle and `host` a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn compositor_animation_effect_publish_pending(- state: *mut c_void,+pub extern "C" fn compositor_animation_effect_publish_pending(+ state: &mut crate::painting::visual_animation_builder::CompositorAnimationEffectState,host: &crate::render_state::DocumentHost,reuse_retained_timing_anchors: bool,) {- // SAFETY: Guaranteed by the caller.- let animations = unsafe { crate::painting::visual_animation_builder::effect_state_from_handle(state) }- .publish_pending(reuse_retained_timing_anchors);+ let animations = state.publish_pending(reuse_retained_timing_anchors);host.publish_compositor_animations(animations);}diff --git a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rsindex fe10c8de34a..0cf668a3849 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs@@ -9,8 +9,6 @@//! values, the animations an effect has built and published, and the document-wide list the visual//! context tree receives.-use std::ffi::c_void;-use crate::css::absolutize::number_from_value;use crate::css::color_resolution::{ColorResolutionInput, FfiColorResolutionStyle, to_color};use crate::css::css_enums::keyword;@@ -863,14 +861,6 @@ impl CompositorAnimationEffectState {}}-/// # Safety-///-/// `state` must be a live handle from `compositor_animation_effect_state_create`.-pub(crate) unsafe fn effect_state_from_handle<'a>(state: *mut c_void) -> &'a mut CompositorAnimationEffectState {- // SAFETY: The caller guarantees a live, exclusively used handle.- unsafe { &mut *state.cast::<CompositorAnimationEffectState>() }-}-#[cfg(test)]mod tests {use super::*;@@ -1009,11 +999,11 @@ mod tests {}unsafe extern "C" fn test_resolved_keyframe_value(- context: *mut c_void,+ context: *mut std::ffi::c_void,keyframe_index: usize,property_id: u16,uses_underlying_style: bool,- ) -> *const c_void {+ ) -> *const std::ffi::c_void {let host = unsafe { &*context.cast::<TestHost>() };*host.resolutions.borrow_mut() += 1;host.values