Skip to content

Commit

Permalink
Rename surfaceless to generic and get it working
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Dec 7, 2019
1 parent 059d4f0 commit 9b17328
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions surfman/src/platform/generic/egl/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const EGL_GL_TEXTURE_2D_KHR: EGLenum = 0x30b1;
pub const EGL_IMAGE_PRESERVED_KHR: EGLenum = 0x30d2;
pub const EGL_PLATFORM_DEVICE_EXT: EGLenum = 0x313f;
pub const EGL_NATIVE_BUFFER_ANDROID: EGLenum = 0x3140;
pub const EGL_PLATFORM_SURFACELESS_MESA: EGLenum = 0x31dd;
pub const EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE: EGLenum = 0x3200;
pub const EGL_D3D11_DEVICE_ANGLE: EGLenum = 0x33a1;
pub const EGL_DXGI_KEYED_MUTEX_ANGLE: EGLenum = 0x33a2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// surfman/surfman/src/platform/src/osmesa/connection.rs
// surfman/surfman/src/platform/unix/generic/connection.rs
//
//! Represents a connection to a display server.
use crate::Error;
use crate::egl::types::EGLDisplay;
use crate::egl::types::{EGLAttrib, EGLDisplay};
use crate::egl;
use crate::platform::generic::egl::device::EGL_FUNCTIONS;
use crate::platform::generic::egl::ffi::EGL_PLATFORM_SURFACELESS_MESA;
use super::device::{Adapter, Device, NativeDevice};
use super::surface::NativeWidget;

use std::os::raw::c_void;
use std::sync::Arc;

#[cfg(feature = "sm-winit")]
Expand All @@ -25,7 +27,6 @@ pub struct Connection {
pub struct NativeConnection(Arc<NativeConnectionWrapper>);

/// Native connections.
#[derive(Clone)]
pub struct NativeConnectionWrapper {
pub(crate) egl_display: EGLDisplay,
pub(crate) is_owned: bool,
Expand All @@ -35,12 +36,15 @@ unsafe impl Send for NativeConnectionWrapper {}
unsafe impl Sync for NativeConnectionWrapper {}

impl Connection {
/// Connects to the default display.
/// Opens a surfaceless Mesa display.
#[inline]
pub fn new() -> Result<Connection, Error> {
unsafe {
EGL_FUNCTIONS.with(|egl| {
let egl_display = egl.GetDisplay(egl::DEFAULT_DISPLAY);
let egl_display_attributes = [egl::NONE as EGLAttrib];
let egl_display = egl.GetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA,
egl::DEFAULT_DISPLAY as *mut c_void,
egl_display_attributes.as_ptr());
if egl_display == egl::NO_DISPLAY {
return Err(Error::ConnectionFailed);
}
Expand Down Expand Up @@ -139,12 +143,3 @@ impl Connection {
}
}

impl Drop for NativeConnectionWrapper {
fn drop(&mut self) {
unsafe {
if self.is_owned {
EGL_FUNCTIONS.with(|egl| egl.Terminate(self.egl_display));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// surfman/surfman/src/platform/generic/mesa/context.rs
// surfman/surfman/src/platform/unix/generic/context.rs
//
//! Wrapper for Mesa surfaceless contexts.
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Device {
let egl_context = context::create_context(egl_display, descriptor)?;

// Create a dummy pbuffer.
let pbuffer = context::create_dummy_pbuffer(egl_display, egl_config);
let pbuffer = context::create_dummy_pbuffer(egl_display, egl_context);

// Wrap up the EGL context.
let context = Context {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// surfman/surfman/src/platform/generic/mesa/device.rs
// surfman/surfman/src/platform/unix/generic/device.rs
//
//! A wrapper around surfaceless Mesa `EGLDisplay`s.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// surfman/surfman/src/platform/unix/surfaceless/mod.rs
// surfman/surfman/src/platform/unix/generic/mod.rs
//
//! The Mesa "surfaceless" backend, which only supports off-screen surfaces and cannot directly
//! display surfaces on a screen.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! surfman/surfman/src/platform/generic/mesa/surface.rs
//! surfman/surfman/src/platform/unix/generic/surface.rs
//!
//! Wrapper for EGL surfaces on Mesa.
Expand Down Expand Up @@ -224,6 +224,8 @@ impl Device {
return Err(Error::IncompatibleSurface);
}

let _guard = self.temporarily_make_context_current(context)?;

unsafe {
GL_FUNCTIONS.with(|gl| {
gl.BindFramebuffer(gl::FRAMEBUFFER, 0);
Expand All @@ -234,6 +236,11 @@ impl Device {
let egl_display = self.native_connection.egl_display;
let result = (EGL_EXTENSION_FUNCTIONS.DestroyImageKHR)(egl_display,
surface.egl_image);
if result == egl::FALSE {
EGL_FUNCTIONS.with(|egl| {
panic!("EGL error: {:x}, image={:x}", egl.GetError(), surface.egl_image as usize);
})
}
assert_ne!(result, egl::FALSE);
surface.egl_image = EGL_NO_IMAGE_KHR;

Expand Down
2 changes: 0 additions & 2 deletions surfman/src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub mod default;
#[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))]
pub mod generic;
#[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))]
pub mod surfaceless;
#[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))]
pub mod wayland;
#[cfg(all(any(feature = "sm-x11",
all(unix, not(any(target_os = "macos", target_os = "android"))))))]
Expand Down
1 change: 1 addition & 0 deletions surfman/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn test_gl() {
.unbind_surface_from_context(&mut env.context)
.unwrap()
.unwrap();
env.gl.BindFramebuffer(gl::FRAMEBUFFER, 0);
env.gl.ClearColor(1.0, 0.0, 0.0, 1.0); env.gl.GetError();
env.gl.Clear(gl::COLOR_BUFFER_BIT); env.gl.GetError();
env.device.bind_surface_to_context(&mut env.context, green_surface).unwrap();
Expand Down

0 comments on commit 9b17328

Please # to comment.