anvil: Move import_bitmap into anvil
This commit is contained in:
parent
a938c2874f
commit
56f5557f8c
|
@ -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"]
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -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<UdevData> {
|
|||
&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<C: std::ops::Deref<Target = [u8]>>(
|
||||
renderer: &mut Gles2Renderer,
|
||||
image: &image::ImageBuffer<image::Rgba<u8>, C>,
|
||||
) -> Result<Gles2Texture, Gles2Error> {
|
||||
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())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1015,50 +1015,6 @@ impl Renderer for Gles2Renderer {
|
|||
type TextureId = Gles2Texture;
|
||||
type Frame = Gles2Frame;
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
fn import_bitmap<C: std::ops::Deref<Target = [u8]>>(
|
||||
&mut self,
|
||||
image: &image::ImageBuffer<image::Rgba<u8>, C>,
|
||||
) -> Result<Self::TextureId, Self::Error> {
|
||||
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<F, R>(
|
||||
&mut self,
|
||||
size: Size<i32, Physical>,
|
||||
|
|
|
@ -217,20 +217,6 @@ pub trait Renderer {
|
|||
/// Type representing a currently in-progress frame during the [`Renderer::render`]-call
|
||||
type Frame: Frame<Error = Self::Error, TextureId = Self::TextureId>;
|
||||
|
||||
/// 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<C: std::ops::Deref<Target = [u8]>>(
|
||||
&mut self,
|
||||
image: &image::ImageBuffer<image::Rgba<u8>, C>,
|
||||
) -> Result<Self::TextureId, Self::Error>;
|
||||
|
||||
/// Initialize a rendering context on the current rendering target with given dimensions and transformation.
|
||||
///
|
||||
/// This function *may* error, if:
|
||||
|
|
Loading…
Reference in New Issue