mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Merge pull request #1339 from kmcallister/native_graphics_context
Return None from get_graphics_metadata in headless compositor
This commit is contained in:
commit
2c4714e803
6 changed files with 25 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -107,7 +107,7 @@ pub struct RenderTask<C,T> {
|
|||
graphics_context: GraphicsContext,
|
||||
|
||||
/// The native graphics context.
|
||||
native_graphics_context: NativePaintingGraphicsContext,
|
||||
native_graphics_context: Option<NativePaintingGraphicsContext>,
|
||||
|
||||
/// The layer to be rendered
|
||||
render_layer: Option<RenderLayer<T>>,
|
||||
|
@ -122,6 +122,14 @@ pub struct RenderTask<C,T> {
|
|||
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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
||||
pub fn create(id: PipelineId,
|
||||
port: Port<Msg<T>>,
|
||||
|
@ -132,10 +140,9 @@ impl<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
// (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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
// 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<C: RenderListener + Send,T:Send+Freeze> RenderTask<C,T> {
|
|||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<NativeGraphicsMetadata> {
|
||||
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<NativeGraphicsMetadata>),
|
||||
///
|
||||
/// The headless compositor returns `None`.
|
||||
GetGraphicsMetadata(Chan<Option<NativeGraphicsMetadata>>),
|
||||
|
||||
/// Alerts the compositor that there is a new layer to be rendered.
|
||||
NewLayer(PipelineId, Size2D<f32>),
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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, _) => {
|
||||
|
|
|
@ -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<NativeGraphicsMetadata>;
|
||||
fn new_layer(&self, PipelineId, Size2D<uint>);
|
||||
fn set_layer_page_size_and_color(&self, PipelineId, Size2D<uint>, Epoch, Color);
|
||||
fn set_layer_clip_rect(&self, PipelineId, Rect<uint>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue