Mark get_proc_address as safe
This commit is contained in:
parent
a684f5d8d6
commit
b8df85e744
|
@ -94,7 +94,7 @@ where
|
||||||
self.surface.swap_buffers()
|
self.surface.swap_buffers()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
||||||
get_proc_address(symbol)
|
get_proc_address(symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl EGLContext {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (pixel_format, config_id) = unsafe { display.choose_config(version, reqs)? };
|
let (pixel_format, config_id) = display.choose_config(version, reqs)?;
|
||||||
|
|
||||||
let mut context_attributes = Vec::with_capacity(10);
|
let mut context_attributes = Vec::with_capacity(10);
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLDisplay<B, N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a compatible [`EGLConfig`] for a given set of requirements
|
/// Finds a compatible [`EGLConfig`] for a given set of requirements
|
||||||
pub unsafe fn choose_config(
|
pub fn choose_config(
|
||||||
&self,
|
&self,
|
||||||
version: (u8, u8),
|
version: (u8, u8),
|
||||||
reqs: PixelFormatRequirements,
|
reqs: PixelFormatRequirements,
|
||||||
|
@ -257,19 +257,21 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLDisplay<B, N> {
|
||||||
// calling `eglChooseConfig`
|
// calling `eglChooseConfig`
|
||||||
let mut config_id = MaybeUninit::uninit();
|
let mut config_id = MaybeUninit::uninit();
|
||||||
let mut num_configs = MaybeUninit::uninit();
|
let mut num_configs = MaybeUninit::uninit();
|
||||||
if ffi::egl::ChooseConfig(
|
if unsafe {
|
||||||
*self.display,
|
ffi::egl::ChooseConfig(
|
||||||
descriptor.as_ptr(),
|
*self.display,
|
||||||
config_id.as_mut_ptr(),
|
descriptor.as_ptr(),
|
||||||
1,
|
config_id.as_mut_ptr(),
|
||||||
num_configs.as_mut_ptr(),
|
1,
|
||||||
) == 0
|
num_configs.as_mut_ptr(),
|
||||||
|
)
|
||||||
|
} == 0
|
||||||
{
|
{
|
||||||
return Err(Error::ConfigFailed);
|
return Err(Error::ConfigFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_id = config_id.assume_init();
|
let config_id = unsafe { config_id.assume_init() };
|
||||||
let num_configs = num_configs.assume_init();
|
let num_configs = unsafe { num_configs.assume_init() };
|
||||||
|
|
||||||
if num_configs == 0 {
|
if num_configs == 0 {
|
||||||
error!(self.logger, "No matching color format found");
|
error!(self.logger, "No matching color format found");
|
||||||
|
@ -295,21 +297,23 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLDisplay<B, N> {
|
||||||
}};
|
}};
|
||||||
};
|
};
|
||||||
|
|
||||||
let desc = PixelFormat {
|
let desc = unsafe {
|
||||||
hardware_accelerated: attrib!(self.display, config_id, ffi::egl::CONFIG_CAVEAT)
|
PixelFormat {
|
||||||
!= ffi::egl::SLOW_CONFIG as i32,
|
hardware_accelerated: attrib!(self.display, config_id, ffi::egl::CONFIG_CAVEAT)
|
||||||
color_bits: attrib!(self.display, config_id, ffi::egl::RED_SIZE) as u8
|
!= ffi::egl::SLOW_CONFIG as i32,
|
||||||
+ attrib!(self.display, config_id, ffi::egl::BLUE_SIZE) as u8
|
color_bits: attrib!(self.display, config_id, ffi::egl::RED_SIZE) as u8
|
||||||
+ attrib!(self.display, config_id, ffi::egl::GREEN_SIZE) as u8,
|
+ attrib!(self.display, config_id, ffi::egl::BLUE_SIZE) as u8
|
||||||
alpha_bits: attrib!(self.display, config_id, ffi::egl::ALPHA_SIZE) as u8,
|
+ attrib!(self.display, config_id, ffi::egl::GREEN_SIZE) as u8,
|
||||||
depth_bits: attrib!(self.display, config_id, ffi::egl::DEPTH_SIZE) as u8,
|
alpha_bits: attrib!(self.display, config_id, ffi::egl::ALPHA_SIZE) as u8,
|
||||||
stencil_bits: attrib!(self.display, config_id, ffi::egl::STENCIL_SIZE) as u8,
|
depth_bits: attrib!(self.display, config_id, ffi::egl::DEPTH_SIZE) as u8,
|
||||||
stereoscopy: false,
|
stencil_bits: attrib!(self.display, config_id, ffi::egl::STENCIL_SIZE) as u8,
|
||||||
multisampling: match attrib!(self.display, config_id, ffi::egl::SAMPLES) {
|
stereoscopy: false,
|
||||||
0 | 1 => None,
|
multisampling: match attrib!(self.display, config_id, ffi::egl::SAMPLES) {
|
||||||
a => Some(a as u16),
|
0 | 1 => None,
|
||||||
},
|
a => Some(a as u16),
|
||||||
srgb: false, // TODO: use EGL_KHR_gl_colorspace to know that
|
},
|
||||||
|
srgb: false, // TODO: use EGL_KHR_gl_colorspace to know that
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
info!(self.logger, "Selected color format: {:?}", desc);
|
info!(self.logger, "Selected color format: {:?}", desc);
|
||||||
|
@ -443,7 +447,7 @@ impl WaylandEGLDisplay {
|
||||||
extensions: &Vec<String>,
|
extensions: &Vec<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
#[cfg(feature = "renderer_gl")]
|
#[cfg(feature = "renderer_gl")]
|
||||||
let gl = gl_ffi::Gles2::load_with(|s| unsafe { get_proc_address(s) as *const _ });
|
let gl = gl_ffi::Gles2::load_with(|s| get_proc_address(s) as *const _);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
display,
|
display,
|
||||||
|
|
|
@ -65,10 +65,12 @@ impl ::std::error::Error for EglExtensionNotSupportedError {}
|
||||||
/// Returns the address of an OpenGL function.
|
/// Returns the address of an OpenGL function.
|
||||||
///
|
///
|
||||||
/// Result is independent of displays and does not guarantee an extension is actually supported at runtime.
|
/// Result is independent of displays and does not guarantee an extension is actually supported at runtime.
|
||||||
pub unsafe fn get_proc_address(symbol: &str) -> *const c_void {
|
pub fn get_proc_address(symbol: &str) -> *const c_void {
|
||||||
let addr = CString::new(symbol.as_bytes()).unwrap();
|
unsafe {
|
||||||
let addr = addr.as_ptr();
|
let addr = CString::new(symbol.as_bytes()).unwrap();
|
||||||
ffi::egl::GetProcAddress(addr) as *const _
|
let addr = addr.as_ptr();
|
||||||
|
ffi::egl::GetProcAddress(addr) as *const _
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error that can occur when accessing an EGL buffer
|
/// Error that can occur when accessing an EGL buffer
|
||||||
|
|
|
@ -18,11 +18,7 @@ pub trait GLGraphicsBackend {
|
||||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
|
fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
|
||||||
|
|
||||||
/// Returns the address of an OpenGL function.
|
/// Returns the address of an OpenGL function.
|
||||||
///
|
fn get_proc_address(&self, symbol: &str) -> *const c_void;
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The context must have been made current before this function is called.
|
|
||||||
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void;
|
|
||||||
|
|
||||||
/// Returns the dimensions of the window, or screen, etc in points.
|
/// Returns the dimensions of the window, or screen, etc in points.
|
||||||
///
|
///
|
||||||
|
@ -51,5 +47,5 @@ pub trait GLGraphicsBackend {
|
||||||
/// and may only be used in combination with the backend. Using this with any
|
/// and may only be used in combination with the backend. Using this with any
|
||||||
/// other gl context or after the backend was dropped *may* cause undefined behavior.
|
/// other gl context or after the backend was dropped *may* cause undefined behavior.
|
||||||
pub fn load_raw_gl<B: GLGraphicsBackend>(backend: &B) -> Gles2 {
|
pub fn load_raw_gl<B: GLGraphicsBackend>(backend: &B) -> Gles2 {
|
||||||
Gles2::load_with(|s| unsafe { backend.get_proc_address(s) as *const _ })
|
Gles2::load_with(|s| { backend.get_proc_address(s) as *const _ })
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl GLGraphicsBackend for WinitGraphicsBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
||||||
trace!(self.logger, "Getting symbol for {:?}", symbol);
|
trace!(self.logger, "Getting symbol for {:?}", symbol);
|
||||||
get_proc_address(symbol)
|
get_proc_address(symbol)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue