all: remove bitflags dependency
This commit is contained in:
parent
63ed3fa689
commit
9497d6b0cf
12 changed files with 134 additions and 151 deletions
|
|
@ -5,7 +5,7 @@ use {
|
|||
EGL_DEBUG_MSG_ERROR_KHR, EGL_DEBUG_MSG_INFO_KHR, EGL_DEBUG_MSG_WARN_KHR, EGL_NONE,
|
||||
EGL_OPENGL_ES_API, EGL_TRUE,
|
||||
},
|
||||
ext::{get_client_ext, ClientExt},
|
||||
ext::{get_client_ext, ClientExt, EXT_PLATFORM_BASE, KHR_DEBUG, KHR_PLATFORM_GBM},
|
||||
proc::ExtProc,
|
||||
RenderError,
|
||||
},
|
||||
|
|
@ -32,13 +32,13 @@ pub(crate) static PROCS: Lazy<ExtProc> = Lazy::new(ExtProc::load);
|
|||
pub(crate) static EXTS: Lazy<ClientExt> = Lazy::new(get_client_ext);
|
||||
|
||||
pub(in crate::gfx_apis::gl) fn init() -> Result<(), RenderError> {
|
||||
if !EXTS.contains(ClientExt::EXT_PLATFORM_BASE) {
|
||||
if !EXTS.contains(EXT_PLATFORM_BASE) {
|
||||
return Err(RenderError::ExtPlatformBase);
|
||||
}
|
||||
if !EXTS.contains(ClientExt::KHR_PLATFORM_GBM) {
|
||||
if !EXTS.contains(KHR_PLATFORM_GBM) {
|
||||
return Err(RenderError::GbmExt);
|
||||
}
|
||||
if EXTS.contains(ClientExt::KHR_DEBUG) {
|
||||
if EXTS.contains(KHR_DEBUG) {
|
||||
let attrib: &[EGLAttrib] = &[
|
||||
EGL_DEBUG_MSG_CRITICAL_KHR as _,
|
||||
EGL_TRUE as _,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use {
|
|||
},
|
||||
PROCS,
|
||||
},
|
||||
ext::{DisplayExt, GlExt},
|
||||
ext::{GlExt, EXT_CREATE_CONTEXT_ROBUSTNESS},
|
||||
sys::{
|
||||
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB,
|
||||
GL_UNKNOWN_CONTEXT_RESET_ARB,
|
||||
|
|
@ -44,11 +44,7 @@ static mut CURRENT: EGLContext = EGLContext::none();
|
|||
|
||||
impl EglContext {
|
||||
pub fn reset_status(&self) -> Option<ResetStatus> {
|
||||
if !self
|
||||
.dpy
|
||||
.exts
|
||||
.contains(DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS)
|
||||
{
|
||||
if !self.dpy.exts.contains(EXT_CREATE_CONTEXT_ROBUSTNESS) {
|
||||
return None;
|
||||
}
|
||||
let status = self.with_current(|| unsafe {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ use {
|
|||
},
|
||||
PROCS,
|
||||
},
|
||||
ext::{get_display_ext, get_gl_ext, DisplayExt, GlExt},
|
||||
ext::{
|
||||
get_display_ext, get_gl_ext, DisplayExt, GlExt, EXT_CREATE_CONTEXT_ROBUSTNESS,
|
||||
EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS, GL_OES_EGL_IMAGE, GL_OES_EGL_IMAGE_EXTERNAL,
|
||||
KHR_IMAGE_BASE, KHR_NO_CONFIG_CONTEXT, KHR_SURFACELESS_CONTEXT,
|
||||
MESA_CONFIGLESS_CONTEXT,
|
||||
},
|
||||
sys::{
|
||||
eglInitialize, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
|
||||
EGL_LOSE_CONTEXT_ON_RESET_EXT, EGL_PLATFORM_GBM_KHR,
|
||||
|
|
@ -74,7 +79,7 @@ impl EglDisplay {
|
|||
return Err(RenderError::GetDisplay);
|
||||
}
|
||||
let mut dpy = EglDisplay {
|
||||
exts: DisplayExt::empty(),
|
||||
exts: DisplayExt::none(),
|
||||
formats: AHashMap::new(),
|
||||
gbm: Rc::new(gbm),
|
||||
dpy,
|
||||
|
|
@ -85,22 +90,19 @@ impl EglDisplay {
|
|||
return Err(RenderError::Initialize);
|
||||
}
|
||||
dpy.exts = get_display_ext(dpy.dpy);
|
||||
if !dpy.exts.intersects(DisplayExt::KHR_IMAGE_BASE) {
|
||||
if !dpy.exts.intersects(KHR_IMAGE_BASE) {
|
||||
return Err(RenderError::ImageBase);
|
||||
}
|
||||
if !dpy
|
||||
.exts
|
||||
.intersects(DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS)
|
||||
{
|
||||
if !dpy.exts.intersects(EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS) {
|
||||
return Err(RenderError::DmaBufImport);
|
||||
}
|
||||
if !dpy
|
||||
.exts
|
||||
.intersects(DisplayExt::KHR_NO_CONFIG_CONTEXT | DisplayExt::MESA_CONFIGLESS_CONTEXT)
|
||||
.intersects(KHR_NO_CONFIG_CONTEXT | MESA_CONFIGLESS_CONTEXT)
|
||||
{
|
||||
return Err(RenderError::ConfiglessContext);
|
||||
}
|
||||
if !dpy.exts.intersects(DisplayExt::KHR_SURFACELESS_CONTEXT) {
|
||||
if !dpy.exts.intersects(KHR_SURFACELESS_CONTEXT) {
|
||||
return Err(RenderError::SurfacelessContext);
|
||||
}
|
||||
dpy.formats = query_formats(dpy.dpy)?;
|
||||
|
|
@ -113,10 +115,7 @@ impl EglDisplay {
|
|||
self: &Rc<Self>,
|
||||
) -> Result<Rc<EglContext>, RenderError> {
|
||||
let mut attrib = vec![EGL_CONTEXT_CLIENT_VERSION, 2];
|
||||
if self
|
||||
.exts
|
||||
.contains(DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS)
|
||||
{
|
||||
if self.exts.contains(EXT_CREATE_CONTEXT_ROBUSTNESS) {
|
||||
attrib.push(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
|
||||
attrib.push(EGL_LOSE_CONTEXT_ON_RESET_EXT);
|
||||
} else {
|
||||
|
|
@ -136,17 +135,17 @@ impl EglDisplay {
|
|||
}
|
||||
let mut ctx = EglContext {
|
||||
dpy: self.clone(),
|
||||
ext: GlExt::empty(),
|
||||
ext: GlExt::none(),
|
||||
ctx,
|
||||
formats: Default::default(),
|
||||
};
|
||||
ctx.ext = ctx.with_current(|| Ok(get_gl_ext()))?;
|
||||
if !ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE) {
|
||||
if !ctx.ext.contains(GL_OES_EGL_IMAGE) {
|
||||
return Err(RenderError::OesEglImage);
|
||||
}
|
||||
ctx.formats = {
|
||||
let mut formats = AHashMap::new();
|
||||
let supports_external_only = ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL);
|
||||
let supports_external_only = ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL);
|
||||
for (&drm, format) in &self.formats {
|
||||
if format.implicit_external_only && !supports_external_only {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -46,95 +46,74 @@ where
|
|||
base
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct ClientExt: u32 {
|
||||
const EXT_CLIENT_EXTENSION = 1 << 0;
|
||||
const EXT_PLATFORM_BASE = 1 << 1;
|
||||
const KHR_PLATFORM_GBM = 1 << 2;
|
||||
const KHR_DEBUG = 1 << 3;
|
||||
}
|
||||
bitflags! {
|
||||
ClientExt: u32;
|
||||
EXT_CLIENT_EXTENSION = 1 << 0,
|
||||
EXT_PLATFORM_BASE = 1 << 1,
|
||||
KHR_PLATFORM_GBM = 1 << 2,
|
||||
KHR_DEBUG = 1 << 3,
|
||||
}
|
||||
|
||||
pub fn get_client_ext() -> ClientExt {
|
||||
let map = [
|
||||
("EGL_EXT_platform_base", ClientExt::EXT_PLATFORM_BASE),
|
||||
("EGL_KHR_platform_gbm", ClientExt::KHR_PLATFORM_GBM),
|
||||
("EGL_KHR_debug", ClientExt::KHR_DEBUG),
|
||||
("EGL_EXT_platform_base", EXT_PLATFORM_BASE),
|
||||
("EGL_KHR_platform_gbm", KHR_PLATFORM_GBM),
|
||||
("EGL_KHR_debug", KHR_DEBUG),
|
||||
];
|
||||
match unsafe { get_dpy_extensions(EGLDisplay::none()) } {
|
||||
Some(exts) => get_typed_ext(&exts, ClientExt::EXT_CLIENT_EXTENSION, &map),
|
||||
_ => ClientExt::empty(),
|
||||
Some(exts) => get_typed_ext(&exts, EXT_CLIENT_EXTENSION, &map),
|
||||
_ => ClientExt::none(),
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct DisplayExt: u32 {
|
||||
const KHR_IMAGE_BASE = 1 << 0;
|
||||
const EXT_IMAGE_DMA_BUF_IMPORT = 1 << 1;
|
||||
const EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS = 1 << 2;
|
||||
const KHR_NO_CONFIG_CONTEXT = 1 << 3;
|
||||
const MESA_CONFIGLESS_CONTEXT = 1 << 4;
|
||||
const KHR_SURFACELESS_CONTEXT = 1 << 5;
|
||||
const IMG_CONTEXT_PRIORITY = 1 << 6;
|
||||
const EXT_CREATE_CONTEXT_ROBUSTNESS = 1 << 7;
|
||||
}
|
||||
bitflags! {
|
||||
DisplayExt: u32;
|
||||
KHR_IMAGE_BASE = 1 << 0,
|
||||
EXT_IMAGE_DMA_BUF_IMPORT = 1 << 1,
|
||||
EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS = 1 << 2,
|
||||
KHR_NO_CONFIG_CONTEXT = 1 << 3,
|
||||
MESA_CONFIGLESS_CONTEXT = 1 << 4,
|
||||
KHR_SURFACELESS_CONTEXT = 1 << 5,
|
||||
IMG_CONTEXT_PRIORITY = 1 << 6,
|
||||
EXT_CREATE_CONTEXT_ROBUSTNESS = 1 << 7,
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt {
|
||||
let map = [
|
||||
("EGL_KHR_image_base", DisplayExt::KHR_IMAGE_BASE),
|
||||
(
|
||||
"EGL_EXT_image_dma_buf_import",
|
||||
DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT,
|
||||
),
|
||||
("EGL_KHR_image_base", KHR_IMAGE_BASE),
|
||||
("EGL_EXT_image_dma_buf_import", EXT_IMAGE_DMA_BUF_IMPORT),
|
||||
(
|
||||
"EGL_EXT_image_dma_buf_import_modifiers",
|
||||
DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS,
|
||||
EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS,
|
||||
),
|
||||
(
|
||||
"EGL_KHR_no_config_context",
|
||||
DisplayExt::KHR_NO_CONFIG_CONTEXT,
|
||||
),
|
||||
(
|
||||
"EGL_MESA_configless_context",
|
||||
DisplayExt::MESA_CONFIGLESS_CONTEXT,
|
||||
),
|
||||
(
|
||||
"EGL_KHR_surfaceless_context",
|
||||
DisplayExt::KHR_SURFACELESS_CONTEXT,
|
||||
),
|
||||
("EGL_IMG_context_priority", DisplayExt::IMG_CONTEXT_PRIORITY),
|
||||
("EGL_KHR_no_config_context", KHR_NO_CONFIG_CONTEXT),
|
||||
("EGL_MESA_configless_context", MESA_CONFIGLESS_CONTEXT),
|
||||
("EGL_KHR_surfaceless_context", KHR_SURFACELESS_CONTEXT),
|
||||
("EGL_IMG_context_priority", IMG_CONTEXT_PRIORITY),
|
||||
(
|
||||
"EGL_EXT_create_context_robustness",
|
||||
DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS,
|
||||
EXT_CREATE_CONTEXT_ROBUSTNESS,
|
||||
),
|
||||
];
|
||||
match get_dpy_extensions(dpy) {
|
||||
Some(exts) => get_typed_ext(&exts, DisplayExt::empty(), &map),
|
||||
_ => DisplayExt::empty(),
|
||||
Some(exts) => get_typed_ext(&exts, DisplayExt::none(), &map),
|
||||
_ => DisplayExt::none(),
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GlExt: u32 {
|
||||
const GL_OES_EGL_IMAGE = 1 << 0;
|
||||
const GL_OES_EGL_IMAGE_EXTERNAL = 1 << 1;
|
||||
}
|
||||
bitflags! {
|
||||
GlExt: u32;
|
||||
GL_OES_EGL_IMAGE = 1 << 0,
|
||||
GL_OES_EGL_IMAGE_EXTERNAL = 1 << 1,
|
||||
}
|
||||
|
||||
pub fn get_gl_ext() -> GlExt {
|
||||
let map = [
|
||||
("GL_OES_EGL_image", GlExt::GL_OES_EGL_IMAGE),
|
||||
(
|
||||
"GL_OES_EGL_image_external",
|
||||
GlExt::GL_OES_EGL_IMAGE_EXTERNAL,
|
||||
),
|
||||
("GL_OES_EGL_image", GL_OES_EGL_IMAGE),
|
||||
("GL_OES_EGL_image_external", GL_OES_EGL_IMAGE_EXTERNAL),
|
||||
];
|
||||
match unsafe { get_extensions(glGetString(GL_EXTENSIONS) as _) } {
|
||||
Some(exts) => get_typed_ext(&exts, GlExt::empty(), &map),
|
||||
_ => GlExt::empty(),
|
||||
Some(exts) => get_typed_ext(&exts, GlExt::none(), &map),
|
||||
_ => GlExt::none(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use {
|
|||
format::Format,
|
||||
gfx_apis::gl::{
|
||||
egl::{context::EglContext, image::EglImage, PROCS},
|
||||
ext::GlExt,
|
||||
ext::GL_OES_EGL_IMAGE_EXTERNAL,
|
||||
gl::sys::{
|
||||
glBindTexture, glDeleteTextures, glGenTextures, glPixelStorei, glTexImage2D,
|
||||
glTexParameteri, GLint, GLuint, GL_CLAMP_TO_EDGE, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
|
|
@ -38,7 +38,7 @@ impl GlTexture {
|
|||
ctx: &Rc<EglContext>,
|
||||
img: &Rc<EglImage>,
|
||||
) -> Result<GlTexture, RenderError> {
|
||||
if !ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL) {
|
||||
if !ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL) {
|
||||
return Err(RenderError::ExternalUnsupported);
|
||||
}
|
||||
let target = image_target(img.external_only);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use {
|
|||
},
|
||||
gfx_apis::gl::{
|
||||
egl::{context::EglContext, display::EglDisplay},
|
||||
ext::GlExt,
|
||||
ext::GL_OES_EGL_IMAGE_EXTERNAL,
|
||||
gl::{
|
||||
program::GlProgram, render_buffer::GlRenderBuffer, sys::GLint, texture::GlTexture,
|
||||
},
|
||||
|
|
@ -100,7 +100,7 @@ impl GlRenderContext {
|
|||
tex_vert,
|
||||
include_str!("../shaders/tex-alpha.frag.glsl"),
|
||||
)?;
|
||||
let tex_external = if ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL) {
|
||||
let tex_external = if ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL) {
|
||||
let solid = GlProgram::from_shaders(
|
||||
ctx,
|
||||
tex_vert,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue