auto merge of #552 : metajack/servo/detect-page-loaded, r=pcwalton

This doesn't do anything, but adds the stuff to detect the page load. This will be needed to write out the composited texture to PNGs for reftests.

r? @sfowler
This commit is contained in:
bors-servo 2013-07-11 16:36:36 -07:00
commit 17fcf806ce
7 changed files with 56 additions and 12 deletions

View file

@ -12,12 +12,14 @@ use std::float;
use std::result;
use std::uint;
#[deriving(Clone)]
pub struct Opts {
urls: ~[~str],
render_backend: BackendType,
n_render_threads: uint,
tile_size: uint,
profiler_period: Option<float>,
exit_after_load: bool,
}
#[allow(non_implicitly_copyable_typarams)]
@ -32,6 +34,7 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
getopts::optopt("s"), // size of tiles
getopts::optopt("t"), // threads to render with
getopts::optflagopt("p"), // profiler flag and output interval
getopts::optflag("x"), // exit after load flag
];
let opt_match = match getopts::getopts(args, opts) {
@ -85,11 +88,14 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
None => None,
};
let exit_after_load = getopts::opt_present(&opt_match, "x");
Opts {
urls: urls,
render_backend: render_backend,
n_render_threads: n_render_threads,
tile_size: tile_size,
profiler_period: profiler_period,
exit_after_load: exit_after_load,
}
}

View file

@ -15,6 +15,7 @@ use servo_msg::compositor_msg::{ReadyState, ScriptListener};
use servo_msg::constellation_msg::{CompositorAck, ConstellationChan};
use servo_msg::constellation_msg;
use gfx::render_task::{RenderChan, ReRenderMsg};
use gfx::opts::Opts;
use azure::azure_hl::{DataSourceSurface, DrawTarget, SourceSurfaceMethods, current_gl_context};
use azure::azure::AzGLContext;
@ -162,17 +163,20 @@ impl ImageData for AzureDrawTargetImageData {
}
pub struct CompositorTask {
opts: Opts,
port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: SharedChan<()>,
}
impl CompositorTask {
pub fn new(port: Port<Msg>,
pub fn new(opts: Opts,
port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: Chan<()>)
-> CompositorTask {
CompositorTask {
opts: opts,
port: port,
profiler_chan: profiler_chan,
shutdown_chan: SharedChan::new(shutdown_chan),
@ -180,13 +184,16 @@ impl CompositorTask {
}
/// Starts the compositor, which listens for messages on the specified port.
pub fn create(port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: Chan<()>) {
pub fn create(opts: Opts,
port: Port<Msg>,
profiler_chan: ProfilerChan,
shutdown_chan: Chan<()>) {
let port = Cell::new(port);
let shutdown_chan = Cell::new(shutdown_chan);
let opts = Cell::new(opts);
do on_osmain {
let compositor_task = CompositorTask::new(port.take(),
let compositor_task = CompositorTask::new(opts.take(),
port.take(),
profiler_chan.clone(),
shutdown_chan.take());
debug!("preparing to enter main loop");
@ -499,8 +506,6 @@ impl CompositorTask {
*recomposite = true;
}
// When the user pinch-zooms, scale the layer
do window.set_zoom_callback |magnification| {
*zoom_action = true;
@ -540,6 +545,12 @@ impl CompositorTask {
*recomposite = true;
}
if self.opts.exit_after_load {
do window.set_finished_callback || {
*done = true;
}
}
// Enter the main event loop.
while !*done {
// Check for new messages coming from the rendering task.

View file

@ -4,7 +4,7 @@
//! A windowing implementation using GLFW.
use windowing::{ApplicationMethods, LoadUrlCallback, MouseCallback};
use windowing::{ApplicationMethods, LoadUrlCallback, MouseCallback, FinishedCallback};
use windowing::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent, WindowClickEvent};
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback, Forward, Back, NavigationCallback};
@ -13,7 +13,7 @@ use std::libc::c_int;
use geom::point::Point2D;
use geom::size::Size2D;
use servo_msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState};
use servo_msg::compositor_msg::{FinishedLoading, Loading, PerformingLayout, ReadyState};
use servo_msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState};
use glfw;
@ -45,6 +45,7 @@ pub struct Window {
scroll_callback: Option<ScrollCallback>,
zoom_callback: Option<ZoomCallback>,
navigation_callback: Option<NavigationCallback>,
finished_callback: Option<FinishedCallback>,
drag_origin: Point2D<c_int>,
@ -73,13 +74,14 @@ impl WindowMethods<Application> for Window {
scroll_callback: None,
zoom_callback: None,
navigation_callback: None,
finished_callback: None,
drag_origin: Point2D(0 as c_int, 0),
mouse_down_button: @mut 0,
mouse_down_point: @mut Point2D(0 as c_int, 0),
ready_state: FinishedLoading,
ready_state: Blank,
render_state: IdleRenderState,
throbber_frame: 0,
};
@ -153,6 +155,10 @@ impl WindowMethods<Application> for Window {
self.navigation_callback = Some(new_navigation_callback)
}
pub fn set_finished_callback(&mut self, new_finished_callback: FinishedCallback) {
self.finished_callback = Some(new_finished_callback)
}
/// Spins the event loop.
pub fn check_loop(@mut self) -> bool {
glfw::poll_events();
@ -169,6 +175,16 @@ impl WindowMethods<Application> for Window {
/// Sets the render state.
pub fn set_render_state(@mut self, render_state: RenderState) {
if self.ready_state == FinishedLoading &&
self.render_state == RenderingRenderState &&
render_state == IdleRenderState {
// page loaded
for self.finished_callback.iter().advance |&callback| {
callback();
}
}
self.render_state = render_state;
self.update_window_title()
}
@ -179,6 +195,9 @@ impl Window {
fn update_window_title(&self) {
let throbber = THROBBER[self.throbber_frame];
match self.ready_state {
Blank => {
self.glfw_window.set_title(fmt!("blank — Servo"));
}
Loading => {
self.glfw_window.set_title(fmt!("%c Loading — Servo", throbber))
}

View file

@ -118,7 +118,7 @@ fn run(opts: &Opts) {
// Create the compositor.
let (compositor_port, compositor_chan) = comm::stream();
let compositor_chan = CompositorChan::new(compositor_chan);
CompositorTask::create(compositor_port, profiler_chan.clone(), shutdown_chan);
CompositorTask::create(opts.clone(), compositor_port, profiler_chan.clone(), shutdown_chan);
// Create a Servo instance.

View file

@ -37,6 +37,9 @@ pub type ZoomCallback = @fn(f32);
/// Type of the function that is called when the user clicks backspace or shift-backspace
pub type NavigationCallback = @fn(WindowNavigateMsg);
/// Type of the function that is called when the rendering is finished
pub type FinishedCallback = @fn();
/// Methods for an abstract Application.
pub trait ApplicationMethods {
fn new() -> Self;
@ -62,6 +65,8 @@ pub trait WindowMethods<A> {
pub fn set_zoom_callback(&mut self, new_zoom_callback: ZoomCallback);
/// Registers a callback to run when the user presses backspace or shift-backspace.
pub fn set_navigation_callback(&mut self, new_navigation_callback: NavigationCallback);
/// Registers a callback to run when rendering is finished.
pub fn set_finished_callback(&mut self, new_finish_callback: FinishedCallback);
/// Spins the event loop. Returns whether the window should close.
pub fn check_loop(@mut self) -> bool;

View file

@ -40,7 +40,10 @@ pub enum RenderState {
RenderingRenderState,
}
#[deriving(Eq)]
pub enum ReadyState {
/// Informs the compositor that nothing has been done yet. Used for setting status
Blank,
/// Informs the compositor that a page is loading. Used for setting status
Loading,
/// Informs the compositor that a page is performing layout. Used for setting status

@ -1 +1 @@
Subproject commit ba24db51b38c9875e1356f7bc08c13a683071710
Subproject commit ae7c99be106e5767b0384f16887579d55e222e71