diff --git a/src/draw_buffer.rs b/src/draw_buffer.rs index 0d7b055..b9c2ed9 100644 --- a/src/draw_buffer.rs +++ b/src/draw_buffer.rs @@ -266,7 +266,7 @@ impl DrawBufferHelpers for DrawBuffer { let mut texture = Texture::new(target, Size2D::new(self.size.width as usize, self.size.height as usize)); texture.flip = flip; - let surface_wrapper = LayersSurfaceWrapper::new(context.get_metadata(), self.size); + let surface_wrapper = LayersSurfaceWrapper::new(context.get_display(), self.size); surface_wrapper.bind_to_texture(&texture); Some(ColorAttachment::TextureWithSurface(surface_wrapper, texture)) diff --git a/src/gl_context.rs b/src/gl_context.rs index 170e49f..ddf84c7 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -11,7 +11,7 @@ use ColorAttachmentType; use NativeGLContext; #[cfg(feature="texture_surface")] -use layers::platform::surface::NativeGraphicsMetadata; +use layers::platform::surface::NativeDisplay; /// This is a wrapper over a native headless GL context @@ -130,8 +130,8 @@ impl GLContext { } #[cfg(feature="texture_surface")] - pub fn get_metadata(&self) -> NativeGraphicsMetadata { - self.native_context.get_metadata() + pub fn get_display(&self) -> NativeDisplay { + self.native_context.get_display() } } diff --git a/src/layers_surface_wrapper.rs b/src/layers_surface_wrapper.rs index 240ba53..1718875 100644 --- a/src/layers_surface_wrapper.rs +++ b/src/layers_surface_wrapper.rs @@ -1,45 +1,26 @@ -use layers::platform::surface::{NativeSurface, NativeGraphicsMetadata, NativePaintingGraphicsContext, NativeCompositingGraphicsContext}; +use layers::platform::surface::{NativeSurface, NativeDisplay}; use layers::texturegl::Texture; use euclid::Size2D; /// A surface wrapper that owns the surface, -/// and thus destroys it on drop -/// We need a graphics context to create the surface -/// And a compositing context to bind it to a texture +/// and thus destroys it on drop. We need a display +/// to create the surface and to bind it to a texture. /// /// Note that the GraphicsContext/CompositingContext /// structs are not really GL context, just metadata pub struct LayersSurfaceWrapper { - graphics_context: NativePaintingGraphicsContext, - compositing_context: NativeCompositingGraphicsContext, + display: NativeDisplay, surface: NativeSurface, size: Size2D, } -#[cfg(target_os="linux")] -#[inline(always)] -fn create_compositing_context(metadata: &NativeGraphicsMetadata) -> NativeCompositingGraphicsContext { - NativeCompositingGraphicsContext::from_display(metadata.display) -} - -#[cfg(not(target_os="linux"))] -#[inline(always)] -fn create_compositing_context(_: &NativeGraphicsMetadata) -> NativeCompositingGraphicsContext { - NativeCompositingGraphicsContext::new() -} - impl LayersSurfaceWrapper { - pub fn new(metadata: NativeGraphicsMetadata, size: Size2D) -> LayersSurfaceWrapper { - let graphics_ctx = NativePaintingGraphicsContext::from_metadata(&metadata); - - let compositing_ctx = create_compositing_context(&metadata); - - let mut surf = NativeSurface::new(&graphics_ctx, size); + pub fn new(display: NativeDisplay, size: Size2D) -> LayersSurfaceWrapper { + let mut surf = NativeSurface::new(&display, size); surf.mark_will_leak(); LayersSurfaceWrapper { - graphics_context: graphics_ctx, - compositing_context: compositing_ctx, + display: display, surface: surf, size: size, } @@ -47,7 +28,7 @@ impl LayersSurfaceWrapper { pub fn bind_to_texture(&self, texture: &Texture) { let size = Size2D::new(self.size.width as isize, self.size.height as isize); - self.surface.bind_to_texture(&self.compositing_context, texture, size) + self.surface.bind_to_texture(&self.display, texture, size) } pub fn borrow_surface(&self) -> &NativeSurface { @@ -61,6 +42,6 @@ impl LayersSurfaceWrapper { impl Drop for LayersSurfaceWrapper { fn drop(&mut self) { - self.surface.destroy(&self.graphics_context); + self.surface.destroy(&self.display); } } diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 876c54c..50fdec7 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -1,5 +1,5 @@ #[cfg(feature="texture_surface")] -use layers::platform::surface::NativeGraphicsMetadata; +use layers::platform::surface::NativeDisplay; pub trait NativeGLContextMethods { fn get_proc_address(&str) -> *const (); @@ -10,7 +10,7 @@ pub trait NativeGLContextMethods { fn unbind(&self) -> Result<(), &'static str>; #[cfg(feature="texture_surface")] - fn get_metadata(&self) -> NativeGraphicsMetadata; + fn get_display(&self) -> NativeDisplay; } #[cfg(target_os="linux")] diff --git a/src/platform/with_cgl/native_gl_context.rs b/src/platform/with_cgl/native_gl_context.rs index d3eb8cb..fe2ab7a 100644 --- a/src/platform/with_cgl/native_gl_context.rs +++ b/src/platform/with_cgl/native_gl_context.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use platform::NativeGLContextMethods; #[cfg(feature="texture_surface")] -use layers::platform::surface::NativeGraphicsMetadata; +use layers::platform::surface::NativeDisplay; pub struct NativeGLContext { native_context: CGLContextObj, @@ -125,8 +125,8 @@ impl NativeGLContextMethods for NativeGLContext { } #[cfg(feature="texture_surface")] - fn get_metadata(&self) -> NativeGraphicsMetadata { - NativeGraphicsMetadata { + fn get_display(&self) -> NativeDisplay { + NativeDisplay { pixel_format: self.pixel_format, } } diff --git a/src/platform/with_egl/native_gl_context.rs b/src/platform/with_egl/native_gl_context.rs index 7f9150d..a3f8d52 100644 --- a/src/platform/with_egl/native_gl_context.rs +++ b/src/platform/with_egl/native_gl_context.rs @@ -6,7 +6,7 @@ use egl; use egl::types::{EGLint, EGLBoolean, EGLDisplay, EGLSurface, EGLConfig, EGLContext}; #[cfg(feature="texture_surface")] -use layers::platform::surface::NativeGraphicsMetadata; +use layers::platform::surface::NativeDisplay; #[cfg(feature="texture_surface")] use std::mem; @@ -119,10 +119,10 @@ impl NativeGLContextMethods for NativeGLContext { } #[cfg(feature="texture_surface")] - fn get_metadata(&self) -> NativeGraphicsMetadata { - NativeGraphicsMetadata { + fn get_display(&self) -> NativeDisplay { + unsafe { // FIXME: https://github.com/servo/servo/pull/6423#issuecomment-113282933 - display: unsafe { mem::transmute(self.native_display) } + NativeDisplay::new_with_display(mem::transmute(self.native_display)) } } } diff --git a/src/platform/with_glx/native_gl_context.rs b/src/platform/with_glx/native_gl_context.rs index 1261b63..ef92039 100644 --- a/src/platform/with_glx/native_gl_context.rs +++ b/src/platform/with_glx/native_gl_context.rs @@ -10,7 +10,7 @@ use super::utils::{create_offscreen_pixmap_backed_context}; use platform::NativeGLContextMethods; #[cfg(feature="texture_surface")] -use layers::platform::surface::NativeGraphicsMetadata; +use layers::platform::surface::NativeDisplay; pub struct NativeGLContext { native_context: GLXContext, @@ -117,10 +117,8 @@ impl NativeGLContextMethods for NativeGLContext { } #[cfg(feature="texture_surface")] - fn get_metadata(&self) -> NativeGraphicsMetadata { - NativeGraphicsMetadata { - display: self.native_display as *mut Display, - } + fn get_display(&self) -> NativeDisplay { + NativeDisplay::new(self.native_display as *mut Display) } }