Fix egl_to_texture check

This commit is contained in:
Victor Brekenfeld 2020-04-18 13:55:20 +02:00
parent 8678738d01
commit bcb2aa3864
3 changed files with 25 additions and 20 deletions

View File

@ -177,7 +177,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
.unwrap(); .unwrap();
unsafe { unsafe {
images images
.bind_to_texture(0, opengl_texture.get_id()) .bind_to_texture(0, opengl_texture.get_id(), &*self.display.borrow())
.expect("Failed to bind to texture"); .expect("Failed to bind to texture");
} }
Ok(TextureMetadata { Ok(TextureMetadata {

View File

@ -430,11 +430,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLGraphicsBackend for EGL
if res == 0 { if res == 0 {
return Err(Error::OtherEGLDisplayAlreadyBound); return Err(Error::OtherEGLDisplayAlreadyBound);
} }
Ok(EGLBufferReader::new( Ok(EGLBufferReader::new(self.display.clone(), display.c_ptr()))
self.display.clone(),
display.c_ptr(),
&self.extensions,
))
} }
} }
@ -447,13 +443,11 @@ pub struct EGLBufferReader {
wayland: *mut wl_display, wayland: *mut wl_display,
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
gl: gl_ffi::Gles2, gl: gl_ffi::Gles2,
#[cfg(feature = "renderer_gl")]
egl_to_texture_support: bool,
} }
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
impl EGLBufferReader { impl EGLBufferReader {
fn new(display: Arc<EGLDisplayHandle>, wayland: *mut wl_display, extensions: &[String]) -> Self { fn new(display: Arc<EGLDisplayHandle>, wayland: *mut wl_display) -> Self {
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
let gl = gl_ffi::Gles2::load_with(|s| get_proc_address(s) as *const _); let gl = gl_ffi::Gles2::load_with(|s| get_proc_address(s) as *const _);
@ -461,10 +455,6 @@ impl EGLBufferReader {
display, display,
wayland, wayland,
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
egl_to_texture_support: extensions
.iter()
.any(|s| s == "GL_OES_EGL_image" || s == "GL_OES_EGL_image_base"),
#[cfg(feature = "renderer_gl")]
gl, gl,
} }
} }
@ -570,8 +560,6 @@ impl EGLBufferReader {
buffer, buffer,
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
gl: self.gl.clone(), gl: self.gl.clone(),
#[cfg(feature = "renderer_gl")]
egl_to_texture_support: self.egl_to_texture_support,
}) })
} }

View File

@ -19,7 +19,7 @@
//! of an EGL-based [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer) for rendering. //! of an EGL-based [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer) for rendering.
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
use crate::backend::graphics::gl::ffi as gl_ffi; use crate::backend::graphics::gl::{ffi as gl_ffi, GLGraphicsBackend};
use nix::libc::c_uint; use nix::libc::c_uint;
use std::fmt; use std::fmt;
#[cfg(feature = "wayland_frontend")] #[cfg(feature = "wayland_frontend")]
@ -43,6 +43,8 @@ pub use self::surface::EGLSurface;
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
use crate::backend::egl::display::EGLBufferReader; use crate::backend::egl::display::EGLBufferReader;
use crate::backend::egl::display::EGLDisplayHandle; use crate::backend::egl::display::EGLDisplayHandle;
#[cfg(feature = "renderer_gl")]
use std::ffi::CStr;
use std::ffi::CString; use std::ffi::CString;
use std::sync::Arc; use std::sync::Arc;
@ -181,8 +183,6 @@ pub struct EGLImages {
buffer: WlBuffer, buffer: WlBuffer,
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
gl: gl_ffi::Gles2, gl: gl_ffi::Gles2,
#[cfg(feature = "renderer_gl")]
egl_to_texture_support: bool,
} }
#[cfg(feature = "wayland_frontend")] #[cfg(feature = "wayland_frontend")]
@ -195,17 +195,34 @@ impl EGLImages {
/// Bind plane to an OpenGL texture id /// Bind plane to an OpenGL texture id
/// ///
/// This does only temporarily modify the OpenGL state any changes are reverted before returning. /// This does only temporarily modify the OpenGL state any changes are reverted before returning.
/// The given `GLGraphicsBackend` must be the one belonging to the `tex_id` and will be the current
/// context (and surface if applicable) after this function returns.
/// ///
/// # Safety /// # Safety
/// ///
/// The given `tex_id` needs to be a valid GL texture otherwise undefined behavior might occur. /// The given `tex_id` needs to be a valid GL texture in the given context otherwise undefined behavior might occur.
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
pub unsafe fn bind_to_texture( pub unsafe fn bind_to_texture(
&self, &self,
plane: usize, plane: usize,
tex_id: c_uint, tex_id: c_uint,
backend: &dyn GLGraphicsBackend,
) -> ::std::result::Result<(), TextureCreationError> { ) -> ::std::result::Result<(), TextureCreationError> {
if !self.egl_to_texture_support { // receive the list of extensions for *this* context
backend
.make_current()
.map_err(|_| TextureCreationError::ContextLost)?;
let egl_to_texture_support = {
// the list of gl extensions supported by the context
let data = CStr::from_ptr(self.gl.GetString(gl_ffi::EXTENSIONS) as *const _)
.to_bytes()
.to_vec();
let list = String::from_utf8(data).unwrap();
list.split(' ')
.any(|s| s == "GL_OES_EGL_image" || s == "GL_OES_EGL_image_base")
};
if !egl_to_texture_support {
return Err(TextureCreationError::GLExtensionNotSupported("GL_OES_EGL_image")); return Err(TextureCreationError::GLExtensionNotSupported("GL_OES_EGL_image"));
} }