mirror of
https://github.com/Smithay/smithay.git
synced 2024-09-28 03:21:14 +02:00
Merge pull request #753 from cmeissl/egl_display_segfaults
egl: make EGLDisplay::new unsafe
This commit is contained in:
commit
556004e3df
6 changed files with 26 additions and 25 deletions
|
@ -378,7 +378,7 @@ fn scan_connectors(
|
|||
let mut backends = HashMap::new();
|
||||
|
||||
let (render_node, formats) = {
|
||||
let display = EGLDisplay::new(&*gbm.borrow(), logger.clone()).unwrap();
|
||||
let display = unsafe { EGLDisplay::new(&*gbm.borrow(), logger.clone()).unwrap() };
|
||||
let node = match EGLDevice::device_for_display(&display)
|
||||
.ok()
|
||||
.and_then(|x| x.try_get_render_node().ok().flatten())
|
||||
|
|
|
@ -95,7 +95,7 @@ pub fn run_x11(log: Logger) {
|
|||
// Create the gbm device for buffer allocation.
|
||||
let device = gbm::Device::new(fd).expect("Failed to create gbm device");
|
||||
// Initialize EGL using the GBM device.
|
||||
let egl = EGLDisplay::new(&device, log.clone()).expect("Failed to create EGLDisplay");
|
||||
let egl = unsafe { EGLDisplay::new(&device, log.clone()).expect("Failed to create EGLDisplay") };
|
||||
// Create the OpenGL context
|
||||
let context = EGLContext::new(&egl, log.clone()).expect("Failed to create EGLContext");
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ pub struct EGLDisplay {
|
|||
logger: slog::Logger,
|
||||
}
|
||||
|
||||
fn select_platform_display<N: EGLNativeDisplay + 'static>(
|
||||
unsafe fn select_platform_display<N: EGLNativeDisplay + 'static>(
|
||||
native: &N,
|
||||
dp_extensions: &[String],
|
||||
log: &::slog::Logger,
|
||||
|
@ -102,16 +102,14 @@ fn select_platform_display<N: EGLNativeDisplay + 'static>(
|
|||
continue;
|
||||
}
|
||||
|
||||
let display = unsafe {
|
||||
wrap_egl_call(|| {
|
||||
ffi::egl::GetPlatformDisplayEXT(
|
||||
platform.platform,
|
||||
platform.native_display,
|
||||
platform.attrib_list.as_ptr(),
|
||||
)
|
||||
})
|
||||
.map_err(Error::DisplayCreationError)
|
||||
};
|
||||
let display = wrap_egl_call(|| {
|
||||
ffi::egl::GetPlatformDisplayEXT(
|
||||
platform.platform,
|
||||
platform.native_display,
|
||||
platform.attrib_list.as_ptr(),
|
||||
)
|
||||
})
|
||||
.map_err(Error::DisplayCreationError);
|
||||
|
||||
let display = match display {
|
||||
Ok(display) => {
|
||||
|
@ -144,7 +142,12 @@ fn select_platform_display<N: EGLNativeDisplay + 'static>(
|
|||
|
||||
impl EGLDisplay {
|
||||
/// Create a new [`EGLDisplay`] from a given [`EGLNativeDisplay`]
|
||||
pub fn new<N, L>(native: &N, logger: L) -> Result<EGLDisplay, Error>
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - `native`: The native display handle has to be kept alive for the lifetime of the
|
||||
/// created [`EGLDisplay`]
|
||||
pub unsafe fn new<N, L>(native: &N, logger: L) -> Result<EGLDisplay, Error>
|
||||
where
|
||||
N: EGLNativeDisplay + 'static,
|
||||
L: Into<Option<::slog::Logger>>,
|
||||
|
@ -161,13 +164,11 @@ impl EGLDisplay {
|
|||
let mut major: MaybeUninit<ffi::egl::types::EGLint> = MaybeUninit::uninit();
|
||||
let mut minor: MaybeUninit<ffi::egl::types::EGLint> = MaybeUninit::uninit();
|
||||
|
||||
wrap_egl_call(|| unsafe {
|
||||
ffi::egl::Initialize(display, major.as_mut_ptr(), minor.as_mut_ptr())
|
||||
})
|
||||
.map_err(Error::InitFailed)?;
|
||||
wrap_egl_call(|| ffi::egl::Initialize(display, major.as_mut_ptr(), minor.as_mut_ptr()))
|
||||
.map_err(Error::InitFailed)?;
|
||||
|
||||
let major = unsafe { major.assume_init() };
|
||||
let minor = unsafe { minor.assume_init() };
|
||||
let major = major.assume_init();
|
||||
let minor = minor.assume_init();
|
||||
|
||||
info!(log, "EGL Initialized");
|
||||
info!(log, "EGL Version: {:?}", (major, minor));
|
||||
|
@ -187,7 +188,7 @@ impl EGLDisplay {
|
|||
if egl_version <= (1, 2) {
|
||||
return Err(Error::OpenGlesNotSupported(None));
|
||||
}
|
||||
wrap_egl_call(|| unsafe { ffi::egl::BindAPI(ffi::egl::OPENGL_ES_API) })
|
||||
wrap_egl_call(|| ffi::egl::BindAPI(ffi::egl::OPENGL_ES_API))
|
||||
.map_err(|source| Error::OpenGlesNotSupported(Some(source)))?;
|
||||
|
||||
Ok(EGLDisplay {
|
||||
|
|
|
@ -78,7 +78,7 @@ impl GraphicsApi for EglGlesBackend {
|
|||
.filter(|(_, node)| !list.iter().any(|renderer| &renderer.node == node))
|
||||
.map(|(device, node)| {
|
||||
slog::info!(log, "Trying to initialize {:?} from {}", device, node);
|
||||
let display = EGLDisplay::new(&device, None).map_err(Error::Egl)?;
|
||||
let display = unsafe { EGLDisplay::new(&device, None).map_err(Error::Egl)? };
|
||||
let context = EGLContext::new(&display, None).map_err(Error::Egl)?;
|
||||
let renderer = unsafe { Gles2Renderer::new(context, None).map_err(Error::Gl)? };
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ where
|
|||
|
||||
let reqs = Default::default();
|
||||
let (display, context, surface, is_x11) = {
|
||||
let display = EGLDisplay::new(&winit_window, log.clone())?;
|
||||
let display = unsafe { EGLDisplay::new(&winit_window, log.clone())? };
|
||||
let context = EGLContext::new_with_config(&display, attributes, reqs, log.clone())?;
|
||||
|
||||
let (surface, is_x11) = if let Some(wl_surface) = winit_window.wayland_surface() {
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
//! // Create the gbm device for allocating buffers
|
||||
//! let device = gbm::Device::new(fd)?;
|
||||
//! // Initialize EGL to retrieve the support modifier list
|
||||
//! let egl = EGLDisplay::new(&device, logger.clone()).expect("Failed to create EGLDisplay");
|
||||
//! let egl = unsafe { EGLDisplay::new(&device, logger.clone()).expect("Failed to create EGLDisplay") };
|
||||
//! let context = EGLContext::new(&egl, logger).expect("Failed to create EGLContext");
|
||||
//! let modifiers = context.dmabuf_render_formats().iter().map(|format| format.modifier).collect::<HashSet<_>>();
|
||||
//!
|
||||
|
@ -927,7 +927,7 @@ impl X11Inner {
|
|||
}
|
||||
|
||||
fn egl_init(_: &X11Inner) -> Result<(DrmNode, RawFd), EGLInitError> {
|
||||
let display = EGLDisplay::new(&X11DefaultDisplay, None)?;
|
||||
let display = unsafe { EGLDisplay::new(&X11DefaultDisplay, None)? };
|
||||
let device = EGLDevice::device_for_display(&display)?;
|
||||
let path = path_to_type(device.drm_device_path()?, NodeType::Render)?;
|
||||
let node = DrmNode::from_path(&path)
|
||||
|
|
Loading…
Reference in a new issue