Skip to content
Browse files

Use the high-level Azure API everywhere

  • Loading branch information...
1 parent 989302d commit 160baa61be48674f843501b7b09e2a606fd4635d @pcwalton pcwalton committed Aug 16, 2012
Showing with 29 additions and 28 deletions.
  1. +1 −1 src/rust-azure
  2. +11 −11 src/servo/gfx/pngsink.rs
  3. +9 −8 src/servo/gfx/renderer.rs
  4. +8 −8 src/servo/platform/osmain.rs
2 src/rust-azure
@@ -1 +1 @@
-Subproject commit 9e604c78152cda2fa43f1e11427fcccf658dff6d
+Subproject commit f47c170c826a5634c894097d1778062c42e2896c
View
22 src/servo/gfx/pngsink.rs
@@ -8,7 +8,6 @@ Each time the renderer renders a frame the bufsink will output a
export PngSink, Msg, Exit;
import libc::{c_int, c_uint, c_void, c_uchar};
-import azure::AzDrawTargetRef;
import azure_bg = azure::bindgen;
import azure_bg::{AzCreateDrawTargetForCairoSurface, AzReleaseDrawTarget};
import azure::cairo;
@@ -27,20 +26,21 @@ import ptr::addr_of;
import dom::event::Event;
import dvec::dvec;
import layout::display_list::display_list;
+import std::cell::Cell;
type PngSink = Chan<Msg>;
enum Msg {
- BeginDrawing(pipes::chan<AzDrawTargetRef>),
- Draw(pipes::chan<AzDrawTargetRef>, AzDrawTargetRef),
+ BeginDrawing(pipes::chan<DrawTarget>),
+ Draw(pipes::chan<DrawTarget>, DrawTarget),
Exit
}
impl Chan<Msg> : Sink {
- fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
+ fn begin_drawing(+next_dt: pipes::chan<DrawTarget>) {
self.send(BeginDrawing(next_dt))
}
- fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
+ fn draw(+next_dt: pipes::chan<DrawTarget>, +draw_me: DrawTarget) {
self.send(Draw(next_dt, draw_me))
}
fn add_event_listener(_listener: Chan<Event>) {
@@ -51,26 +51,26 @@ impl Chan<Msg> : Sink {
fn PngSink(output: Chan<~[u8]>) -> PngSink {
do spawn_listener |po: Port<Msg>| {
let cairo_surface = ImageSurface(CAIRO_FORMAT_ARGB32, 800, 600);
- let draw_target = DrawTarget(cairo_surface);
+ let draw_target = Cell(DrawTarget(cairo_surface));
loop {
match po.recv() {
BeginDrawing(sender) => {
debug!("pngsink: begin_drawing");
- sender.send(draw_target.azure_draw_target);
+ sender.send(draw_target.take());
}
Draw(sender, dt) => {
debug!("pngsink: draw");
- do_draw(sender, dt, output, cairo_surface);
+ do_draw(sender, dt.clone(), output, cairo_surface);
}
Exit => break
}
}
}
}
-fn do_draw(sender: pipes::chan<AzDrawTargetRef>,
- dt: AzDrawTargetRef,
+fn do_draw(sender: pipes::chan<DrawTarget>,
+ +dt: DrawTarget,
output: Chan<~[u8]>,
cairo_surface: ImageSurface) {
let buffer = io::mem_buffer();
@@ -79,7 +79,7 @@ fn do_draw(sender: pipes::chan<AzDrawTargetRef>,
output.send(vec::from_mut(dvec::unwrap(move buffer)));
// Send the next draw target to the renderer
- sender.send(dt);
+ sender.send(move dt);
}
#[test]
View
17 src/servo/gfx/renderer.rs
@@ -17,6 +17,7 @@ import azure_hl::{DrawTarget, Linear};
import ptr::addr_of;
import std::arc::arc;
import azure::cairo::{cairo_font_face_t, cairo_scaled_font_t};
+import std::cell::Cell;
import pipes::{port, chan};
@@ -34,8 +35,8 @@ each rendered frame and submit them to be drawn to the display
FIXME: Change this name to Compositor.
"]
trait Sink {
- fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>);
- fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef);
+ fn begin_drawing(+next_dt: pipes::chan<DrawTarget>);
+ fn draw(+next_dt: pipes::chan<DrawTarget>, +draw_me: DrawTarget);
fn add_event_listener(listener: comm::Chan<Event>);
}
@@ -53,7 +54,7 @@ fn Renderer<S: Sink send copy>(sink: S) -> comm::Chan<Msg> {
match po.recv() {
RenderMsg(display_list) => {
#debug("renderer: got render request");
- let azure_draw_target = draw_target_po.recv();
+ let draw_target = Cell(draw_target_po.recv());
let (ch, po) = pipes::stream();
let mut draw_target_ch_ = some(ch);
draw_target_po = po;
@@ -63,13 +64,13 @@ fn Renderer<S: Sink send copy>(sink: S) -> comm::Chan<Msg> {
draw_target_ch_ <-> draw_target_ch;
let draw_target_ch = option::unwrap(draw_target_ch);
- let draw_target =
- azure_hl::new_draw_target_from_azure_draw_target(azure_draw_target);
- clear(&draw_target);
- draw_display_list(&draw_target, display_list);
+ do draw_target.with_ref |draw_target| {
+ clear(draw_target);
+ draw_display_list(draw_target, display_list);
+ }
#debug("renderer: returning surface");
- sink.draw(draw_target_ch, azure_draw_target);
+ sink.draw(draw_target_ch, draw_target.take());
}
}
ExitMsg(response_ch) => {
View
16 src/servo/platform/osmain.rs
@@ -23,8 +23,8 @@ import pipes::chan;
type OSMain = comm::Chan<Msg>;
enum Msg {
- BeginDrawing(pipes::chan<AzDrawTargetRef>),
- Draw(pipes::chan<AzDrawTargetRef>, AzDrawTargetRef),
+ BeginDrawing(pipes::chan<DrawTarget>),
+ Draw(pipes::chan<DrawTarget>, DrawTarget),
AddKeyHandler(pipes::chan<()>),
AddEventListener(comm::Chan<Event>),
Exit
@@ -125,10 +125,10 @@ Implementation to allow the osmain channel to be used as a graphics
sink for the renderer
"]
impl OSMain : Sink {
- fn begin_drawing(+next_dt: pipes::chan<AzDrawTargetRef>) {
+ fn begin_drawing(+next_dt: pipes::chan<DrawTarget>) {
self.send(BeginDrawing(next_dt))
}
- fn draw(+next_dt: pipes::chan<AzDrawTargetRef>, draw_me: AzDrawTargetRef) {
+ fn draw(+next_dt: pipes::chan<DrawTarget>, +draw_me: DrawTarget) {
self.send(Draw(next_dt, draw_me))
}
fn add_event_listener(listener: comm::Chan<Event>) {
@@ -141,11 +141,11 @@ struct SurfaceSet {
mut back: Surface;
}
-fn lend_surface(surfaces: SurfaceSet, receiver: pipes::chan<AzDrawTargetRef>) {
+fn lend_surface(surfaces: SurfaceSet, receiver: pipes::chan<DrawTarget>) {
// We are in a position to lend out the surface?
assert surfaces.front.have;
// Ok then take it
- let draw_target = surfaces.front.draw_target.azure_draw_target;
+ let draw_target = azure_hl::clone_mutable_draw_target(&mut surfaces.front.draw_target);
#debug("osmain: lending surface %?", draw_target);
receiver.send(draw_target);
// Now we don't have it
@@ -156,14 +156,14 @@ fn lend_surface(surfaces: SurfaceSet, receiver: pipes::chan<AzDrawTargetRef>) {
assert surfaces.front.have;
}
-fn return_surface(surfaces: SurfaceSet, draw_target: AzDrawTargetRef) {
+fn return_surface(surfaces: SurfaceSet, draw_target: DrawTarget) {
#debug("osmain: returning surface %?", draw_target);
// We have room for a return
assert surfaces.front.have;
assert !surfaces.back.have;
// FIXME: This is incompatible with page resizing.
- assert surfaces.back.draw_target.azure_draw_target == draw_target;
+ assert surfaces.back.draw_target.azure_draw_target == draw_target.azure_draw_target;
// Now we have it again
surfaces.back.have = true;

0 comments on commit 160baa6

Please sign in to comment.
Something went wrong with that request. Please try again.