mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move most animation processing to script
This is preparation for sharing this code with layout_2020 and implementing selective off-the-main-thread animations. We still look for nodes not in the flow tree in the layout thread.
This commit is contained in:
parent
aa9f16ce45
commit
3b0619aedd
21 changed files with 444 additions and 371 deletions
|
@ -93,6 +93,7 @@ use net_traits::response::HttpsState;
|
|||
use net_traits::response::{Response, ResponseBody};
|
||||
use net_traits::storage_thread::StorageType;
|
||||
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceFetchTiming, ResourceThreads};
|
||||
use parking_lot::RwLock;
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||
use script_layout_interface::message::PendingRestyle;
|
||||
|
@ -100,9 +101,11 @@ use script_layout_interface::rpc::LayoutRPC;
|
|||
use script_layout_interface::StyleAndOpaqueLayoutData;
|
||||
use script_traits::serializable::BlobImpl;
|
||||
use script_traits::transferable::MessagePortImpl;
|
||||
use script_traits::{DocumentActivity, DrawAPaintImageResult};
|
||||
use script_traits::{MediaSessionActionType, ScriptToConstellationChan, TimerEventId, TimerSource};
|
||||
use script_traits::{UntrustedNodeAddress, WebrenderIpcSender, WindowSizeData, WindowSizeType};
|
||||
use script_traits::{
|
||||
DocumentActivity, DrawAPaintImageResult, MediaSessionActionType, ScriptToConstellationChan,
|
||||
TimerEventId, TimerSource, UntrustedNodeAddress, WebrenderIpcSender, WindowSizeData,
|
||||
WindowSizeType,
|
||||
};
|
||||
use selectors::matching::ElementSelectorFlags;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
|
@ -131,6 +134,7 @@ use std::rc::Rc;
|
|||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Instant, SystemTime};
|
||||
use style::animation::ElementAnimationSet;
|
||||
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
|
||||
use style::author_styles::AuthorStyles;
|
||||
use style::context::QuirksMode;
|
||||
|
@ -172,7 +176,6 @@ unsafe_no_jsmanaged_fields!(Box<dyn TaskBox>, Box<dyn EventLoopWaker>);
|
|||
|
||||
unsafe_no_jsmanaged_fields!(MessagePortImpl);
|
||||
unsafe_no_jsmanaged_fields!(MessagePortId);
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Option<MessagePortId>>);
|
||||
unsafe_no_jsmanaged_fields!(MessagePortRouterId);
|
||||
|
||||
unsafe_no_jsmanaged_fields!(BroadcastChannelRouterId);
|
||||
|
@ -184,8 +187,7 @@ unsafe_no_jsmanaged_fields!(CSSError);
|
|||
|
||||
unsafe_no_jsmanaged_fields!(&'static Encoding);
|
||||
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Decoder>);
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Vec<u8>>);
|
||||
unsafe_no_jsmanaged_fields!(Decoder);
|
||||
|
||||
unsafe_no_jsmanaged_fields!(Reflector);
|
||||
|
||||
|
@ -252,6 +254,12 @@ unsafe impl<T: JSTraceable> JSTraceable for ServoArc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: JSTraceable> JSTraceable for RwLock<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
self.read().trace(trc)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: JSTraceable + ?Sized> JSTraceable for Box<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
(**self).trace(trc)
|
||||
|
@ -284,6 +292,12 @@ unsafe impl<T: JSTraceable> JSTraceable for DomRefCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: JSTraceable> JSTraceable for RefCell<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
(*self).borrow().trace(trc)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for Heap<*mut JSObject> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
if self.get().is_null() {
|
||||
|
@ -530,8 +544,7 @@ unsafe_no_jsmanaged_fields!(WebGLTextureId);
|
|||
unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
|
||||
unsafe_no_jsmanaged_fields!(WebGLVersion);
|
||||
unsafe_no_jsmanaged_fields!(WebGLSLVersion);
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Option<WebGPU>>);
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Identities>);
|
||||
unsafe_no_jsmanaged_fields!(Identities);
|
||||
unsafe_no_jsmanaged_fields!(WebGPU);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUAdapter);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUBuffer);
|
||||
|
@ -544,7 +557,7 @@ unsafe_no_jsmanaged_fields!(WebGPUShaderModule);
|
|||
unsafe_no_jsmanaged_fields!(WebGPUCommandBuffer);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUCommandEncoder);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUDevice);
|
||||
unsafe_no_jsmanaged_fields!(RefCell<Option<RawPass>>);
|
||||
unsafe_no_jsmanaged_fields!(Option<RawPass>);
|
||||
unsafe_no_jsmanaged_fields!(GPUBufferState);
|
||||
unsafe_no_jsmanaged_fields!(WebXRSwapChainId);
|
||||
unsafe_no_jsmanaged_fields!(MediaList);
|
||||
|
@ -586,6 +599,7 @@ unsafe_no_jsmanaged_fields!(MediaSessionActionType);
|
|||
unsafe_no_jsmanaged_fields!(MediaMetadata);
|
||||
unsafe_no_jsmanaged_fields!(WebrenderIpcSender);
|
||||
unsafe_no_jsmanaged_fields!(StreamConsumer);
|
||||
unsafe_no_jsmanaged_fields!(ElementAnimationSet);
|
||||
|
||||
unsafe impl<'a> JSTraceable for &'a str {
|
||||
#[inline]
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::animation_timeline::AnimationTimeline;
|
||||
use crate::animations::{Animations, AnimationsUpdate};
|
||||
use crate::document_loader::{DocumentLoader, LoadType};
|
||||
use crate::dom::attr::Attr;
|
||||
use crate::dom::beforeunloadevent::BeforeUnloadEvent;
|
||||
|
@ -384,6 +385,8 @@ pub struct Document {
|
|||
/// A timeline for animations which is used for synchronizing animations.
|
||||
/// https://drafts.csswg.org/web-animations/#timeline
|
||||
animation_timeline: DomRefCell<AnimationTimeline>,
|
||||
/// Animations for this Document
|
||||
animations: DomRefCell<Animations>,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
|
@ -2913,6 +2916,7 @@ impl Document {
|
|||
} else {
|
||||
DomRefCell::new(AnimationTimeline::new())
|
||||
},
|
||||
animations: DomRefCell::new(Animations::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3615,17 +3619,27 @@ impl Document {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn advance_animation_timeline_for_testing(&self, delta: f64) {
|
||||
pub(crate) fn advance_animation_timeline_for_testing(&self, delta: f64) {
|
||||
self.animation_timeline.borrow_mut().advance_specific(delta);
|
||||
}
|
||||
|
||||
pub fn update_animation_timeline(&self) {
|
||||
pub(crate) fn update_animation_timeline(&self) {
|
||||
self.animation_timeline.borrow_mut().update();
|
||||
}
|
||||
|
||||
pub fn current_animation_timeline_value(&self) -> f64 {
|
||||
pub(crate) fn current_animation_timeline_value(&self) -> f64 {
|
||||
self.animation_timeline.borrow().current_value()
|
||||
}
|
||||
|
||||
pub(crate) fn animations(&self) -> Ref<Animations> {
|
||||
self.animations.borrow()
|
||||
}
|
||||
|
||||
pub(crate) fn update_animations(&self) -> AnimationsUpdate {
|
||||
self.animations
|
||||
.borrow_mut()
|
||||
.do_post_reflow_update(&self.window, self.current_animation_timeline_value())
|
||||
}
|
||||
}
|
||||
|
||||
impl Element {
|
||||
|
|
|
@ -81,7 +81,7 @@ use dom_struct::dom_struct;
|
|||
use embedder_traits::{EmbedderMsg, EventLoopWaker, PromptDefinition, PromptOrigin, PromptResult};
|
||||
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect};
|
||||
use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use ipc_channel::ipc::{channel, IpcSender};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::jsapi::Heap;
|
||||
use js::jsapi::JSAutoRealm;
|
||||
|
@ -1305,9 +1305,9 @@ impl WindowMethods for Window {
|
|||
}
|
||||
|
||||
fn RunningAnimationCount(&self) -> u32 {
|
||||
let (sender, receiver) = channel().unwrap();
|
||||
let _ = self.layout_chan.send(Msg::GetRunningAnimations(sender));
|
||||
receiver.recv().unwrap_or(0) as u32
|
||||
self.document
|
||||
.get()
|
||||
.map_or(0, |d| d.animations().running_animation_count() as u32)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-name
|
||||
|
@ -1643,6 +1643,7 @@ impl Window {
|
|||
dom_count: document.dom_count(),
|
||||
pending_restyles: document.drain_pending_restyles(),
|
||||
animation_timeline_value: document.current_animation_timeline_value(),
|
||||
animations: document.animations().sets.clone(),
|
||||
};
|
||||
|
||||
self.layout_chan
|
||||
|
@ -1706,8 +1707,9 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
let update = document.update_animations();
|
||||
unsafe {
|
||||
ScriptThread::note_newly_animating_nodes(pipeline_id, complete.newly_animating_nodes);
|
||||
ScriptThread::process_animations_update(update);
|
||||
}
|
||||
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue