script: Start replacing time with std::time and chrono (#30639)

* Replace `time` with `chrono` in `script/animation_timeline`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_thread.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` and `chrono` in `script/script_thread.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_runtime.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/script_runtime.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/workerglobalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `chrono` in `script/dom/workerglobalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlmedialelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/globalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `chrono` in `script/dom/globalscope.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Replace `time` with `std::time` in `script/dom/htmlformelement.rs`

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>

* Increase precision of animation timeline

* Some fixes

Use Instant a bit more and stop using chrono. Do not transition
`navigation_start_precise` to Instant yet as we need to coordinate this
across all crates.

---------

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Auguste Baum 2024-01-16 13:23:18 +01:00 committed by GitHub
parent c06ae7faf2
commit 9654363c18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 61 deletions

View file

@ -6,6 +6,7 @@ use std::cell::Cell;
use std::collections::VecDeque;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use std::{f64, mem};
use dom_struct::dom_struct;
@ -33,7 +34,6 @@ use servo_media::player::video::{VideoFrame, VideoFrameRenderer};
use servo_media::player::{PlaybackState, Player, PlayerError, PlayerEvent, SeekLock, StreamType};
use servo_media::{ClientContextId, ServoMedia, SupportsMediaType};
use servo_url::ServoUrl;
use time::{self, Duration, Timespec};
use webrender_api::{
ExternalImageData, ExternalImageId, ExternalImageType, ImageBufferKind, ImageData,
ImageDescriptor, ImageDescriptorFlags, ImageFormat, ImageKey,
@ -377,9 +377,8 @@ pub struct HTMLMediaElement {
/// https://html.spec.whatwg.org/multipage/#dom-media-texttracks
text_tracks_list: MutNullableDom<TextTrackList>,
/// Time of last timeupdate notification.
#[ignore_malloc_size_of = "Defined in time"]
#[no_trace]
next_timeupdate_event: Cell<Timespec>,
#[ignore_malloc_size_of = "Defined in std::time"]
next_timeupdate_event: Cell<Instant>,
/// Latest fetch request context.
current_fetch_context: DomRefCell<Option<HTMLMediaElementFetchContext>>,
/// Player Id reported the player thread
@ -452,7 +451,7 @@ impl HTMLMediaElement {
audio_tracks_list: Default::default(),
video_tracks_list: Default::default(),
text_tracks_list: Default::default(),
next_timeupdate_event: Cell::new(time::get_time() + Duration::milliseconds(250)),
next_timeupdate_event: Cell::new(Instant::now() + Duration::from_millis(250)),
current_fetch_context: DomRefCell::new(None),
id: Cell::new(0),
media_controls_id: DomRefCell::new(None),
@ -502,14 +501,14 @@ impl HTMLMediaElement {
/// https://html.spec.whatwg.org/multipage/#time-marches-on
fn time_marches_on(&self) {
// Step 6.
if time::get_time() > self.next_timeupdate_event.get() {
if Instant::now() > self.next_timeupdate_event.get() {
let window = window_from_node(self);
window
.task_manager()
.media_element_task_source()
.queue_simple_event(self.upcast(), atom!("timeupdate"), &window);
self.next_timeupdate_event
.set(time::get_time() + Duration::milliseconds(350));
.set(Instant::now() + Duration::from_millis(350));
}
}
@ -2602,7 +2601,7 @@ struct HTMLMediaElementFetchListener {
/// The generation of the media element when this fetch started.
generation_id: u32,
/// Time of last progress notification.
next_progress_event: Timespec,
next_progress_event: Instant,
/// Timing data for this resource.
resource_timing: ResourceFetchTiming,
/// Url for the resource.
@ -2751,13 +2750,13 @@ impl FetchResponseListener for HTMLMediaElementFetchListener {
// https://html.spec.whatwg.org/multipage/#concept-media-load-resource step 4,
// => "If mode is remote" step 2
if time::get_time() > self.next_progress_event {
if Instant::now() > self.next_progress_event {
let window = window_from_node(&*elem);
window
.task_manager()
.media_element_task_source()
.queue_simple_event(elem.upcast(), atom!("progress"), &window);
self.next_progress_event = time::get_time() + Duration::milliseconds(350);
self.next_progress_event = Instant::now() + Duration::from_millis(350);
}
}
@ -2886,7 +2885,7 @@ impl HTMLMediaElementFetchListener {
elem: Trusted::new(elem),
metadata: None,
generation_id: elem.generation_id.get(),
next_progress_event: time::get_time() + Duration::milliseconds(350),
next_progress_event: Instant::now() + Duration::from_millis(350),
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
url,
expected_content_length: None,