mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Simplify devtools frame marker notification. Record each frame tick based on a single message sent from the script task that ticked.
This commit is contained in:
parent
47b9e89c66
commit
e59de75608
8 changed files with 33 additions and 72 deletions
|
@ -22,7 +22,7 @@ pub struct FramerateActor {
|
||||||
script_sender: IpcSender<DevtoolScriptControlMsg>,
|
script_sender: IpcSender<DevtoolScriptControlMsg>,
|
||||||
devtools_sender: Sender<DevtoolsControlMsg>,
|
devtools_sender: Sender<DevtoolsControlMsg>,
|
||||||
start_time: Option<u64>,
|
start_time: Option<u64>,
|
||||||
is_recording: Arc<Mutex<bool>>,
|
is_recording: bool,
|
||||||
ticks: Arc<Mutex<Vec<HighResolutionStamp>>>,
|
ticks: Arc<Mutex<Vec<HighResolutionStamp>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ impl FramerateActor {
|
||||||
script_sender: script_sender,
|
script_sender: script_sender,
|
||||||
devtools_sender: devtools_sender,
|
devtools_sender: devtools_sender,
|
||||||
start_time: None,
|
start_time: None,
|
||||||
is_recording: Arc::new(Mutex::new(false)),
|
is_recording: false,
|
||||||
ticks: Arc::new(Mutex::new(Vec::new())),
|
ticks: Arc::new(Mutex::new(Vec::new())),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,6 +67,12 @@ impl FramerateActor {
|
||||||
let mut lock = self.ticks.lock();
|
let mut lock = self.ticks.lock();
|
||||||
let mut ticks = lock.as_mut().unwrap();
|
let mut ticks = lock.as_mut().unwrap();
|
||||||
ticks.push(HighResolutionStamp::wrap(tick));
|
ticks.push(HighResolutionStamp::wrap(tick));
|
||||||
|
|
||||||
|
if self.is_recording {
|
||||||
|
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline,
|
||||||
|
self.name());
|
||||||
|
self.script_sender.send(msg).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_pending_ticks(&self) -> Vec<HighResolutionStamp> {
|
pub fn take_pending_ticks(&self) -> Vec<HighResolutionStamp> {
|
||||||
|
@ -76,74 +82,23 @@ impl FramerateActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_recording(&mut self) {
|
fn start_recording(&mut self) {
|
||||||
let mut lock = self.is_recording.lock();
|
if self.is_recording {
|
||||||
if **lock.as_ref().unwrap() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.start_time = Some(precise_time_ns());
|
self.start_time = Some(precise_time_ns());
|
||||||
let is_recording = lock.as_mut();
|
self.is_recording = true;
|
||||||
**is_recording.unwrap() = true;
|
|
||||||
|
|
||||||
fn get_closure(is_recording: Arc<Mutex<bool>>,
|
|
||||||
name: String,
|
|
||||||
pipeline: PipelineId,
|
|
||||||
script_sender: IpcSender<DevtoolScriptControlMsg>,
|
|
||||||
devtools_sender: Sender<DevtoolsControlMsg>)
|
|
||||||
-> Box<Fn(f64, ) + Send> {
|
|
||||||
|
|
||||||
let closure = move |now: f64| {
|
|
||||||
let msg = DevtoolsControlMsg::FromChrome(ChromeToDevtoolsControlMsg::FramerateTick(
|
|
||||||
name.clone(), now));
|
|
||||||
devtools_sender.send(msg).unwrap();
|
|
||||||
|
|
||||||
if !*is_recording.lock().unwrap() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let closure = get_closure(is_recording.clone(),
|
|
||||||
name.clone(),
|
|
||||||
pipeline.clone(),
|
|
||||||
script_sender.clone(),
|
|
||||||
devtools_sender.clone());
|
|
||||||
let (request_animation_frame_sender, request_animation_frame_receiver) =
|
|
||||||
ipc::channel().unwrap();
|
|
||||||
ROUTER.add_route(request_animation_frame_receiver.to_opaque(), box move |message| {
|
|
||||||
let value: f64 = message.to().unwrap();
|
|
||||||
closure(value);
|
|
||||||
});
|
|
||||||
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(
|
|
||||||
pipeline,
|
|
||||||
request_animation_frame_sender);
|
|
||||||
script_sender.send(msg).unwrap();
|
|
||||||
};
|
|
||||||
Box::new(closure)
|
|
||||||
};
|
|
||||||
|
|
||||||
let closure = get_closure(self.is_recording.clone(),
|
|
||||||
self.name(),
|
|
||||||
self.pipeline.clone(),
|
|
||||||
self.script_sender.clone(),
|
|
||||||
self.devtools_sender.clone());
|
|
||||||
let (request_animation_frame_sender, request_animation_frame_receiver) =
|
|
||||||
ipc::channel().unwrap();
|
|
||||||
ROUTER.add_route(request_animation_frame_receiver.to_opaque(), box move |message| {
|
|
||||||
let value: f64 = message.to().unwrap();
|
|
||||||
closure(value);
|
|
||||||
});
|
|
||||||
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline,
|
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline,
|
||||||
request_animation_frame_sender);
|
self.name());
|
||||||
self.script_sender.send(msg).unwrap();
|
self.script_sender.send(msg).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_recording(&mut self) {
|
fn stop_recording(&mut self) {
|
||||||
let mut lock = self.is_recording.lock();
|
if !self.is_recording {
|
||||||
if !**lock.as_ref().unwrap() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
self.is_recording = false;
|
||||||
let is_recording = lock.as_mut();
|
|
||||||
**is_recording.unwrap() = false;
|
|
||||||
self.start_time = None;
|
self.start_time = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,7 +406,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
handle_client(actors, stream.try_clone().unwrap())
|
handle_client(actors, stream.try_clone().unwrap())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Ok(DevtoolsControlMsg::FromChrome(ChromeToDevtoolsControlMsg::FramerateTick(
|
Ok(DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::FramerateTick(
|
||||||
actor_name, tick))) =>
|
actor_name, tick))) =>
|
||||||
handle_framerate_tick(actors.clone(), actor_name, tick),
|
handle_framerate_tick(actors.clone(), actor_name, tick),
|
||||||
Ok(DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::NewGlobal(
|
Ok(DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::NewGlobal(
|
||||||
|
|
|
@ -59,9 +59,6 @@ pub enum DevtoolsControlMsg {
|
||||||
pub enum ChromeToDevtoolsControlMsg {
|
pub enum ChromeToDevtoolsControlMsg {
|
||||||
/// A new client has connected to the server.
|
/// A new client has connected to the server.
|
||||||
AddClient(TcpStream),
|
AddClient(TcpStream),
|
||||||
/// An animation frame with the given timestamp was processed in a script task.
|
|
||||||
/// The actor with the provided name should be notified.
|
|
||||||
FramerateTick(String, f64),
|
|
||||||
/// The browser is shutting down.
|
/// The browser is shutting down.
|
||||||
ServerExitMsg,
|
ServerExitMsg,
|
||||||
/// A network event occurred (request, reply, etc.). The actor with the
|
/// A network event occurred (request, reply, etc.). The actor with the
|
||||||
|
@ -79,6 +76,9 @@ pub enum ScriptToDevtoolsControlMsg {
|
||||||
DevtoolsPageInfo),
|
DevtoolsPageInfo),
|
||||||
/// A particular page has invoked the console API.
|
/// A particular page has invoked the console API.
|
||||||
ConsoleAPI(PipelineId, ConsoleMessage, Option<WorkerId>),
|
ConsoleAPI(PipelineId, ConsoleMessage, Option<WorkerId>),
|
||||||
|
/// An animation frame with the given timestamp was processed in a script task.
|
||||||
|
/// The actor with the provided name should be notified.
|
||||||
|
FramerateTick(String, f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialized JS return values
|
/// Serialized JS return values
|
||||||
|
@ -158,7 +158,7 @@ pub enum DevtoolScriptControlMsg {
|
||||||
WantsLiveNotifications(PipelineId, bool),
|
WantsLiveNotifications(PipelineId, bool),
|
||||||
SetTimelineMarkers(PipelineId, Vec<TimelineMarkerType>, IpcSender<TimelineMarker>),
|
SetTimelineMarkers(PipelineId, Vec<TimelineMarkerType>, IpcSender<TimelineMarker>),
|
||||||
DropTimelineMarkers(PipelineId, Vec<TimelineMarkerType>),
|
DropTimelineMarkers(PipelineId, Vec<TimelineMarkerType>),
|
||||||
RequestAnimationFrame(PipelineId, IpcSender<f64>),
|
RequestAnimationFrame(PipelineId, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable, Deserialize, Serialize)]
|
#[derive(RustcEncodable, Deserialize, Serialize)]
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
|
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
|
||||||
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
|
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
|
||||||
use devtools_traits::{ConsoleAPI, PageError};
|
use devtools_traits::{ConsoleAPI, PageError, ScriptToDevtoolsControlMsg};
|
||||||
use dom::bindings::conversions::jsstring_to_str;
|
use dom::bindings::conversions::jsstring_to_str;
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
use dom::bindings::conversions::FromJSValConvertible;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -202,10 +202,13 @@ pub fn handle_drop_timeline_markers(page: &Rc<Page>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_request_animation_frame(page: &Rc<Page>, id: PipelineId, callback: IpcSender<f64>) {
|
pub fn handle_request_animation_frame(page: &Rc<Page>, id: PipelineId, actor_name: String) {
|
||||||
let page = page.find(id).expect("There is no such page");
|
let page = page.find(id).expect("There is no such page");
|
||||||
let doc = page.document();
|
let doc = page.document();
|
||||||
|
let devtools_sender = page.window().devtools_chan();
|
||||||
doc.r().request_animation_frame(box move |time| {
|
doc.r().request_animation_frame(box move |time| {
|
||||||
callback.send(time).unwrap()
|
devtools_sender.unwrap()
|
||||||
|
.send(ScriptToDevtoolsControlMsg::FramerateTick(actor_name, time))
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ use net_traits::image::base::Image;
|
||||||
use profile_traits::mem::ProfilerChan;
|
use profile_traits::mem::ProfilerChan;
|
||||||
use util::str::{LengthOrPercentageOrAuto};
|
use util::str::{LengthOrPercentageOrAuto};
|
||||||
use selectors::parser::PseudoElement;
|
use selectors::parser::PseudoElement;
|
||||||
|
use std::boxed::FnBox;
|
||||||
use std::cell::{Cell, UnsafeCell, RefCell};
|
use std::cell::{Cell, UnsafeCell, RefCell};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::collections::hash_state::HashState;
|
use std::collections::hash_state::HashState;
|
||||||
|
@ -314,7 +315,7 @@ impl JSTraceable for Box<ScriptChan+Send> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JSTraceable for Box<Fn(f64, )> {
|
impl JSTraceable for Box<FnBox(f64, )> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trace(&self, _trc: *mut JSTracer) {
|
fn trace(&self, _trc: *mut JSTracer) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|
|
@ -94,6 +94,7 @@ use js::jsapi::{JSContext, JSObject, JSRuntime};
|
||||||
use num::ToPrimitive;
|
use num::ToPrimitive;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use std::boxed::FnBox;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
@ -148,7 +149,7 @@ pub struct Document {
|
||||||
/// https://html.spec.whatwg.org/multipage/#list-of-animation-frame-callbacks
|
/// https://html.spec.whatwg.org/multipage/#list-of-animation-frame-callbacks
|
||||||
/// List of animation frame callbacks
|
/// List of animation frame callbacks
|
||||||
#[ignore_heap_size_of = "closures are hard"]
|
#[ignore_heap_size_of = "closures are hard"]
|
||||||
animation_frame_list: RefCell<HashMap<i32, Box<Fn(f64)>>>,
|
animation_frame_list: RefCell<HashMap<i32, Box<FnBox(f64)>>>,
|
||||||
/// Tracks all outstanding loads related to this document.
|
/// Tracks all outstanding loads related to this document.
|
||||||
loader: DOMRefCell<DocumentLoader>,
|
loader: DOMRefCell<DocumentLoader>,
|
||||||
/// The current active HTML parser, to allow resuming after interruptions.
|
/// The current active HTML parser, to allow resuming after interruptions.
|
||||||
|
@ -292,7 +293,7 @@ pub trait DocumentHelpers<'a> {
|
||||||
fn set_current_script(self, script: Option<&HTMLScriptElement>);
|
fn set_current_script(self, script: Option<&HTMLScriptElement>);
|
||||||
fn trigger_mozbrowser_event(self, event: MozBrowserEvent);
|
fn trigger_mozbrowser_event(self, event: MozBrowserEvent);
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
||||||
fn request_animation_frame(self, callback: Box<Fn(f64, )>) -> i32;
|
fn request_animation_frame(self, callback: Box<FnBox(f64, )>) -> i32;
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe
|
/// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe
|
||||||
fn cancel_animation_frame(self, ident: i32);
|
fn cancel_animation_frame(self, ident: i32);
|
||||||
/// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks
|
/// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks
|
||||||
|
@ -949,7 +950,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
||||||
fn request_animation_frame(self, callback: Box<Fn(f64, )>) -> i32 {
|
fn request_animation_frame(self, callback: Box<FnBox(f64)>) -> i32 {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let ident = self.animation_frame_ident.get() + 1;
|
let ident = self.animation_frame_ident.get() + 1;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#![feature(custom_attribute)]
|
#![feature(custom_attribute)]
|
||||||
#![feature(custom_derive)]
|
#![feature(custom_derive)]
|
||||||
#![feature(drain)]
|
#![feature(drain)]
|
||||||
|
#![feature(fnbox)]
|
||||||
#![feature(hashmap_hasher)]
|
#![feature(hashmap_hasher)]
|
||||||
#![feature(mpsc_select)]
|
#![feature(mpsc_select)]
|
||||||
#![feature(nonzero)]
|
#![feature(nonzero)]
|
||||||
|
|
|
@ -914,8 +914,8 @@ impl ScriptTask {
|
||||||
devtools::handle_set_timeline_markers(&page, self, marker_types, reply),
|
devtools::handle_set_timeline_markers(&page, self, marker_types, reply),
|
||||||
DevtoolScriptControlMsg::DropTimelineMarkers(_pipeline_id, marker_types) =>
|
DevtoolScriptControlMsg::DropTimelineMarkers(_pipeline_id, marker_types) =>
|
||||||
devtools::handle_drop_timeline_markers(&page, self, marker_types),
|
devtools::handle_drop_timeline_markers(&page, self, marker_types),
|
||||||
DevtoolScriptControlMsg::RequestAnimationFrame(pipeline_id, callback) =>
|
DevtoolScriptControlMsg::RequestAnimationFrame(pipeline_id, name) =>
|
||||||
devtools::handle_request_animation_frame(&page, pipeline_id, callback),
|
devtools::handle_request_animation_frame(&page, pipeline_id, name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue