mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
Use pipes for drawing interface
This commit is contained in:
parent
41a68d1813
commit
8f1f4f479d
3 changed files with 40 additions and 33 deletions
|
@ -30,16 +30,16 @@ import layout::display_list::display_list;
|
|||
type PngSink = chan<Msg>;
|
||||
|
||||
enum Msg {
|
||||
BeginDrawing(chan<AzDrawTargetRef>),
|
||||
Draw(chan<AzDrawTargetRef>, AzDrawTargetRef),
|
||||
BeginDrawing(pipes::chan<AzDrawTargetRef>),
|
||||
Draw(pipes::chan<AzDrawTargetRef>, AzDrawTargetRef),
|
||||
Exit
|
||||
}
|
||||
|
||||
impl PngSink of Sink for chan<Msg> {
|
||||
fn begin_drawing(next_dt: chan<AzDrawTargetRef>) {
|
||||
fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
|
||||
self.send(BeginDrawing(next_dt))
|
||||
}
|
||||
fn draw(next_dt: chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
|
||||
fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
|
||||
self.send(Draw(next_dt, draw_me))
|
||||
}
|
||||
fn add_event_listener(_listener: chan<Event>) {
|
||||
|
@ -76,7 +76,7 @@ fn PngSink(output: chan<~[u8]>) -> PngSink {
|
|||
})
|
||||
}
|
||||
|
||||
fn do_draw(sender: chan<AzDrawTargetRef>,
|
||||
fn do_draw(sender: pipes::chan<AzDrawTargetRef>,
|
||||
dt: AzDrawTargetRef,
|
||||
output: chan<~[u8]>,
|
||||
cairo_surf: *cairo_surface_t) {
|
||||
|
|
|
@ -31,38 +31,45 @@ each rendered frame and submit them to be drawn to the display
|
|||
FIXME: Change this name to Compositor.
|
||||
"]
|
||||
iface Sink {
|
||||
fn begin_drawing(next_dt: comm::chan<AzDrawTargetRef>);
|
||||
fn draw(next_dt: comm::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef);
|
||||
fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>);
|
||||
fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef);
|
||||
fn add_event_listener(listener: comm::chan<Event>);
|
||||
}
|
||||
|
||||
fn Renderer<S: Sink send copy>(sink: S) -> comm::chan<Msg> {
|
||||
task::spawn_listener::<Msg>(|po| {
|
||||
listen(|draw_target_ch| {
|
||||
#debug("renderer: beginning rendering loop");
|
||||
sink.begin_drawing(draw_target_ch);
|
||||
let (draw_target_ch, draw_target_po) = pipes::stream();
|
||||
let mut draw_target_ch = draw_target_ch;
|
||||
let mut draw_target_po = draw_target_po;
|
||||
|
||||
loop {
|
||||
alt po.recv() {
|
||||
RenderMsg(display_list) {
|
||||
#debug("renderer: got render request");
|
||||
let draw_target = draw_target_ch.recv();
|
||||
#debug("renderer: rendering");
|
||||
#debug("renderer: beginning rendering loop");
|
||||
sink.begin_drawing(draw_target_ch);
|
||||
|
||||
do util::time::time(~"rendering") {
|
||||
clear(draw_target);
|
||||
draw_display_list(draw_target, display_list);
|
||||
#debug("renderer: returning surface");
|
||||
sink.draw(draw_target_ch, draw_target);
|
||||
}
|
||||
}
|
||||
ExitMsg(response_ch) {
|
||||
response_ch.send(());
|
||||
break;
|
||||
}
|
||||
loop {
|
||||
alt po.recv() {
|
||||
RenderMsg(display_list) {
|
||||
#debug("renderer: got render request");
|
||||
let draw_target = draw_target_po.recv();
|
||||
let (ch, po) = pipes::stream();
|
||||
let mut draw_target_ch_ = some(ch);
|
||||
draw_target_po = po;
|
||||
#debug("renderer: rendering");
|
||||
do util::time::time(~"rendering") {
|
||||
let mut draw_target_ch = none;
|
||||
draw_target_ch_ <-> draw_target_ch;
|
||||
let draw_target_ch = option::unwrap(draw_target_ch);
|
||||
clear(draw_target);
|
||||
draw_display_list(draw_target, display_list);
|
||||
#debug("renderer: returning surface");
|
||||
sink.draw(draw_target_ch, draw_target);
|
||||
}
|
||||
}
|
||||
ExitMsg(response_ch) {
|
||||
response_ch.send(());
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ import pipes::chan;
|
|||
type OSMain = comm::chan<Msg>;
|
||||
|
||||
enum Msg {
|
||||
BeginDrawing(comm::chan<AzDrawTargetRef>),
|
||||
Draw(comm::chan<AzDrawTargetRef>, AzDrawTargetRef),
|
||||
BeginDrawing(pipes::chan<AzDrawTargetRef>),
|
||||
Draw(pipes::chan<AzDrawTargetRef>, AzDrawTargetRef),
|
||||
AddKeyHandler(pipes::chan<()>),
|
||||
AddEventListener(comm::chan<Event>),
|
||||
Exit
|
||||
|
@ -138,10 +138,10 @@ Implementation to allow the osmain channel to be used as a graphics
|
|||
sink for the renderer
|
||||
"]
|
||||
impl OSMain of Sink for OSMain {
|
||||
fn begin_drawing(next_dt: comm::chan<AzDrawTargetRef>) {
|
||||
fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
|
||||
self.send(BeginDrawing(next_dt))
|
||||
}
|
||||
fn draw(next_dt: comm::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
|
||||
fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
|
||||
self.send(Draw(next_dt, draw_me))
|
||||
}
|
||||
fn add_event_listener(listener: comm::chan<Event>) {
|
||||
|
@ -160,7 +160,7 @@ type surface_set = {
|
|||
}
|
||||
};
|
||||
|
||||
fn lend_surface(surfaces: surface_set, recvr: comm::chan<AzDrawTargetRef>) {
|
||||
fn lend_surface(surfaces: surface_set, recvr: pipes::chan<AzDrawTargetRef>) {
|
||||
// We are in a position to lend out the surface?
|
||||
assert surfaces.s1.have;
|
||||
// Ok then take it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue