From fb3db6a72d84a3bf91a7d6d6956163245f61c930 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 12 Aug 2013 18:17:13 -0700 Subject: [PATCH] Un-stub timer code --- src/components/main/compositing/mod.rs | 8 +++---- src/components/main/servo.rc | 13 +++++------ src/components/script/dom/window.rs | 31 +++++++++++++------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index 666808b7e9d..7cd2ff027ca 100644 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -26,6 +26,8 @@ use std::comm::{Chan, SharedChan, Port}; use std::num::Orderable; use std::task; use std::vec; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; use geom::matrix::identity; use geom::point::Point2D; use geom::size::Size2D; @@ -480,6 +482,7 @@ impl CompositorTask { }; // Enter the main event loop. + let tm = Timer::new().unwrap(); while !done { // Check for new messages coming from the rendering task. check_for_messages(&self.port); @@ -492,10 +495,7 @@ impl CompositorTask { composite(); } - /* - timer::sleep(&uv_global_loop::get(), 10); - */ - fail!("stubbed out!"); + tm.sleep(10); // If a pinch-zoom happened recently, ask for tiles at the new resolution if zoom_action && precise_time_s() - zoom_time > 0.3 { diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index d3c898486fc..d539b6f1355 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -49,6 +49,8 @@ pub use gfx::text; pub use servo_util::url::make_url; use std::comm; use std::os; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; #[path="compositing/mod.rs"] pub mod compositing; @@ -104,20 +106,17 @@ fn run(opts: &Opts) { let (profiler_port, profiler_chan) = comm::stream(); let profiler_chan = ProfilerChan::new(profiler_chan); Profiler::create(profiler_port); - /* - do opts.profiler_period.map |period| { + do opts.profiler_period.map |&period| { let profiler_chan = profiler_chan.clone(); - let period = *period; + let period = (period * 1000f) as u64; do spawn { + let tm = Timer::new().unwrap(); loop { - extra::timer::sleep(&uv_global_loop::get(), - (period * 1000f) as uint); + tm.sleep(period); profiler_chan.send(PrintMsg); } } }; - */ - fail!("stubbed out!"); // Create the compositor. let (compositor_port, compositor_chan) = comm::stream(); diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index a9b07e0b320..38f7901eafb 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -18,9 +18,12 @@ use js::{JSVAL_NULL, JSPROP_ENUMERATE}; use std::cast; use std::comm; -use std::comm::Chan; +use std::comm::SharedChan; use std::io; use std::ptr; +use std::int; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; use js::jsapi::JSVal; pub enum TimerControlMsg { @@ -35,7 +38,7 @@ pub struct Window { script_chan: ScriptChan, compositor: @ScriptListener, wrapper: WrapperCache, - timer_chan: Chan, + timer_chan: SharedChan, } #[unsafe_destructor] @@ -139,21 +142,19 @@ impl BindingObject for Window { impl Window { pub fn SetTimeout(&self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { - /* - let timeout = int::max(0, timeout) as uint; + let timeout = int::max(0, timeout) as u64; // Post a delayed message to the per-window timer task; it will dispatch it // to the relevant script handler that will deal with it. - let data = ~TimerData { - funval: callback, - args: ~[] - }; - timer::delayed_send(&uv_global_loop::get(), - timeout, - &self.timer_chan, - TimerMessage_Fire(data)); - */ - fail!("stubbed out!"); + let tm = Timer::new().unwrap(); + let chan = self.timer_chan.clone(); + do spawn { + tm.sleep(timeout); + chan.send(TimerMessage_Fire(~TimerData { + funval: callback, + args: ~[] + })); + } return 0; //TODO return handle into list of active timers } @@ -182,7 +183,7 @@ impl Window { } } } - timer_chan + SharedChan::new(timer_chan) }, };