1
0
Fork 0
forked from wry/wry

autocommit 2022-04-04 23:09:39 CEST

This commit is contained in:
Julian Orth 2022-04-04 23:09:39 +02:00
parent e897d271af
commit 5f79aab15f
21 changed files with 870 additions and 731 deletions

View file

@ -1,100 +0,0 @@
use crate::format::{formats, Format};
use crate::render::egl::display::EglDisplay;
use crate::render::egl::sys::{
eglInitialize, EGLDeviceEXT, EGLDisplay, EGLint, EGL_PLATFORM_DEVICE_EXT, EGL_TRUE,
};
use crate::render::egl::PROCS;
use crate::render::ext::{get_display_ext, DeviceExt, DisplayExt};
use crate::render::RenderError;
use ahash::AHashMap;
use std::ffi::CStr;
use std::ptr;
use std::rc::Rc;
#[derive(Debug, Copy, Clone)]
pub struct EglDevice {
pub exts: DeviceExt,
pub dev: EGLDeviceEXT,
}
impl EglDevice {
pub fn query_string(&self, name: EGLint) -> Result<&'static CStr, RenderError> {
unsafe {
let res = PROCS.eglQueryDeviceStringEXT(self.dev, name);
if res.is_null() {
return Err(RenderError::DeviceQueryString);
}
Ok(CStr::from_ptr(res))
}
}
pub fn create_display(&self) -> Result<Rc<EglDisplay>, RenderError> {
unsafe {
let dpy = PROCS.eglGetPlatformDisplayEXT(
EGL_PLATFORM_DEVICE_EXT as _,
self.dev.0,
ptr::null(),
);
if dpy.is_none() {
return Err(RenderError::GetDisplay);
}
let mut dpy = EglDisplay {
exts: DisplayExt::empty(),
formats: Rc::new(AHashMap::new()),
dev: Some(*self),
gbm: None,
dpy,
};
let mut major = 0;
let mut minor = 0;
if eglInitialize(dpy.dpy, &mut major, &mut minor) != EGL_TRUE {
return Err(RenderError::Initialize);
}
dpy.exts = get_display_ext(dpy.dpy);
if !dpy.exts.intersects(DisplayExt::KHR_IMAGE_BASE) {
return Err(RenderError::ImageBase);
}
if !dpy
.exts
.intersects(DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS)
{
return Err(RenderError::DmaBufImport);
}
if !dpy
.exts
.intersects(DisplayExt::KHR_NO_CONFIG_CONTEXT | DisplayExt::MESA_CONFIGLESS_CONTEXT)
{
return Err(RenderError::ConfiglessContext);
}
if !dpy.exts.intersects(DisplayExt::KHR_SURFACELESS_CONTEXT) {
return Err(RenderError::SurfacelessContext);
}
dpy.formats = Rc::new(query_formats(dpy.dpy)?);
Ok(Rc::new(dpy))
}
}
}
unsafe fn query_formats(dpy: EGLDisplay) -> Result<AHashMap<u32, &'static Format>, RenderError> {
let mut vec = vec![];
let mut num = 0;
let res = PROCS.eglQueryDmaBufFormatsEXT(dpy, num, ptr::null_mut(), &mut num);
if res != EGL_TRUE {
return Err(RenderError::QueryDmaBufFormats);
}
vec.reserve_exact(num as usize);
let res = PROCS.eglQueryDmaBufFormatsEXT(dpy, num, vec.as_mut_ptr(), &mut num);
if res != EGL_TRUE {
return Err(RenderError::QueryDmaBufFormats);
}
vec.set_len(num as usize);
let mut res = AHashMap::new();
let formats = formats();
for fmt in vec {
if let Some(format) = formats.get(&(fmt as u32)) {
res.insert(format.drm, *format);
}
}
Ok(res)
}

View file

@ -1,9 +1,9 @@
use std::ptr;
use crate::drm::dma::DmaBuf;
use crate::drm::drm::Drm;
use crate::drm::gbm::GbmDevice;
use crate::drm::INVALID_MODIFIER;
use crate::format::{Format, formats};
use crate::format::{formats, Format};
use crate::render::egl::context::EglContext;
use crate::render::egl::device::EglDevice;
use crate::render::egl::image::EglImage;
use crate::render::egl::sys::{
eglCreateContext, eglTerminate, EGLClientBuffer, EGLConfig, EGLContext, EGLDisplay, EGLint,
@ -19,20 +19,18 @@ use crate::render::egl::sys::{
EGL_LINUX_DRM_FOURCC_EXT, EGL_NONE, EGL_TRUE, EGL_WIDTH,
};
use crate::render::egl::PROCS;
use crate::render::ext::{get_gl_ext, DisplayExt, GlExt, get_display_ext};
use crate::render::ext::{get_display_ext, get_gl_ext, DisplayExt, GlExt};
use crate::render::sys::{eglInitialize, EGL_PLATFORM_GBM_KHR};
use crate::render::RenderError;
use ahash::AHashMap;
use std::ptr;
use std::rc::Rc;
use crate::drm::drm::Drm;
use crate::drm::gbm::GbmDevice;
use crate::render::sys::{EGL_PLATFORM_GBM_KHR, eglInitialize};
#[derive(Debug)]
pub struct EglDisplay {
pub exts: DisplayExt,
pub formats: Rc<AHashMap<u32, &'static Format>>,
pub dev: Option<EglDevice>,
pub gbm: Option<GbmDevice>,
pub gbm: GbmDevice,
pub dpy: EGLDisplay,
}
@ -54,8 +52,7 @@ impl EglDisplay {
let mut dpy = EglDisplay {
exts: DisplayExt::empty(),
formats: Rc::new(AHashMap::new()),
dev: None,
gbm: Some(gbm),
gbm,
dpy,
};
let mut major = 0;

View file

@ -14,7 +14,6 @@ egl_transparent!(EGLImageKHR);
egl_transparent!(EGLContext);
egl_transparent!(EGLClientBuffer);
egl_transparent!(EGLLabelKHR);
egl_transparent!(EGLDeviceEXT);
pub type EGLDEBUGPROCKHR = unsafe extern "C" fn(
error: EGLenum,
@ -50,8 +49,6 @@ pub const EGL_BAD_SURFACE: EGLint = 0x300D;
pub const EGL_CONTEXT_LOST: EGLint = 0x300E;
pub const EGL_BAD_DEVICE_EXT: EGLint = 0x322B;
pub const EGL_OPENGL_ES_API: EGLenum = 0x30A0;
pub const EGL_DRM_DEVICE_FILE_EXT: EGLint = 0x3233;
pub const EGL_PLATFORM_DEVICE_EXT: EGLint = 0x313F;
pub const EGL_PLATFORM_GBM_KHR: EGLint = 0x31D7;
pub const EGL_CONTEXT_CLIENT_VERSION: EGLint = 0x3098;