1
0
Fork 0
forked from wry/wry

autocommit 2022-01-28 03:35:35 CET

This commit is contained in:
Julian Orth 2022-01-28 03:35:35 +01:00
parent c340df0d08
commit a5573b8a3a
36 changed files with 3046 additions and 114 deletions

View file

@ -3,11 +3,13 @@ mod types;
use crate::client::{Client, DynEventFormatter};
use crate::clientmem::{ClientMem, ClientMemOffset};
use crate::format::Format;
use crate::gles2::gl::GlTexture;
use crate::ifs::wl_surface::{WlSurface, WlSurfaceId};
use crate::object::{Interface, Object, ObjectId};
use crate::pixman;
use crate::rect::Rect;
use crate::utils::buffd::MsgParser;
use crate::utils::clonecell::CloneCell;
use crate::utils::copyhashmap::CopyHashMap;
use std::rc::Rc;
pub use types::*;
@ -23,10 +25,14 @@ pub struct WlBuffer {
pub client: Rc<Client>,
_offset: usize,
pub rect: Rect,
_stride: i32,
_format: &'static Format,
stride: i32,
format: &'static Format,
pub image: Rc<pixman::Image<ClientMemOffset>>,
mem: ClientMemOffset,
pub texture: CloneCell<Option<Rc<GlTexture>>>,
pub(super) surfaces: CopyHashMap<WlSurfaceId, Rc<WlSurface>>,
width: i32,
height: i32,
}
impl WlBuffer {
@ -52,8 +58,8 @@ impl WlBuffer {
return Err(WlBufferError::StrideTooSmall);
}
let image = pixman::Image::new(
mem,
format.pixman,
mem.clone(),
format.pixman.unwrap(),
width as u32,
height as u32,
stride as u32,
@ -63,13 +69,27 @@ impl WlBuffer {
client: client.clone(),
_offset: offset,
rect: Rect::new_sized(0, 0, width, height).unwrap(),
_stride: stride,
_format: format,
stride,
format,
image: Rc::new(image),
mem,
width,
height,
texture: CloneCell::new(None),
surfaces: Default::default(),
})
}
pub fn update_texture(&self) -> Result<(), WlBufferError> {
self.texture.set(None);
let ctx = self.client.state.egl.get().unwrap();
let tex = self.mem.access(|mem| {
GlTexture::import_texture(&ctx, mem, self.format, self.width, self.height, self.stride)
})??;
self.texture.set(Some(tex));
Ok(())
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.client.parse(self, parser)?;
{

View file

@ -1,8 +1,10 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::gles2::GlesError;
use crate::ifs::wl_buffer::{WlBuffer, RELEASE};
use crate::object::Object;
use crate::pixman::PixmanError;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use crate::ClientMemError;
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
@ -17,8 +19,14 @@ pub enum WlBufferError {
DestroyError(#[from] DestroyError),
#[error("Pixman returned an error")]
PixmanError(#[source] Box<PixmanError>),
#[error("Could not access the client memory")]
ClientMemError(#[source] Box<ClientMemError>),
#[error("GLES could not import the client image")]
GlesError(#[source] Box<GlesError>),
}
efrom!(WlBufferError, PixmanError, PixmanError);
efrom!(WlBufferError, ClientMemError, ClientMemError);
efrom!(WlBufferError, GlesError, GlesError);
#[derive(Debug, Error)]
pub enum DestroyError {

View file

@ -8,7 +8,7 @@ use crate::client::{Client, ClientId, DynEventFormatter};
use crate::fixed::Fixed;
use crate::globals::{Global, GlobalName};
use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardId};
use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerId};
use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerId, POINTER_FRAME_SINCE_VERSION};
use crate::ifs::wl_seat::wl_touch::WlTouch;
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId};
use crate::ifs::wl_surface::WlSurface;
@ -139,12 +139,12 @@ impl WlSeatGlobal {
KeyState::Released => wl_pointer::RELEASED,
KeyState::Pressed => wl_pointer::PRESSED,
};
self.surface_pointer_event(surface, |p| p.button(0, 0, button, state));
self.surface_pointer_event(0, surface, |p| p.button(0, 0, button, state));
}
pub fn focus_surface(&self, surface: &Rc<WlSurface>) {
let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect();
self.surface_kb_event(&surface, |k| {
self.surface_kb_event(0, &surface, |k| {
k.enter(0, surface.id, pressed_keys.clone())
});
let ModifierState {
@ -153,15 +153,13 @@ impl WlSeatGlobal {
mods_locked,
group,
} = self.kb_state.borrow().mods();
self.surface_kb_event(surface, |k| {
self.surface_kb_event(0, surface, |k| {
k.modifiers(0, mods_depressed, mods_latched, mods_locked, group)
});
}
pub fn unfocus_surface(&self, surface: &Rc<WlSurface>) {
self.surface_kb_event(surface, |k| {
k.leave(0, surface.id)
})
self.surface_kb_event(0, surface, |k| k.leave(0, surface.id))
}
fn focus_toplevel(&self, toplevel: &Rc<XdgToplevel>) {
@ -191,23 +189,25 @@ impl WlSeatGlobal {
self.set_new_position(x, y);
}
fn for_each_seat<C>(&self, client: ClientId, mut f: C)
fn for_each_seat<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlSeatObj>),
{
let bindings = self.bindings.borrow();
if let Some(hm) = bindings.get(&client) {
for seat in hm.values() {
f(seat);
if seat.version >= ver {
f(seat);
}
}
}
}
fn for_each_pointer<C>(&self, client: ClientId, mut f: C)
fn for_each_pointer<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlPointer>),
{
self.for_each_seat(client, |seat| {
self.for_each_seat(ver, client, |seat| {
let pointers = seat.pointers.lock();
for pointer in pointers.values() {
f(pointer);
@ -215,11 +215,11 @@ impl WlSeatGlobal {
})
}
fn for_each_kb<C>(&self, client: ClientId, mut f: C)
fn for_each_kb<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlKeyboard>),
{
self.for_each_seat(client, |seat| {
self.for_each_seat(ver, client, |seat| {
let keyboards = seat.keyboards.lock();
for keyboard in keyboards.values() {
f(keyboard);
@ -227,23 +227,23 @@ impl WlSeatGlobal {
})
}
fn surface_pointer_event<F>(&self, surface: &WlSurface, mut f: F)
fn surface_pointer_event<F>(&self, ver: u32, surface: &WlSurface, mut f: F)
where
F: FnMut(&Rc<WlPointer>) -> DynEventFormatter,
{
let client = &surface.client;
self.for_each_pointer(client.id, |p| {
self.for_each_pointer(ver, client.id, |p| {
client.event(f(p));
});
client.flush();
}
fn surface_kb_event<F>(&self, surface: &WlSurface, mut f: F)
fn surface_kb_event<F>(&self, ver: u32, surface: &WlSurface, mut f: F)
where
F: FnMut(&Rc<WlKeyboard>) -> DynEventFormatter,
{
let client = &surface.client;
self.for_each_kb(client.id, |p| {
self.for_each_kb(ver, client.id, |p| {
client.event(f(p));
});
client.flush();
@ -321,7 +321,7 @@ impl WlSeatGlobal {
}
pub fn leave_surface(&self, n: &WlSurface) {
self.surface_pointer_event(n, |p| p.leave(0, n.id));
self.surface_pointer_event(0, n, |p| p.leave(0, n.id));
}
pub fn enter_toplevel(&self, n: &Rc<XdgToplevel>) {
@ -329,12 +329,12 @@ impl WlSeatGlobal {
}
pub fn enter_surface(&self, n: &WlSurface, x: Fixed, y: Fixed) {
self.surface_pointer_event(n, |p| p.enter(0, n.id, x, y));
self.surface_pointer_event(0, n, |p| p.enter(0, n.id, x, y));
}
pub fn motion_surface(&self, n: &WlSurface, x: Fixed, y: Fixed) {
self.surface_pointer_event(n, |p| p.motion(0, x, y));
self.surface_pointer_event(n, |p| p.frame());
self.surface_pointer_event(0, n, |p| p.motion(0, x, y));
self.surface_pointer_event(POINTER_FRAME_SINCE_VERSION, n, |p| p.frame());
}
fn motion_event(&self, dx: Fixed, dy: Fixed) {
@ -370,8 +370,8 @@ impl WlSeatGlobal {
ScrollAxis::Horizontal => wl_pointer::HORIZONTAL_SCROLL,
ScrollAxis::Vertical => wl_pointer::VERTICAL_SCROLL,
};
self.surface_pointer_event(surface, |p| p.axis(0, axis, Fixed::from_int(delta)));
self.surface_pointer_event(surface, |p| p.frame());
self.surface_pointer_event(0, surface, |p| p.axis(0, axis, Fixed::from_int(delta)));
self.surface_pointer_event(POINTER_FRAME_SINCE_VERSION, surface, |p| p.frame());
}
fn scroll_event(&self, delta: i32, axis: ScrollAxis) {

View file

@ -40,6 +40,8 @@ const CONTINUOUS: u32 = 2;
#[allow(dead_code)]
const WHEEL_TILT: u32 = 3;
pub const POINTER_FRAME_SINCE_VERSION: u32 = 5;
id!(WlPointerId);
pub struct WlPointer {

View file

@ -1,6 +1,7 @@
mod types;
use crate::client::Client;
use crate::format::FORMATS;
use crate::globals::{Global, GlobalName};
use crate::ifs::wl_shm_pool::WlShmPool;
use crate::object::{Interface, Object, ObjectId};
@ -41,7 +42,7 @@ impl WlShmGlobal {
client: client.clone(),
});
client.add_client_obj(&obj)?;
for &format in client.state.formats.values() {
for format in FORMATS {
client.event(Box::new(FormatE {
obj: obj.clone(),
format,

View file

@ -65,7 +65,8 @@ pub(super) struct FormatE {
}
impl EventFormatter for FormatE {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, FORMAT).uint(self.format.id);
fmt.header(self.obj.id, FORMAT)
.uint(self.format.wl_id.unwrap_or(self.format.drm));
}
fn obj(&self) -> &dyn Object {
&*self.obj
@ -76,7 +77,8 @@ impl Debug for FormatE {
write!(
f,
"format(format: \"{}\" (0x{:x}))",
self.format.name, self.format.id
self.format.name,
self.format.wl_id.unwrap_or(self.format.drm),
)
}
}

View file

@ -2,6 +2,7 @@ mod types;
use crate::client::Client;
use crate::clientmem::ClientMem;
use crate::format::{formats, map_wayland_format_id};
use crate::ifs::wl_buffer::WlBuffer;
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
@ -40,7 +41,8 @@ impl WlShmPool {
fn create_buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateBufferError> {
let req: CreateBuffer = self.client.parse(self, parser)?;
let format = match self.client.state.formats.get(&req.format) {
let drm_format = map_wayland_format_id(req.format);
let format = match formats().get(&drm_format) {
Some(f) => *f,
_ => return Err(CreateBufferError::InvalidFormat(req.format)),
};

View file

@ -2,9 +2,13 @@ mod types;
pub mod wl_subsurface;
pub mod xdg_surface;
use crate::backend::{KeyState, ScrollAxis};
use crate::client::{Client, RequestParser};
use crate::fixed::Fixed;
use crate::gles2::gl::GlTexture;
use crate::ifs::wl_buffer::WlBuffer;
use crate::ifs::wl_callback::WlCallback;
use crate::ifs::wl_seat::WlSeatGlobal;
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
use crate::object::{Interface, Object, ObjectId};
use crate::pixman::Region;
@ -20,9 +24,6 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
pub use types::*;
use crate::backend::{KeyState, ScrollAxis};
use crate::fixed::Fixed;
use crate::ifs::wl_seat::WlSeatGlobal;
const DESTROY: u32 = 0;
const ATTACH: u32 = 1;
@ -342,6 +343,7 @@ impl WlSurface {
buffer.surfaces.remove(&self.id);
}
if let Some((dx, dy, buffer)) = buffer_change {
let _ = buffer.update_texture();
new_size = Some(buffer.rect);
self.buffer.set(Some(buffer));
self.buf_x.fetch_add(dx);

View file

@ -1,5 +1,8 @@
mod types;
use crate::backend::{KeyState, ScrollAxis};
use crate::fixed::Fixed;
use crate::ifs::wl_seat::WlSeatGlobal;
use crate::ifs::wl_surface::{
CommitAction, CommitContext, StackElement, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceId,
};
@ -13,9 +16,6 @@ use std::cell::{Cell, RefCell};
use std::ops::Deref;
use std::rc::Rc;
pub use types::*;
use crate::backend::{KeyState, ScrollAxis};
use crate::fixed::Fixed;
use crate::ifs::wl_seat::WlSeatGlobal;
const DESTROY: u32 = 0;
const SET_POSITION: u32 = 1;