diff --git a/src/servo/gfx/renderer.rs b/src/servo/gfx/renderer.rs index d58eff1c7f7..8f11316e811 100644 --- a/src/servo/gfx/renderer.rs +++ b/src/servo/gfx/renderer.rs @@ -13,6 +13,7 @@ import geom::rect::Rect; import geom::point::Point2D; import azure_hl::AsAzureRect; import ptr::addr_of; +import arc::arc; type Renderer = chan; @@ -82,7 +83,7 @@ fn draw_display_list(draw_target: AzDrawTargetRef, display_list: dl::display_lis draw_solid_color(draw_target, item, r, g, b); } dl::display_item_image(image) { - draw_image(draw_target, item, copy image); + draw_image(draw_target, item, *image); } dl::display_item_text(text_run) { draw_text(draw_target, item, text_run); @@ -121,7 +122,8 @@ fn draw_solid_color(draw_target: AzDrawTargetRef, item: dl::display_item, AzReleaseColorPattern(red_pattern); } -fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item, -image: ~image) unsafe { +fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item, image: arc<~image>) unsafe { + let image = arc::get(&image); let size = Size2D(image.width as i32, image.height as i32); let stride = image.width * 4; diff --git a/src/servo/layout/base.rs b/src/servo/layout/base.rs index fce119c2d22..0211b3e0c9c 100644 --- a/src/servo/layout/base.rs +++ b/src/servo/layout/base.rs @@ -20,6 +20,7 @@ import text::text_layout_methods; import vec::{push, push_all}; import future::future; +import arc::arc; enum BoxKind { BlockBox, @@ -29,7 +30,7 @@ enum BoxKind { } class Appearance { - let mut background_image: option>; + let mut background_image: option<~future<~arc<~image>>>; let mut background_color: Color; new() { diff --git a/src/servo/layout/display_list.rs b/src/servo/layout/display_list.rs index 9ff753f50c5..acb8663488d 100644 --- a/src/servo/layout/display_list.rs +++ b/src/servo/layout/display_list.rs @@ -3,9 +3,12 @@ import geom::rect::Rect; import image::base::image; import servo_text::text_run::TextRun; +import arc::arc; +import dvec::dvec; + enum item_type { display_item_solid_color(u8, u8, u8), - display_item_image(~image), + display_item_image(~arc<~image>), display_item_text(TextRun), // FIXME: Shape code does not understand the alignment without this padding(u8, u8, u8, u8) @@ -16,4 +19,4 @@ enum display_item = { bounds: Rect }; -type display_list = ~[display_item]; +type display_list = dvec; diff --git a/src/servo/layout/display_list_builder.rs b/src/servo/layout/display_list_builder.rs index 09eeab8d524..259972aa5a9 100644 --- a/src/servo/layout/display_list_builder.rs +++ b/src/servo/layout/display_list_builder.rs @@ -14,6 +14,7 @@ import text::text_layout_methods; import util::color::methods; import util::tree; +import dvec::{dvec, extensions}; import vec::push; #[doc = " @@ -22,7 +23,9 @@ Builds a display list for a box and all its children "] fn build_display_list(box : @Box) -> dl::display_list { - ret build_display_list_from_origin(box, Point2D(au(0), au(0))); + let list = dvec(); + build_display_list_from_origin(list, box, Point2D(au(0), au(0))); + ret list; } #[doc=" @@ -36,22 +39,18 @@ Builds a display list for a box and all its children. passed-in box. "] -fn build_display_list_from_origin(box: @Box, origin: Point2D) - -> dl::display_list { +fn build_display_list_from_origin(list: dl::display_list, box: @Box, origin: Point2D) { 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); - let mut list = box_to_display_items(box, box_origin); + box_to_display_items(list, box, box_origin); for BTree.each_child(box) |c| { #debug("Recursively building display list with origin %?", box_origin); - list += build_display_list_from_origin(c, box_origin); + build_display_list_from_origin(list, c, box_origin); } - - #debug("display_list: %?", list); - ret list; } #[doc=" @@ -65,46 +64,43 @@ Creates a display list item for a single block. "] #[warn(no_non_implicitly_copyable_typarams)] -fn box_to_display_items(box: @Box, origin: Point2D) -> ~[dl::display_item] { - let mut items = ~[]; - +fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D) { #debug("request to display a box from origin %?", origin); let bounds = Rect(origin, copy box.bounds.size); let col = box.appearance.background_color; - alt (box.kind, box.appearance.background_image) { + alt (box.kind, copy box.appearance.background_image) { (TextBox(subbox), _) { let run = copy subbox.run; assert run.is_some(); - push(items, dl::display_item({ + list.push(dl::display_item({ item_type: dl::display_item_solid_color(255u8, 255u8, 255u8), bounds: bounds })); - push(items, dl::display_item({ + list.push(dl::display_item({ item_type: dl::display_item_text(run.get()), bounds: bounds })); } (_, some(image)) { - // FIXME: This should not copy and instead should use an ARC. - push(items, dl::display_item({ - item_type: dl::display_item_image(copy image.get()), + let display_item = dl::display_item({ + item_type: do future::with(*image) |image| { + dl::display_item_image(~arc::clone(&*image)) + }, bounds: bounds - })); + }); + list.push(display_item); } (_, none) { #debug("Assigning color %? to box with bounds %?", col, bounds); let col = box.appearance.background_color; - push(items, dl::display_item({ + list.push(dl::display_item({ item_type: dl::display_item_solid_color(col.red, col.green, col.blue), bounds: bounds })); } } - - #debug("layout: display items: %?", items); - ret items; } diff --git a/src/servo/layout/style/apply.rs b/src/servo/layout/style/apply.rs index 4c5b27f7d45..1ba87737f97 100644 --- a/src/servo/layout/style/apply.rs +++ b/src/servo/layout/style/apply.rs @@ -46,10 +46,10 @@ impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box { some(url) { // FIXME: Some sort of BASE HREF support! // FIXME: Parse URLs! - self.appearance.background_image = some(do future_spawn { - ~load(url) - }); #debug("loading image from %s", url); + self.appearance.background_image = some(~do future_spawn |copy url| { + ~arc::arc(~load(url)) + }); } none { /* Ignore. */ diff --git a/src/servo/platform/osmain.rs b/src/servo/platform/osmain.rs index b6950a9c7f6..b8839b90690 100644 --- a/src/servo/platform/osmain.rs +++ b/src/servo/platform/osmain.rs @@ -61,7 +61,6 @@ fn mainloop(po: port) { let check_for_messages = fn@() { // Handle messages #debug("osmain: peeking"); - let mut i = 0u; while po.peek() { alt po.recv() { AddKeyHandler(key_ch) { diff --git a/src/test/test-many-images.html b/src/test/test-many-images.html index bc8b83e9a19..488a5f30743 100644 --- a/src/test/test-many-images.html +++ b/src/test/test-many-images.html @@ -88,6 +88,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +