mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Put images in an ARC to avoid copying. Make test-many-images harder.
This commit is contained in:
parent
4c02e812c0
commit
9196990384
7 changed files with 278 additions and 31 deletions
|
@ -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<Msg>;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<future<~image>>;
|
||||
let mut background_image: option<~future<~arc<~image>>>;
|
||||
let mut background_color: Color;
|
||||
|
||||
new() {
|
||||
|
|
|
@ -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<au>
|
||||
};
|
||||
|
||||
type display_list = ~[display_item];
|
||||
type display_list = dvec<display_item>;
|
||||
|
|
|
@ -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<au>)
|
||||
-> dl::display_list {
|
||||
fn build_display_list_from_origin(list: dl::display_list, 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);
|
||||
|
||||
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<au>) -> ~[dl::display_item] {
|
||||
let mut items = ~[];
|
||||
|
||||
fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>) {
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -61,7 +61,6 @@ fn mainloop(po: port<Msg>) {
|
|||
let check_for_messages = fn@() {
|
||||
// Handle messages
|
||||
#debug("osmain: peeking");
|
||||
let mut i = 0u;
|
||||
while po.peek() {
|
||||
alt po.recv() {
|
||||
AddKeyHandler(key_ch) {
|
||||
|
|
|
@ -88,6 +88,252 @@
|
|||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
<img src="test.jpeg" width="64" height="64"></img>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
|
||||
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
<img src="test.jpeg" width="64" height="64"/>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue