Use opts as a global, to avoid cloning and passing the struct all over the code.

This commit is contained in:
Glenn Watson 2014-10-20 10:43:49 +10:00
parent a983debaf1
commit 076495db94
20 changed files with 108 additions and 132 deletions

View file

@ -42,7 +42,7 @@ use servo_msg::constellation_msg::{LoadData, PipelineId, ResizedWindowMsg, Windo
use servo_msg::constellation_msg;
use servo_util::geometry::{PagePx, ScreenPx, ViewportPx};
use servo_util::memory::MemoryProfilerChan;
use servo_util::opts::Opts;
use servo_util::opts;
use servo_util::time::{profile, TimeProfilerChan};
use servo_util::{memory, time};
use std::io::timer::sleep;
@ -112,9 +112,6 @@ pub struct IOCompositor<Window: WindowMethods> {
/// many times for a single page.
got_load_complete_message: bool,
/// The command line option flags.
opts: Opts,
/// The channel on which messages can be sent to the constellation.
constellation_chan: ConstellationChan,
@ -137,7 +134,6 @@ enum ShutdownState {
impl<Window: WindowMethods> IOCompositor<Window> {
fn new(window: Rc<Window>,
opts: Opts,
port: Receiver<Msg>,
constellation_chan: ConstellationChan,
time_profiler_chan: TimeProfilerChan,
@ -150,11 +146,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let window_size = window.framebuffer_size();
let hidpi_factor = window.hidpi_factor();
let show_debug_borders = opts.show_debug_borders;
let show_debug_borders = opts::get().show_debug_borders;
IOCompositor {
window: window,
port: port,
opts: opts,
context: rendergl::RenderContext::new(CompositorTask::create_graphics_context(),
show_debug_borders),
root_pipeline: None,
@ -183,13 +178,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
pub fn create(window: Rc<Window>,
opts: Opts,
port: Receiver<Msg>,
constellation_chan: ConstellationChan,
time_profiler_chan: TimeProfilerChan,
memory_profiler_chan: MemoryProfilerChan) {
let mut compositor = IOCompositor::new(window,
opts,
port,
constellation_chan,
time_profiler_chan,
@ -373,7 +366,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn has_render_msg_tracking(&self) -> bool {
// only track RenderMsg's if the compositor outputs to a file.
self.opts.output_file.is_some()
opts::get().output_file.is_some()
}
fn has_outstanding_render_msgs(&self) -> bool {
@ -440,7 +433,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let root_layer = CompositorData::new_layer(frame_tree.pipeline.clone(),
layer_properties,
WantsScrollEvents,
self.opts.tile_size);
opts::get().tile_size);
match frame_rect {
Some(ref frame_rect) => {
@ -500,7 +493,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let first_child = CompositorData::new_layer(root_layer_pipeline.clone(),
layer_properties,
DoesntWantScrollEvents,
self.opts.tile_size);
opts::get().tile_size);
// Add the first child / base layer to the front of the child list, so that
// child iframe layers are rendered on top of the base layer. These iframe
@ -671,7 +664,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
FinishedWindowEvent => {
let exit = self.opts.exit_after_load;
let exit = opts::get().exit_after_load;
if exit {
debug!("shutting down the constellation for FinishedWindowEvent");
let ConstellationChan(ref chan) = self.constellation_chan;
@ -758,9 +751,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
fn device_pixels_per_screen_px(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32> {
match self.opts.device_pixels_per_px {
match opts::get().device_pixels_per_px {
Some(device_pixels_per_px) => device_pixels_per_px,
None => match self.opts.output_file {
None => match opts::get().output_file {
Some(_) => ScaleFactor(1.0),
None => self.hidpi_factor
}
@ -917,7 +910,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
fn composite(&mut self) {
let output_image = self.opts.output_file.is_some() &&
let output_image = opts::get().output_file.is_some() &&
self.is_ready_to_render_image_output();
let mut framebuffer_ids = vec!();
@ -959,7 +952,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
});
if output_image {
let path = from_str::<Path>(self.opts.output_file.as_ref().unwrap().as_slice()).unwrap();
let path = from_str::<Path>(opts::get().output_file.as_ref().unwrap().as_slice()).unwrap();
let mut pixels = gl2::read_pixels(0, 0,
width as gl2::GLsizei,
height as gl2::GLsizei,
@ -998,7 +991,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.window.present();
let exit = self.opts.exit_after_load;
let exit = opts::get().exit_after_load;
if exit {
debug!("shutting down the constellation for exit_after_load");
let ConstellationChan(ref chan) = self.constellation_chan;

View file

@ -19,7 +19,6 @@ use servo_msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
use servo_msg::compositor_msg::{RenderListener, RenderState, ScriptListener, ScrollPolicy};
use servo_msg::constellation_msg::{ConstellationChan, PipelineId};
use servo_util::memory::MemoryProfilerChan;
use servo_util::opts::Opts;
use servo_util::time::TimeProfilerChan;
use std::comm::{channel, Sender, Receiver};
use std::rc::Rc;
@ -200,7 +199,6 @@ impl CompositorTask {
pub fn create<Window: WindowMethods>(
window: Option<Rc<Window>>,
opts: Opts,
port: Receiver<Msg>,
constellation_chan: ConstellationChan,
time_profiler_chan: TimeProfilerChan,
@ -209,7 +207,6 @@ impl CompositorTask {
match window {
Some(window) => {
compositor::IOCompositor::create(window,
opts,
port,
constellation_chan.clone(),
time_profiler_chan,

View file

@ -25,7 +25,7 @@ use gfx::font_cache_task::FontCacheTask;
use servo_net::resource_task::ResourceTask;
use servo_net::resource_task;
use servo_util::geometry::PagePx;
use servo_util::opts::Opts;
use servo_util::opts;
use servo_util::time::TimeProfilerChan;
use servo_util::task::spawn_named;
use std::cell::RefCell;
@ -50,7 +50,6 @@ pub struct Constellation<LTF, STF> {
pending_sizes: HashMap<(PipelineId, SubpageId), TypedRect<PagePx, f32>>,
pub time_profiler_chan: TimeProfilerChan,
pub window_size: WindowSizeData,
pub opts: Opts,
}
/// Stores the Id of the outermost frame's pipeline, along with a vector of children frames
@ -241,7 +240,6 @@ impl NavigationContext {
impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
pub fn start(compositor_chan: CompositorChan,
opts: &Opts,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
@ -250,7 +248,6 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
-> ConstellationChan {
let (constellation_port, constellation_chan) = ConstellationChan::new();
let constellation_chan_clone = constellation_chan.clone();
let opts_clone = opts.clone();
spawn_named("Constellation", proc() {
let mut constellation : Constellation<LTF, STF> = Constellation {
chan: constellation_chan_clone,
@ -267,11 +264,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
pending_sizes: HashMap::new(),
time_profiler_chan: time_profiler_chan,
window_size: WindowSizeData {
visible_viewport: opts_clone.initial_window_size.as_f32() * ScaleFactor(1.0),
initial_viewport: opts_clone.initial_window_size.as_f32() * ScaleFactor(1.0),
visible_viewport: opts::get().initial_window_size.as_f32() * ScaleFactor(1.0),
initial_viewport: opts::get().initial_window_size.as_f32() * ScaleFactor(1.0),
device_pixel_ratio: ScaleFactor(1.0),
},
opts: opts_clone,
};
constellation.run();
});
@ -304,7 +300,6 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
self.resource_task.clone(),
self.time_profiler_chan.clone(),
self.window_size,
self.opts.clone(),
script_pipeline,
load_data);
pipe.load();
@ -405,7 +400,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
fn handle_failure_msg(&mut self, pipeline_id: PipelineId, subpage_id: Option<SubpageId>) {
debug!("handling failure message from pipeline {:?}, {:?}", pipeline_id, subpage_id);
if self.opts.hard_fail {
if opts::get().hard_fail {
// It's quite difficult to make Servo exit cleanly if some tasks have failed.
// Hard fail exists for test runners so we crash and that's good enough.
let mut stderr = io::stderr();

View file

@ -15,7 +15,6 @@ use servo_msg::constellation_msg::{LoadData, WindowSizeData};
use servo_net::image_cache_task::ImageCacheTask;
use gfx::font_cache_task::FontCacheTask;
use servo_net::resource_task::ResourceTask;
use servo_util::opts::Opts;
use servo_util::time::TimeProfilerChan;
use std::rc::Rc;
@ -55,7 +54,6 @@ impl Pipeline {
resource_task: ResourceTask,
time_profiler_chan: TimeProfilerChan,
window_size: WindowSizeData,
opts: Opts,
script_pipeline: Option<Rc<Pipeline>>,
load_data: LoadData)
-> Pipeline {
@ -107,7 +105,6 @@ impl Pipeline {
constellation_chan.clone(),
font_cache_task.clone(),
failure.clone(),
opts.clone(),
time_profiler_chan.clone(),
render_shutdown_chan);
@ -122,7 +119,6 @@ impl Pipeline {
resource_task,
image_cache_task,
font_cache_task,
opts.clone(),
time_profiler_chan,
layout_shutdown_chan);

View file

@ -25,6 +25,7 @@ use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D};
use libc::uintptr_t;
use servo_net::image::base::Image;
use servo_util::geometry::Au;
use servo_util::opts;
use servo_util::range::Range;
use std::fmt;
use std::mem;
@ -562,7 +563,7 @@ impl DisplayItem {
&text.range,
baseline_origin,
text.text_color,
render_context.opts.enable_text_antialiasing
opts::get().enable_text_antialiasing
);
// Undo the transform, only when we did one.

View file

@ -18,13 +18,11 @@ use libc::size_t;
use png::{RGB8, RGBA8, K8, KA8};
use servo_net::image::base::Image;
use servo_util::geometry::Au;
use servo_util::opts::Opts;
use sync::Arc;
pub struct RenderContext<'a> {
pub draw_target: &'a DrawTarget,
pub font_ctx: &'a mut Box<FontContext>,
pub opts: &'a Opts,
/// The rectangle that this context encompasses in page coordinates.
pub page_rect: Rect<f32>,
/// The rectangle that this context encompasses in screen coordinates (pixels).

View file

@ -26,7 +26,7 @@ use servo_msg::constellation_msg::{ConstellationChan, Failure, FailureMsg, Pipel
use servo_msg::constellation_msg::{RendererReadyMsg};
use servo_msg::platform::surface::NativeSurfaceAzureMethods;
use servo_util::geometry::{Au, mod};
use servo_util::opts::Opts;
use servo_util::opts;
use servo_util::smallvec::{SmallVec, SmallVec1};
use servo_util::task::spawn_named_with_send_on_failure;
use servo_util::time::{TimeProfilerChan, profile};
@ -99,7 +99,6 @@ pub struct RenderTask<C> {
compositor: C,
constellation_chan: ConstellationChan,
font_ctx: Box<FontContext>,
opts: Opts,
/// A channel to the time profiler.
time_profiler_chan: TimeProfilerChan,
@ -154,7 +153,6 @@ impl<C:RenderListener + Send> RenderTask<C> {
constellation_chan: ConstellationChan,
font_cache_task: FontCacheTask,
failure_msg: Failure,
opts: Opts,
time_profiler_chan: TimeProfilerChan,
shutdown_chan: Sender<()>) {
@ -165,7 +163,7 @@ impl<C:RenderListener + Send> RenderTask<C> {
{ // Ensures RenderTask and graphics context are destroyed before shutdown msg
let native_graphics_context = compositor.get_graphics_metadata().map(
|md| NativePaintingGraphicsContext::from_metadata(&md));
let cpu_painting = opts.cpu_painting;
let cpu_painting = opts::get().cpu_painting;
// FIXME: rust/#5967
let mut render_task = RenderTask {
@ -174,7 +172,6 @@ impl<C:RenderListener + Send> RenderTask<C> {
compositor: compositor,
constellation_chan: constellation_chan,
font_ctx: box FontContext::new(fc.clone()),
opts: opts,
time_profiler_chan: time_profiler_chan,
graphics_context: if cpu_painting {
@ -342,7 +339,6 @@ impl<C:RenderListener + Send> RenderTask<C> {
let mut ctx = RenderContext {
draw_target: &draw_target,
font_ctx: &mut self.font_ctx,
opts: &self.opts,
page_rect: tile.page_rect,
screen_rect: tile.screen_rect,
};

View file

@ -58,6 +58,7 @@ use script::dom::node::{CommentNodeTypeId, DoctypeNodeTypeId, DocumentFragmentNo
use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId};
use script::dom::node::{TextNodeTypeId};
use script::dom::htmlobjectelement::is_image_data;
use servo_util::opts;
use std::mem;
use std::sync::atomics::Relaxed;
use style::ComputedValues;
@ -83,8 +84,8 @@ pub enum ConstructionResult {
}
impl ConstructionResult {
pub fn swap_out(&mut self, layout_context: &LayoutContext) -> ConstructionResult {
if layout_context.shared.opts.incremental_layout {
pub fn swap_out(&mut self) -> ConstructionResult {
if opts::get().incremental_layout {
return (*self).clone();
}
@ -352,7 +353,7 @@ impl<'a> FlowConstructor<'a> {
inline_flow.minimum_depth_below_baseline = descent;
}
inline_flow_ref.finish(self.layout_context);
inline_flow_ref.finish();
if flow.need_anonymous_flow(&*inline_flow_ref) {
flow_list.push(inline_flow_ref)
@ -370,7 +371,7 @@ impl<'a> FlowConstructor<'a> {
&mut InlineFragmentsAccumulator,
abs_descendants: &mut Descendants,
first_fragment: &mut bool) {
match kid.swap_out_construction_result(self.layout_context) {
match kid.swap_out_construction_result() {
NoConstructionResult => {}
FlowConstructionResult(kid_flow, kid_abs_descendants) => {
// If kid_flow is TableCaptionFlow, kid_flow should be added under
@ -522,7 +523,7 @@ impl<'a> FlowConstructor<'a> {
}
// The flow is done.
flow.finish(self.layout_context);
flow.finish();
// Set up the absolute descendants.
let is_positioned = flow.as_block().is_positioned();
@ -573,7 +574,7 @@ impl<'a> FlowConstructor<'a> {
if kid.get_pseudo_element_type() != Normal {
self.process(&kid);
}
match kid.swap_out_construction_result(self.layout_context) {
match kid.swap_out_construction_result() {
NoConstructionResult => {}
FlowConstructionResult(flow, kid_abs_descendants) => {
// {ib} split. Flush the accumulator to our new split and make a new
@ -757,7 +758,7 @@ impl<'a> FlowConstructor<'a> {
table_wrapper_flow: &mut FlowRef,
node: &ThreadSafeLayoutNode) {
for kid in node.children() {
match kid.swap_out_construction_result(self.layout_context) {
match kid.swap_out_construction_result() {
NoConstructionResult | ConstructionItemConstructionResult(_) => {}
FlowConstructionResult(kid_flow, _) => {
// Only kid flows with table-caption are matched here.
@ -794,7 +795,7 @@ impl<'a> FlowConstructor<'a> {
self.generate_anonymous_missing_child(consecutive_siblings, &mut anonymous_flow, node);
}
// The flow is done.
anonymous_flow.finish(self.layout_context);
anonymous_flow.finish();
flow.add_new_child(anonymous_flow);
}
@ -836,7 +837,7 @@ impl<'a> FlowConstructor<'a> {
}
// The flow is done.
wrapper_flow.finish(self.layout_context);
wrapper_flow.finish();
let is_positioned = wrapper_flow.as_block().is_positioned();
let is_fixed_positioned = wrapper_flow.as_block().is_fixed();
let is_absolutely_positioned = wrapper_flow.as_block().is_absolutely_positioned();
@ -918,7 +919,7 @@ impl<'a> FlowConstructor<'a> {
for kid in node.children() {
// CSS 2.1 § 17.2.1. Treat all non-column child fragments of `table-column-group`
// as `display: none`.
match kid.swap_out_construction_result(self.layout_context) {
match kid.swap_out_construction_result() {
ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(
fragment)) => {
col_fragments.push(fragment);
@ -933,7 +934,7 @@ impl<'a> FlowConstructor<'a> {
}
let flow = box TableColGroupFlow::from_node_and_fragments(node, fragment, col_fragments);
let mut flow = FlowRef::new(flow as Box<Flow>);
flow.finish(self.layout_context);
flow.finish();
FlowConstructionResult(flow, Descendants::new())
}
@ -987,7 +988,7 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
// results of children.
(display::none, _, _) => {
for child in node.children() {
drop(child.swap_out_construction_result(self.layout_context))
drop(child.swap_out_construction_result())
}
}
@ -1099,7 +1100,7 @@ trait NodeUtils {
/// Replaces the flow construction result in a node with `NoConstructionResult` and returns the
/// old value.
fn swap_out_construction_result(self, layout_context: &LayoutContext) -> ConstructionResult;
fn swap_out_construction_result(self) -> ConstructionResult;
}
impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
@ -1137,11 +1138,11 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
}
#[inline(always)]
fn swap_out_construction_result(self, layout_context: &LayoutContext) -> ConstructionResult {
fn swap_out_construction_result(self) -> ConstructionResult {
let mut layout_data_ref = self.mutate_layout_data();
let layout_data = layout_data_ref.as_mut().expect("no layout data");
self.get_construction_result(layout_data).swap_out(layout_context)
self.get_construction_result(layout_data).swap_out()
}
}
@ -1189,7 +1190,7 @@ pub trait FlowConstructionUtils {
///
/// All flows must be finished at some point, or they will not have their intrinsic inline-sizes
/// properly computed. (This is not, however, a memory safety problem.)
fn finish(&mut self, context: &LayoutContext);
fn finish(&mut self);
}
impl FlowConstructionUtils for FlowRef {
@ -1216,8 +1217,8 @@ impl FlowConstructionUtils for FlowRef {
/// properly computed. (This is not, however, a memory safety problem.)
///
/// This must not be public because only the layout constructor can do this.
fn finish(&mut self, context: &LayoutContext) {
if !context.shared.opts.bubble_inline_sizes_separately {
fn finish(&mut self) {
if !opts::get().bubble_inline_sizes_separately {
self.bubble_inline_sizes()
}
}

View file

@ -15,7 +15,6 @@ use script_traits::UntrustedNodeAddress;
use servo_msg::constellation_msg::ConstellationChan;
use servo_net::local_image_cache::LocalImageCache;
use servo_util::geometry::Au;
use servo_util::opts::Opts;
use sync::{Arc, Mutex};
use std::mem;
use style::Stylist;
@ -75,9 +74,6 @@ pub struct SharedLayoutContext {
/// The URL.
pub url: Url,
/// The command line options.
pub opts: Opts,
/// The dirty rectangle, used during display list building.
pub dirty: Rect<Au>,

View file

@ -7,7 +7,7 @@
use css::node_style::StyledNode;
use construct::FlowConstructionResult;
use context::{LayoutContext, SharedLayoutContext};
use context::SharedLayoutContext;
use flow::{Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
use flow;
use flow_ref::FlowRef;
@ -50,7 +50,7 @@ use servo_net::resource_task::{ResourceTask, load_bytes_iter};
use servo_util::geometry::Au;
use servo_util::geometry;
use servo_util::logical_geometry::LogicalPoint;
use servo_util::opts::Opts;
use servo_util::opts;
use servo_util::smallvec::{SmallVec, SmallVec1, VecLike};
use servo_util::task::spawn_named_with_send_on_failure;
use servo_util::time::{TimeProfilerChan, profile};
@ -130,9 +130,6 @@ pub struct LayoutTask {
/// Public interface to the font cache task.
pub font_cache_task: FontCacheTask,
/// The command-line options.
pub opts: Opts,
/// Is this the first reflow in this LayoutTask?
pub first_reflow: Cell<bool>,
@ -181,7 +178,6 @@ impl LayoutTaskFactory for LayoutTask {
resource_task: ResourceTask,
img_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
opts: Opts,
time_profiler_chan: TimeProfilerChan,
shutdown_chan: Sender<()>) {
let ConstellationChan(con_chan) = constellation_chan.clone();
@ -200,7 +196,6 @@ impl LayoutTaskFactory for LayoutTask {
resource_task,
img_cache_task,
font_cache_task,
&opts,
time_profiler_chan);
layout.start();
}
@ -250,14 +245,13 @@ impl LayoutTask {
resource_task: ResourceTask,
image_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
opts: &Opts,
time_profiler_chan: TimeProfilerChan)
-> LayoutTask {
let local_image_cache = Arc::new(Mutex::new(LocalImageCache::new(image_cache_task.clone())));
let screen_size = Size2D(Au(0), Au(0));
let device = Device::new(Screen, opts.initial_window_size.as_f32());
let parallel_traversal = if opts.layout_threads != 1 {
Some(WorkQueue::new("LayoutWorker", opts.layout_threads, ptr::null()))
let device = Device::new(Screen, opts::get().initial_window_size.as_f32());
let parallel_traversal = if opts::get().layout_threads != 1 {
Some(WorkQueue::new("LayoutWorker", opts::get().layout_threads, ptr::null()))
} else {
None
};
@ -274,7 +268,6 @@ impl LayoutTask {
resource_task: resource_task,
image_cache_task: image_cache_task.clone(),
font_cache_task: font_cache_task,
opts: opts.clone(),
first_reflow: Cell::new(true),
device: device,
rw_data: Arc::new(Mutex::new(
@ -315,7 +308,6 @@ impl LayoutTask {
stylist: &*rw_data.stylist,
url: (*url).clone(),
reflow_root: OpaqueNodeMethods::from_layout_node(reflow_root),
opts: self.opts.clone(),
dirty: Rect::zero(),
generation: rw_data.generation,
}
@ -484,11 +476,11 @@ impl LayoutTask {
}
/// Retrieves the flow tree root from the root node.
fn get_layout_root(&self, node: LayoutNode, layout_context: &LayoutContext) -> FlowRef {
fn get_layout_root(&self, node: LayoutNode) -> FlowRef {
let mut layout_data_ref = node.mutate_layout_data();
let layout_data = layout_data_ref.as_mut().expect("no layout data for root node");
let result = layout_data.data.flow_construction_result.swap_out(layout_context);
let result = layout_data.data.flow_construction_result.swap_out();
let mut flow = match result {
FlowConstructionResult(mut flow, abs_descendants) => {
@ -628,7 +620,7 @@ impl LayoutTask {
}
}
self.get_layout_root((*node).clone(), &LayoutContext::new(&shared_layout_ctx))
self.get_layout_root((*node).clone())
});
profile(time::LayoutRestyleDamagePropagation,
@ -642,7 +634,7 @@ impl LayoutTask {
Some((&data.url, data.iframe, self.first_reflow.get())),
self.time_profiler_chan.clone(),
|| {
if shared_layout_ctx.opts.incremental_layout {
if opts::get().incremental_layout {
layout_root.nonincremental_reset();
}
});
@ -652,7 +644,7 @@ impl LayoutTask {
// memory safety but is a useful debugging tool.)
self.verify_flow_tree(&mut layout_root);
if self.opts.trace_layout {
if opts::get().trace_layout {
layout_debug::begin_trace(layout_root.clone());
}
@ -673,7 +665,7 @@ impl LayoutTask {
}
});
if self.opts.dump_flow_tree {
if opts::get().dump_flow_tree {
layout_root.dump();
}
@ -772,11 +764,11 @@ impl LayoutTask {
self.first_reflow.set(false);
if self.opts.trace_layout {
if opts::get().trace_layout {
layout_debug::end_trace();
}
if self.opts.dump_flow_tree {
if opts::get().dump_flow_tree {
layout_root.dump();
}

View file

@ -19,6 +19,7 @@ use wrapper::{layout_node_to_unsafe_layout_node, layout_node_from_unsafe_layout_
use wrapper::{PostorderNodeMutTraversal, UnsafeLayoutNode};
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};
use servo_util::opts;
use servo_util::time::{TimeProfilerChan, profile};
use servo_util::time;
use servo_util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
@ -427,7 +428,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
time_profiler_chan: TimeProfilerChan,
shared_layout_context: &SharedLayoutContext,
queue: &mut WorkQueue<*const SharedLayoutContext,UnsafeFlow>) {
if shared_layout_context.opts.bubble_inline_sizes_separately {
if opts::get().bubble_inline_sizes_separately {
let layout_context = LayoutContext::new(shared_layout_context);
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
root.traverse_postorder(&bubble_inline_sizes);

View file

@ -8,6 +8,7 @@ use context::{LayoutContext, SharedLayoutContext};
use flow::{Flow, MutableFlowUtils, PreorderFlowTraversal, PostorderFlowTraversal};
use flow;
use flow_ref::FlowRef;
use servo_util::opts;
use traversal::{BubbleISizes, RecalcStyleForNode, ConstructFlows};
use traversal::{AssignBSizesAndStoreOverflow, AssignISizes};
use traversal::{ComputeAbsolutePositions, BuildDisplayList};
@ -54,7 +55,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
let root = root.deref_mut();
if layout_context.shared.opts.bubble_inline_sizes_separately {
if opts::get().bubble_inline_sizes_separately {
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
root.traverse_postorder(&bubble_inline_sizes);
}

View file

@ -16,6 +16,7 @@ use wrapper::{PostorderNodeMutTraversal, ThreadSafeLayoutNode, UnsafeLayoutNode}
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};
use servo_util::bloom::BloomFilter;
use servo_util::opts;
use servo_util::tid::tid;
use style::TNode;
@ -204,7 +205,7 @@ impl<'a> PostorderDomTraversal for ConstructFlows<'a> {
let tnode = ThreadSafeLayoutNode::new(&node);
// Always re-construct if incremental layout is turned off.
if !self.layout_context.shared.opts.incremental_layout {
if !opts::get().incremental_layout {
unsafe {
node.set_dirty_descendants(true);
}

View file

@ -24,7 +24,6 @@ use servo_msg::constellation_msg::{ConstellationChan, PipelineId};
use servo_msg::constellation_msg::Failure;
use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::ResourceTask;
use servo_util::opts::Opts;
use servo_util::time::TimeProfilerChan;
use script_traits::{ScriptControlChan, OpaqueScriptLayoutChannel};
use std::comm::Sender;
@ -52,7 +51,6 @@ pub trait LayoutTaskFactory {
resource_task: ResourceTask,
img_cache_task: ImageCacheTask,
font_cache_task: FontCacheTask,
opts: Opts,
time_profiler_chan: TimeProfilerChan,
shutdown_chan: Sender<()>);
}

View file

@ -15,6 +15,7 @@ use std::cmp;
use std::io;
use std::mem;
use std::os;
use std::ptr;
use std::rt;
/// Global flags for Servo, currently set on the command line.
@ -107,7 +108,15 @@ fn args_fail(msg: &str) {
os::set_exit_status(1);
}
pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
// Always use CPU rendering on android.
#[cfg(target_os="android")]
static FORCE_CPU_PAINTING: bool = true;
#[cfg(not(target_os="android"))]
static FORCE_CPU_PAINTING: bool = false;
pub fn from_cmdline_args(args: &[String]) -> bool {
let app_name = args[0].to_string();
let args = args.tail();
@ -141,19 +150,19 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
Ok(m) => m,
Err(f) => {
args_fail(format!("{}", f).as_slice());
return None;
return false;
}
};
if opt_match.opt_present("h") || opt_match.opt_present("help") {
print_usage(app_name.as_slice(), opts.as_slice());
return None;
return false;
};
let urls = if opt_match.free.is_empty() {
print_usage(app_name.as_slice(), opts.as_slice());
args_fail("servo asks that you provide 1 or more URLs");
return None;
return false;
} else {
opt_match.free.clone()
};
@ -180,7 +189,7 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
from_str(period.as_slice()).unwrap()
});
let cpu_painting = opt_match.opt_present("c");
let cpu_painting = FORCE_CPU_PAINTING || opt_match.opt_present("c");
let mut layout_threads: uint = match opt_match.opt_str("y") {
Some(layout_threads_str) => from_str(layout_threads_str.as_slice()).unwrap(),
@ -237,12 +246,8 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
dump_flow_tree: opt_match.opt_present("dump-flow-tree"),
};
unsafe {
let box_opts = box opts.clone();
OPTIONS = mem::transmute(box_opts);
}
Some(opts)
set_opts(opts);
true
}
static mut EXPERIMENTAL_ENABLED: bool = false;
@ -262,10 +267,19 @@ pub fn experimental_enabled() -> bool {
// Make Opts available globally. This saves having to clone and pass
// opts everywhere it is used, which gets particularly cumbersome
// when passing through the DOM structures.
// GWTODO: Change existing code that takes copies of opts to instead
// make use of the global copy.
static mut OPTIONS: *mut Opts = 0 as *mut Opts;
pub fn get() -> &'static Opts {
unsafe { mem::transmute(OPTIONS) }
pub fn set_opts(opts: Opts) {
unsafe {
let box_opts = box opts;
OPTIONS = mem::transmute(box_opts);
}
}
#[inline]
pub fn get<'a>() -> &'a Opts {
unsafe {
assert!(OPTIONS != ptr::null_mut());
mem::transmute(OPTIONS)
}
}

View file

@ -30,14 +30,14 @@ use glut::glut::{init, init_display_mode, DOUBLE};
mod window;
pub fn create_window(opts: &opts::Opts) -> Rc<Window> {
pub fn create_window() -> Rc<Window> {
// Initialize GLUT.
init();
init_display_mode(DOUBLE);
// Read command-line options.
let scale_factor = opts.device_pixels_per_px.unwrap_or(ScaleFactor(1.0));
let size = opts.initial_window_size.as_f32() * scale_factor;
let scale_factor = opts::get().device_pixels_per_px.unwrap_or(ScaleFactor(1.0));
let size = opts::get().initial_window_size.as_f32() * scale_factor;
// Open a window.
Window::new(size.as_uint())
@ -54,11 +54,9 @@ pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int {
}
}
opts::from_cmdline_args(args.as_slice()).map(|mut opts| {
// Always use CPU rendering on android.
opts.cpu_painting = true;
let window = Some(create_window(&opts));
servo::run(opts, window);
});
if opts::from_cmdline_args(args.as_slice()) {
let window = Some(create_window());
servo::run(window);
}
})
}

View file

@ -75,8 +75,8 @@ pub extern "C" fn cef_run_message_loop() {
dump_flow_tree: false,
};
native::start(0, 0 as *const *const u8, proc() {
let window = Some(glfw_app::create_window(&opts));
servo::run(opts, window);
let window = Some(glfw_app::create_window());
servo::run(window);
});
}

View file

@ -21,10 +21,11 @@ extern crate util;
use geom::scale_factor::ScaleFactor;
use std::rc::Rc;
use window::Window;
use util::opts;
mod window;
pub fn create_window(opts: &util::opts::Opts) -> Rc<Window> {
pub fn create_window() -> Rc<Window> {
// Initialize GLFW.
let glfw = glfw::init(glfw::LOG_ERRORS).unwrap_or_else(|_| {
// handles things like inability to connect to X
@ -34,9 +35,9 @@ pub fn create_window(opts: &util::opts::Opts) -> Rc<Window> {
});
// Read command-line options.
let foreground = opts.output_file.is_none();
let scale_factor = opts.device_pixels_per_px.unwrap_or(ScaleFactor(1.0));
let size = opts.initial_window_size.as_f32() * scale_factor;
let foreground = opts::get().output_file.is_none();
let scale_factor = opts::get().device_pixels_per_px.unwrap_or(ScaleFactor(1.0));
let size = opts::get().initial_window_size.as_f32() * scale_factor;
// Open a window.
Window::new(glfw, foreground, size.as_uint())

View file

@ -62,8 +62,9 @@ use std::rc::Rc;
use std::task::TaskBuilder;
#[cfg(not(test))]
pub fn run<Window: WindowMethods>(opts: opts::Opts, window: Option<Rc<Window>>) {
::servo_util::opts::set_experimental_enabled(opts.enable_experimental);
pub fn run<Window: WindowMethods>(window: Option<Rc<Window>>) {
::servo_util::opts::set_experimental_enabled(opts::get().enable_experimental);
let opts = opts::get();
RegisterBindings::RegisterProxyHandlers();
let mut pool_config = green::PoolConfig::new();
@ -77,14 +78,12 @@ pub fn run<Window: WindowMethods>(opts: opts::Opts, window: Option<Rc<Window>>)
devtools::start_server(port)
});
let opts_clone = opts.clone();
let time_profiler_chan_clone = time_profiler_chan.clone();
let (result_chan, result_port) = channel();
TaskBuilder::new()
.green(&mut pool)
.spawn(proc() {
let opts = &opts_clone;
// Create a Servo instance.
let resource_task = new_resource_task(opts.user_agent.clone());
// If we are emitting an output file, then we need to block on
@ -99,7 +98,6 @@ pub fn run<Window: WindowMethods>(opts: opts::Opts, window: Option<Rc<Window>>)
let constellation_chan = Constellation::<layout::layout_task::LayoutTask,
script::script_task::ScriptTask>::start(
compositor_chan,
opts,
resource_task,
image_cache_task,
font_cache_task,
@ -128,7 +126,6 @@ pub fn run<Window: WindowMethods>(opts: opts::Opts, window: Option<Rc<Window>>)
debug!("preparing to enter main loop");
CompositorTask::create(window,
opts,
compositor_port,
constellation_chan,
time_profiler_chan,

View file

@ -28,14 +28,14 @@ use std::os;
#[allow(dead_code)]
fn start(argc: int, argv: *const *const u8) -> int {
native::start(argc, argv, proc() {
opts::from_cmdline_args(os::args().as_slice()).map(|opts| {
let window = if opts.headless {
if opts::from_cmdline_args(os::args().as_slice()) {
let window = if opts::get().headless {
None
} else {
Some(glfw_app::create_window(&opts))
Some(glfw_app::create_window())
};
run(opts, window);
});
run(window);
}
})
}