diff options
Diffstat (limited to 'src/components/msg')
-rw-r--r-- | src/components/msg/compositor_msg.rs | 47 | ||||
-rw-r--r-- | src/components/msg/msg.rc | 28 | ||||
-rw-r--r-- | src/components/msg/platform/linux/surface.rs | 20 | ||||
-rw-r--r-- | src/components/msg/platform/macos/surface.rs | 26 | ||||
-rw-r--r-- | src/components/msg/platform/surface.rs | 12 |
5 files changed, 118 insertions, 15 deletions
diff --git a/src/components/msg/compositor_msg.rs b/src/components/msg/compositor_msg.rs index 89a01604766..9a0e5883575 100644 --- a/src/components/msg/compositor_msg.rs +++ b/src/components/msg/compositor_msg.rs @@ -2,38 +2,46 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use azure::azure_hl::DrawTarget; -use azure::azure::AzGLContext; use geom::rect::Rect; use geom::size::Size2D; +use layers::platform::surface::{NativeGraphicsMetadata, NativePaintingGraphicsContext}; +use layers::platform::surface::{NativeSurface, NativeSurfaceMethods}; use constellation_msg::PipelineId; -#[deriving(Clone)] pub struct LayerBuffer { - draw_target: DrawTarget, + /// The native surface which can be shared between threads or processes. On Mac this is an + /// `IOSurface`; on Linux this is an X Pixmap; on Android this is an `EGLImageKHR`. + native_surface: NativeSurface, - // The rect in the containing RenderLayer that this represents. + /// The rect in the containing RenderLayer that this represents. rect: Rect<f32>, - // The rect in pixels that will be drawn to the screen. + /// The rect in pixels that will be drawn to the screen. screen_pos: Rect<uint>, - // The scale at which this tile is rendered + /// The scale at which this tile is rendered resolution: f32, - // NB: stride is in pixels, like OpenGL GL_UNPACK_ROW_LENGTH. + /// NB: stride is in pixels, like OpenGL GL_UNPACK_ROW_LENGTH. stride: uint, - } /// A set of layer buffers. This is an atomic unit used to switch between the front and back /// buffers. -#[deriving(Clone)] pub struct LayerBufferSet { buffers: ~[~LayerBuffer] } +impl LayerBufferSet { + /// Notes all buffer surfaces will leak if not destroyed via a call to `destroy`. + pub fn mark_will_leak(&mut self) { + for buffer in self.buffers.mut_iter() { + buffer.native_surface.mark_will_leak() + } + } +} + /// The status of the renderer. #[deriving(Eq)] pub enum RenderState { @@ -66,7 +74,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_gl_context(&self) -> AzGLContext; + fn get_graphics_metadata(&self) -> NativeGraphicsMetadata; fn new_layer(&self, PipelineId, Size2D<uint>); fn set_layer_page_size(&self, PipelineId, Size2D<uint>, Epoch); fn set_layer_clip_rect(&self, PipelineId, Rect<uint>); @@ -83,7 +91,7 @@ pub trait ScriptListener : Clone { fn close(&self); } -/// The interface used by the quadtree to get info about LayerBuffers +/// The interface used by the quadtree and buffer map to get info about layer buffers. pub trait Tile { /// Returns the amount of memory used by the tile fn get_mem(&self) -> uint; @@ -91,6 +99,13 @@ pub trait Tile { fn is_valid(&self, f32) -> bool; /// Returns the Size2D of the tile fn get_size_2d(&self) -> Size2D<uint>; + + /// Marks the layer buffer as not leaking. See comments on + /// `NativeSurfaceMethods::mark_wont_leak` for how this is used. + fn mark_wont_leak(&mut self); + + /// Destroys the layer buffer. Painting task only. + fn destroy(self, graphics_context: &NativePaintingGraphicsContext); } impl Tile for ~LayerBuffer { @@ -104,4 +119,12 @@ impl Tile for ~LayerBuffer { fn get_size_2d(&self) -> Size2D<uint> { self.screen_pos.size } + fn mark_wont_leak(&mut self) { + self.native_surface.mark_wont_leak() + } + fn destroy(self, graphics_context: &NativePaintingGraphicsContext) { + let mut this = self; + this.native_surface.destroy(graphics_context) + } } + diff --git a/src/components/msg/msg.rc b/src/components/msg/msg.rc index 318d91fbdc6..3811f5bffa7 100644 --- a/src/components/msg/msg.rc +++ b/src/components/msg/msg.rc @@ -8,11 +8,33 @@ url = "http://servo.org/")]; #[crate_type = "lib"]; - extern mod azure; -extern mod std; -extern mod geom; extern mod extra; +extern mod geom; +extern mod layers; +extern mod std; + +#[cfg(target_os="macos")] +extern mod core_foundation; +#[cfg(target_os="macos")] +extern mod io_surface; pub mod compositor_msg; pub mod constellation_msg; + +pub mod platform { + #[cfg(target_os="macos")] + pub mod macos { + #[cfg(target_os="macos")] + pub mod surface; + } + + #[cfg(target_os="linux")] + pub mod linux { + #[cfg(target_os="linux")] + pub mod surface; + } + + pub mod surface; +} + diff --git a/src/components/msg/platform/linux/surface.rs b/src/components/msg/platform/linux/surface.rs new file mode 100644 index 00000000000..3ebd1d5b643 --- /dev/null +++ b/src/components/msg/platform/linux/surface.rs @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! X11-specific implementation of cross-process surfaces. This uses X pixmaps. + +use platform::surface::NativeSurfaceAzureMethods; + +use azure::AzSkiaGrGLSharedSurfaceRef; +use layers::platform::surface::NativeSurface; +use std::cast; + +impl NativeSurfaceAzureMethods for NativeSurface { + fn from_azure_surface(surface: AzSkiaGrGLSharedSurfaceRef) -> NativeSurface { + unsafe { + NativeSurface::from_pixmap(cast::transmute(surface)) + } + } +} + diff --git a/src/components/msg/platform/macos/surface.rs b/src/components/msg/platform/macos/surface.rs new file mode 100644 index 00000000000..3bf5f9b5ab7 --- /dev/null +++ b/src/components/msg/platform/macos/surface.rs @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Mac OS-specific implementation of cross-process surfaces. This uses `IOSurface`, introduced +//! in Mac OS X 10.6 Snow Leopard. + +use platform::surface::NativeSurfaceAzureMethods; + +use azure::AzSkiaGrGLSharedSurfaceRef; +use core_foundation::base::CFWrapper; +use io_surface::IOSurface; +use layers::platform::surface::NativeSurface; +use std::cast; + +impl NativeSurfaceAzureMethods for NativeSurface { + fn from_azure_surface(surface: AzSkiaGrGLSharedSurfaceRef) -> NativeSurface { + unsafe { + let io_surface = IOSurface { + contents: CFWrapper::wrap_owned(cast::transmute(surface)), + }; + NativeSurface::from_io_surface(io_surface) + } + } +} + diff --git a/src/components/msg/platform/surface.rs b/src/components/msg/platform/surface.rs new file mode 100644 index 00000000000..eee8dfa5598 --- /dev/null +++ b/src/components/msg/platform/surface.rs @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Declarations of types for cross-process surfaces. + +use azure::AzSkiaGrGLSharedSurfaceRef; + +pub trait NativeSurfaceAzureMethods { + fn from_azure_surface(surface: AzSkiaGrGLSharedSurfaceRef) -> Self; +} + |