servo: Finish fixing build
authorBrian J. Burg <burg@cs.washington.edu>
Mon, 10 Sep 2012 16:36:55 -0700
changeset 361893 966a38a16636fa4fbfde45548b7eecda61f77337
parent 361892 a2b01f75162944928cc6ec4f5724315054fc2e21
child 361894 9120594508f27e8b6fcd49a0b74224b41fc281eb
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
servo: Finish fixing build Source-Repo: https://github.com/servo/servo Source-Revision: 2d8e764c9d66f93db4f6dbcdc73728c1043a4f02
servo/src/servo/gfx/png_compositor.rs
servo/src/servo/gfx/render_task.rs
servo/src/servo/layout/base.rs
servo/src/servo/layout/display_list.rs
servo/src/servo/layout/display_list_builder.rs
servo/src/servo/platform/osmain.rs
servo/src/servo/util/url.rs
--- a/servo/src/servo/gfx/png_compositor.rs
+++ b/servo/src/servo/gfx/png_compositor.rs
@@ -1,42 +1,40 @@
 #[doc = "
 A graphics compositor that renders to PNG format buffers
 
 Each time the renderer renders a frame the compositor will output a
 `~[u8]` containing the frame in PNG format.
 "];
 
-export PngCompositor, Msg, Exit;
-
-import libc::{c_int, c_uint, c_void, c_uchar};
-import azure_bg = azure::bindgen;
-import azure_bg::{AzCreateDrawTargetForCairoSurface, AzReleaseDrawTarget};
-import azure::cairo;
-import azure::azure_hl::DrawTarget;
-import azure::cairo_hl::ImageSurface;
-import cairo::{CAIRO_FORMAT_ARGB32, cairo_surface_t, cairo_status_t, CAIRO_STATUS_SUCCESS};
-import cairo_bg = cairo::bindgen;
-import cairo_bg::{cairo_image_surface_create, cairo_surface_destroy,
+use libc::{c_int, c_uint, c_void, c_uchar};
+use azure_bg = azure::bindgen;
+use azure_bg::{AzCreateDrawTargetForCairoSurface, AzReleaseDrawTarget};
+use azure::cairo;
+use azure::azure_hl::DrawTarget;
+use azure::cairo_hl::ImageSurface;
+use cairo::{CAIRO_FORMAT_ARGB32, cairo_surface_t, cairo_status_t, CAIRO_STATUS_SUCCESS};
+use cairo_bg = cairo::bindgen;
+use cairo_bg::{cairo_image_surface_create, cairo_surface_destroy,
                   cairo_surface_write_to_png_stream};
-import compositor::Compositor;
-import render_task::{RenderTask, RenderMsg};
-import task::spawn_listener;
-import comm::{Chan, Port};
-import unsafe::reinterpret_cast;
-import vec_from_buf = vec::unsafe::from_buf;
-import ptr::addr_of;
-import dom::event::Event;
-import dvec::DVec;
-import layout::display_list::display_list;
-import std::cell::Cell;
+use compositor::Compositor;
+use render_task::{RenderTask, RenderMsg};
+use task::spawn_listener;
+use comm::{Chan, Port};
+use unsafe::reinterpret_cast;
+use vec_from_buf = vec::unsafe::from_buf;
+use ptr::addr_of;
+use dom::event::Event;
+use dvec::DVec;
+use layout::display_list::DisplayList;
+use std::cell::Cell;
 
-type PngCompositor = Chan<Msg>;
+pub type PngCompositor = Chan<Msg>;
 
-enum Msg {
+pub enum Msg {
     BeginDrawing(pipes::Chan<DrawTarget>),
     Draw(pipes::Chan<DrawTarget>, DrawTarget),
     Exit
 }
 
 impl Chan<Msg> : Compositor {
     fn begin_drawing(+next_dt: pipes::Chan<DrawTarget>) {
         self.send(BeginDrawing(next_dt))
@@ -44,17 +42,17 @@ impl Chan<Msg> : Compositor {
     fn draw(+next_dt: pipes::Chan<DrawTarget>, +draw_me: DrawTarget) {
         self.send(Draw(next_dt, draw_me))
     }
     fn add_event_listener(_listener: Chan<Event>) {
         // No events in this compositor.
     }
 }
 
-fn PngCompositor(output: Chan<~[u8]>) -> PngCompositor {
+pub fn PngCompositor(output: Chan<~[u8]>) -> PngCompositor {
     do spawn_listener |po: Port<Msg>| {
         let cairo_surface = ImageSurface(CAIRO_FORMAT_ARGB32, 800, 600);
         let draw_target = Cell(DrawTarget(cairo_surface));
 
         loop {
             match po.recv() {
                 BeginDrawing(sender) => {
                     debug!("png_compositor: begin_drawing");
@@ -84,17 +82,17 @@ fn do_draw(sender: pipes::Chan<DrawTarge
 }
 
 #[test]
 fn sanity_check() {
     do listen |self_channel| {
         let compositor = PngCompositor(self_channel);
         let renderer = RenderTask(compositor);
 
-        let dlist : display_list = DVec();
+        let dlist : DisplayList = DVec();
         renderer.send(RenderMsg(dlist));
         let (exit_chan, exit_response_from_engine) = pipes::stream();
         renderer.send(render_task::ExitMsg(exit_chan));
         exit_response_from_engine.recv();
 
         compositor.send(Exit)
     }
 }
--- a/servo/src/servo/gfx/render_task.rs
+++ b/servo/src/servo/gfx/render_task.rs
@@ -19,17 +19,17 @@ import azure::cairo::{cairo_font_face_t,
 import std::cell::Cell;
 import compositor::Compositor;
 
 import pipes::{Port, Chan};
 
 type Renderer = comm::Chan<Msg>;
 
 enum Msg {
-    RenderMsg(dl::display_list),
+    RenderMsg(dl::DisplayList),
     ExitMsg(pipes::Chan<()>)
 }
 
 type RenderTask = comm::Chan<Msg>;
 
 fn RenderTask<C: Compositor Send>(+compositor: C) -> RenderTask {
     do task::spawn_listener |po: comm::Port<Msg>| {
         let (draw_target_ch, draw_target_po) = pipes::stream();
@@ -77,82 +77,82 @@ trait to_float {
 }
 
 impl u8 : to_float {
     fn to_float() -> float {
         (self as float) / 255f
     }
 }
 
-fn draw_display_list(draw_target: &DrawTarget, display_list: dl::display_list) {
+fn draw_display_list(draw_target: &DrawTarget, display_list: dl::DisplayList) {
     for display_list.each |item| {
         #debug["drawing %?", item];
 
-        match item.item_type {
-          dl::display_item_solid_color(r, g, b) => draw_solid_color(draw_target, item, r, g, b),
-          dl::display_item_image(image) => draw_image(draw_target, item, *image),
-          dl::display_item_text(text_run) => draw_text(draw_target, item, text_run),
-          dl::padding(*) => fail ~"should never see padding"
+        match item.item {
+          dl::SolidColor(r, g, b) => draw_solid_color(draw_target, item, r, g, b),
+          dl::Image(image) => draw_image(draw_target, item, image),
+          dl::Text(text_run) => draw_text(draw_target, item, text_run),
+          dl::Padding(*) => fail ~"should never see padding"
         }
     }
 }
 
 trait ToAzureRect {
     fn to_azure_rect() -> Rect<AzFloat>;
 }
 
 impl Rect<au> : ToAzureRect {
     fn to_azure_rect() -> Rect<AzFloat> {
         Rect(Point2D(au_to_px(self.origin.x) as AzFloat, au_to_px(self.origin.y) as AzFloat),
              Size2D(au_to_px(self.size.width) as AzFloat, au_to_px(self.size.height) as AzFloat))
     }
 }
 
-fn draw_solid_color(draw_target: &DrawTarget, item: dl::display_item, r: u8, g: u8, b: u8) {
+fn draw_solid_color(draw_target: &DrawTarget, item: dl::DisplayItem, r: u8, g: u8, b: u8) {
     let color = Color(r.to_float() as AzFloat,
                       g.to_float() as AzFloat,
                       b.to_float() as AzFloat,
                       1f as AzFloat);
 
     draw_target.fill_rect(item.bounds.to_azure_rect(), ColorPattern(color));
 }
 
-fn draw_image(draw_target: &DrawTarget, item: dl::display_item, image: ARC<~Image>) unsafe {
+fn draw_image(draw_target: &DrawTarget, item: dl::DisplayItem, image: ARC<~Image>) unsafe {
     let image = std::arc::get(&image);
     let size = Size2D(image.width as i32, image.height as i32);
     let stride = image.width * 4;
 
     let azure_surface = draw_target.create_source_surface_from_data(image.data, size, stride as i32,
                                                                     B8G8R8A8);
     let source_rect = Rect(Point2D(0 as AzFloat, 0 as AzFloat),
                            Size2D(image.width as AzFloat, image.height as AzFloat));
     let dest_rect = item.bounds.to_azure_rect();
     let draw_surface_options = DrawSurfaceOptions(Linear, true);
     let draw_options = DrawOptions(1.0f as AzFloat, 0);
     draw_target.draw_surface(azure_surface, dest_rect, source_rect, draw_surface_options,
                              draw_options);
 }
 
-fn draw_text(draw_target: &DrawTarget, item: dl::display_item, text_run: TextRun) {
+fn draw_text(draw_target: &DrawTarget, item: dl::DisplayItem, text_run: TextRun) {
     import ptr::{addr_of, null};
     import vec::unsafe::to_ptr;
     import libc::types::common::c99::{uint16_t, uint32_t};
     import geom::point::Point2D;
     import text::font_library::FontLibrary;
     import text::font::Font;
     import azure::{AzNativeFont, AzFloat, AZ_NATIVE_FONT_CAIRO_FONT_FACE};
     import azure::bindgen::{AzCreateScaledFontWithCairo,
                             AzReleaseScaledFont,
                             AzCreateColorPattern,
                             AzReleaseColorPattern};
     import azure::cairo::bindgen::cairo_scaled_font_destroy;
 
     let draw_target = draw_target.azure_draw_target;
 
-    let bounds = copy (*item).bounds;
+    let bounds = copy item.bounds;
     // FIXME: The font library should not be created here
     let flib = FontLibrary();
     let font = flib.get_test_font();
 
     let nfont: AzNativeFont = {
         mType: AZ_NATIVE_FONT_CAIRO_FONT_FACE,
         mFont: null()
     };
--- a/servo/src/servo/layout/base.rs
+++ b/servo/src/servo/layout/base.rs
@@ -48,17 +48,17 @@ struct Appearance {
     // TODO: create some sort of layout-specific enum to differentiate between
     // relative and resolved values.
     mut width: BoxSizing,
     mut height: BoxSizing,
     mut font_size: Length,
 
     // This will be very unhappy if it is getting run in parallel with
     // anything trying to read the background image
-    fn get_image() -> Option<~ARC<~Image>> {
+    fn get_image() -> Option<ARC<~Image>> {
         let mut image = None;
 
         // Do a dance where we swap the ImageHolder out before we can
         // get the image out of it because we can't match against it
         // because holder.get_image() is not pure.
         if (self.background_image).is_some() {
             let mut temp = None;
             temp <-> self.background_image;
@@ -129,17 +129,17 @@ fn ImageHolder(-url : Url, image_cache_t
     image_cache_task.send(image_cache_task::Prefetch(copy url));
     image_cache_task.send(image_cache_task::Decode(move url));
 
     holder
 }
 
 impl ImageHolder {
     // This function should not be called by two tasks at the same time
-    fn get_image() -> Option<~ARC<~Image>> {
+    fn get_image() -> Option<ARC<~Image>> {
         // If this is the first time we've called this function, load
         // the image and store it for the future
         if self.image.is_none() {
             assert self.url.is_some();
 
             let mut temp = None;
             temp <-> self.url;
             let url = option::unwrap(temp);
@@ -175,17 +175,17 @@ impl ImageHolder {
             // Temporarily swap out the arc of the image so we can clone
             // it without breaking purity, then put it back and return the
             // clone.  This is not threadsafe.
             let mut temp = None;
             temp <-> self.image;
             let im_arc = option::unwrap(temp);
             self.image = Some(clone(&im_arc));
 
-            return Some(~im_arc);
+            return Some(im_arc);
         } else {
             return None;
         }
     }
 }
 
 enum LayoutData = {
     mut specified_style: ~SpecifiedStyle,
--- a/servo/src/servo/layout/display_list.rs
+++ b/servo/src/servo/layout/display_list.rs
@@ -1,22 +1,25 @@
 import gfx::geometry::*;
 import geom::rect::Rect;
 import image::base::Image;
 import servo_text::text_run::TextRun;
 
 import std::arc::ARC;
 import dvec::DVec;
 
-enum item_type {
-    display_item_solid_color(u8, u8, u8),
-    display_item_image(~ARC<~Image>),
-    display_item_text(TextRun),
+// TODO: convert to DisplayItem trait with methods like bounds(), paint(), etc.
+enum ItemKind {
+    SolidColor(u8, u8, u8),
+    Image(ARC<~Image>),
+    Text(TextRun),
     // FIXME: Shape code does not understand the alignment without this
-    padding(u8, u8, u8, u8)
+    Padding(u8, u8, u8, u8)
 }
 
-enum display_item = {
-    item_type: item_type,
+struct DisplayItem {
+    item: ItemKind,
     bounds: Rect<au>
-};
+}
 
-type display_list = DVec<display_item>;
+impl DisplayItem : Copy { }
+
+type DisplayList = DVec<DisplayItem>;
--- a/servo/src/servo/layout/display_list_builder.rs
+++ b/servo/src/servo/layout/display_list_builder.rs
@@ -1,13 +1,13 @@
 export build_display_list;
 
 import css::values::{BgColor, BgTransparent, Specified};
 import base::{Box, BTree, ImageHolder, TextBoxKind};
-import dl = display_list;
+import dl = layout::display_list;
 import dom::base::{Text, NodeScope};
 import dom::rcu::Scope;
 import either::{Left, Right};
 import geom::point::Point2D;
 import geom::rect::Rect;
 import geom::size::Size2D;
 import gfx::geometry::{au, au_to_px, box, px_to_au};
 import util::tree;
@@ -15,34 +15,34 @@ import util::tree;
 import dvec::DVec;
 import vec::push;
 
 #[doc = "
 
 Builds a display list for a box and all its children
 
 "]
-fn build_display_list(box : @Box) -> dl::display_list {
+fn build_display_list(box : @Box) -> dl::DisplayList {
     let list = DVec();
     build_display_list_from_origin(list, box, Point2D(au(0), au(0)));
     return list;
 }
 
 #[doc="
 
 Builds a display list for a box and all its children.
 
 # Arguments
 
 * `box` - The box to build the display list for.
 * `origin` - The coordinates of upper-left corner of the box containing the
              passed-in box.
 
 "]
-fn build_display_list_from_origin(list: dl::display_list, box: @Box, origin: Point2D<au>) {
+fn build_display_list_from_origin(list: dl::DisplayList, box: @Box, origin: Point2D<au>) {
     let box_origin = Point2D(
         px_to_au(au_to_px(origin.x) + au_to_px(box.bounds.origin.x)),
         px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y)));
     #debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin);
 
     box_to_display_items(list, box, box_origin);
 
     for BTree.each_child(box) |c| {
@@ -57,62 +57,62 @@ Creates a display list item for a single
 
 # Arguments 
 
 * `box` - The box to build the display list for
 * `origin` - The coordinates of upper-left corner of the passed in box.
 
 "]
 #[allow(non_implicitly_copyable_typarams)]
-fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>) {
+fn box_to_display_items(list: dl::DisplayList, box: @Box, origin: Point2D<au>) {
     #debug("request to display a box from origin %?", origin);
 
     let bounds = Rect(origin, copy box.bounds.size);
 
     match box.kind {
       TextBoxKind(subbox) => {
         let run = copy subbox.run;
         assert run.is_some();
-        list.push(dl::display_item({
-            item_type: dl::display_item_solid_color(255u8, 255u8, 255u8),
+        list.push(dl::DisplayItem {
+            item: dl::SolidColor(255u8, 255u8, 255u8),
             bounds: bounds
-        }));
-        list.push(dl::display_item({
-            item_type: dl::display_item_text(run.get()),
+        } );
+        list.push(dl::DisplayItem {
+            item: dl::Text(run.get()),
             bounds: bounds
-        }));
+        });
         return;
       }
       _ => {
         // Fall through
       }
     };
 
     // Check if there is a background image, if not set the background color.
     let image = box.appearance.get_image();
     
     if image.is_some() {
-        let display_item = dl::display_item({
-            item_type: dl::display_item_image(option::unwrap(image)),
+        let display_item = dl::DisplayItem {
+            item: dl::Image(option::unwrap(image)),
             bounds: bounds
-        });
+        };
         list.push(display_item);
     } else {
         // DAC
         // TODO: shouldn't need to unbox CSSValue by now
         let boxed_color = box.node.get_specified_style().background_color;
         let color = match boxed_color {
             Specified(BgColor(c)) => c,
             Specified(BgTransparent) | _ => util::color::rgba(0,0,0,0.0)
         };
         #debug("Assigning color %? to box with bounds %?", color, bounds);
-        list.push(dl::display_item({
-            item_type: dl::display_item_solid_color(color.red, color.green, color.blue),
+        list.push(dl::DisplayItem {
+            item: dl::SolidColor(color.red, color.green, color.blue),
             bounds: bounds
-        }));
+        });
     }
 }
 
 
 fn should_convert_text_boxes_to_solid_color_background_items() {
     #[test];
 
     let s = Scope();
@@ -123,21 +123,22 @@ fn should_convert_text_boxes_to_solid_co
       TextBoxKind(subbox) => subbox,
       _ => fail
     };
 
     b.reflow_text(subbox);
     let list = DVec();
     box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
 
-    match list[0].item_type {
-      dl::display_item_solid_color(*) => { }
-      _ => { fail }
-    }
-    
+    do list.borrow |l| {
+        match l[0].item {
+            dl::SolidColor(*) => { }
+            _ => { fail }
+        }
+    }    
 }
 
 fn should_convert_text_boxes_to_text_items() {
     #[test];
 
     let s = Scope();
     let n = s.new_node(Text(~"firecracker"));
     let b = n.construct_boxes().get();
@@ -146,19 +147,21 @@ fn should_convert_text_boxes_to_text_ite
       TextBoxKind(subbox) => { subbox },
       _ => fail
     };
 
     b.reflow_text(subbox);
     let list = DVec();
     box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
 
-    match list[1].item_type {
-      dl::display_item_text(_) => { }
-      _ => { fail }
+    do list.borrow |l| {
+        match l[1].item {
+            dl::Text(_) => { }
+            _ => { fail }
+        }
     }
 }
 
 fn should_calculate_the_bounds_of_the_text_box_background_color() {
     #[test];
     #[ignore(cfg(target_os = "macos"))];
 
     let s = Scope();
@@ -174,17 +177,17 @@ fn should_calculate_the_bounds_of_the_te
     let list = DVec();
     box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
 
     let expected = Rect(
         Point2D(px_to_au(0), px_to_au(0)),
         Size2D(px_to_au(84), px_to_au(20))
     );
 
-    assert list[0].bounds == expected;
+    do list.borrow |l| { assert l[0].bounds == expected }
 }
 
 fn should_calculate_the_bounds_of_the_text_items() {
     #[test];
     #[ignore(cfg(target_os = "macos"))];
 
     let s = Scope();
     let n = s.new_node(Text(~"firecracker"));
@@ -199,10 +202,10 @@ fn should_calculate_the_bounds_of_the_te
     let list = DVec();
     box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
 
     let expected = Rect(
         Point2D(px_to_au(0), px_to_au(0)),
         Size2D(px_to_au(84), px_to_au(20))
     );
 
-    assert list[1].bounds == expected;
+    do list.borrow |l| { assert l[1].bounds == expected; }
 }
--- a/servo/src/servo/platform/osmain.rs
+++ b/servo/src/servo/platform/osmain.rs
@@ -58,22 +58,27 @@ fn mainloop(po: Port<Msg>) {
     image_layer.common.set_transform
         (image_layer.common.transform.scale(800.0f32, 600.0f32, 1.0f32));
 
     let scene = @mut layers::scene::Scene(layers::layers::ImageLayerKind(image_layer),
                                           Size2D(800.0f32, 600.0f32));
 
     let done = @mut false;
 
+    #macro[
+        [#moov[x],
+         unsafe { let y <- *ptr::addr_of(x); y }]
+    ];
+
     let check_for_messages = fn@() {
         // Handle messages
         #debug("osmain: peeking");
         while po.peek() {
             match po.recv() {
-              AddKeyHandler(key_ch) => key_handlers.push(move key_ch),
+              AddKeyHandler(key_ch) => key_handlers.push(#moov(key_ch)),
               AddEventListener(event_listener) => event_listeners.push(event_listener),
               BeginDrawing(sender) => lend_surface(*surfaces, sender),
               Draw(sender, dt) => {
                 #debug("osmain: received new frame");
                 return_surface(*surfaces, dt);
                 lend_surface(*surfaces, sender);
 
                 let buffer = surfaces.front.cairo_surface.data();
--- a/servo/src/servo/util/url.rs
+++ b/servo/src/servo/util/url.rs
@@ -100,11 +100,10 @@ mod make_url_tests {
 
 }
 
 type UrlMap<T: Copy> = hashmap<Url, T>;
 
 fn url_map<T: Copy>() -> UrlMap<T> {
     import core::to_str::ToStr;
 
-    hashmap::<Url, T>(|a| str::hash(&a.to_str()),
-                      |a, b| str::eq(&a.to_str(), &b.to_str()))
+    hashmap::<Url, T>()
 }