From 56f5557f8c1fa31b1d27ed1331f5e6d2d4a4b955 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Wed, 7 Jul 2021 20:49:17 +0200 Subject: [PATCH] anvil: Move import_bitmap into anvil --- Cargo.toml | 3 +-- anvil/Cargo.toml | 4 +-- anvil/src/udev.rs | 35 +++++++++++++++++++++--- src/backend/renderer/gles2/mod.rs | 44 ------------------------------- src/backend/renderer/mod.rs | 14 ---------- 5 files changed, 34 insertions(+), 66 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e6c051..78d3cfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ drm = { version = "0.4.0", optional = true } drm-ffi = { version = "0.1.0", optional = true } gbm = { version = "0.6.0", optional = true, default-features = false, features = ["drm-support"] } input = { version = "0.6", default-features = false, features=["libinput_1_14"], optional = true } -image = { version = "0.23.14", default-features = false, optional = true } lazy_static = "1" libc = "0.2.70" libseat= { version = "0.1.1", optional = true } @@ -50,7 +49,7 @@ gl_generator = { version = "0.14", optional = true } pkg-config = { version = "0.3.17", optional = true } [features] -default = ["backend_drm", "backend_gbm", "backend_libinput", "backend_udev", "backend_session_logind", "backend_winit", "image", "renderer_gl", "xwayland", "wayland_frontend", "slog-stdlog"] +default = ["backend_drm", "backend_gbm", "backend_libinput", "backend_udev", "backend_session_logind", "backend_winit", "renderer_gl", "xwayland", "wayland_frontend", "slog-stdlog"] backend_winit = ["winit", "wayland-server/dlopen", "backend_egl", "wayland-egl", "renderer_gl"] backend_drm = ["drm", "drm-ffi"] backend_gbm = ["gbm"] diff --git a/anvil/Cargo.toml b/anvil/Cargo.toml index d321b5b..c99a90d 100644 --- a/anvil/Cargo.toml +++ b/anvil/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] bitflags = "1.2.1" input = { version = "0.5.0", features = ["udev"], optional = true } -image = { version = "0.23.0", optional = true, default-features = false } +image = { version = "0.23.14", default-features = false, optional = true } rand = "0.7" slog = { version = "2.1.1" } slog-term = "2.8" @@ -36,7 +36,7 @@ gl_generator = "0.14" default = [ "winit", "udev", "logind", "egl", "xwayland" ] egl = [ "smithay/use_system_lib", "smithay/backend_egl" ] winit = [ "smithay/backend_winit" ] -udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm", "smithay/backend_gbm", "smithay/backend_egl", "smithay/backend_session", "input", "image", "smithay/image"] +udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm", "smithay/backend_gbm", "smithay/backend_egl", "smithay/backend_session", "input", "image" ] logind = [ "smithay/backend_session_logind" ] elogind = ["logind", "smithay/backend_session_elogind" ] libseat = ["smithay/backend_session_libseat" ] diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index f95473c..eb955e7 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -19,7 +19,7 @@ use smithay::{ egl::{EGLContext, EGLDisplay}, libinput::{LibinputInputBackend, LibinputSessionInterface}, renderer::{ - gles2::{Gles2Renderer, Gles2Texture}, + gles2::{Gles2Error, Gles2Renderer, Gles2Texture}, Bind, Frame, Renderer, Transform, }, session::{auto::AutoSession, Session, Signal as SessionSignal}, @@ -469,9 +469,7 @@ impl AnvilState { &self.log, ))); - let pointer_image = renderer - .borrow_mut() - .import_bitmap(&self.backend_data.pointer_image) + let pointer_image = import_bitmap(&mut *renderer.borrow_mut(), &self.backend_data.pointer_image) .expect("Failed to load pointer"); let dev_id = device.device_id(); @@ -801,3 +799,32 @@ fn initial_render(surface: &mut RenderSurface, renderer: &mut Gles2Renderer) -> surface.queue_buffer()?; Ok(()) } + +fn import_bitmap>( + renderer: &mut Gles2Renderer, + image: &image::ImageBuffer, C>, +) -> Result { + use smithay::backend::renderer::gles2::ffi; + + renderer.with_context(|renderer, gl| unsafe { + let mut tex = 0; + gl.GenTextures(1, &mut tex); + gl.BindTexture(ffi::TEXTURE_2D, tex); + gl.TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_WRAP_S, ffi::CLAMP_TO_EDGE as i32); + gl.TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_WRAP_T, ffi::CLAMP_TO_EDGE as i32); + gl.TexImage2D( + ffi::TEXTURE_2D, + 0, + ffi::RGBA as i32, + image.width() as i32, + image.height() as i32, + 0, + ffi::RGBA, + ffi::UNSIGNED_BYTE as u32, + image.as_ptr() as *const _, + ); + gl.BindTexture(ffi::TEXTURE_2D, 0); + + Gles2Texture::from_raw(renderer, tex, image.width(), image.height()) + }) +} diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index e783189..9583055 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -1015,50 +1015,6 @@ impl Renderer for Gles2Renderer { type TextureId = Gles2Texture; type Frame = Gles2Frame; - #[cfg(feature = "image")] - fn import_bitmap>( - &mut self, - image: &image::ImageBuffer, C>, - ) -> Result { - self.make_current()?; - - let mut tex = 0; - unsafe { - self.gl.GenTextures(1, &mut tex); - self.gl.BindTexture(ffi::TEXTURE_2D, tex); - self.gl - .TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_WRAP_S, ffi::CLAMP_TO_EDGE as i32); - self.gl - .TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_WRAP_T, ffi::CLAMP_TO_EDGE as i32); - self.gl.TexImage2D( - ffi::TEXTURE_2D, - 0, - ffi::RGBA as i32, - image.width() as i32, - image.height() as i32, - 0, - ffi::RGBA, - ffi::UNSIGNED_BYTE as u32, - image.as_ptr() as *const _, - ); - self.gl.BindTexture(ffi::TEXTURE_2D, 0); - } - - let texture = Gles2Texture(Rc::new(Gles2TextureInternal { - texture: tex, - texture_kind: 0, - is_external: false, - y_inverted: false, - width: image.width(), - height: image.height(), - egl_images: None, - destruction_callback_sender: self.destruction_callback_sender.clone(), - })); - self.egl.unbind()?; - - Ok(texture) - } - fn render( &mut self, size: Size, diff --git a/src/backend/renderer/mod.rs b/src/backend/renderer/mod.rs index 96b78ca..7947920 100644 --- a/src/backend/renderer/mod.rs +++ b/src/backend/renderer/mod.rs @@ -217,20 +217,6 @@ pub trait Renderer { /// Type representing a currently in-progress frame during the [`Renderer::render`]-call type Frame: Frame; - /// Import a given bitmap into the renderer. - /// - /// Returns a texture_id, which can be used with `render_texture(_at)` or implementation-specific functions. - /// - /// If not otherwise defined by the implementation, this texture id is only valid for the renderer, that created it, - /// and needs to be freed by calling `destroy_texture` on this renderer to avoid a resource leak. - /// - /// This operation needs no bound or default rendering target. - #[cfg(feature = "image")] - fn import_bitmap>( - &mut self, - image: &image::ImageBuffer, C>, - ) -> Result; - /// Initialize a rendering context on the current rendering target with given dimensions and transformation. /// /// This function *may* error, if: