Truly independent web browser
LibCompositing: Derive IPC codecs
Aliaksandr Kalenikc72d26bf49c4
diff --git a/Libraries/LibCompositing/Rust/src/animation_timing/effect_timing.rs b/Libraries/LibCompositing/Rust/src/animation_timing/effect_timing.rsindex e40c279bcdb..a4c2bdfc80e 100644--- a/Libraries/LibCompositing/Rust/src/animation_timing/effect_timing.rs+++ b/Libraries/LibCompositing/Rust/src/animation_timing/effect_timing.rs@@ -7,11 +7,12 @@//! The timing properties of an animation effect, as specified and as normalized.use super::time_value::{TimeValue, TimeValueType};+use libipc_rust::wire::{Decode, Encode};/// https://www.w3.org/TR/web-animations-1/#enumdef-fillmode/// In IDL order.#[repr(u8)]-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]pub enum FillMode {None,Forwards,@@ -24,7 +25,7 @@ pub enum FillMode {/// https://www.w3.org/TR/web-animations-1/#enumdef-playbackdirection/// In IDL order.#[repr(u8)]-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]pub enum PlaybackDirection {#[default]Normal,@@ -161,7 +162,7 @@ impl Default for SpecifiedEffectTiming {/// The timing properties of an animation effect the timing calculations use: the specified/// timing normalized against the effect's timeline, every time in the timeline's unit.#[repr(C)]-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]pub struct AnimationEffectTiming {/// https://www.w3.org/TR/web-animations-1/#start-delaypub start_delay: TimeValue,diff --git a/Libraries/LibCompositing/Rust/src/animation_timing/time_value.rs b/Libraries/LibCompositing/Rust/src/animation_timing/time_value.rsindex 84fe73ec613..e2fc575616e 100644--- a/Libraries/LibCompositing/Rust/src/animation_timing/time_value.rs+++ b/Libraries/LibCompositing/Rust/src/animation_timing/time_value.rs@@ -7,12 +7,13 @@//! Time values of the Web Animations timing model: a time in milliseconds, or a percentage of a//! progress-based timeline.+use libipc_rust::wire::{Decode, Encode};use std::cmp::Ordering;use std::ops::{Add, Div, Mul, Neg, Sub};/// The unit of a time value.#[repr(u8)]-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]pub enum TimeValueType {#[default]Milliseconds,@@ -24,7 +25,7 @@ pub enum TimeValueType {////// cbindgen:field-names=[type, value]#[repr(C)]-#[derive(Clone, Copy, Debug, Default, PartialEq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Encode, Decode)]pub struct TimeValue {pub r#type: TimeValueType,pub value: f64,diff --git a/Libraries/LibCompositing/Rust/src/css_pixels.rs b/Libraries/LibCompositing/Rust/src/css_pixels.rsindex f9db7feb5e5..849e97855cc 100644--- a/Libraries/LibCompositing/Rust/src/css_pixels.rs+++ b/Libraries/LibCompositing/Rust/src/css_pixels.rs@@ -5,6 +5,7 @@*/use ak::math;+use libipc_rust::wire::{Decode, Encode};// CSSPixels fixed-point arithmetic, bit-exact with the C++ implementation in// PixelUnits.h: an i32 with 6 fractional bits. The parity test on the C++@@ -27,7 +28,7 @@ pub const RADIX_MASK: i32 = FIXED_POINT_DENOMINATOR - 1;pub const MAX_INTEGER_VALUE: i32 = i32::MAX >> FRACTIONAL_BITS;pub const MIN_INTEGER_VALUE: i32 = i32::MIN >> FRACTIONAL_BITS;-#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]+#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug, Encode, Decode)]#[repr(transparent)]pub struct CssPixels(i32);@@ -352,7 +353,7 @@ impl std::ops::Div<usize> for CssPixels {}}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]pub struct CssPixelPoint {pub x: CssPixels,pub y: CssPixels,@@ -653,7 +654,7 @@ pub extern "C" fn rust_css_pixels_scaled(raw: i32, factor: f64) -> i32 {}// The plain-value mirrors of CSSPixelPoint, CSSPixelSize and CSSPixelRect that cross the FFI boundary.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(C)]pub struct FfiCssPixelPoint {pub x: CssPixels,@@ -676,7 +677,7 @@ pub struct FfiCssPixelSize {pub height: CssPixels,}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]#[repr(C)]pub struct FfiCssPixelRect {pub x: CssPixels,diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rsindex 09ba8131958..6650f13c4a4 100644--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs@@ -10,6 +10,7 @@ use crate::display_list_record_fields;use crate::ffi_bytes_fields;use crate::ffi_enum_bytes;use libgfx_rust::*;+use libipc_rust::wire::{Decode, Encode};// The layout of records and runs on the tape, which only Rust reads.pub use super::tape::*;@@ -172,7 +173,7 @@ impl DisplayListCommandType {}}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]#[repr(transparent)]pub struct SpatialNodeIndex(pub u32);@@ -186,7 +187,7 @@ impl FfiBytes for SpatialNodeIndex {// Indices into the clip and effect trees. `u32::MAX` is the absent node.macro_rules! optional_node_index {($name:ident) => {- #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]+ #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]#[repr(transparent)]pub struct $name(pub u32);@@ -225,7 +226,7 @@ pub struct ContextRef {}ffi_bytes_fields!(ContextRef { spatial, clip, effect });-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum ClipMode {#[default]@@ -337,7 +338,7 @@ impl FfiBytes for CanvasId {}}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]#[repr(transparent)]pub struct CompositorContextId(pub u64);@@ -348,7 +349,7 @@ impl FfiBytes for CompositorContextId {}}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode)]#[repr(transparent)]pub struct UniqueNodeId(pub i64);diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rsindex 5a0ce57e1ec..552b3de4155 100644--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs@@ -17,6 +17,7 @@ use super::effect_clip_plan::EffectClipPlan;use super::summary::{DisplayListSummary, summarize};use super::validate::validate_tape;use crate::visual_context::VisualContextTree;+use libipc_rust::wire::{Decode, Encode};use std::sync::{Arc, OnceLock};// Tape bytes in memory aligned for every command struct, which a Vec<u8> does not promise.@@ -178,7 +179,7 @@ pub(super) fn write_run(run: &DisplayListCommandRun, out: &mut [u8]) {}/// The size of one chunk packed for transport: its records, and then its runs.-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]pub struct PackedChunkSize {pub record_bytes: u64,pub run_count: u64,diff --git a/Libraries/LibCompositing/Rust/src/easing.rs b/Libraries/LibCompositing/Rust/src/easing.rsindex d4bcf20dc61..8eee50c06d3 100644--- a/Libraries/LibCompositing/Rust/src/easing.rs+++ b/Libraries/LibCompositing/Rust/src/easing.rs@@ -7,13 +7,15 @@//! Easing functions: the flat descriptor a host hands across FFI, an owned form that outlives the//! host's storage, and the evaluation both share.+use libipc_rust::wire::{Decode, Encode};+pub const STEP_POSITION_JUMP_START: u8 = 0;pub const STEP_POSITION_JUMP_NONE: u8 = 2;pub const STEP_POSITION_JUMP_BOTH: u8 = 3;pub const STEP_POSITION_START: u8 = 4;const MAXIMUM_STEP_POSITION: u8 = 5;-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum FfiEasingKind {Linear,@@ -21,18 +23,7 @@ pub enum FfiEasingKind {Steps,}-impl FfiEasingKind {- pub fn from_u8(value: u8) -> Option<Self> {- match value {- 0 => Some(Self::Linear),- 1 => Some(Self::CubicBezier),- 2 => Some(Self::Steps),- _ => None,- }- }-}--#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]#[repr(C)]pub struct FfiLinearEasingPoint {pub input: f64,@@ -55,7 +46,7 @@ pub struct FfiEasingDescriptor {/// An easing function that owns its control points, for values that outlive the descriptor they/// were handed in.-#[derive(Clone, Debug, PartialEq)]+#[derive(Clone, Debug, PartialEq, Encode, Decode)]pub enum Easing {Linear(Vec<FfiLinearEasingPoint>),CubicBezier { x1: f64, y1: f64, x2: f64, y2: f64 },diff --git a/Libraries/LibCompositing/Rust/src/filter_bytes.rs b/Libraries/LibCompositing/Rust/src/filter_bytes.rsindex b38253866b3..6658681fdd8 100644--- a/Libraries/LibCompositing/Rust/src/filter_bytes.rs+++ b/Libraries/LibCompositing/Rust/src/filter_bytes.rs@@ -9,8 +9,9 @@use libgfx_rust::FloatRect;use libgfx_rust::filter::Filter;+use libipc_rust::wire::{Decode, Encode};-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum FfiFilterFunctionKind {Blur,@@ -21,7 +22,7 @@ pub enum FfiFilterFunctionKind {/// One function of a CSS filter list with its lengths already in device pixels, for a host that/// builds filter graphs outside the style system: compositor animation samples and canvas filters.-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]#[repr(C)]pub struct FfiFilterFunction {pub kind: FfiFilterFunctionKind,diff --git a/Libraries/LibCompositing/Rust/src/ipc_types.rs b/Libraries/LibCompositing/Rust/src/ipc_types.rsindex 4b3de32a97e..1e3de4a5252 100644--- a/Libraries/LibCompositing/Rust/src/ipc_types.rs+++ b/Libraries/LibCompositing/Rust/src/ipc_types.rs@@ -10,7 +10,7 @@#![allow(non_camel_case_types)]-use crate::css_pixels::{CssPixelPoint, CssPixels};+use crate::css_pixels::CssPixelPoint;use crate::display_list::chunks::ChunkId;use crate::display_list::commands::{CompositorContextId, UniqueNodeId};use crate::display_list::storage::PackedChunkSize;@@ -31,76 +31,12 @@ pub type Compositing_VisualContextTree = Arc<VisualContextTree>;pub type Compositing_ScrollStateSnapshot = crate::scrolling::ScrollStateSnapshot;pub type Compositing_DisplayList = SharedDisplayList;-impl Encode for CompositorContextId {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.0)- }-}--impl Decode for CompositorContextId {- const MIN_ENCODED_SIZE: usize = size_of::<u64>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self(decoder.decode()?))- }-}--impl Encode for UniqueNodeId {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.0)- }-}--impl Decode for UniqueNodeId {- const MIN_ENCODED_SIZE: usize = size_of::<i64>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self(decoder.decode()?))- }-}--impl Encode for CssPixelPoint {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.x.raw_value())?;- encoder.encode(&self.y.raw_value())- }-}--impl Decode for CssPixelPoint {- const MIN_ENCODED_SIZE: usize = 2 * size_of::<i32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- x: CssPixels::from_raw(decoder.decode()?),- y: CssPixels::from_raw(decoder.decode()?),- })- }-}--#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]pub struct Web_DevicePixelPoint {pub x: i32,pub y: i32,}-impl Encode for Web_DevicePixelPoint {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.x)?;- encoder.encode(&self.y)- }-}--impl Decode for Web_DevicePixelPoint {- const MIN_ENCODED_SIZE: usize = 2 * size_of::<i32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- x: decoder.decode()?,- y: decoder.decode()?,- })- }-}-#[allow(non_upper_case_globals)]impl Web_UIEvents_KeyModifier {pub const Mod_PlatformCtrl: Self = if cfg!(target_os = "macos") {@@ -160,7 +96,7 @@ impl Decode for Core_AnonymousBuffer {/// `Compositing::DisplayList`: a display list on its way to the compositor. It names its chunks in paint order, and/// carries the records and runs of those the compositor does not keep packed in shared memory, which the compositor/// copies out of it, with what travels beside them.-#[derive(Debug)]+#[derive(Debug, Encode, Decode)]pub struct SharedDisplayList {pub chunks_in_paint_order: Vec<ChunkId>,pub packed_chunks: Core_AnonymousBuffer,@@ -170,28 +106,6 @@ pub struct SharedDisplayList {pub async_scrolling_metadata: Option<Compositing_AsyncScrollingMetadata>,}-impl Encode for SharedDisplayList {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.chunks_in_paint_order)?;- encoder.encode(&self.packed_chunks)?;- encoder.encode(&self.packed_chunk_sizes)?;- encoder.encode(&self.properties)?;- encoder.encode(&self.async_scrolling_metadata)- }-}--impl Decode for SharedDisplayList {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- chunks_in_paint_order: decoder.decode()?,- packed_chunks: decoder.decode()?,- packed_chunk_sizes: decoder.decode()?,- properties: decoder.decode()?,- async_scrolling_metadata: decoder.decode()?,- })- }-}-impl Encode for ChunkId {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.0[0])?;@@ -207,24 +121,6 @@ impl Decode for ChunkId {}}-impl Encode for PackedChunkSize {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.record_bytes)?;- encoder.encode(&self.run_count)- }-}--impl Decode for PackedChunkSize {- const MIN_ENCODED_SIZE: usize = 2 * size_of::<u64>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- record_bytes: decoder.decode()?,- run_count: decoder.decode()?,- })- }-}-include!(concat!(env!("OUT_DIR"), "/AsyncScrollNodeStableID.rs"));include!(concat!(env!("OUT_DIR"), "/DisplayListProperties.rs"));include!(concat!(env!("OUT_DIR"), "/InputEvent.rs"));diff --git a/Libraries/LibCompositing/Rust/src/node_slot_id.rs b/Libraries/LibCompositing/Rust/src/node_slot_id.rsindex 15db57108ab..1bded9a061c 100644--- a/Libraries/LibCompositing/Rust/src/node_slot_id.rs+++ b/Libraries/LibCompositing/Rust/src/node_slot_id.rs@@ -7,6 +7,8 @@//! The identity of a layout node's slot in the arena: a 24-bit index and a generation, which the//! visual context tree carries to name the box a node was built for.+use libipc_rust::wire::{Decode, Encode};+pub const INVALID_NODE_SLOT_INDEX: u32 = u32::MAX;const NODE_SLOT_INDEX_BITS: u32 = 24;@@ -14,7 +16,7 @@ const NODE_SLOT_INDEX_MASK: u32 = (1 << NODE_SLOT_INDEX_BITS) - 1;/// cbindgen:ignorepub const MAX_NODE_SLOT_COUNT: u32 = NODE_SLOT_INDEX_MASK;-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Encode, Decode)]#[repr(C)]pub struct NodeSlotId {pub index: u32,diff --git a/Libraries/LibCompositing/Rust/src/visual_animation.rs b/Libraries/LibCompositing/Rust/src/visual_animation.rsindex 5c5d142be1b..3bdd6e1a21d 100644--- a/Libraries/LibCompositing/Rust/src/visual_animation.rs+++ b/Libraries/LibCompositing/Rust/src/visual_animation.rs@@ -20,58 +20,10 @@ use crate::host::{FfiVisualAnimationTargetKind, FfiVisualAnimationTransformOperause ak::math;use libgfx_rust::filter::Filter;use libgfx_rust::{Color, ColorFilterType, FloatMatrix4x4, rotation_matrix, scale_matrix, translation_matrix};+use libipc_rust::wire::{Decode, Encode};pub const MAXIMUM_TRANSFORM_OPERATION_VALUE_COUNT: usize = 3;-impl FfiVisualAnimationTargetKind {- pub fn from_u8(value: u8) -> Option<Self> {- match value {- 0 => Some(Self::Opacity),- 1 => Some(Self::BackgroundColor),- 2 => Some(Self::Filter),- 3 => Some(Self::Transform),- _ => None,- }- }-}--impl FfiVisualAnimationTransformOperationKind {- pub fn from_u8(value: u8) -> Option<Self> {- Some(match value {- 0 => Self::Translate,- 1 => Self::Translate3d,- 2 => Self::TranslateX,- 3 => Self::TranslateY,- 4 => Self::TranslateZ,- 5 => Self::Scale,- 6 => Self::Scale3d,- 7 => Self::ScaleX,- 8 => Self::ScaleY,- 9 => Self::ScaleZ,- 10 => Self::Rotate,- 11 => Self::RotateX,- 12 => Self::RotateY,- 13 => Self::RotateZ,- 14 => Self::Skew,- 15 => Self::SkewX,- 16 => Self::SkewY,- _ => return None,- })- }-}--impl FfiFilterFunctionKind {- pub fn from_u8(value: u8) -> Option<Self> {- match value {- 0 => Some(Self::Blur),- 1 => Some(Self::DropShadow),- 2 => Some(Self::Color),- 3 => Some(Self::HueRotate),- _ => None,- }- }-}-/// One operation of a transform list, holding as many values as any operation takes.#[derive(Clone, Copy, Debug, PartialEq)]pub struct VisualAnimationTransformOperation {@@ -265,7 +217,7 @@ pub fn filter_function_is_valid(function: &FfiFilterFunction) -> bool {!color_operation_amount_is_a_fraction(function.color_operation) || function.amount <= 1.0}-#[derive(Clone, Debug, PartialEq)]+#[derive(Clone, Debug, PartialEq, Encode, Decode)]pub enum VisualAnimationValue {Opacity(f32),BackgroundColor(Color),@@ -326,7 +278,7 @@ impl VisualAnimationValue {}}-#[derive(Clone, Debug, PartialEq)]+#[derive(Clone, Debug, PartialEq, Encode, Decode)]pub struct VisualAnimationKeyframe {pub offset: f64,pub easing: Easing,@@ -345,7 +297,7 @@ pub enum VisualAnimationSample {/// A compositor animation: the timing of the effect at the moment the main thread anchored it to/// the shared monotonic clock, and the keyframes it interpolates between.-#[derive(Clone, Debug, PartialEq)]+#[derive(Clone, Debug, PartialEq, Encode, Decode)]pub struct VisualAnimation {pub target_kind: FfiVisualAnimationTargetKind,/// The effect nodes of an opacity, background color or filter animation, or the spatial nodesdiff --git a/Libraries/LibCompositing/Rust/src/visual_context/ffi_types.rs b/Libraries/LibCompositing/Rust/src/visual_context/ffi_types.rsindex fd5c6e5a378..9a550d6b8ec 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/ffi_types.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/ffi_types.rs@@ -8,6 +8,7 @@//! compositor process boundary.use libgfx_rust::{FloatMatrix4x4, FloatPoint};+use libipc_rust::wire::{Decode, Encode};#[derive(Clone, Copy, Debug)]#[repr(C)]@@ -25,7 +26,7 @@ pub struct FfiVisualViewportTransform {pub origin: FloatPoint,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum FfiVisualAnimationTargetKind {Opacity,@@ -34,7 +35,7 @@ pub enum FfiVisualAnimationTargetKind {Transform,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum FfiVisualAnimationTransformOperationKind {Translate,diff --git a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs b/Libraries/LibCompositing/Rust/src/visual_context/mod.rsindex ed7ba348097..199aad77ec3 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs@@ -20,6 +20,7 @@ use libgfx_rust::{CompositingAndBlendingOperator, CornerRadii, FloatMatrix4x4, FloatPoint, FloatRect, FloatSize, IntRect, MaskKind,WindingRule, translation_matrix,};+use libipc_rust::wire::{Decode, Encode};use scroll_state::{NO_SCROLL_STATE_SLOT, ScrollStateSlot};pub use crate::display_list::commands::{@@ -32,14 +33,14 @@ pub use scroll_table::{};pub use world_transforms::{RectMapping, WorldTransforms};-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum TransformDataRole {CssTransform,SvgViewportTransform,}-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]pub struct TransformData {pub matrix: FloatMatrix4x4,pub origin: FloatPoint,@@ -61,19 +62,19 @@ impl TransformData {}}-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]pub struct PerspectiveData {pub matrix: FloatMatrix4x4,pub flattens_inherited_transform: bool,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]pub struct BackfaceVisibilityData {pub plane_root_index: SpatialNodeIndex,pub flattens_inherited_transform: bool,}-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]pub struct ClipData {pub rect: FloatRect,pub corner_radii: CornerRadii,@@ -89,20 +90,20 @@ pub struct ClipPathData {// The filtered backdrop, limited to the box's rounded border box, is the initial content of the box's// layer, so the layer's opacity, blend mode and filter apply to it along with the box's content.-#[derive(Clone, PartialEq)]+#[derive(Clone, PartialEq, Encode, Decode)]pub struct BackdropFilterData {- pub filter: std::sync::Arc<Vec<u8>>,pub region: IntRect,pub corner_radii: CornerRadii,+ pub filter: std::sync::Arc<Vec<u8>>,}-#[derive(Clone)]+#[derive(Clone, Encode, Decode)]pub struct EffectsData {- pub isolation: bool,pub opacity: f32,pub blend_mode: CompositingAndBlendingOperator,pub filter: Option<std::sync::Arc<Vec<u8>>>,pub backdrop_filter: Option<BackdropFilterData>,+ pub isolation: bool,}impl EffectNodeData {@@ -137,7 +138,7 @@ impl EffectsData {}}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum MaskLayerOrigin {CssMaskLayers,@@ -145,7 +146,7 @@ pub enum MaskLayerOrigin {SvgClip,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]pub struct MaskData {pub rect: IntRect,pub kind: MaskKind,@@ -155,9 +156,11 @@ pub struct MaskData {pub masks_backdrop: bool,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]pub struct ScrollData {+ #[ipc(skip = NO_SCROLL_STATE_SLOT)]pub state_slot: ScrollStateSlot,+ #[ipc(skip = NodeSlotId::INVALID)]pub owner_paintable: NodeSlotId,}@@ -165,7 +168,7 @@ pub struct ScrollData {// entry and the parent sticky chain. Both references follow the containing block chain, which// continues through fixed-position ancestors, so they need not be spatial ancestors of the node.// Geometry is in device pixels.-#[derive(Clone, Copy, Debug, PartialEq)]+#[derive(Clone, Copy, Debug, PartialEq, Encode, Decode)]pub struct StickyData {pub scroller: SpatialNodeIndex,pub parent_sticky: Option<SpatialNodeIndex>,@@ -184,7 +187,9 @@ pub struct StickyData {pub inset_right: Option<f32>,pub inset_bottom: Option<f32>,pub inset_left: Option<f32>,+ #[ipc(skip = NO_SCROLL_STATE_SLOT)]pub state_slot: ScrollStateSlot,+ #[ipc(skip = NodeSlotId::INVALID)]pub owner_paintable: NodeSlotId,}@@ -219,7 +224,7 @@ impl StickyData {}}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, PartialEq, Eq, Encode, Decode)]pub struct AnchorScrollShift {pub scroll_node_index: SpatialNodeIndex,pub negate: bool,@@ -291,7 +296,7 @@ impl LocalTransform {}}-#[derive(Clone)]+#[derive(Clone, Encode, Decode)]pub enum SpatialData {Scroll(ScrollData),Sticky(StickyData),@@ -305,14 +310,14 @@ pub enum SpatialData {// The clip tree holds what narrows the painted region without a layer: rectangle (possibly rounded,// possibly subtractive) clips and clip paths. The effect tree holds what needs a layer or a// per-box marker: opacity/blend/filter layers, masks and compositor background-color animations.-#[derive(Clone)]+#[derive(Clone, Encode, Decode)]pub enum ClipNodeData {Rect(ClipData),Path(ClipPathData),Dead,}-#[derive(Clone)]+#[derive(Clone, Encode, Decode)]pub enum EffectNodeData {Effects(EffectsData),Mask(MaskData),diff --git a/Libraries/LibCompositing/Rust/src/visual_context/scroll_table.rs b/Libraries/LibCompositing/Rust/src/visual_context/scroll_table.rsindex ddc921700e3..1d6dfa9ee36 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/scroll_table.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/scroll_table.rs@@ -9,6 +9,7 @@ use crate::css_pixels::{FfiCssPixelPoint, FfiCssPixelRect};use crate::display_list::commands::UniqueNodeId;use crate::ffi_enum_bytes;use libgfx_rust::{FloatPoint, IntRect};+use libipc_rust::wire::{Decode, Encode};use std::sync::Arc;// The values of SnapStrictness and SnapAlign in scrolling::scroll_snap_selection.@@ -22,7 +23,7 @@ enum ParentChainMark {KnownToEndAtARoot,}-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode)]#[repr(u8)]pub enum CompositorScrollNodeKind {Viewport,@@ -32,7 +33,7 @@ pub enum CompositorScrollNodeKind {}ffi_enum_bytes!(CompositorScrollNodeKind as u8);-#[derive(Clone, Copy, Debug, Default, PartialEq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Encode, Decode)]#[repr(C)]pub struct CompositorScrollNodeRecord {pub scrollable_node_id: UniqueNodeId,@@ -52,7 +53,7 @@ pub struct CompositorScrollNodeRecord {pub shows_overscroll_effect_vertically: bool,}-#[derive(Clone, Copy, Debug, Default, PartialEq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Encode, Decode)]#[repr(C)]pub struct CompositorSnapContainerRecord {pub scroll_node_index: SpatialNodeIndex,@@ -67,7 +68,7 @@ pub struct CompositorSnapContainerRecord {pub area_count: u32,}-#[derive(Clone, Copy, Debug, Default, PartialEq)]+#[derive(Clone, Copy, Debug, Default, PartialEq, Encode, Decode)]#[repr(C)]pub struct CompositorSnapAreaRecord {pub area_node_id: UniqueNodeId,@@ -78,7 +79,7 @@ pub struct CompositorSnapAreaRecord {pub always_stop: bool,}-#[derive(Clone, Debug, Default, PartialEq)]+#[derive(Clone, Debug, Default, PartialEq, Encode, Decode)]pub struct CompositorScrollTable {pub nodes: Arc<[CompositorScrollNodeRecord]>,pub snap_containers: Arc<[CompositorSnapContainerRecord]>,diff --git a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rsindex 8b8bbc725a3..742bf52766d 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs@@ -5,123 +5,16 @@*/use super::{- AnchorScrollShift, BackdropFilterData, BackfaceVisibilityData, ClipData, ClipMode, ClipNode, ClipNodeData,- ClipNodeIndex, ClipPathData, EffectNode, EffectNodeData, EffectNodeIndex, EffectsData, MaskData, MaskLayerOrigin,- PerspectiveData, ScrollData, SpatialData, SpatialNode, SpatialNodeIndex, StickyData, TransformData,- TransformDataRole, VISUAL_VIEWPORT_NODE_INDEX, VisualContextTree, scroll_state::NO_SCROLL_STATE_SLOT,+ ClipNode, ClipNodeData, ClipNodeIndex, ClipPathData, CompositorScrollTable, EffectNode, EffectNodeData,+ EffectNodeIndex, SpatialData, SpatialNode, SpatialNodeIndex, VISUAL_VIEWPORT_NODE_INDEX, VisualContextTree,};-use super::{- CompositorScrollNodeKind, CompositorScrollNodeRecord, CompositorScrollTable, CompositorSnapAreaRecord,- CompositorSnapContainerRecord,-};-use crate::animation_timing::{AnimationEffectTiming, FillMode, PlaybackDirection, TimeValue, TimeValueType};-use crate::css_pixels::{CssPixels, FfiCssPixelPoint, FfiCssPixelRect};-use crate::easing::{Easing, FfiEasingKind, FfiLinearEasingPoint};-use crate::filter_bytes::{FfiFilterFunction, FfiFilterFunctionKind};-use crate::host::{FfiVisualAnimationTargetKind, FfiVisualAnimationTransformOperationKind};-use crate::node_slot_id::NodeSlotId;+use crate::host::FfiVisualAnimationTransformOperationKind;use crate::visual_animation::{- MAXIMUM_TRANSFORM_OPERATION_VALUE_COUNT, VisualAnimation, VisualAnimationKeyframe,- VisualAnimationTransformOperation, VisualAnimationValue,+ MAXIMUM_TRANSFORM_OPERATION_VALUE_COUNT, VisualAnimation, VisualAnimationTransformOperation,};use libgfx_rust::path::Path;use libipc_rust::wire::{Decode, DecodeError, Decoder, Encode, EncodeError, Encoder};-const SPATIAL_KIND_SCROLL: u8 = 0;-const SPATIAL_KIND_STICKY: u8 = 1;-const SPATIAL_KIND_TRANSFORM: u8 = 2;-const SPATIAL_KIND_PERSPECTIVE: u8 = 3;-const SPATIAL_KIND_BACKFACE_VISIBILITY: u8 = 4;-const SPATIAL_KIND_ANCHOR_SCROLL_SHIFT: u8 = 5;-const SPATIAL_KIND_DEAD: u8 = 6;--const CLIP_KIND_RECT: u8 = 0;-const CLIP_KIND_PATH: u8 = 1;-const CLIP_KIND_DEAD: u8 = 2;--const EFFECT_KIND_EFFECTS: u8 = 0;-const EFFECT_KIND_MASK: u8 = 1;-const EFFECT_KIND_BACKGROUND_COLOR_ANIMATION: u8 = 2;-const EFFECT_KIND_DEAD: u8 = 3;--macro_rules! impl_codec_of_node_index {- ($($type:ident),*) => {- $(- impl Encode for $type {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.0)- }- }-- impl Decode for $type {- const MIN_ENCODED_SIZE: usize = size_of::<u32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self(decoder.decode()?))- }- }- )*- };-}--impl_codec_of_node_index!(SpatialNodeIndex, ClipNodeIndex, EffectNodeIndex);--macro_rules! impl_codec_of_enum_going_as_u8 {- ($type:ident, $from_u8:expr) => {- impl Encode for $type {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&(*self as u8))- }- }-- impl Decode for $type {- const MIN_ENCODED_SIZE: usize = size_of::<u8>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- let from_u8: fn(u8) -> Option<Self> = $from_u8;- from_u8(decoder.decode()?).ok_or(DecodeError::InvalidValue(stringify!($type)))- }- }- };-}--impl_codec_of_enum_going_as_u8!(ClipMode, |value| match value {- value if value == ClipMode::Intersect as u8 => Some(ClipMode::Intersect),- value if value == ClipMode::Difference as u8 => Some(ClipMode::Difference),- _ => None,-});-impl_codec_of_enum_going_as_u8!(TransformDataRole, |value| match value {- value if value == TransformDataRole::CssTransform as u8 => Some(TransformDataRole::CssTransform),- value if value == TransformDataRole::SvgViewportTransform as u8 => Some(TransformDataRole::SvgViewportTransform),- _ => None,-});-impl_codec_of_enum_going_as_u8!(MaskLayerOrigin, |value| match value {- value if value == MaskLayerOrigin::CssMaskLayers as u8 => Some(MaskLayerOrigin::CssMaskLayers),- value if value == MaskLayerOrigin::SvgMask as u8 => Some(MaskLayerOrigin::SvgMask),- value if value == MaskLayerOrigin::SvgClip as u8 => Some(MaskLayerOrigin::SvgClip),- _ => None,-});-impl_codec_of_enum_going_as_u8!(CompositorScrollNodeKind, |value| match value {- value if value == CompositorScrollNodeKind::Viewport as u8 => Some(CompositorScrollNodeKind::Viewport),- value if value == CompositorScrollNodeKind::Element as u8 => Some(CompositorScrollNodeKind::Element),- value if value == CompositorScrollNodeKind::PseudoElement as u8 => Some(CompositorScrollNodeKind::PseudoElement),- _ => None,-});-impl_codec_of_enum_going_as_u8!(FfiEasingKind, FfiEasingKind::from_u8);-impl_codec_of_enum_going_as_u8!(FfiFilterFunctionKind, FfiFilterFunctionKind::from_u8);-impl_codec_of_enum_going_as_u8!(FfiVisualAnimationTargetKind, FfiVisualAnimationTargetKind::from_u8);-impl_codec_of_enum_going_as_u8!(PlaybackDirection, |value| PlaybackDirection::try_from(value).ok());-impl_codec_of_enum_going_as_u8!(FillMode, |value| FillMode::try_from(value).ok());-impl_codec_of_enum_going_as_u8!(TimeValueType, |value| match value {- value if value == TimeValueType::Milliseconds as u8 => Some(TimeValueType::Milliseconds),- value if value == TimeValueType::Percentage as u8 => Some(TimeValueType::Percentage),- _ => None,-});-impl_codec_of_enum_going_as_u8!(- FfiVisualAnimationTransformOperationKind,- FfiVisualAnimationTransformOperationKind::from_u8-);-fn decode_nodes_reserving_their_count<T: Decode>(decoder: &mut Decoder<'_>,node_count: usize,@@ -139,177 +32,6 @@ fn decode_nodes_reserving_their_count<T: Decode>(Ok(nodes)}-impl Encode for StickyData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.scroller)?;- encoder.encode(&self.parent_sticky)?;- encoder.encode(&self.position_relative_to_scroller)?;- encoder.encode(&self.border_box_origin)?;- encoder.encode(&self.border_box_size)?;- encoder.encode(&self.scrollport_size)?;- encoder.encode(&self.containing_block_region)?;- encoder.encode(&self.needs_parent_offset_adjustment)?;- encoder.encode(&self.non_scrolling_scroll_container.index)?;- encoder.encode(&self.inset_top)?;- encoder.encode(&self.inset_right)?;- encoder.encode(&self.inset_bottom)?;- encoder.encode(&self.inset_left)- }-}--impl Decode for StickyData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- scroller: decoder.decode()?,- parent_sticky: decoder.decode()?,- position_relative_to_scroller: decoder.decode()?,- border_box_origin: decoder.decode()?,- border_box_size: decoder.decode()?,- scrollport_size: decoder.decode()?,- containing_block_region: decoder.decode()?,- needs_parent_offset_adjustment: decoder.decode()?,- non_scrolling_scroll_container: NodeSlotId {- index: decoder.decode()?,- },- inset_top: decoder.decode()?,- inset_right: decoder.decode()?,- inset_bottom: decoder.decode()?,- inset_left: decoder.decode()?,- state_slot: NO_SCROLL_STATE_SLOT,- owner_paintable: NodeSlotId::INVALID,- })- }-}--impl Encode for TransformData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.matrix)?;- encoder.encode(&self.origin)?;- encoder.encode(&self.sorting_context_root_index)?;- encoder.encode(&self.flattens_inherited_transform)?;- encoder.encode(&self.role)?;- encoder.encode(&self.synthetic_plane)?;- encoder.encode(&self.establishes_sorting_context)?;- encoder.encode(&self.bounds)- }-}--impl Decode for TransformData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- matrix: decoder.decode()?,- origin: decoder.decode()?,- sorting_context_root_index: decoder.decode()?,- flattens_inherited_transform: decoder.decode()?,- role: decoder.decode()?,- synthetic_plane: decoder.decode()?,- establishes_sorting_context: decoder.decode()?,- bounds: decoder.decode()?,- })- }-}--impl Encode for PerspectiveData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.matrix)?;- encoder.encode(&self.flattens_inherited_transform)- }-}--impl Decode for PerspectiveData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- matrix: decoder.decode()?,- flattens_inherited_transform: decoder.decode()?,- })- }-}--impl Encode for BackfaceVisibilityData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.plane_root_index)?;- encoder.encode(&self.flattens_inherited_transform)- }-}--impl Decode for BackfaceVisibilityData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- plane_root_index: decoder.decode()?,- flattens_inherited_transform: decoder.decode()?,- })- }-}--impl Encode for AnchorScrollShift {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.scroll_node_index)?;- encoder.encode(&self.negate)?;- encoder.encode(&self.compensate_horizontal_scroll)?;- encoder.encode(&self.compensate_vertical_scroll)- }-}--impl Decode for AnchorScrollShift {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- scroll_node_index: decoder.decode()?,- negate: decoder.decode()?,- compensate_horizontal_scroll: decoder.decode()?,- compensate_vertical_scroll: decoder.decode()?,- })- }-}--impl Encode for SpatialData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- match self {- SpatialData::Scroll(_) => encoder.encode(&SPATIAL_KIND_SCROLL),- SpatialData::Sticky(sticky) => {- encoder.encode(&SPATIAL_KIND_STICKY)?;- encoder.encode(sticky)- }- SpatialData::Transform(transform) => {- encoder.encode(&SPATIAL_KIND_TRANSFORM)?;- encoder.encode(transform)- }- SpatialData::Perspective(perspective) => {- encoder.encode(&SPATIAL_KIND_PERSPECTIVE)?;- encoder.encode(perspective)- }- SpatialData::BackfaceVisibility(backface) => {- encoder.encode(&SPATIAL_KIND_BACKFACE_VISIBILITY)?;- encoder.encode(backface)- }- SpatialData::AnchorScrollShift(shift) => {- encoder.encode(&SPATIAL_KIND_ANCHOR_SCROLL_SHIFT)?;- encoder.encode(shift)- }- SpatialData::Dead => encoder.encode(&SPATIAL_KIND_DEAD),- }- }-}--impl Decode for SpatialData {- const MIN_ENCODED_SIZE: usize = size_of::<u8>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(match decoder.decode::<u8>()? {- SPATIAL_KIND_SCROLL => SpatialData::Scroll(ScrollData {- state_slot: NO_SCROLL_STATE_SLOT,- owner_paintable: NodeSlotId::INVALID,- }),- SPATIAL_KIND_STICKY => SpatialData::Sticky(decoder.decode()?),- SPATIAL_KIND_TRANSFORM => SpatialData::Transform(decoder.decode()?),- SPATIAL_KIND_PERSPECTIVE => SpatialData::Perspective(decoder.decode()?),- SPATIAL_KIND_BACKFACE_VISIBILITY => SpatialData::BackfaceVisibility(decoder.decode()?),- SPATIAL_KIND_ANCHOR_SCROLL_SHIFT => SpatialData::AnchorScrollShift(decoder.decode()?),- SPATIAL_KIND_DEAD => SpatialData::Dead,- _ => return Err(DecodeError::InvalidValue("SpatialData")),- })- }-}-impl Encode for SpatialNode {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.parent)?;@@ -331,24 +53,6 @@ impl Decode for SpatialNode {}}-impl Encode for ClipData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.rect)?;- encoder.encode(&self.corner_radii)?;- encoder.encode(&self.mode)- }-}--impl Decode for ClipData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- rect: decoder.decode()?,- corner_radii: decoder.decode()?,- mode: decoder.decode()?,- })- }-}-impl Encode for ClipPathData {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.bounding_rect)?;@@ -371,35 +75,6 @@ impl Decode for ClipPathData {}}-impl Encode for ClipNodeData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- match self {- ClipNodeData::Rect(clip) => {- encoder.encode(&CLIP_KIND_RECT)?;- encoder.encode(clip)- }- ClipNodeData::Path(clip_path) => {- encoder.encode(&CLIP_KIND_PATH)?;- encoder.encode(clip_path)- }- ClipNodeData::Dead => encoder.encode(&CLIP_KIND_DEAD),- }- }-}--impl Decode for ClipNodeData {- const MIN_ENCODED_SIZE: usize = size_of::<u8>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(match decoder.decode::<u8>()? {- CLIP_KIND_RECT => ClipNodeData::Rect(decoder.decode()?),- CLIP_KIND_PATH => ClipNodeData::Path(decoder.decode()?),- CLIP_KIND_DEAD => ClipNodeData::Dead,- _ => return Err(DecodeError::InvalidValue("ClipNodeData")),- })- }-}-impl Encode for ClipNode {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.parent)?;@@ -424,97 +99,6 @@ impl Decode for ClipNode {}}-impl Encode for BackdropFilterData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.region)?;- encoder.encode(&self.corner_radii)?;- encoder.encode(&self.filter)- }-}--impl Decode for BackdropFilterData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- region: decoder.decode()?,- corner_radii: decoder.decode()?,- filter: decoder.decode()?,- })- }-}--impl Encode for EffectsData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.opacity)?;- encoder.encode(&self.blend_mode)?;- encoder.encode(&self.filter)?;- encoder.encode(&self.backdrop_filter)?;- encoder.encode(&self.isolation)- }-}--impl Decode for EffectsData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- opacity: decoder.decode()?,- blend_mode: decoder.decode()?,- filter: decoder.decode()?,- backdrop_filter: decoder.decode()?,- isolation: decoder.decode()?,- })- }-}--impl Encode for MaskData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.rect)?;- encoder.encode(&self.kind)?;- encoder.encode(&self.origin)?;- encoder.encode(&self.masks_backdrop)- }-}--impl Decode for MaskData {- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- rect: decoder.decode()?,- kind: decoder.decode()?,- origin: decoder.decode()?,- masks_backdrop: decoder.decode()?,- })- }-}--impl Encode for EffectNodeData {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- match self {- EffectNodeData::Effects(effects) => {- encoder.encode(&EFFECT_KIND_EFFECTS)?;- encoder.encode(effects)- }- EffectNodeData::Mask(mask) => {- encoder.encode(&EFFECT_KIND_MASK)?;- encoder.encode(mask)- }- EffectNodeData::BackgroundColorAnimation => encoder.encode(&EFFECT_KIND_BACKGROUND_COLOR_ANIMATION),- EffectNodeData::Dead => encoder.encode(&EFFECT_KIND_DEAD),- }- }-}--impl Decode for EffectNodeData {- const MIN_ENCODED_SIZE: usize = size_of::<u8>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(match decoder.decode::<u8>()? {- EFFECT_KIND_EFFECTS => EffectNodeData::Effects(decoder.decode()?),- EFFECT_KIND_MASK => EffectNodeData::Mask(decoder.decode()?),- EFFECT_KIND_BACKGROUND_COLOR_ANIMATION => EffectNodeData::BackgroundColorAnimation,- EFFECT_KIND_DEAD => EffectNodeData::Dead,- _ => return Err(DecodeError::InvalidValue("EffectNodeData")),- })- }-}-impl Encode for EffectNode {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.parent)?;@@ -544,92 +128,6 @@ impl Decode for EffectNode {}}-impl Encode for FfiLinearEasingPoint {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.input)?;- encoder.encode(&self.output)- }-}--impl Decode for FfiLinearEasingPoint {- const MIN_ENCODED_SIZE: usize = 2 * size_of::<f64>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- input: decoder.decode()?,- output: decoder.decode()?,- })- }-}--impl Encode for Easing {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.kind())?;- match self {- Easing::Linear(points) => encoder.encode(points),- Easing::CubicBezier { x1, y1, x2, y2 } => {- encoder.encode(x1)?;- encoder.encode(y1)?;- encoder.encode(x2)?;- encoder.encode(y2)- }- Easing::Steps {- interval_count,- position,- } => {- encoder.encode(interval_count)?;- encoder.encode(position)- }- }- }-}--impl Decode for Easing {- const MIN_ENCODED_SIZE: usize = FfiEasingKind::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(match decoder.decode()? {- FfiEasingKind::Linear => Easing::Linear(decoder.decode()?),- FfiEasingKind::CubicBezier => Easing::CubicBezier {- x1: decoder.decode()?,- y1: decoder.decode()?,- x2: decoder.decode()?,- y2: decoder.decode()?,- },- FfiEasingKind::Steps => Easing::Steps {- interval_count: decoder.decode()?,- position: decoder.decode()?,- },- })- }-}--impl Encode for FfiFilterFunction {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.kind)?;- encoder.encode(&self.amount)?;- encoder.encode(&self.offset_x)?;- encoder.encode(&self.offset_y)?;- encoder.encode(&self.color)?;- encoder.encode(&self.color_operation)- }-}--impl Decode for FfiFilterFunction {- const MIN_ENCODED_SIZE: usize = FfiFilterFunctionKind::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- kind: decoder.decode()?,- amount: decoder.decode()?,- offset_x: decoder.decode()?,- offset_y: decoder.decode()?,- color: decoder.decode()?,- color_operation: decoder.decode()?,- })- }-}-impl Encode for VisualAnimationTransformOperation {fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {encoder.encode(&self.kind)?;@@ -655,309 +153,6 @@ impl Decode for VisualAnimationTransformOperation {}}-impl Encode for VisualAnimationValue {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- match self {- VisualAnimationValue::Opacity(opacity) => {- encoder.encode(&FfiVisualAnimationTargetKind::Opacity)?;- encoder.encode(opacity)- }- VisualAnimationValue::BackgroundColor(color) => {- encoder.encode(&FfiVisualAnimationTargetKind::BackgroundColor)?;- encoder.encode(color)- }- VisualAnimationValue::Filter(functions) => {- encoder.encode(&FfiVisualAnimationTargetKind::Filter)?;- encoder.encode(functions)- }- VisualAnimationValue::Transform(operations) => {- encoder.encode(&FfiVisualAnimationTargetKind::Transform)?;- encoder.encode(operations)- }- }- }-}--impl Decode for VisualAnimationValue {- const MIN_ENCODED_SIZE: usize = FfiVisualAnimationTargetKind::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(match decoder.decode()? {- FfiVisualAnimationTargetKind::Opacity => VisualAnimationValue::Opacity(decoder.decode()?),- FfiVisualAnimationTargetKind::BackgroundColor => VisualAnimationValue::BackgroundColor(decoder.decode()?),- FfiVisualAnimationTargetKind::Filter => VisualAnimationValue::Filter(decoder.decode()?),- FfiVisualAnimationTargetKind::Transform => VisualAnimationValue::Transform(decoder.decode()?),- })- }-}--impl Encode for VisualAnimationKeyframe {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.offset)?;- encoder.encode(&self.easing)?;- encoder.encode(&self.value)- }-}--impl Decode for VisualAnimationKeyframe {- const MIN_ENCODED_SIZE: usize =- size_of::<f64>() + Easing::MIN_ENCODED_SIZE + VisualAnimationValue::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- offset: decoder.decode()?,- easing: decoder.decode()?,- value: decoder.decode()?,- })- }-}--impl Encode for TimeValue {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.r#type)?;- encoder.encode(&self.value)- }-}--impl Decode for TimeValue {- const MIN_ENCODED_SIZE: usize = TimeValueType::MIN_ENCODED_SIZE + size_of::<f64>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self::new(decoder.decode()?, decoder.decode()?))- }-}--impl Encode for AnimationEffectTiming {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.start_delay)?;- encoder.encode(&self.end_delay)?;- encoder.encode(&self.iteration_duration)?;- encoder.encode(&self.iteration_start)?;- encoder.encode(&self.iteration_count)?;- encoder.encode(&self.fill_mode)?;- encoder.encode(&self.playback_direction)- }-}--impl Decode for AnimationEffectTiming {- const MIN_ENCODED_SIZE: usize = 3 * TimeValue::MIN_ENCODED_SIZE- + 2 * size_of::<f64>()- + FillMode::MIN_ENCODED_SIZE- + PlaybackDirection::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- start_delay: decoder.decode()?,- end_delay: decoder.decode()?,- iteration_duration: decoder.decode()?,- iteration_start: decoder.decode()?,- iteration_count: decoder.decode()?,- fill_mode: decoder.decode()?,- playback_direction: decoder.decode()?,- })- }-}--impl Encode for VisualAnimation {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.target_kind)?;- encoder.encode(&self.node_indices)?;- encoder.encode(&self.monotonic_time_at_anchor_ns)?;- encoder.encode(&self.local_time_at_anchor_ms)?;- encoder.encode(&self.playback_rate)?;- encoder.encode(&self.timing)?;- encoder.encode(&self.easing)?;- encoder.encode(&self.keyframes)- }-}--impl Decode for VisualAnimation {- const MIN_ENCODED_SIZE: usize = FfiVisualAnimationTargetKind::MIN_ENCODED_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- target_kind: decoder.decode()?,- node_indices: decoder.decode()?,- monotonic_time_at_anchor_ns: decoder.decode()?,- local_time_at_anchor_ms: decoder.decode()?,- playback_rate: decoder.decode()?,- timing: decoder.decode()?,- easing: decoder.decode()?,- keyframes: decoder.decode()?,- })- }-}--impl Encode for FfiCssPixelPoint {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.x.raw_value())?;- encoder.encode(&self.y.raw_value())- }-}--impl Decode for FfiCssPixelPoint {- const MIN_ENCODED_SIZE: usize = 2 * size_of::<i32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- x: CssPixels::from_raw(decoder.decode()?),- y: CssPixels::from_raw(decoder.decode()?),- })- }-}--impl Encode for FfiCssPixelRect {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.x.raw_value())?;- encoder.encode(&self.y.raw_value())?;- encoder.encode(&self.width.raw_value())?;- encoder.encode(&self.height.raw_value())- }-}--impl Decode for FfiCssPixelRect {- const MIN_ENCODED_SIZE: usize = 4 * size_of::<i32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- x: CssPixels::from_raw(decoder.decode()?),- y: CssPixels::from_raw(decoder.decode()?),- width: CssPixels::from_raw(decoder.decode()?),- height: CssPixels::from_raw(decoder.decode()?),- })- }-}--const SERIALIZED_COMPOSITOR_SCROLL_NODE_SIZE: usize = 57;--impl Encode for CompositorScrollNodeRecord {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.scrollable_node_id)?;- encoder.encode(&self.scroll_node_index)?;- encoder.encode(&self.parent_scroll_node_index)?;- encoder.encode(&self.scrollport_rect)?;- encoder.encode(&self.min_scroll_offset)?;- encoder.encode(&self.max_scroll_offset)?;- encoder.encode(&self.scroll_node_kind)?;- encoder.encode(&self.pseudo_element_type)?;- encoder.encode(&self.is_viewport)?;- encoder.encode(&self.can_be_wheel_scrolled_horizontally)?;- encoder.encode(&self.can_be_wheel_scrolled_vertically)?;- encoder.encode(&self.chains_scroll_to_ancestors_horizontally)?;- encoder.encode(&self.chains_scroll_to_ancestors_vertically)?;- encoder.encode(&self.shows_overscroll_effect_horizontally)?;- encoder.encode(&self.shows_overscroll_effect_vertically)- }-}--impl Decode for CompositorScrollNodeRecord {- const MIN_ENCODED_SIZE: usize = SERIALIZED_COMPOSITOR_SCROLL_NODE_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- scrollable_node_id: decoder.decode()?,- scroll_node_index: decoder.decode()?,- parent_scroll_node_index: decoder.decode()?,- scrollport_rect: decoder.decode()?,- min_scroll_offset: decoder.decode()?,- max_scroll_offset: decoder.decode()?,- scroll_node_kind: decoder.decode()?,- pseudo_element_type: decoder.decode()?,- is_viewport: decoder.decode()?,- can_be_wheel_scrolled_horizontally: decoder.decode()?,- can_be_wheel_scrolled_vertically: decoder.decode()?,- chains_scroll_to_ancestors_horizontally: decoder.decode()?,- chains_scroll_to_ancestors_vertically: decoder.decode()?,- shows_overscroll_effect_horizontally: decoder.decode()?,- shows_overscroll_effect_vertically: decoder.decode()?,- })- }-}--const SERIALIZED_COMPOSITOR_SNAP_CONTAINER_SIZE: usize = 48;--impl Encode for CompositorSnapContainerRecord {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.scroll_node_index)?;- encoder.encode(&self.snapport)?;- encoder.encode(&self.min_scroll_offset)?;- encoder.encode(&self.max_scroll_offset)?;- encoder.encode(&self.strictness)?;- encoder.encode(&self.snaps_x)?;- encoder.encode(&self.snaps_y)?;- encoder.encode(&self.horizontal_writing_mode)?;- encoder.encode(&self.first_area_index)?;- encoder.encode(&self.area_count)- }-}--impl Decode for CompositorSnapContainerRecord {- const MIN_ENCODED_SIZE: usize = SERIALIZED_COMPOSITOR_SNAP_CONTAINER_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- scroll_node_index: decoder.decode()?,- snapport: decoder.decode()?,- min_scroll_offset: decoder.decode()?,- max_scroll_offset: decoder.decode()?,- strictness: decoder.decode()?,- snaps_x: decoder.decode()?,- snaps_y: decoder.decode()?,- horizontal_writing_mode: decoder.decode()?,- first_area_index: decoder.decode()?,- area_count: decoder.decode()?,- })- }-}--const SERIALIZED_COMPOSITOR_SNAP_AREA_SIZE: usize = 28;--impl Encode for CompositorSnapAreaRecord {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&self.area_node_id)?;- encoder.encode(&self.pseudo_element_type)?;- encoder.encode(&self.rect)?;- encoder.encode(&self.align_x)?;- encoder.encode(&self.align_y)?;- encoder.encode(&self.always_stop)- }-}--impl Decode for CompositorSnapAreaRecord {- const MIN_ENCODED_SIZE: usize = SERIALIZED_COMPOSITOR_SNAP_AREA_SIZE;-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- area_node_id: decoder.decode()?,- pseudo_element_type: decoder.decode()?,- rect: decoder.decode()?,- align_x: decoder.decode()?,- align_y: decoder.decode()?,- always_stop: decoder.decode()?,- })- }-}--impl Encode for CompositorScrollTable {- fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {- encoder.encode(&*self.nodes)?;- encoder.encode(&*self.snap_containers)?;- encoder.encode(&*self.snap_areas)- }-}--impl Decode for CompositorScrollTable {- const MIN_ENCODED_SIZE: usize = 3 * size_of::<u32>();-- fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {- Ok(Self {- nodes: decoder.decode::<Vec<_>>()?.into(),- snap_containers: decoder.decode::<Vec<_>>()?.into(),- snap_areas: decoder.decode::<Vec<_>>()?.into(),- })- }-}-fn spatial_node_has_ancestor(nodes: &[SpatialNode], mut node: usize, ancestor: SpatialNodeIndex) -> bool {while node != VISUAL_VIEWPORT_NODE_INDEX.0 as usize {node = nodes[node].parent.0 as usize;@@ -1118,8 +313,21 @@ impl VisualContextTree {#[cfg(test)]mod tests {+ use super::super::{+ AnchorScrollShift, BackdropFilterData, BackfaceVisibilityData, ClipData, ClipMode, CompositorScrollNodeKind,+ CompositorScrollNodeRecord, CompositorSnapAreaRecord, CompositorSnapContainerRecord, EffectsData, MaskData,+ MaskLayerOrigin, PerspectiveData, ScrollData, StickyData, TransformData, TransformDataRole,+ scroll_state::NO_SCROLL_STATE_SLOT,+ };use super::*;+ use crate::animation_timing::{AnimationEffectTiming, FillMode, PlaybackDirection, TimeValue};+ use crate::css_pixels::{CssPixels, FfiCssPixelPoint, FfiCssPixelRect};use crate::display_list::commands::UniqueNodeId;+ use crate::easing::{Easing, FfiLinearEasingPoint};+ use crate::filter_bytes::{FfiFilterFunction, FfiFilterFunctionKind};+ use crate::host::FfiVisualAnimationTargetKind;+ use crate::node_slot_id::NodeSlotId;+ use crate::visual_animation::{VisualAnimationKeyframe, VisualAnimationValue};use libgfx_rust::{Color, ColorFilterType, CompositingAndBlendingOperator, CornerRadii, CornerRadius, FloatMatrix4x4, FloatPoint,FloatRect, FloatSize, IntRect, MaskKind, WindingRule, perspective_matrix, translation_matrix,@@ -1789,9 +997,9 @@ mod tests {);}let nodes_start = section_start + 4;- let container_count_offset = nodes_start + 2 * SERIALIZED_COMPOSITOR_SCROLL_NODE_SIZE;+ let container_count_offset = nodes_start + 2 * CompositorScrollNodeRecord::MIN_ENCODED_SIZE;let container_start = container_count_offset + 4;- let area_count_offset = container_start + SERIALIZED_COMPOSITOR_SNAP_CONTAINER_SIZE;+ let area_count_offset = container_start + CompositorSnapContainerRecord::MIN_ENCODED_SIZE;let area_start = area_count_offset + 4;for offset in [section_start, container_count_offset, area_count_offset] {let mut invalid = bytes.clone();