mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move drawing code to compositor module
This commit is contained in:
parent
897c9dbc07
commit
2d13075f63
3 changed files with 100 additions and 96 deletions
96
src/servo/gfx/compositor.rs
Normal file
96
src/servo/gfx/compositor.rs
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
type model = {
|
||||||
|
x1: int, y1: int, w1: int, h1: int,
|
||||||
|
x2: int, y2: int, w2: int, h2: int
|
||||||
|
};
|
||||||
|
|
||||||
|
enum msg {
|
||||||
|
draw(model),
|
||||||
|
exit(comm::chan<()>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compositor(osmain_ch: comm::chan<osmain_msg>) -> comm::chan<msg> {
|
||||||
|
task::spawn_listener {|po|
|
||||||
|
let draw_target_po = comm::port();
|
||||||
|
comm::send(osmain_ch, om_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) }
|
||||||
|
);
|
||||||
|
|
||||||
|
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, om_draw(comm::chan(draw_po)));
|
||||||
|
comm::recv(draw_po);
|
||||||
|
}
|
||||||
|
exit(response_ch) {
|
||||||
|
exit_confirm_ch = some(response_ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AzReleaseColorPattern(red_pattern);
|
||||||
|
AzReleaseColorPattern(green_pattern);
|
||||||
|
|
||||||
|
assert exit_confirm_ch.is_some();
|
||||||
|
comm::send(exit_confirm_ch.get(), ());
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ mod dom {
|
||||||
mod gfx {
|
mod gfx {
|
||||||
mod geom;
|
mod geom;
|
||||||
mod surface;
|
mod surface;
|
||||||
|
mod compositor;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod image {
|
mod image {
|
||||||
|
|
|
@ -33,16 +33,6 @@ enum osmain_msg {
|
||||||
om_exit
|
om_exit
|
||||||
}
|
}
|
||||||
|
|
||||||
enum draw_msg {
|
|
||||||
dm_draw(model),
|
|
||||||
dm_exit(comm::chan<()>)
|
|
||||||
}
|
|
||||||
|
|
||||||
type model = {
|
|
||||||
x1: int, y1: int, w1: int, h1: int,
|
|
||||||
x2: int, y2: int, w2: int, h2: int
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// The platform event handler thread
|
// The platform event handler thread
|
||||||
let osmain_ch = on_osmain::<osmain_msg> {|po|
|
let osmain_ch = on_osmain::<osmain_msg> {|po|
|
||||||
|
@ -119,90 +109,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// The drawing task
|
// The drawing task
|
||||||
let draw_ch = task::spawn_listener {|po|
|
let draw_ch = gfx::compositor::compositor(osmain_ch);
|
||||||
let draw_target_po = comm::port();
|
|
||||||
comm::send(osmain_ch, om_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::<draw_msg>(po) {
|
|
||||||
dm_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) }
|
|
||||||
);
|
|
||||||
|
|
||||||
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, 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(green_pattern);
|
|
||||||
|
|
||||||
assert exit_confirm_ch.is_some();
|
|
||||||
comm::send(exit_confirm_ch.get(), ());
|
|
||||||
};
|
|
||||||
|
|
||||||
// The model
|
// The model
|
||||||
let model_ch = task::spawn_listener {|po|
|
let model_ch = task::spawn_listener {|po|
|
||||||
|
@ -220,7 +127,7 @@ fn main() {
|
||||||
x1: x1, y1: y1, w1: w1, h1: h1,
|
x1: x1, y1: y1, w1: w1, h1: h1,
|
||||||
x2: x2, y2: y2, w2: w2, h2: h2
|
x2: x2, y2: y2, w2: w2, h2: h2
|
||||||
};
|
};
|
||||||
comm::send(draw_ch, dm_draw(model));
|
comm::send(draw_ch, gfx::compositor::draw(model));
|
||||||
|
|
||||||
sleep();
|
sleep();
|
||||||
|
|
||||||
|
@ -244,7 +151,7 @@ fn main() {
|
||||||
_ {
|
_ {
|
||||||
comm::send(model_ch, ());
|
comm::send(model_ch, ());
|
||||||
let draw_exit_confirm_po = comm::port();
|
let draw_exit_confirm_po = comm::port();
|
||||||
comm::send(draw_ch, dm_exit(comm::chan(draw_exit_confirm_po)));
|
comm::send(draw_ch, gfx::compositor::exit(comm::chan(draw_exit_confirm_po)));
|
||||||
comm::recv(draw_exit_confirm_po);
|
comm::recv(draw_exit_confirm_po);
|
||||||
comm::send(osmain_ch, om_exit);
|
comm::send(osmain_ch, om_exit);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue