servo: Use a display list

Source-Repo: https://github.com/servo/servo
Source-Revision: 8131d62e4148118e19afd573c9d91f51b25543e6
This commit is contained in:
Brian Anderson 2012-05-03 16:31:40 -07:00
parent 43b14a2451
commit df726d641e
5 changed files with 108 additions and 71 deletions

View File

@ -29,3 +29,10 @@ fn zero_rect_au() -> rect<au> {
{mut origin: point(z, z), mut size: size(z, z)}
}
fn int_to_au(i: int) -> au {
au(i * 60)
}
fn au_to_int(au: au) -> int {
*au / 60
}

View File

@ -1,10 +1,9 @@
type model = {
x1: int, y1: int, w1: int, h1: int,
x2: int, y2: int, w2: int, h2: int
};
import geom::*;
import comm::*;
import layout::display_list::*;
enum msg {
draw(model),
draw(display_list),
exit(comm::chan<()>)
}
@ -14,68 +13,13 @@ fn renderer(osmain_ch: comm::chan<osmain::msg>) -> comm::chan<msg> {
comm::send(osmain_ch, osmain::get_draw_target(comm::chan(draw_target_po)));
let draw_target = comm::recv(draw_target_po);
let black_color = {
r: 0f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 1f as azure::AzFloat
};
let black_pattern = AzCreateColorPattern(ptr::addr_of(black_color));
let red_color = {
r: 1f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let red_pattern = AzCreateColorPattern(ptr::addr_of(red_color));
let green_color = {
r: 0f as azure::AzFloat,
g: 1f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let green_pattern = AzCreateColorPattern(ptr::addr_of(green_color));
let mut exit_confirm_ch = none;
loop {
alt comm::recv::<msg>(po) {
draw(model) {
let black_rect = {
x: 0 as azure::AzFloat,
y: 0 as azure::AzFloat,
width: 800 as azure::AzFloat,
height: 600 as azure::AzFloat,
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(black_rect),
unsafe { unsafe::reinterpret_cast(black_pattern) }
);
draw(display_list) {
draw_display_list(draw_target, display_list);
let red_rect = {
x: model.x1 as azure::AzFloat,
y: model.y1 as azure::AzFloat,
width: model.w1 as azure::AzFloat,
height: model.h1 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(red_rect),
unsafe { unsafe::reinterpret_cast(red_pattern) }
);
let green_rect = {
x: model.x2 as azure::AzFloat,
y: model.y2 as azure::AzFloat,
width: model.w2 as azure::AzFloat,
height: model.h2 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(green_rect),
unsafe { unsafe::reinterpret_cast(green_pattern) }
);
let draw_po = comm::port();
comm::send(osmain_ch, osmain::draw(comm::chan(draw_po)));
comm::recv(draw_po);
@ -87,10 +31,65 @@ fn renderer(osmain_ch: comm::chan<osmain::msg>) -> comm::chan<msg> {
}
}
AzReleaseColorPattern(red_pattern);
AzReleaseColorPattern(green_pattern);
assert exit_confirm_ch.is_some();
comm::send(exit_confirm_ch.get(), ());
}
}
fn draw_display_list(
draw_target: AzDrawTargetRef,
display_list: display_list
) {
clear(draw_target);
for display_list.each {|item|
let bounds = (*item).bounds;
let red_color = {
r: 1f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let red_pattern = AzCreateColorPattern(ptr::addr_of(red_color));
let red_rect = {
x: au_to_int(bounds.origin.x) as azure::AzFloat,
y: au_to_int(bounds.origin.y) as azure::AzFloat,
width: au_to_int(bounds.size.width) as azure::AzFloat,
height: au_to_int(bounds.size.height) as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(red_rect),
unsafe { unsafe::reinterpret_cast(red_pattern) }
);
AzReleaseColorPattern(red_pattern);
}
}
fn clear(draw_target: AzDrawTargetRef) {
let black_color = {
r: 0f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 1f as azure::AzFloat
};
let black_pattern = AzCreateColorPattern(ptr::addr_of(black_color));
let black_rect = {
x: 0 as azure::AzFloat,
y: 0 as azure::AzFloat,
width: 800 as azure::AzFloat,
height: 600 as azure::AzFloat,
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(black_rect),
unsafe { unsafe::reinterpret_cast(black_pattern) }
);
}

View File

@ -0,0 +1,12 @@
import gfx::geom::*;
enum item_type {
solid_color
}
enum display_item = {
item_type: item_type,
bounds: rect<au>
};
type display_list = [display_item];

View File

@ -6,6 +6,9 @@ Builds display lists on request and passes them to the renderer
import task::*;
import comm::*;
import display_list::*;
import gfx::geom;
import gfx::geom::*;
import gfx::renderer;
enum msg {
@ -26,11 +29,26 @@ fn lister(renderer: chan<renderer::msg>) -> chan<msg> {
let mut h2 = 300;
while !peek(po) {
let model = {
x1: x1, y1: y1, w1: w1, h1: h1,
x2: x2, y2: y2, w2: w2, h2: h2
};
send(renderer, gfx::renderer::draw(model));
let dlist = [
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x1),
int_to_au(y1),
int_to_au(w1),
int_to_au(h1))
}),
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x2),
int_to_au(y2),
int_to_au(w2),
int_to_au(h2))
})
];
send(renderer, gfx::renderer::draw(dlist));
std::timer::sleep(100u);

View File

@ -29,6 +29,7 @@ mod image {
mod layout {
mod base;
mod display_list;
mod lister;
}