egl: Add `UserDataMap` to `EGLContext`

This commit is contained in:
Victor Brekenfeld 2022-01-07 20:14:50 +01:00
parent 6e0268f407
commit 6e1f6ab1f3
1 changed files with 29 additions and 6 deletions

View File

@ -1,12 +1,21 @@
//! EGL context related structs //! EGL context related structs
use std::collections::HashSet; use std::{
use std::os::raw::c_int; collections::HashSet,
use std::sync::atomic::Ordering; os::raw::c_int,
sync::{atomic::Ordering, Arc},
};
use super::{ffi, wrap_egl_call, Error, MakeCurrentError}; use super::{ffi, wrap_egl_call, Error, MakeCurrentError};
use crate::backend::allocator::Format as DrmFormat; use crate::{
use crate::backend::egl::display::{EGLDisplay, PixelFormat}; backend::{
use crate::backend::egl::EGLSurface; allocator::Format as DrmFormat,
egl::{
display::{EGLDisplay, PixelFormat},
EGLSurface,
},
},
utils::user_data::UserDataMap,
};
use slog::{info, o, trace}; use slog::{info, o, trace};
@ -17,6 +26,7 @@ pub struct EGLContext {
pub(crate) display: EGLDisplay, pub(crate) display: EGLDisplay,
config_id: ffi::egl::types::EGLConfig, config_id: ffi::egl::types::EGLConfig,
pixel_format: Option<PixelFormat>, pixel_format: Option<PixelFormat>,
user_data: Arc<UserDataMap>,
} }
// EGLContexts can be moved between threads safely // EGLContexts can be moved between threads safely
unsafe impl Send for EGLContext {} unsafe impl Send for EGLContext {}
@ -162,6 +172,11 @@ impl EGLContext {
display: display.clone(), display: display.clone(),
config_id, config_id,
pixel_format, pixel_format,
user_data: if let Some(shared) = shared {
shared.user_data.clone()
} else {
Arc::new(UserDataMap::default())
},
}) })
} }
@ -241,6 +256,14 @@ impl EGLContext {
pub fn dmabuf_texture_formats(&self) -> &HashSet<DrmFormat> { pub fn dmabuf_texture_formats(&self) -> &HashSet<DrmFormat> {
&self.display.dmabuf_import_formats &self.display.dmabuf_import_formats
} }
/// Retrieve user_data associated with this context
///
/// *Note:* UserData is shared between shared context, if constructed with
/// [`new_shared`](EGLContext::new_shared) or [`new_shared_with_config`](EGLContext::new_shared_with_config).
pub fn user_data(&self) -> &UserDataMap {
&*self.user_data
}
} }
impl Drop for EGLContext { impl Drop for EGLContext {