Animation: Aggregate Animated Image Info to Document (#36141)

Signed-off-by: rayguo17 <rayguo17@gmail.com>
This commit is contained in:
TIN TUN AUNG 2025-03-29 07:19:49 +08:00 committed by GitHub
parent 53f7c7b1de
commit ed3dd8fbe0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 145 additions and 9 deletions

View file

@ -21,6 +21,7 @@ euclid = { workspace = true }
fnv = { workspace = true }
fonts = { path = "../../fonts" }
fonts_traits = { workspace = true }
fxhash = { workspace = true }
html5ever = { workspace = true }
ipc-channel = { workspace = true }
libc = { workspace = true }

View file

@ -24,10 +24,12 @@ use euclid::Size2D;
use euclid::default::{Point2D, Rect};
use fnv::FnvHashMap;
use fonts::{FontContext, SystemFontServiceProxy};
use fxhash::FxHashMap;
use ipc_channel::ipc::IpcSender;
use libc::c_void;
use malloc_size_of_derive::MallocSizeOf;
use net_traits::image_cache::{ImageCache, PendingImageId};
use pixels::Image;
use profile_traits::mem::Report;
use profile_traits::time;
use script_traits::{InitialScriptState, LoadData, Painter, ScriptThreadMessage};
@ -400,6 +402,8 @@ pub struct ReflowResult {
/// to communicate them with the Constellation and also the `Window`
/// element of their content pages.
pub iframe_sizes: IFrameSizes,
/// The mapping of node to animated image, need to be returned to ImageAnimationManager
pub node_to_image_animation_map: FxHashMap<OpaqueNode, ImageAnimationState>,
}
/// Information needed for a script-initiated reflow.
@ -427,6 +431,8 @@ pub struct ReflowRequest {
pub animation_timeline_value: f64,
/// The set of animations for this document.
pub animations: DocumentAnimationSet,
/// The set of image animations.
pub node_to_image_animation_map: FxHashMap<OpaqueNode, ImageAnimationState>,
/// The theme for the window
pub theme: PrefersColorScheme,
}
@ -501,3 +507,25 @@ pub fn node_id_from_scroll_id(id: usize) -> Option<usize> {
}
None
}
#[derive(Clone, Debug, MallocSizeOf)]
pub struct ImageAnimationState {
#[ignore_malloc_size_of = "Arc is hard"]
image: Arc<Image>,
active_frame: usize,
last_update_time: f64,
}
impl ImageAnimationState {
pub fn new(image: Arc<Image>) -> Self {
Self {
image,
active_frame: 0,
last_update_time: 0.,
}
}
pub fn image_key(&self) -> Option<ImageKey> {
self.image.id
}
}