mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Only draw on request
This commit is contained in:
parent
0265bc4da2
commit
6dfb977c19
1 changed files with 55 additions and 40 deletions
|
@ -20,10 +20,15 @@ fn on_osmain<T: send>(f: fn~(comm::port<T>)) -> comm::chan<T> {
|
||||||
|
|
||||||
// Messages to the platform event handler task
|
// Messages to the platform event handler task
|
||||||
enum osmain_msg {
|
enum osmain_msg {
|
||||||
get_draw_target(comm::chan<AzDrawTargetRef>),
|
om_get_draw_target(comm::chan<AzDrawTargetRef>),
|
||||||
add_key_handler(comm::chan<()>),
|
om_add_key_handler(comm::chan<()>),
|
||||||
draw(comm::chan<()>),
|
om_draw(comm::chan<()>),
|
||||||
exit
|
om_exit
|
||||||
|
}
|
||||||
|
|
||||||
|
enum draw_msg {
|
||||||
|
dm_draw,
|
||||||
|
dm_exit(comm::chan<()>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -77,13 +82,13 @@ fn main() {
|
||||||
// Handle messages
|
// Handle messages
|
||||||
if comm::peek(po) {
|
if comm::peek(po) {
|
||||||
alt check comm::recv(po) {
|
alt check comm::recv(po) {
|
||||||
add_key_handler(key_ch) {
|
om_add_key_handler(key_ch) {
|
||||||
key_handlers += [key_ch];
|
key_handlers += [key_ch];
|
||||||
}
|
}
|
||||||
get_draw_target(response_ch) {
|
om_get_draw_target(response_ch) {
|
||||||
comm::send(response_ch, azure_target);
|
comm::send(response_ch, azure_target);
|
||||||
}
|
}
|
||||||
draw(response_ch) {
|
om_draw(response_ch) {
|
||||||
sdl::video::unlock_surface(sdl_surf);
|
sdl::video::unlock_surface(sdl_surf);
|
||||||
sdl::video::blit_surface(sdl_surf, ptr::null(),
|
sdl::video::blit_surface(sdl_surf, ptr::null(),
|
||||||
screen, ptr::null());
|
screen, ptr::null());
|
||||||
|
@ -102,9 +107,9 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// The drawing task
|
// The drawing task
|
||||||
let draw_exit_ch = task::spawn_listener {|exit_po|
|
let draw_ch = task::spawn_listener {|po|
|
||||||
let draw_target_po = comm::port();
|
let draw_target_po = comm::port();
|
||||||
comm::send(osmain_ch, get_draw_target(comm::chan(draw_target_po)));
|
comm::send(osmain_ch, om_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 red_color = {
|
let red_color = {
|
||||||
|
@ -123,56 +128,66 @@ fn main() {
|
||||||
};
|
};
|
||||||
let green_pattern = AzCreateColorPattern(ptr::addr_of(green_color));
|
let green_pattern = AzCreateColorPattern(ptr::addr_of(green_color));
|
||||||
|
|
||||||
while !comm::peek(exit_po) {
|
let mut exit_confirm_ch = none;
|
||||||
let red_rect = {
|
loop {
|
||||||
x: 100f as azure::AzFloat,
|
alt comm::recv::<draw_msg>(po) {
|
||||||
y: 100f as azure::AzFloat,
|
dm_draw {
|
||||||
width: 200f as azure::AzFloat,
|
let red_rect = {
|
||||||
height: 200f as azure::AzFloat
|
x: 100f as azure::AzFloat,
|
||||||
};
|
y: 100f as azure::AzFloat,
|
||||||
AzDrawTargetFillRect(
|
width: 200f as azure::AzFloat,
|
||||||
draw_target,
|
height: 200f as azure::AzFloat
|
||||||
ptr::addr_of(red_rect),
|
};
|
||||||
unsafe { unsafe::reinterpret_cast(red_pattern) }
|
AzDrawTargetFillRect(
|
||||||
);
|
draw_target,
|
||||||
let green_rect = {
|
ptr::addr_of(red_rect),
|
||||||
x: 200f as azure::AzFloat,
|
unsafe { unsafe::reinterpret_cast(red_pattern) }
|
||||||
y: 200f as azure::AzFloat,
|
);
|
||||||
width: 200f as azure::AzFloat,
|
let green_rect = {
|
||||||
height: 200f as azure::AzFloat
|
x: 200f as azure::AzFloat,
|
||||||
};
|
y: 200f as azure::AzFloat,
|
||||||
AzDrawTargetFillRect(
|
width: 200f as azure::AzFloat,
|
||||||
draw_target,
|
height: 200f as azure::AzFloat
|
||||||
ptr::addr_of(green_rect),
|
};
|
||||||
unsafe { unsafe::reinterpret_cast(green_pattern) }
|
AzDrawTargetFillRect(
|
||||||
);
|
draw_target,
|
||||||
let draw_po = comm::port();
|
ptr::addr_of(green_rect),
|
||||||
comm::send(osmain_ch, draw(comm::chan(draw_po)));
|
unsafe { unsafe::reinterpret_cast(green_pattern) }
|
||||||
comm::recv(draw_po);
|
);
|
||||||
|
let draw_po = comm::port();
|
||||||
|
comm::send(osmain_ch, om_draw(comm::chan(draw_po)));
|
||||||
|
comm::recv(draw_po);
|
||||||
|
}
|
||||||
|
dm_exit(response_ch) {
|
||||||
|
exit_confirm_ch = some(response_ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AzReleaseColorPattern(red_pattern);
|
AzReleaseColorPattern(red_pattern);
|
||||||
AzReleaseColorPattern(green_pattern);
|
AzReleaseColorPattern(green_pattern);
|
||||||
|
|
||||||
let exit_confirm_ch = comm::recv(exit_po);
|
assert exit_confirm_ch.is_some();
|
||||||
comm::send(exit_confirm_ch, ());
|
comm::send(exit_confirm_ch.get(), ());
|
||||||
};
|
};
|
||||||
|
|
||||||
// The keyboard handler
|
// The keyboard handler
|
||||||
task::spawn {||
|
task::spawn {||
|
||||||
let key_po = comm::port();
|
let key_po = comm::port();
|
||||||
comm::send(osmain_ch, add_key_handler(comm::chan(key_po)));
|
comm::send(osmain_ch, om_add_key_handler(comm::chan(key_po)));
|
||||||
loop {
|
loop {
|
||||||
alt comm::recv(key_po) {
|
alt comm::recv(key_po) {
|
||||||
_ {
|
_ {
|
||||||
let draw_exit_confirm_po = comm::port();
|
let draw_exit_confirm_po = comm::port();
|
||||||
comm::send(draw_exit_ch, comm::chan(draw_exit_confirm_po));
|
comm::send(draw_ch, dm_exit(comm::chan(draw_exit_confirm_po)));
|
||||||
comm::recv(draw_exit_confirm_po);
|
comm::recv(draw_exit_confirm_po);
|
||||||
comm::send(osmain_ch, exit);
|
comm::send(osmain_ch, om_exit);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comm::send(draw_ch, dm_draw);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue