Finish fixing build

This commit is contained in:
Brian J. Burg 2012-09-10 16:36:55 -07:00
parent 0300776298
commit 2d8e764c9d
7 changed files with 86 additions and 78 deletions

View file

@ -5,33 +5,31 @@ Each time the renderer renders a frame the compositor will output a
`~[u8]` containing the frame in PNG format. `~[u8]` containing the frame in PNG format.
"]; "];
export PngCompositor, Msg, Exit; use libc::{c_int, c_uint, c_void, c_uchar};
use azure_bg = azure::bindgen;
import libc::{c_int, c_uint, c_void, c_uchar}; use azure_bg::{AzCreateDrawTargetForCairoSurface, AzReleaseDrawTarget};
import azure_bg = azure::bindgen; use azure::cairo;
import azure_bg::{AzCreateDrawTargetForCairoSurface, AzReleaseDrawTarget}; use azure::azure_hl::DrawTarget;
import azure::cairo; use azure::cairo_hl::ImageSurface;
import azure::azure_hl::DrawTarget; use cairo::{CAIRO_FORMAT_ARGB32, cairo_surface_t, cairo_status_t, CAIRO_STATUS_SUCCESS};
import azure::cairo_hl::ImageSurface; use cairo_bg = cairo::bindgen;
import cairo::{CAIRO_FORMAT_ARGB32, cairo_surface_t, cairo_status_t, CAIRO_STATUS_SUCCESS}; use cairo_bg::{cairo_image_surface_create, cairo_surface_destroy,
import cairo_bg = cairo::bindgen;
import cairo_bg::{cairo_image_surface_create, cairo_surface_destroy,
cairo_surface_write_to_png_stream}; cairo_surface_write_to_png_stream};
import compositor::Compositor; use compositor::Compositor;
import render_task::{RenderTask, RenderMsg}; use render_task::{RenderTask, RenderMsg};
import task::spawn_listener; use task::spawn_listener;
import comm::{Chan, Port}; use comm::{Chan, Port};
import unsafe::reinterpret_cast; use unsafe::reinterpret_cast;
import vec_from_buf = vec::unsafe::from_buf; use vec_from_buf = vec::unsafe::from_buf;
import ptr::addr_of; use ptr::addr_of;
import dom::event::Event; use dom::event::Event;
import dvec::DVec; use dvec::DVec;
import layout::display_list::display_list; use layout::display_list::DisplayList;
import std::cell::Cell; use std::cell::Cell;
type PngCompositor = Chan<Msg>; pub type PngCompositor = Chan<Msg>;
enum Msg { pub enum Msg {
BeginDrawing(pipes::Chan<DrawTarget>), BeginDrawing(pipes::Chan<DrawTarget>),
Draw(pipes::Chan<DrawTarget>, DrawTarget), Draw(pipes::Chan<DrawTarget>, DrawTarget),
Exit Exit
@ -49,7 +47,7 @@ impl Chan<Msg> : Compositor {
} }
} }
fn PngCompositor(output: Chan<~[u8]>) -> PngCompositor { pub fn PngCompositor(output: Chan<~[u8]>) -> PngCompositor {
do spawn_listener |po: Port<Msg>| { do spawn_listener |po: Port<Msg>| {
let cairo_surface = ImageSurface(CAIRO_FORMAT_ARGB32, 800, 600); let cairo_surface = ImageSurface(CAIRO_FORMAT_ARGB32, 800, 600);
let draw_target = Cell(DrawTarget(cairo_surface)); let draw_target = Cell(DrawTarget(cairo_surface));
@ -89,7 +87,7 @@ fn sanity_check() {
let compositor = PngCompositor(self_channel); let compositor = PngCompositor(self_channel);
let renderer = RenderTask(compositor); let renderer = RenderTask(compositor);
let dlist : display_list = DVec(); let dlist : DisplayList = DVec();
renderer.send(RenderMsg(dlist)); renderer.send(RenderMsg(dlist));
let (exit_chan, exit_response_from_engine) = pipes::stream(); let (exit_chan, exit_response_from_engine) = pipes::stream();
renderer.send(render_task::ExitMsg(exit_chan)); renderer.send(render_task::ExitMsg(exit_chan));

View file

@ -24,7 +24,7 @@ import pipes::{Port, Chan};
type Renderer = comm::Chan<Msg>; type Renderer = comm::Chan<Msg>;
enum Msg { enum Msg {
RenderMsg(dl::display_list), RenderMsg(dl::DisplayList),
ExitMsg(pipes::Chan<()>) ExitMsg(pipes::Chan<()>)
} }
@ -82,15 +82,15 @@ impl u8 : to_float {
} }
} }
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| { for display_list.each |item| {
#debug["drawing %?", item]; #debug["drawing %?", item];
match item.item_type { match item.item {
dl::display_item_solid_color(r, g, b) => draw_solid_color(draw_target, item, r, g, b), dl::SolidColor(r, g, b) => draw_solid_color(draw_target, item, r, g, b),
dl::display_item_image(image) => draw_image(draw_target, item, *image), dl::Image(image) => draw_image(draw_target, item, image),
dl::display_item_text(text_run) => draw_text(draw_target, item, text_run), dl::Text(text_run) => draw_text(draw_target, item, text_run),
dl::padding(*) => fail ~"should never see padding" dl::Padding(*) => fail ~"should never see padding"
} }
} }
} }
@ -106,7 +106,7 @@ impl Rect<au> : ToAzureRect {
} }
} }
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, let color = Color(r.to_float() as AzFloat,
g.to_float() as AzFloat, g.to_float() as AzFloat,
b.to_float() as AzFloat, b.to_float() as AzFloat,
@ -115,7 +115,7 @@ fn draw_solid_color(draw_target: &DrawTarget, item: dl::display_item, r: u8, g:
draw_target.fill_rect(item.bounds.to_azure_rect(), ColorPattern(color)); 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 image = std::arc::get(&image);
let size = Size2D(image.width as i32, image.height as i32); let size = Size2D(image.width as i32, image.height as i32);
let stride = image.width * 4; let stride = image.width * 4;
@ -131,7 +131,7 @@ fn draw_image(draw_target: &DrawTarget, item: dl::display_item, image: ARC<~Imag
draw_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 ptr::{addr_of, null};
import vec::unsafe::to_ptr; import vec::unsafe::to_ptr;
import libc::types::common::c99::{uint16_t, uint32_t}; import libc::types::common::c99::{uint16_t, uint32_t};
@ -147,7 +147,7 @@ fn draw_text(draw_target: &DrawTarget, item: dl::display_item, text_run: TextRun
let draw_target = draw_target.azure_draw_target; 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 // FIXME: The font library should not be created here
let flib = FontLibrary(); let flib = FontLibrary();
let font = flib.get_test_font(); let font = flib.get_test_font();

View file

@ -53,7 +53,7 @@ struct Appearance {
// This will be very unhappy if it is getting run in parallel with // This will be very unhappy if it is getting run in parallel with
// anything trying to read the background image // anything trying to read the background image
fn get_image() -> Option<~ARC<~Image>> { fn get_image() -> Option<ARC<~Image>> {
let mut image = None; let mut image = None;
// Do a dance where we swap the ImageHolder out before we can // Do a dance where we swap the ImageHolder out before we can
@ -134,7 +134,7 @@ fn ImageHolder(-url : Url, image_cache_task: ImageCacheTask, reflow: fn~()) -> I
impl ImageHolder { impl ImageHolder {
// This function should not be called by two tasks at the same time // 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 // If this is the first time we've called this function, load
// the image and store it for the future // the image and store it for the future
if self.image.is_none() { if self.image.is_none() {
@ -180,7 +180,7 @@ impl ImageHolder {
let im_arc = option::unwrap(temp); let im_arc = option::unwrap(temp);
self.image = Some(clone(&im_arc)); self.image = Some(clone(&im_arc));
return Some(~im_arc); return Some(im_arc);
} else { } else {
return None; return None;
} }

View file

@ -6,17 +6,20 @@ import servo_text::text_run::TextRun;
import std::arc::ARC; import std::arc::ARC;
import dvec::DVec; import dvec::DVec;
enum item_type { // TODO: convert to DisplayItem trait with methods like bounds(), paint(), etc.
display_item_solid_color(u8, u8, u8), enum ItemKind {
display_item_image(~ARC<~Image>), SolidColor(u8, u8, u8),
display_item_text(TextRun), Image(ARC<~Image>),
Text(TextRun),
// FIXME: Shape code does not understand the alignment without this // FIXME: Shape code does not understand the alignment without this
padding(u8, u8, u8, u8) Padding(u8, u8, u8, u8)
} }
enum display_item = { struct DisplayItem {
item_type: item_type, item: ItemKind,
bounds: Rect<au> bounds: Rect<au>
}; }
type display_list = DVec<display_item>; impl DisplayItem : Copy { }
type DisplayList = DVec<DisplayItem>;

View file

@ -2,7 +2,7 @@ export build_display_list;
import css::values::{BgColor, BgTransparent, Specified}; import css::values::{BgColor, BgTransparent, Specified};
import base::{Box, BTree, ImageHolder, TextBoxKind}; import base::{Box, BTree, ImageHolder, TextBoxKind};
import dl = display_list; import dl = layout::display_list;
import dom::base::{Text, NodeScope}; import dom::base::{Text, NodeScope};
import dom::rcu::Scope; import dom::rcu::Scope;
import either::{Left, Right}; import either::{Left, Right};
@ -20,7 +20,7 @@ import vec::push;
Builds a display list for a box and all its children 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(); let list = DVec();
build_display_list_from_origin(list, box, Point2D(au(0), au(0))); build_display_list_from_origin(list, box, Point2D(au(0), au(0)));
return list; return list;
@ -37,7 +37,7 @@ Builds a display list for a box and all its children.
passed-in box. 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( 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.x) + au_to_px(box.bounds.origin.x)),
px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y))); px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y)));
@ -62,7 +62,7 @@ Creates a display list item for a single block.
"] "]
#[allow(non_implicitly_copyable_typarams)] #[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); #debug("request to display a box from origin %?", origin);
let bounds = Rect(origin, copy box.bounds.size); let bounds = Rect(origin, copy box.bounds.size);
@ -71,14 +71,14 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
TextBoxKind(subbox) => { TextBoxKind(subbox) => {
let run = copy subbox.run; let run = copy subbox.run;
assert run.is_some(); assert run.is_some();
list.push(dl::display_item({ list.push(dl::DisplayItem {
item_type: dl::display_item_solid_color(255u8, 255u8, 255u8), item: dl::SolidColor(255u8, 255u8, 255u8),
bounds: bounds bounds: bounds
})); } );
list.push(dl::display_item({ list.push(dl::DisplayItem {
item_type: dl::display_item_text(run.get()), item: dl::Text(run.get()),
bounds: bounds bounds: bounds
})); });
return; return;
} }
_ => { _ => {
@ -90,10 +90,10 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
let image = box.appearance.get_image(); let image = box.appearance.get_image();
if image.is_some() { if image.is_some() {
let display_item = dl::display_item({ let display_item = dl::DisplayItem {
item_type: dl::display_item_image(option::unwrap(image)), item: dl::Image(option::unwrap(image)),
bounds: bounds bounds: bounds
}); };
list.push(display_item); list.push(display_item);
} else { } else {
// DAC // DAC
@ -104,10 +104,10 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
Specified(BgTransparent) | _ => util::color::rgba(0,0,0,0.0) Specified(BgTransparent) | _ => util::color::rgba(0,0,0,0.0)
}; };
#debug("Assigning color %? to box with bounds %?", color, bounds); #debug("Assigning color %? to box with bounds %?", color, bounds);
list.push(dl::display_item({ list.push(dl::DisplayItem {
item_type: dl::display_item_solid_color(color.red, color.green, color.blue), item: dl::SolidColor(color.red, color.green, color.blue),
bounds: bounds bounds: bounds
})); });
} }
} }
@ -128,11 +128,12 @@ fn should_convert_text_boxes_to_solid_color_background_items() {
let list = DVec(); let list = DVec();
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
match list[0].item_type { do list.borrow |l| {
dl::display_item_solid_color(*) => { } match l[0].item {
_ => { fail } dl::SolidColor(*) => { }
} _ => { fail }
}
}
} }
fn should_convert_text_boxes_to_text_items() { fn should_convert_text_boxes_to_text_items() {
@ -151,9 +152,11 @@ fn should_convert_text_boxes_to_text_items() {
let list = DVec(); let list = DVec();
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
match list[1].item_type { do list.borrow |l| {
dl::display_item_text(_) => { } match l[1].item {
_ => { fail } dl::Text(_) => { }
_ => { fail }
}
} }
} }
@ -179,7 +182,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
Size2D(px_to_au(84), px_to_au(20)) 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() { fn should_calculate_the_bounds_of_the_text_items() {
@ -204,5 +207,5 @@ fn should_calculate_the_bounds_of_the_text_items() {
Size2D(px_to_au(84), px_to_au(20)) Size2D(px_to_au(84), px_to_au(20))
); );
assert list[1].bounds == expected; do list.borrow |l| { assert l[1].bounds == expected; }
} }

View file

@ -63,12 +63,17 @@ fn mainloop(po: Port<Msg>) {
let done = @mut false; let done = @mut false;
#macro[
[#moov[x],
unsafe { let y <- *ptr::addr_of(x); y }]
];
let check_for_messages = fn@() { let check_for_messages = fn@() {
// Handle messages // Handle messages
#debug("osmain: peeking"); #debug("osmain: peeking");
while po.peek() { while po.peek() {
match po.recv() { 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), AddEventListener(event_listener) => event_listeners.push(event_listener),
BeginDrawing(sender) => lend_surface(*surfaces, sender), BeginDrawing(sender) => lend_surface(*surfaces, sender),
Draw(sender, dt) => { Draw(sender, dt) => {

View file

@ -105,6 +105,5 @@ type UrlMap<T: Copy> = hashmap<Url, T>;
fn url_map<T: Copy>() -> UrlMap<T> { fn url_map<T: Copy>() -> UrlMap<T> {
import core::to_str::ToStr; import core::to_str::ToStr;
hashmap::<Url, T>(|a| str::hash(&a.to_str()), hashmap::<Url, T>()
|a, b| str::eq(&a.to_str(), &b.to_str()))
} }