From 647425298e73803df574a2e8359261d0bd77f91c Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 26 Jul 2024 09:44:36 +0200 Subject: [PATCH] Remove use of `time` A very ancient version of `time` was used with security vulnerabilities. Remove all uses of time including the `profile` feature. Hopefully in the future, some of this functionality can be restored, but in the meantime get Servo closer to stop using old `time`. Signed-off-by: Martin Robinson --- .github/workflows/rust.yml | 6 ++-- webxr-api/Cargo.toml | 1 - webxr-api/frame.rs | 6 ---- webxr-api/session.rs | 58 +++----------------------------------- webxr/Cargo.toml | 2 -- webxr/glwindow/mod.rs | 3 -- webxr/headless/mod.rs | 3 -- webxr/openxr/mod.rs | 3 -- 8 files changed, 7 insertions(+), 75 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 87f3885d..bc2e9225 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -28,7 +28,7 @@ jobs: cd webxr cargo build --features=glwindow,headless cargo build --features=ipc,glwindow,headless - cargo build --features=glwindow,headless,profile + cargo build --features=glwindow,headless mac: runs-on: macos-latest steps: @@ -39,7 +39,7 @@ jobs: cd webxr cargo build --features=glwindow,headless cargo build --features=ipc,glwindow,headless - cargo build --features=glwindow,headless,profile + cargo build --features=glwindow,headless win: runs-on: windows-latest steps: @@ -50,7 +50,7 @@ jobs: cd webxr cargo build --features=glwindow,headless cargo build --features=ipc,glwindow,headless - cargo build --features=glwindow,headless,profile + cargo build --features=glwindow,headless rustup target add aarch64-pc-windows-msvc cargo build --target=aarch64-pc-windows-msvc --features ipc,openxr-api build_result: diff --git a/webxr-api/Cargo.toml b/webxr-api/Cargo.toml index a67bcae1..11d53e89 100644 --- a/webxr-api/Cargo.toml +++ b/webxr-api/Cargo.toml @@ -19,7 +19,6 @@ path = "lib.rs" [features] ipc = ["serde", "ipc-channel", "euclid/serde"] -profile = ["time"] [dependencies] euclid = "0.22" diff --git a/webxr-api/frame.rs b/webxr-api/frame.rs index ac3a30e4..7f0a3cf3 100644 --- a/webxr-api/frame.rs +++ b/webxr-api/frame.rs @@ -31,12 +31,6 @@ pub struct Frame { /// The subimages to render to pub sub_images: Vec, - /// Value of time::precise_time_ns() when frame was obtained - pub time_ns: u64, - - /// The time the frame was sent (only set with the profile feature) - pub sent_time: u64, - /// The hit test results for this frame, if any pub hit_test_results: Vec, } diff --git a/webxr-api/session.rs b/webxr-api/session.rs index 2e42bce5..fda075c7 100644 --- a/webxr-api/session.rs +++ b/webxr-api/session.rs @@ -95,11 +95,6 @@ impl SessionInit { } } -#[cfg(feature = "profile")] -fn to_ms(ns: u64) -> f64 { - ns as f64 / 1_000_000. -} - /// https://immersive-web.github.io/webxr-ar-module/#xrenvironmentblendmode-enum #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))] @@ -119,7 +114,7 @@ enum SessionMsg { SetEventDest(Sender), UpdateClipPlanes(/* near */ f32, /* far */ f32), StartRenderLoop, - RenderAnimationFrame(/* request time */ u64), + RenderAnimationFrame, RequestHitTest(HitTestSource), CancelHitTest(HitTestId), Quit, @@ -221,13 +216,7 @@ impl Session { } pub fn render_animation_frame(&mut self) { - #[allow(unused)] - let mut time = 0; - #[cfg(feature = "profile")] - { - time = time::precise_time_ns(); - } - let _ = self.sender.send(SessionMsg::RenderAnimationFrame(time)); + let _ = self.sender.send(SessionMsg::RenderAnimationFrame); } pub fn end_session(&mut self) { @@ -376,18 +365,9 @@ where let _ = self.frame_sender.send(frame); } SessionMsg::UpdateClipPlanes(near, far) => self.device.update_clip_planes(near, far), - SessionMsg::RenderAnimationFrame(_sent_time) => { + SessionMsg::RenderAnimationFrame => { self.frame_count += 1; - #[cfg(feature = "profile")] - let render_start = time::precise_time_ns(); - #[cfg(feature = "profile")] - println!( - "WEBXR PROFILING [raf transmitted]:\t{}ms", - to_ms(render_start - _sent_time) - ); - - #[cfg(feature = "profile")] - let end_frame = time::precise_time_ns(); + self.device.end_animation_frame(&self.layers[..]); if self.render_state == RenderState::PendingQuit { @@ -395,16 +375,6 @@ where return false; } - #[cfg(feature = "profile")] - let ended_frame = time::precise_time_ns(); - #[cfg(feature = "profile")] - println!( - "WEBXR PROFILING [raf end frame]:\t{}ms", - to_ms(ended_frame - end_frame) - ); - - #[cfg(feature = "profile")] - let begin_frame = time::precise_time_ns(); if let Some(layers) = self.pending_layers.take() { self.layers = layers; } @@ -416,16 +386,6 @@ where return false; } }; - #[cfg(feature = "profile")] - let begun_frame = time::precise_time_ns(); - #[cfg(feature = "profile")] - { - println!( - "WEBXR PROFILING [raf begin frame]:\t{}ms", - to_ms(begun_frame - begin_frame) - ); - frame.sent_time = begun_frame; - } let _ = self.frame_sender.send(frame); } @@ -459,8 +419,6 @@ where { fn run_one_frame(&mut self) { let frame_count = self.frame_count; - #[cfg(feature = "profile")] - let start_run = time::precise_time_ns(); while frame_count == self.frame_count && self.running { if let Ok(msg) = crate::recv_timeout(&self.receiver, TIMEOUT) { self.running = self.handle_msg(msg); @@ -468,14 +426,6 @@ where break; } } - #[cfg(feature = "profile")] - { - let end_run = time::precise_time_ns(); - println!( - "WEBXR PROFILING [run_one_frame]:\t{}ms", - to_ms(end_run - start_run) - ); - } } fn running(&self) -> bool { diff --git a/webxr/Cargo.toml b/webxr/Cargo.toml index fefa2dad..35cacf3a 100644 --- a/webxr/Cargo.toml +++ b/webxr/Cargo.toml @@ -25,7 +25,6 @@ glwindow = [] headless = [] ipc = ["webxr-api/ipc", "serde"] openxr-api = ["angle", "openxr", "winapi", "wio", "surfman/sm-angle-default"] -profile = ["webxr-api/profile"] [dependencies] webxr-api = { path = "../webxr-api" } @@ -36,7 +35,6 @@ openxr = { version = "0.18", optional = true } serde = { version = "1.0", optional = true } sparkle = "0.1" surfman = { version = "0.9", features = ["chains"] } -time = "0.1.42" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["dxgi", "d3d11", "winerror"], optional = true } diff --git a/webxr/glwindow/mod.rs b/webxr/glwindow/mod.rs index 1ec7c6de..586bdd45 100644 --- a/webxr/glwindow/mod.rs +++ b/webxr/glwindow/mod.rs @@ -176,7 +176,6 @@ impl DeviceAPI for GlWindowDevice { fn begin_animation_frame(&mut self, layers: &[(ContextId, LayerId)]) -> Option { log::debug!("Begin animation frame for layers {:?}", layers); - let time_ns = time::precise_time_ns(); let translation = Vector3D::from_untyped(self.window.get_translation()); let translation: RigidTransform3D<_, _, Native> = RigidTransform3D::from_translation(translation); @@ -191,9 +190,7 @@ impl DeviceAPI for GlWindowDevice { }), inputs: vec![], events: vec![], - time_ns, sub_images, - sent_time: 0, hit_test_results: vec![], }) } diff --git a/webxr/headless/mod.rs b/webxr/headless/mod.rs index befd84d7..982a3995 100644 --- a/webxr/headless/mod.rs +++ b/webxr/headless/mod.rs @@ -323,7 +323,6 @@ macro_rules! with_all_sessions { impl HeadlessDeviceData { fn get_frame(&self, s: &PerSessionData, sub_images: Vec) -> Frame { - let time_ns = time::precise_time_ns(); let views = self.views.clone(); let pose = self.viewer_origin.map(|transform| { @@ -358,9 +357,7 @@ impl HeadlessDeviceData { pose, inputs, events: vec![], - time_ns, sub_images, - sent_time: 0, hit_test_results: vec![], } } diff --git a/webxr/openxr/mod.rs b/webxr/openxr/mod.rs index fca2718a..0b99cf19 100644 --- a/webxr/openxr/mod.rs +++ b/webxr/openxr/mod.rs @@ -1237,7 +1237,6 @@ impl DeviceAPI for OpenXrDevice { let mut guard = self.shared_data.lock().unwrap(); let data = guard.as_mut().unwrap(); - let time_ns = time::precise_time_ns(); // XXXManishearth should we check frame_state.should_render? let (_view_flags, mut views) = match self.session.locate_views( @@ -1327,9 +1326,7 @@ impl DeviceAPI for OpenXrDevice { pose: Some(ViewerPose { transform, views }), inputs: vec![right.frame, left.frame], events: vec![], - time_ns, sub_images, - sent_time: 0, hit_test_results: vec![], };