mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Use a display list
This commit is contained in:
parent
1cb3bb593f
commit
8131d62e41
5 changed files with 108 additions and 71 deletions
|
@ -29,3 +29,10 @@ fn zero_rect_au() -> rect<au> {
|
||||||
{mut origin: point(z, z), mut size: size(z, z)}
|
{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
|
||||||
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
type model = {
|
import geom::*;
|
||||||
x1: int, y1: int, w1: int, h1: int,
|
import comm::*;
|
||||||
x2: int, y2: int, w2: int, h2: int
|
import layout::display_list::*;
|
||||||
};
|
|
||||||
|
|
||||||
enum msg {
|
enum msg {
|
||||||
draw(model),
|
draw(display_list),
|
||||||
exit(comm::chan<()>)
|
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)));
|
comm::send(osmain_ch, osmain::get_draw_target(comm::chan(draw_target_po)));
|
||||||
let draw_target = comm::recv(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;
|
let mut exit_confirm_ch = none;
|
||||||
loop {
|
loop {
|
||||||
alt comm::recv::<msg>(po) {
|
alt comm::recv::<msg>(po) {
|
||||||
draw(model) {
|
draw(display_list) {
|
||||||
let black_rect = {
|
|
||||||
x: 0 as azure::AzFloat,
|
draw_display_list(draw_target, display_list);
|
||||||
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) }
|
|
||||||
);
|
|
||||||
|
|
||||||
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();
|
let draw_po = comm::port();
|
||||||
comm::send(osmain_ch, osmain::draw(comm::chan(draw_po)));
|
comm::send(osmain_ch, osmain::draw(comm::chan(draw_po)));
|
||||||
comm::recv(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();
|
assert exit_confirm_ch.is_some();
|
||||||
comm::send(exit_confirm_ch.get(), ());
|
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) }
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
12
src/servo/layout/display_list.rs
Normal file
12
src/servo/layout/display_list.rs
Normal 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];
|
|
@ -6,6 +6,9 @@ Builds display lists on request and passes them to the renderer
|
||||||
|
|
||||||
import task::*;
|
import task::*;
|
||||||
import comm::*;
|
import comm::*;
|
||||||
|
import display_list::*;
|
||||||
|
import gfx::geom;
|
||||||
|
import gfx::geom::*;
|
||||||
import gfx::renderer;
|
import gfx::renderer;
|
||||||
|
|
||||||
enum msg {
|
enum msg {
|
||||||
|
@ -26,11 +29,26 @@ fn lister(renderer: chan<renderer::msg>) -> chan<msg> {
|
||||||
let mut h2 = 300;
|
let mut h2 = 300;
|
||||||
|
|
||||||
while !peek(po) {
|
while !peek(po) {
|
||||||
let model = {
|
let dlist = [
|
||||||
x1: x1, y1: y1, w1: w1, h1: h1,
|
display_item({
|
||||||
x2: x2, y2: y2, w2: w2, h2: h2
|
item_type: solid_color,
|
||||||
};
|
bounds: geom::box(
|
||||||
send(renderer, gfx::renderer::draw(model));
|
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);
|
std::timer::sleep(100u);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ mod image {
|
||||||
|
|
||||||
mod layout {
|
mod layout {
|
||||||
mod base;
|
mod base;
|
||||||
|
mod display_list;
|
||||||
mod lister;
|
mod lister;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue