diff options
Diffstat (limited to 'components/canvas_traits')
-rw-r--r-- | components/canvas_traits/Cargo.toml | 2 | ||||
-rw-r--r-- | components/canvas_traits/webgl.rs | 24 |
2 files changed, 23 insertions, 3 deletions
diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml index 7e0f3a92b2e..9c24bd13aa0 100644 --- a/components/canvas_traits/Cargo.toml +++ b/components/canvas_traits/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" [features] webgl_backtrace = [] +xr-profile = ["webxr-api/profile", "time"] [dependencies] crossbeam-channel = "0.4" @@ -26,6 +27,7 @@ serde = "1.0" serde_bytes = "0.11" servo_config = {path = "../config"} sparkle = "0.1" +time = { version = "0.1.0", optional = true } webrender_api = {git = "https://github.com/servo/webrender"} webvr_traits = {path = "../webvr_traits"} webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]} diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs index 6d3bd9bdc09..6709137b34e 100644 --- a/components/canvas_traits/webgl.rs +++ b/components/canvas_traits/webgl.rs @@ -82,7 +82,11 @@ pub enum WebGLMsg { WebGLSender<Option<WebXRSwapChainId>>, ), /// Performs a buffer swap. - SwapBuffers(Vec<SwapChainId>, WebGLSender<()>), + /// + /// The third field contains the time (in ns) when the request + /// was initiated. The u64 in the second field will be the time the + /// request is fulfilled + SwapBuffers(Vec<SwapChainId>, WebGLSender<u64>, u64), /// Frees all resources and closes the thread. Exit, } @@ -195,9 +199,23 @@ impl WebGLMsgSender { .map(|id| SwapChainId::Framebuffer(self.ctx_id, id)) .unwrap_or_else(|| SwapChainId::Context(self.ctx_id)); let (sender, receiver) = webgl_channel()?; + #[allow(unused)] + let mut time = 0; + #[cfg(feature = "xr-profile")] + { + time = time::precise_time_ns(); + } + self.sender - .send(WebGLMsg::SwapBuffers(vec![swap_id], sender))?; - receiver.recv()?; + .send(WebGLMsg::SwapBuffers(vec![swap_id], sender, time))?; + + #[allow(unused)] + let sent_time = receiver.recv()?; + #[cfg(feature = "xr-profile")] + println!( + "WEBXR PROFILING [swap complete]:\t{}ms", + (time::precise_time_ns() - sent_time) as f64 / 1_000_000. + ); Ok(()) } |