mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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:
parent
c06ae7faf2
commit
9654363c18
7 changed files with 62 additions and 61 deletions
|
@ -11,6 +11,7 @@ use std::rc::Rc;
|
|||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::Instant;
|
||||
use std::{mem, ptr};
|
||||
|
||||
use content_security_policy::CspList;
|
||||
|
@ -54,7 +55,6 @@ use script_traits::{
|
|||
ScriptToConstellationChan, TimerEvent, TimerEventId, TimerSchedulerMsg, TimerSource,
|
||||
};
|
||||
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
||||
use time::{get_time, Timespec};
|
||||
use uuid::Uuid;
|
||||
use webgpu::identity::WebGPUOpResult;
|
||||
use webgpu::{ErrorScopeId, WebGPUDevice};
|
||||
|
@ -203,8 +203,8 @@ pub struct GlobalScope {
|
|||
/// live updates from the worker.
|
||||
devtools_wants_updates: Cell<bool>,
|
||||
|
||||
/// Timers used by the Console API.
|
||||
console_timers: DomRefCell<HashMap<DOMString, u64>>,
|
||||
/// Timers (milliseconds) used by the Console API.
|
||||
console_timers: DomRefCell<HashMap<DOMString, Instant>>,
|
||||
|
||||
/// module map is used when importing JavaScript modules
|
||||
/// https://html.spec.whatwg.org/multipage/#concept-settings-object-module-map
|
||||
|
@ -2262,7 +2262,7 @@ impl GlobalScope {
|
|||
}
|
||||
match timers.entry(label) {
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(timestamp_in_ms(get_time()));
|
||||
entry.insert(Instant::now());
|
||||
Ok(())
|
||||
},
|
||||
Entry::Occupied(_) => Err(()),
|
||||
|
@ -2274,7 +2274,7 @@ impl GlobalScope {
|
|||
.borrow_mut()
|
||||
.remove(label)
|
||||
.ok_or(())
|
||||
.map(|start| timestamp_in_ms(get_time()) - start)
|
||||
.map(|start| (Instant::now() - start).as_millis() as u64)
|
||||
}
|
||||
|
||||
/// Get an `&IpcSender<ScriptToDevtoolsControlMsg>` to send messages
|
||||
|
@ -3111,10 +3111,6 @@ impl GlobalScope {
|
|||
}
|
||||
}
|
||||
|
||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||
(time.sec * 1000 + (time.nsec / 1000000) as i64) as u64
|
||||
}
|
||||
|
||||
/// Returns the Rust global scope from a JS global object.
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn global_scope_from_global(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::Cell;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use encoding_rs::{Encoding, UTF_8};
|
||||
|
@ -20,7 +21,6 @@ use servo_rand::random;
|
|||
use style::attr::AttrValue;
|
||||
use style::str::split_html_space_chars;
|
||||
use style_traits::dom::ElementState;
|
||||
use time::{now, Duration, Tm};
|
||||
|
||||
use super::bindings::trace::{HashMapTracedValues, NoTrace};
|
||||
use crate::body::Extractable;
|
||||
|
@ -94,7 +94,7 @@ pub struct HTMLFormElement {
|
|||
elements: DomOnceCell<HTMLFormControlsCollection>,
|
||||
generation_id: Cell<GenerationId>,
|
||||
controls: DomRefCell<Vec<Dom<Element>>>,
|
||||
past_names_map: DomRefCell<HashMapTracedValues<Atom, (Dom<Element>, NoTrace<Tm>)>>,
|
||||
past_names_map: DomRefCell<HashMapTracedValues<Atom, (Dom<Element>, NoTrace<Instant>)>>,
|
||||
firing_submission_events: Cell<bool>,
|
||||
rel_list: MutNullableDom<DOMTokenList>,
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
|||
name,
|
||||
(
|
||||
Dom::from_ref(&*element_node.downcast::<Element>().unwrap()),
|
||||
NoTrace(now()),
|
||||
NoTrace(Instant::now()),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -556,7 +556,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
|||
let entry = SourcedName {
|
||||
name: key.clone(),
|
||||
element: DomRoot::from_ref(&*val.0),
|
||||
source: SourcedNameSource::Past(now() - val.1 .0), // calculate difference now()-val.1 to find age
|
||||
source: SourcedNameSource::Past(Instant::now().duration_since(val.1 .0)),
|
||||
};
|
||||
sourced_names_vec.push(entry);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue