Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: remove bitflags dependency #93

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ log = { version = "0.4.20", features = ["std"] }
futures-util = "0.3.30"
num-traits = "0.2.17"
num-derive = "0.4.1"
bitflags = "2.4.2"
libloading = "0.8.1"
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
isnt = "0.1.0"
Expand Down
8 changes: 4 additions & 4 deletions src/gfx_apis/gl/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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 _,
Expand Down
8 changes: 2 additions & 6 deletions src/gfx_apis/gl/egl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 15 additions & 16 deletions src/gfx_apis/gl/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)?;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
99 changes: 39 additions & 60 deletions src/gfx_apis/gl/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
4 changes: 2 additions & 2 deletions src/gfx_apis/gl/gl/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/gfx_apis/gl/renderer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions src/ifs/wl_surface/xdg_surface/xdg_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use {
ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal},
wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt},
xdg_positioner::{XdgPositioned, XdgPositioner, CA},
xdg_positioner::{
XdgPositioned, XdgPositioner, CA_FLIP_X, CA_FLIP_Y, CA_RESIZE_X, CA_RESIZE_Y,
CA_SLIDE_X, CA_SLIDE_Y,
},
},
leaks::Tracker,
object::Object,
Expand Down Expand Up @@ -114,8 +117,8 @@ impl XdgPopup {
let output_pos = ws.output.get().global.pos.get();
let mut overflow = output_pos.get_overflow(&abs_pos);
if !overflow.is_contained() {
let mut flip_x = positioner.ca.contains(CA::FLIP_X) && overflow.x_overflow();
let mut flip_y = positioner.ca.contains(CA::FLIP_Y) && overflow.y_overflow();
let mut flip_x = positioner.ca.contains(CA_FLIP_X) && overflow.x_overflow();
let mut flip_y = positioner.ca.contains(CA_FLIP_Y) && overflow.y_overflow();
if flip_x || flip_y {
let mut adj_rel = positioner.get_position(flip_x, flip_y);
let mut adj_abs = adj_rel.move_(parent_abs.x1(), parent_abs.y1());
Expand All @@ -141,14 +144,14 @@ impl XdgPopup {
}
}
let (mut dx, mut dy) = (0, 0);
if positioner.ca.contains(CA::SLIDE_X) && overflow.x_overflow() {
if positioner.ca.contains(CA_SLIDE_X) && overflow.x_overflow() {
dx = if overflow.left > 0 || overflow.left + overflow.right > 0 {
parent_abs.x1() - abs_pos.x1()
} else {
parent_abs.x2() - abs_pos.x2()
};
}
if positioner.ca.contains(CA::SLIDE_Y) && overflow.y_overflow() {
if positioner.ca.contains(CA_SLIDE_Y) && overflow.y_overflow() {
dy = if overflow.top > 0 || overflow.top + overflow.bottom > 0 {
parent_abs.y1() - abs_pos.y1()
} else {
Expand All @@ -161,11 +164,11 @@ impl XdgPopup {
overflow = output_pos.get_overflow(&abs_pos);
}
let (mut dx1, mut dx2, mut dy1, mut dy2) = (0, 0, 0, 0);
if positioner.ca.contains(CA::RESIZE_X) {
if positioner.ca.contains(CA_RESIZE_X) {
dx1 = overflow.left.max(0);
dx2 = -overflow.right.max(0);
}
if positioner.ca.contains(CA::RESIZE_Y) {
if positioner.ca.contains(CA_RESIZE_Y) {
dy1 = overflow.top.max(0);
dy2 = -overflow.bottom.max(0);
}
Expand Down
Loading
Loading