mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Finish fixing build
This commit is contained in:
parent
0300776298
commit
2d8e764c9d
7 changed files with 86 additions and 78 deletions
|
@ -5,33 +5,31 @@ 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
|
||||
|
@ -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>| {
|
||||
let cairo_surface = ImageSurface(CAIRO_FORMAT_ARGB32, 800, 600);
|
||||
let draw_target = Cell(DrawTarget(cairo_surface));
|
||||
|
@ -89,7 +87,7 @@ fn sanity_check() {
|
|||
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));
|
||||
|
|
|
@ -24,7 +24,7 @@ import pipes::{Port, Chan};
|
|||
type Renderer = comm::Chan<Msg>;
|
||||
|
||||
enum Msg {
|
||||
RenderMsg(dl::display_list),
|
||||
RenderMsg(dl::DisplayList),
|
||||
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| {
|
||||
#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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
g.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));
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -131,7 +131,7 @@ fn draw_image(draw_target: &DrawTarget, item: dl::display_item, image: ARC<~Imag
|
|||
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};
|
||||
|
@ -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 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();
|
||||
|
|
|
@ -53,7 +53,7 @@ struct Appearance {
|
|||
|
||||
// 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
|
||||
|
@ -134,7 +134,7 @@ fn ImageHolder(-url : Url, image_cache_task: ImageCacheTask, reflow: fn~()) -> I
|
|||
|
||||
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() {
|
||||
|
@ -180,7 +180,7 @@ impl ImageHolder {
|
|||
let im_arc = option::unwrap(temp);
|
||||
self.image = Some(clone(&im_arc));
|
||||
|
||||
return Some(~im_arc);
|
||||
return Some(im_arc);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -6,17 +6,20 @@ 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>;
|
||||
|
|
|
@ -2,7 +2,7 @@ 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};
|
||||
|
@ -20,7 +20,7 @@ import vec::push;
|
|||
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;
|
||||
|
@ -37,7 +37,7 @@ Builds a display list for a box and all its children.
|
|||
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)));
|
||||
|
@ -62,7 +62,7 @@ Creates a display list item for a single block.
|
|||
|
||||
"]
|
||||
#[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);
|
||||
|
@ -71,14 +71,14 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
|
|||
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;
|
||||
}
|
||||
_ => {
|
||||
|
@ -90,10 +90,10 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
|
|||
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
|
||||
|
@ -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)
|
||||
};
|
||||
#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
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,11 +128,12 @@ fn should_convert_text_boxes_to_solid_color_background_items() {
|
|||
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(*) => { }
|
||||
do list.borrow |l| {
|
||||
match l[0].item {
|
||||
dl::SolidColor(*) => { }
|
||||
_ => { fail }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fn should_convert_text_boxes_to_text_items() {
|
||||
|
@ -151,10 +152,12 @@ fn should_convert_text_boxes_to_text_items() {
|
|||
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(_) => { }
|
||||
do list.borrow |l| {
|
||||
match l[1].item {
|
||||
dl::Text(_) => { }
|
||||
_ => { fail }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn should_calculate_the_bounds_of_the_text_box_background_color() {
|
||||
|
@ -179,7 +182,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
|
|||
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() {
|
||||
|
@ -204,5 +207,5 @@ fn should_calculate_the_bounds_of_the_text_items() {
|
|||
Size2D(px_to_au(84), px_to_au(20))
|
||||
);
|
||||
|
||||
assert list[1].bounds == expected;
|
||||
do list.borrow |l| { assert l[1].bounds == expected; }
|
||||
}
|
||||
|
|
|
@ -63,12 +63,17 @@ fn mainloop(po: Port<Msg>) {
|
|||
|
||||
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) => {
|
||||
|
|
|
@ -105,6 +105,5 @@ 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>()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue