Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using on_refresh_driver_tick #5681 #5753

Merged
merged 1 commit into from May 6, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Start using on_refresh_driver_tick #5681

Final
  • Loading branch information
JIoJIaJIu committed May 5, 2015
commit be2cb665de412c39748b925582646bc2d40725c2
@@ -27,6 +27,7 @@ use layers::rendergl;
use layers::scene::Scene;
use msg::compositor_msg::{Epoch, LayerId};
use msg::compositor_msg::{ReadyState, PaintState, ScrollPolicy};
use msg::constellation_msg::AnimationState;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, NavigationDirection};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
@@ -166,8 +167,11 @@ struct PipelineDetails {
/// The status of this pipeline's PaintTask.
paint_state: PaintState,

/// Whether animations are running.
/// Whether animations are running
animations_running: bool,

/// Whether there are animation callbacks
animation_callbacks_running: bool,
}

impl PipelineDetails {
@@ -177,6 +181,7 @@ impl PipelineDetails {
ready_state: ReadyState::Blank,
paint_state: PaintState::Painting,
animations_running: false,
animation_callbacks_running: false,
}
}
}
@@ -278,9 +283,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.change_paint_state(pipeline_id, paint_state);
}

(Msg::ChangeRunningAnimationsState(pipeline_id, running_animations),
(Msg::ChangeRunningAnimationsState(pipeline_id, animation_state),
ShutdownState::NotShuttingDown) => {
self.change_running_animations_state(pipeline_id, running_animations);
self.change_running_animations_state(pipeline_id, animation_state);
}

(Msg::ChangePageTitle(pipeline_id, title), ShutdownState::NotShuttingDown) => {
@@ -422,11 +427,22 @@ impl<Window: WindowMethods> IOCompositor<Window> {
/// recomposite if necessary.
fn change_running_animations_state(&mut self,
pipeline_id: PipelineId,
animations_running: bool) {
self.get_or_create_pipeline_details(pipeline_id).animations_running = animations_running;

if animations_running {
self.composite_if_necessary(CompositingReason::Animation);
animation_state: AnimationState) {
match animation_state {
AnimationState::AnimationsPresent => {
self.get_or_create_pipeline_details(pipeline_id).animations_running = true;
self.composite_if_necessary(CompositingReason::Animation);
}
AnimationState::AnimationCallbacksPresent => {
self.get_or_create_pipeline_details(pipeline_id).animation_callbacks_running = true;
self.composite_if_necessary(CompositingReason::Animation);
}
AnimationState::NoAnimationsPresent => {
self.get_or_create_pipeline_details(pipeline_id).animations_running = false;
}
AnimationState::NoAnimationCallbacksPresent => {
self.get_or_create_pipeline_details(pipeline_id).animation_callbacks_running = false;
}
}
}

@@ -921,10 +937,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
/// If there are any animations running, dispatches appropriate messages to the constellation.
fn process_animations(&mut self) {
for (pipeline_id, pipeline_details) in self.pipeline_details.iter() {
if !pipeline_details.animations_running {
continue
if pipeline_details.animations_running ||
pipeline_details.animation_callbacks_running {

self.constellation_chan.0.send(ConstellationMsg::TickAnimation(*pipeline_id)).unwrap();
}
self.constellation_chan.0.send(ConstellationMsg::TickAnimation(*pipeline_id)).unwrap();
}
}

@@ -19,7 +19,7 @@ use layers::platform::surface::{NativeCompositingGraphicsContext, NativeGraphics
use layers::layers::LayerBufferSet;
use msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
use msg::compositor_msg::{PaintListener, PaintState, ScriptListener, ScrollPolicy};
use msg::constellation_msg::{ConstellationChan, PipelineId};
use msg::constellation_msg::{AnimationState, ConstellationChan, PipelineId};
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
use profile_traits::mem;
use profile_traits::time;
@@ -202,7 +202,7 @@ pub enum Msg {
/// Alerts the compositor that the current page has changed its URL.
ChangePageUrl(PipelineId, Url),
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
ChangeRunningAnimationsState(PipelineId, bool),
ChangeRunningAnimationsState(PipelineId, AnimationState),
/// Alerts the compositor that a `PaintMsg` has been discarded.
PaintMsgDiscarded,
/// Replaces the current frame tree, typically called during main frame navigation.
@@ -14,6 +14,7 @@ use gfx::font_cache_task::FontCacheTask;
use layout_traits::{LayoutControlMsg, LayoutTaskFactory};
use libc;
use msg::compositor_msg::LayerId;
use msg::constellation_msg::AnimationState;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{FrameId, PipelineExitType, PipelineId};
use msg::constellation_msg::{IFrameSandboxState, MozBrowserEvent, NavigationDirection};
@@ -344,8 +345,8 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
sandbox);
}
ConstellationMsg::SetCursor(cursor) => self.handle_set_cursor_msg(cursor),
ConstellationMsg::ChangeRunningAnimationsState(pipeline_id, animations_running) => {
self.handle_change_running_animations_state(pipeline_id, animations_running)
ConstellationMsg::ChangeRunningAnimationsState(pipeline_id, animation_state) => {
self.handle_change_running_animations_state(pipeline_id, animation_state)
}
ConstellationMsg::TickAnimation(pipeline_id) => {
self.handle_tick_animation(pipeline_id)
@@ -560,9 +561,9 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {

fn handle_change_running_animations_state(&mut self,
pipeline_id: PipelineId,
animations_running: bool) {
animation_state: AnimationState) {
self.compositor_proxy.send(CompositorMsg::ChangeRunningAnimationsState(pipeline_id,
animations_running))
animation_state))
}

fn handle_tick_animation(&mut self, pipeline_id: PipelineId) {
@@ -5,15 +5,23 @@
use rustc_serialize::json;
use std::mem;
use std::net::TcpStream;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use time::precise_time_ns;

use msg::constellation_msg::PipelineId;
use actor::{Actor, ActorRegistry};
use actors::timeline::HighResolutionStamp;
use devtools_traits::{DevtoolsControlMsg, DevtoolScriptControlMsg};

pub struct FramerateActor {
name: String,
pipeline: PipelineId,
script_sender: Sender<DevtoolScriptControlMsg>,
devtools_sender: Sender<DevtoolsControlMsg>,
start_time: Option<u64>,
is_recording: bool,
ticks: Vec<u64>,
is_recording: Arc<Mutex<bool>>,
ticks: Arc<Mutex<Vec<HighResolutionStamp>>>,
}

impl Actor for FramerateActor {
@@ -33,50 +41,91 @@ impl Actor for FramerateActor {

impl FramerateActor {
/// return name of actor
pub fn create(registry: &ActorRegistry) -> String {
pub fn create(registry: &ActorRegistry,
pipeline_id: PipelineId,
script_sender: Sender<DevtoolScriptControlMsg>,
devtools_sender: Sender<DevtoolsControlMsg>) -> String {
let actor_name = registry.new_name("framerate");
let mut actor = FramerateActor {
name: actor_name.clone(),
pipeline: pipeline_id,
script_sender: script_sender,
devtools_sender: devtools_sender,
start_time: None,
is_recording: false,
ticks: Vec::new(),
is_recording: Arc::new(Mutex::new(false)),
ticks: Arc::new(Mutex::new(Vec::new())),
};

actor.start_recording();
registry.register_later(box actor);
actor_name
}

// callback on request animation frame
#[allow(dead_code)]
pub fn on_refresh_driver_tick(&mut self) {
if !self.is_recording {
return;
}
// TODO: Need implement requesting animation frame
// http://hg.mozilla.org/mozilla-central/file/0a46652bd992/dom/base/nsGlobalWindow.cpp#l5314

let start_time = self.start_time.as_ref().unwrap();
self.ticks.push(*start_time - precise_time_ns());
pub fn add_tick(&self, tick: f64) {
let mut lock = self.ticks.lock();
let mut ticks = lock.as_mut().unwrap();
ticks.push(HighResolutionStamp::wrap(tick));
}

pub fn take_pending_ticks(&mut self) -> Vec<u64> {
mem::replace(&mut self.ticks, Vec::new())
pub fn take_pending_ticks(&self) -> Vec<HighResolutionStamp> {
let mut lock = self.ticks.lock();
let mut ticks = lock.as_mut().unwrap();
mem::replace(ticks, Vec::new())
}

fn start_recording(&mut self) {
self.is_recording = true;
let mut lock = self.is_recording.lock();
if **lock.as_ref().unwrap() {
return;
}

self.start_time = Some(precise_time_ns());
let is_recording = lock.as_mut();
**is_recording.unwrap() = true;

fn get_closure(is_recording: Arc<Mutex<bool>>,
name: String,
pipeline: PipelineId,
script_sender: Sender<DevtoolScriptControlMsg>,
devtools_sender: Sender<DevtoolsControlMsg>)
-> Box<Fn(f64, ) + Send> {

let closure = move |now: f64| {
let msg = DevtoolsControlMsg::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 msg = DevtoolScriptControlMsg::RequestAnimationFrame(pipeline, closure);
script_sender.send(msg).unwrap();
};
Box::new(closure)
};

// TODO(#5681): Need implement requesting animation frame
// http://hg.mozilla.org/mozilla-central/file/0a46652bd992/dom/base/nsGlobalWindow.cpp#l5314
let closure = get_closure(self.is_recording.clone(),
self.name(),
self.pipeline.clone(),
self.script_sender.clone(),
self.devtools_sender.clone());
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline, closure);
self.script_sender.send(msg).unwrap();
}

fn stop_recording(&mut self) {
if !self.is_recording {
let mut lock = self.is_recording.lock();
if !**lock.as_ref().unwrap() {
return;
}
self.is_recording = false;

let is_recording = lock.as_mut();
**is_recording.unwrap() = false;
self.start_time = None;
}

@@ -16,7 +16,7 @@ use time::PreciseTime;
use actor::{Actor, ActorRegistry};
use actors::memory::{MemoryActor, TimelineMemoryReply};
use actors::framerate::FramerateActor;
use devtools_traits::DevtoolScriptControlMsg;
use devtools_traits::{DevtoolsControlMsg, DevtoolScriptControlMsg};
use devtools_traits::DevtoolScriptControlMsg::{SetTimelineMarkers, DropTimelineMarkers};
use devtools_traits::{TimelineMarker, TracingMetadata, TimelineMarkerType};
use protocol::JsonPacketStream;
@@ -25,6 +25,7 @@ use util::task;
pub struct TimelineActor {
name: String,
script_sender: Sender<DevtoolScriptControlMsg>,
devtools_sender: Sender<DevtoolsControlMsg>,
marker_types: Vec<TimelineMarkerType>,
pipeline: PipelineId,
is_recording: Arc<Mutex<bool>>,
@@ -93,21 +94,25 @@ struct FramerateEmitterReply {
__type__: String,
from: String,
delta: HighResolutionStamp,
timestamps: Vec<u64>,
timestamps: Vec<HighResolutionStamp>,
}

/// HighResolutionStamp is struct that contains duration in milliseconds
/// with accuracy to microsecond that shows how much time has passed since
/// actor registry inited
/// analog https://w3c.github.io/hr-time/#sec-DOMHighResTimeStamp
struct HighResolutionStamp(f64);
pub struct HighResolutionStamp(f64);

impl HighResolutionStamp {
fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
pub fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
let duration = start_stamp.to(time).num_microseconds()
.expect("Too big duration in microseconds");
HighResolutionStamp(duration as f64 / 1000 as f64)
}

pub fn wrap(time: f64) -> HighResolutionStamp {
HighResolutionStamp(time)
}
}

impl Encodable for HighResolutionStamp {
@@ -121,7 +126,8 @@ static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: u32 = 200; //ms
impl TimelineActor {
pub fn new(name: String,
pipeline: PipelineId,
script_sender: Sender<DevtoolScriptControlMsg>) -> TimelineActor {
script_sender: Sender<DevtoolScriptControlMsg>,
devtools_sender: Sender<DevtoolsControlMsg>) -> TimelineActor {

let marker_types = vec!(TimelineMarkerType::Reflow,
TimelineMarkerType::DOMEvent);
@@ -131,6 +137,7 @@ impl TimelineActor {
pipeline: pipeline,
marker_types: marker_types,
script_sender: script_sender,
devtools_sender: devtools_sender,
is_recording: Arc::new(Mutex::new(false)),
stream: RefCell::new(None),

@@ -248,7 +255,11 @@ impl Actor for TimelineActor {
// init framerate actor
if let Some(with_ticks) = msg.get("withTicks") {
if let Some(true) = with_ticks.as_boolean() {
*self.framerate_actor.borrow_mut() = Some(FramerateActor::create(registry));
let framerate_actor = Some(FramerateActor::create(registry,
self.pipeline.clone(),
self.script_sender.clone(),
self.devtools_sender.clone()));
*self.framerate_actor.borrow_mut() = framerate_actor;
}
}

@@ -352,7 +363,7 @@ impl Emitter {
if let Some(ref actor_name) = self.framerate_actor {
let mut lock = self.registry.lock();
let registry = lock.as_mut().unwrap();
let mut framerate_actor = registry.find_mut::<FramerateActor>(actor_name);
let framerate_actor = registry.find_mut::<FramerateActor>(actor_name);
let framerateReply = FramerateEmitterReply {
__type__: "framerate".to_string(),
from: framerate_actor.name(),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.