it: use single-pixel buffer instead of shm
This commit is contained in:
parent
aaed003ec8
commit
f562f887f0
17 changed files with 280 additions and 76 deletions
48
src/it/test_ifs/test_buffer.rs
Normal file
48
src/it/test_ifs/test_buffer.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use {
|
||||
crate::{
|
||||
it::{
|
||||
test_error::TestError, test_object::TestObject, test_transport::TestTransport,
|
||||
testrun::ParseFull,
|
||||
},
|
||||
utils::buffd::MsgParser,
|
||||
wire::{wl_buffer::*, WlBufferId},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct TestBuffer {
|
||||
pub id: WlBufferId,
|
||||
pub tran: Rc<TestTransport>,
|
||||
pub released: Cell<bool>,
|
||||
pub destroyed: Cell<bool>,
|
||||
}
|
||||
|
||||
impl TestBuffer {
|
||||
pub fn destroy(&self) -> Result<(), TestError> {
|
||||
if self.destroyed.replace(true) {
|
||||
return Ok(());
|
||||
}
|
||||
self.tran.send(Destroy { self_id: self.id })?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_release(&self, parser: MsgParser<'_, '_>) -> Result<(), TestError> {
|
||||
let _ev = Release::parse_full(parser)?;
|
||||
self.released.set(true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestBuffer {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestBuffer, WlBuffer;
|
||||
|
||||
RELEASE => handle_release,
|
||||
}
|
||||
|
||||
impl TestObject for TestBuffer {}
|
||||
|
|
@ -6,7 +6,8 @@ use {
|
|||
test_error::TestError,
|
||||
test_ifs::{
|
||||
test_compositor::TestCompositor, test_jay_compositor::TestJayCompositor,
|
||||
test_shm::TestShm, test_subcompositor::TestSubcompositor,
|
||||
test_shm::TestShm, test_single_pixel_buffer_manager::TestSinglePixelBufferManager,
|
||||
test_subcompositor::TestSubcompositor, test_viewporter::TestViewporter,
|
||||
test_xdg_base::TestXdgWmBase,
|
||||
},
|
||||
test_object::TestObject,
|
||||
|
|
@ -31,6 +32,8 @@ pub struct TestRegistrySingletons {
|
|||
pub wl_subcompositor: u32,
|
||||
pub wl_shm: u32,
|
||||
pub xdg_wm_base: u32,
|
||||
pub wp_single_pixel_buffer_manager_v1: u32,
|
||||
pub wp_viewporter: u32,
|
||||
}
|
||||
|
||||
pub struct TestRegistry {
|
||||
|
|
@ -42,6 +45,8 @@ pub struct TestRegistry {
|
|||
pub compositor: CloneCell<Option<Rc<TestCompositor>>>,
|
||||
pub subcompositor: CloneCell<Option<Rc<TestSubcompositor>>>,
|
||||
pub shm: CloneCell<Option<Rc<TestShm>>>,
|
||||
pub spbm: CloneCell<Option<Rc<TestSinglePixelBufferManager>>>,
|
||||
pub viewporter: CloneCell<Option<Rc<TestViewporter>>>,
|
||||
pub xdg: CloneCell<Option<Rc<TestXdgWmBase>>>,
|
||||
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
|
||||
}
|
||||
|
|
@ -90,6 +95,8 @@ impl TestRegistry {
|
|||
wl_subcompositor,
|
||||
wl_shm,
|
||||
xdg_wm_base,
|
||||
wp_single_pixel_buffer_manager_v1,
|
||||
wp_viewporter,
|
||||
};
|
||||
self.singletons.set(Some(singletons.clone()));
|
||||
Ok(singletons)
|
||||
|
|
@ -151,6 +158,32 @@ impl TestRegistry {
|
|||
Ok(jc)
|
||||
}
|
||||
|
||||
pub async fn get_spbm(&self) -> Result<Rc<TestSinglePixelBufferManager>, TestError> {
|
||||
singleton!(self.spbm);
|
||||
let singletons = self.get_singletons().await?;
|
||||
singleton!(self.spbm);
|
||||
let jc = Rc::new(TestSinglePixelBufferManager {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
});
|
||||
self.bind(&jc, singletons.wp_single_pixel_buffer_manager_v1, 1)?;
|
||||
self.spbm.set(Some(jc.clone()));
|
||||
Ok(jc)
|
||||
}
|
||||
|
||||
pub async fn get_viewporter(&self) -> Result<Rc<TestViewporter>, TestError> {
|
||||
singleton!(self.viewporter);
|
||||
let singletons = self.get_singletons().await?;
|
||||
singleton!(self.viewporter);
|
||||
let jc = Rc::new(TestViewporter {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
});
|
||||
self.bind(&jc, singletons.wp_viewporter, 1)?;
|
||||
self.viewporter.set(Some(jc.clone()));
|
||||
Ok(jc)
|
||||
}
|
||||
|
||||
pub async fn get_xdg(&self) -> Result<Rc<TestXdgWmBase>, TestError> {
|
||||
singleton!(self.xdg);
|
||||
let singletons = self.get_singletons().await?;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ impl TestShm {
|
|||
&self.formats
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create_pool(&self, size: usize) -> Result<Rc<TestShmPool>, TestError> {
|
||||
let mem = TestMem::new(size)?;
|
||||
let pool = Rc::new(TestShmPool {
|
||||
|
|
@ -48,6 +49,7 @@ impl TestShm {
|
|||
Ok(pool)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create_buffer(&self, width: i32, height: i32) -> TestResult<Rc<TestShmBuffer>> {
|
||||
let pool = self.create_pool((width * height * 4) as _)?;
|
||||
pool.create_buffer(0, width, height, width * 4, ARGB8888)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
use {
|
||||
crate::{
|
||||
it::{
|
||||
test_error::TestError, test_mem::TestMem, test_object::TestObject,
|
||||
test_transport::TestTransport, testrun::ParseFull,
|
||||
},
|
||||
it::{test_ifs::test_buffer::TestBuffer, test_mem::TestMem},
|
||||
theme::Color,
|
||||
utils::{buffd::MsgParser, windows::WindowsExt},
|
||||
wire::{wl_buffer::*, WlBufferId},
|
||||
utils::windows::WindowsExt,
|
||||
},
|
||||
std::{
|
||||
cell::Cell,
|
||||
|
|
@ -16,15 +12,13 @@ use {
|
|||
};
|
||||
|
||||
pub struct TestShmBuffer {
|
||||
pub id: WlBufferId,
|
||||
pub tran: Rc<TestTransport>,
|
||||
pub buffer: Rc<TestBuffer>,
|
||||
pub range: Range<usize>,
|
||||
pub mem: Rc<TestMem>,
|
||||
pub released: Cell<bool>,
|
||||
pub destroyed: Cell<bool>,
|
||||
}
|
||||
|
||||
impl TestShmBuffer {
|
||||
#[allow(dead_code)]
|
||||
pub fn fill(&self, color: Color) {
|
||||
let [cr, cg, cb, ca] = color.to_rgba_premultiplied();
|
||||
for [b, g, r, a] in self.deref().array_chunks_ext::<4>() {
|
||||
|
|
@ -34,20 +28,6 @@ impl TestShmBuffer {
|
|||
a.set(ca);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy(&self) -> Result<(), TestError> {
|
||||
if self.destroyed.replace(true) {
|
||||
return Ok(());
|
||||
}
|
||||
self.tran.send(Destroy { self_id: self.id })?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_release(&self, parser: MsgParser<'_, '_>) -> Result<(), TestError> {
|
||||
let _ev = Release::parse_full(parser)?;
|
||||
self.released.set(true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TestShmBuffer {
|
||||
|
|
@ -57,17 +37,3 @@ impl Deref for TestShmBuffer {
|
|||
&self.mem[self.range.clone()]
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestShmBuffer {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestShmBuffer, WlBuffer;
|
||||
|
||||
RELEASE => handle_release,
|
||||
}
|
||||
|
||||
impl TestObject for TestShmBuffer {}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ use {
|
|||
crate::{
|
||||
format::Format,
|
||||
it::{
|
||||
test_error::TestError, test_ifs::test_shm_buffer::TestShmBuffer, test_mem::TestMem,
|
||||
test_object::TestObject, test_transport::TestTransport,
|
||||
test_error::TestError,
|
||||
test_ifs::{test_buffer::TestBuffer, test_shm_buffer::TestShmBuffer},
|
||||
test_mem::TestMem,
|
||||
test_object::TestObject,
|
||||
test_transport::TestTransport,
|
||||
},
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{wl_shm_pool::*, WlShmPoolId},
|
||||
|
|
@ -19,6 +22,7 @@ pub struct TestShmPool {
|
|||
}
|
||||
|
||||
impl TestShmPool {
|
||||
#[allow(dead_code)]
|
||||
pub fn create_buffer(
|
||||
&self,
|
||||
offset: i32,
|
||||
|
|
@ -35,17 +39,19 @@ impl TestShmPool {
|
|||
bail!("Out-of-bounds buffer");
|
||||
}
|
||||
let buffer = Rc::new(TestShmBuffer {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
buffer: Rc::new(TestBuffer {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
released: Cell::new(true),
|
||||
destroyed: Cell::new(false),
|
||||
}),
|
||||
range: start..end,
|
||||
mem,
|
||||
released: Cell::new(true),
|
||||
destroyed: Cell::new(false),
|
||||
});
|
||||
self.tran.add_obj(buffer.clone())?;
|
||||
self.tran.add_obj(buffer.buffer.clone())?;
|
||||
self.tran.send(CreateBuffer {
|
||||
self_id: self.id,
|
||||
id: buffer.id,
|
||||
id: buffer.buffer.id,
|
||||
offset,
|
||||
width,
|
||||
height,
|
||||
|
|
@ -55,6 +61,7 @@ impl TestShmPool {
|
|||
Ok(buffer)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn resize(&self, size: usize) -> Result<(), TestError> {
|
||||
let mem = self.mem.get().grow(size)?;
|
||||
self.mem.set(mem);
|
||||
|
|
|
|||
44
src/it/test_ifs/test_single_pixel_buffer_manager.rs
Normal file
44
src/it/test_ifs/test_single_pixel_buffer_manager.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use {
|
||||
crate::{
|
||||
it::{
|
||||
test_error::TestResult, test_ifs::test_buffer::TestBuffer, test_object::TestObject,
|
||||
test_transport::TestTransport,
|
||||
},
|
||||
theme::Color,
|
||||
wire::{wp_single_pixel_buffer_manager_v1::*, WpSinglePixelBufferManagerV1Id},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct TestSinglePixelBufferManager {
|
||||
pub id: WpSinglePixelBufferManagerV1Id,
|
||||
pub tran: Rc<TestTransport>,
|
||||
}
|
||||
|
||||
impl TestSinglePixelBufferManager {
|
||||
pub fn create_buffer(&self, color: Color) -> TestResult<Rc<TestBuffer>> {
|
||||
let obj = Rc::new(TestBuffer {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
released: Cell::new(true),
|
||||
destroyed: Cell::new(false),
|
||||
});
|
||||
let map = |c: f32| (c as f64 * u32::MAX as f64) as u32;
|
||||
self.tran.send(CreateU32RgbaBuffer {
|
||||
self_id: self.id,
|
||||
id: obj.id,
|
||||
r: map(color.r),
|
||||
g: map(color.g),
|
||||
b: map(color.b),
|
||||
a: map(color.a),
|
||||
})?;
|
||||
self.tran.add_obj(obj.clone())?;
|
||||
Ok(obj)
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestSinglePixelBufferManager, WpSinglePixelBufferManagerV1;
|
||||
}
|
||||
|
||||
impl TestObject for TestSinglePixelBufferManager {}
|
||||
52
src/it/test_ifs/test_viewport.rs
Normal file
52
src/it/test_ifs/test_viewport.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use {
|
||||
crate::{
|
||||
fixed::Fixed,
|
||||
it::{test_error::TestError, test_object::TestObject, test_transport::TestTransport},
|
||||
wire::{wp_viewport::*, WpViewportId},
|
||||
},
|
||||
std::rc::Rc,
|
||||
};
|
||||
|
||||
pub struct TestViewport {
|
||||
pub id: WpViewportId,
|
||||
pub tran: Rc<TestTransport>,
|
||||
}
|
||||
|
||||
impl TestViewport {
|
||||
pub fn destroy(&self) -> Result<(), TestError> {
|
||||
self.tran.send(Destroy { self_id: self.id })?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_source(&self, x: i32, y: i32, width: i32, height: i32) -> Result<(), TestError> {
|
||||
self.tran.send(SetSource {
|
||||
self_id: self.id,
|
||||
x: Fixed::from_int(x),
|
||||
y: Fixed::from_int(y),
|
||||
width: Fixed::from_int(width),
|
||||
height: Fixed::from_int(height),
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_destination(&self, width: i32, height: i32) -> Result<(), TestError> {
|
||||
self.tran.send(SetDestination {
|
||||
self_id: self.id,
|
||||
width: width.max(1),
|
||||
height: height.max(1),
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestViewport {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestViewport, WpViewport;
|
||||
}
|
||||
|
||||
impl TestObject for TestViewport {}
|
||||
39
src/it/test_ifs/test_viewporter.rs
Normal file
39
src/it/test_ifs/test_viewporter.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use {
|
||||
crate::{
|
||||
it::{
|
||||
test_error::TestResult,
|
||||
test_ifs::{test_surface::TestSurface, test_viewport::TestViewport},
|
||||
test_object::TestObject,
|
||||
test_transport::TestTransport,
|
||||
},
|
||||
wire::{wp_viewporter::*, WpViewporterId},
|
||||
},
|
||||
std::rc::Rc,
|
||||
};
|
||||
|
||||
pub struct TestViewporter {
|
||||
pub id: WpViewporterId,
|
||||
pub tran: Rc<TestTransport>,
|
||||
}
|
||||
|
||||
impl TestViewporter {
|
||||
pub fn get_viewport(&self, surface: &TestSurface) -> TestResult<Rc<TestViewport>> {
|
||||
let obj = Rc::new(TestViewport {
|
||||
id: self.tran.id(),
|
||||
tran: self.tran.clone(),
|
||||
});
|
||||
self.tran.send(GetViewport {
|
||||
self_id: self.id,
|
||||
id: obj.id,
|
||||
surface: surface.id,
|
||||
})?;
|
||||
self.tran.add_obj(obj.clone())?;
|
||||
Ok(obj)
|
||||
}
|
||||
}
|
||||
|
||||
test_object! {
|
||||
TestViewporter, WpViewporter;
|
||||
}
|
||||
|
||||
impl TestObject for TestViewporter {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue