diff --git a/src/components/gfx/gfx.rc b/src/components/gfx/gfx.rc index 19977a2d4e5..b38fe166ca6 100644 --- a/src/components/gfx/gfx.rc +++ b/src/components/gfx/gfx.rc @@ -8,7 +8,7 @@ url = "http://servo.org/")]; #[crate_type = "lib"]; -#[feature(globs, managed_boxes)]; +#[feature(globs, managed_boxes, macro_rules)]; extern mod azure; extern mod extra; diff --git a/src/components/gfx/render_task.rs b/src/components/gfx/render_task.rs index a385c9530cf..34ff27cfcb5 100644 --- a/src/components/gfx/render_task.rs +++ b/src/components/gfx/render_task.rs @@ -107,7 +107,7 @@ pub struct RenderTask { graphics_context: GraphicsContext, /// The native graphics context. - native_graphics_context: NativePaintingGraphicsContext, + native_graphics_context: Option, /// The layer to be rendered render_layer: Option>, @@ -122,6 +122,14 @@ pub struct RenderTask { buffer_map: BufferMap<~LayerBuffer>, } +// If we implement this as a function, we get borrowck errors from borrowing +// the whole RenderTask struct. +macro_rules! native_graphics_context( + ($task:expr) => ( + $task.native_graphics_context.as_ref().expect("Need a graphics context to do rendering") + ) +) + impl RenderTask { pub fn create(id: PipelineId, port: Port>, @@ -132,10 +140,9 @@ impl RenderTask { do spawn_with((port, compositor, constellation_chan, opts, profiler_chan)) |(port, compositor, constellation_chan, opts, profiler_chan)| { - let graphics_metadata = compositor.get_graphics_metadata(); + let native_graphics_context = compositor.get_graphics_metadata().map( + |md| NativePaintingGraphicsContext::from_metadata(&md)); let cpu_painting = opts.cpu_painting; - let native_graphics_context = - NativePaintingGraphicsContext::from_metadata(&graphics_metadata); // FIXME: rust/#5967 let mut render_task = RenderTask { @@ -167,7 +174,7 @@ impl RenderTask { render_task.start(); // Destroy all the buffers. - render_task.buffer_map.clear(&render_task.native_graphics_context) + render_task.buffer_map.clear(native_graphics_context!(render_task)); } } @@ -195,7 +202,7 @@ impl RenderTask { UnusedBufferMsg(unused_buffers) => { // move_rev_iter is more efficient for buffer in unused_buffers.move_rev_iter() { - self.buffer_map.insert(&self.native_graphics_context, buffer); + self.buffer_map.insert(native_graphics_context!(self), buffer); } } PaintPermissionGranted => { @@ -249,7 +256,7 @@ impl RenderTask { // (texture color buffer, renderbuffers) instead of recreating them. let draw_target = DrawTarget::new_with_fbo(self.opts.render_backend, - &self.native_graphics_context, + native_graphics_context!(self), size, B8G8R8A8); draw_target.make_current(); @@ -306,7 +313,7 @@ impl RenderTask { // in case it dies in transit to the compositor task. let mut native_surface: NativeSurface = layers::platform::surface::NativeSurfaceMethods::new( - &self.native_graphics_context, + native_graphics_context!(self), Size2D(width as i32, height as i32), width as i32 * 4); native_surface.mark_wont_leak(); @@ -322,7 +329,7 @@ impl RenderTask { }; do draw_target.snapshot().get_data_surface().with_data |data| { - buffer.native_surface.upload(&self.native_graphics_context, data); + buffer.native_surface.upload(native_graphics_context!(self), data); debug!("RENDERER uploading to native surface {:d}", buffer.native_surface.get_id() as int); } diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index 4f915cf82e7..56472b895d1 100755 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -61,7 +61,7 @@ impl ScriptListener for CompositorChan { /// Implementation of the abstract `RenderListener` interface. impl RenderListener for CompositorChan { - fn get_graphics_metadata(&self) -> NativeGraphicsMetadata { + fn get_graphics_metadata(&self) -> Option { let (port, chan) = comm::stream(); self.chan.send(GetGraphicsMetadata(chan)); port.recv() @@ -117,7 +117,9 @@ pub enum Msg { /// Requests the compositor's graphics metadata. Graphics metadata is what the renderer needs /// to create surfaces that the compositor can see. On Linux this is the X display; on Mac this /// is the pixel format. - GetGraphicsMetadata(Chan), + /// + /// The headless compositor returns `None`. + GetGraphicsMetadata(Chan>), /// Alerts the compositor that there is a new layer to be rendered. NewLayer(PipelineId, Size2D), diff --git a/src/components/main/compositing/run.rs b/src/components/main/compositing/run.rs index b1b1a3bf783..a498b7fc9b6 100755 --- a/src/components/main/compositing/run.rs +++ b/src/components/main/compositing/run.rs @@ -131,7 +131,7 @@ pub fn run_compositor(compositor: &CompositorTask) { constellation_chan = Some(new_constellation_chan); } - GetGraphicsMetadata(chan) => chan.send(azure_hl::current_graphics_metadata()), + GetGraphicsMetadata(chan) => chan.send(Some(azure_hl::current_graphics_metadata())), NewLayer(_id, new_size) => { // FIXME: This should create an additional layer instead of replacing the current one. diff --git a/src/components/main/compositing/run_headless.rs b/src/components/main/compositing/run_headless.rs index 914891a124f..29a8e1db96c 100755 --- a/src/components/main/compositing/run_headless.rs +++ b/src/components/main/compositing/run_headless.rs @@ -4,8 +4,6 @@ use compositing::*; -use std::unstable::intrinsics; - /// Starts the compositor, which listens for messages on the specified port. /// /// This is the null compositor which doesn't draw anything to the screen. @@ -15,10 +13,8 @@ pub fn run_compositor(compositor: &CompositorTask) { match compositor.port.recv() { Exit => break, - GetGraphicsMetadata(chan) => { - unsafe { - chan.send(intrinsics::uninit()); - } + GetGraphicsMetadata(chan) => { + chan.send(None); } SetIds(_, response_chan, _) => { diff --git a/src/components/msg/compositor_msg.rs b/src/components/msg/compositor_msg.rs index c1d84cfa062..c5c02c52098 100755 --- a/src/components/msg/compositor_msg.rs +++ b/src/components/msg/compositor_msg.rs @@ -76,7 +76,7 @@ impl Epoch { /// The interface used by the renderer to acquire draw targets for each render frame and /// submit them to be drawn to the display. pub trait RenderListener { - fn get_graphics_metadata(&self) -> NativeGraphicsMetadata; + fn get_graphics_metadata(&self) -> Option; fn new_layer(&self, PipelineId, Size2D); fn set_layer_page_size_and_color(&self, PipelineId, Size2D, Epoch, Color); fn set_layer_clip_rect(&self, PipelineId, Rect);