1
0
Fork 0
forked from wry/wry

wayland: implement alpha_modifier_v1

This commit is contained in:
Julian Orth 2024-03-18 19:18:30 +01:00
parent 131f0481e8
commit ff54a8ab96
37 changed files with 655 additions and 89 deletions

View file

@ -1,4 +1,6 @@
mod test_buffer;
pub mod test_alpha_modifier;
pub mod test_alpha_modifier_surface;
pub mod test_buffer;
pub mod test_callback;
pub mod test_compositor;
pub mod test_content_type;

View file

@ -0,0 +1,49 @@
use {
crate::{
it::{
test_error::TestResult,
test_ifs::{
test_alpha_modifier_surface::TestAlphaModifierSurface, test_surface::TestSurface,
},
test_object::TestObject,
test_transport::TestTransport,
},
wire::{wp_alpha_modifier_v1::*, WpAlphaModifierV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestAlphaModifier {
pub id: WpAlphaModifierV1Id,
pub tran: Rc<TestTransport>,
}
impl TestAlphaModifier {
pub fn new(tran: &Rc<TestTransport>) -> Self {
Self {
id: tran.id(),
tran: tran.clone(),
}
}
pub fn get_surface(&self, surface: &TestSurface) -> TestResult<Rc<TestAlphaModifierSurface>> {
let obj = Rc::new(TestAlphaModifierSurface {
id: self.tran.id(),
tran: self.tran.clone(),
destroyed: Cell::new(false),
});
self.tran.add_obj(obj.clone())?;
self.tran.send(GetSurface {
self_id: self.id,
id: obj.id,
surface: surface.id,
})?;
Ok(obj)
}
}
test_object! {
TestAlphaModifier, WpAlphaModifierV1;
}
impl TestObject for TestAlphaModifier {}

View file

@ -0,0 +1,41 @@
use {
crate::{
it::{test_error::TestError, test_object::TestObject, test_transport::TestTransport},
wire::{wp_alpha_modifier_surface_v1::*, WpAlphaModifierSurfaceV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestAlphaModifierSurface {
pub id: WpAlphaModifierSurfaceV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestAlphaModifierSurface {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn set_multiplier(&self, factor: f64) -> Result<(), TestError> {
self.tran.send(SetMultiplier {
self_id: self.id,
factor: (factor * u32::MAX as f64) as u32,
})
}
}
impl Drop for TestAlphaModifierSurface {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestAlphaModifierSurface, WpAlphaModifierSurfaceV1;
}
impl TestObject for TestAlphaModifierSurface {}

View file

@ -5,7 +5,8 @@ use {
it::{
test_error::TestError,
test_ifs::{
test_compositor::TestCompositor, test_content_type_manager::TestContentTypeManager,
test_alpha_modifier::TestAlphaModifier, test_compositor::TestCompositor,
test_content_type_manager::TestContentTypeManager,
test_cursor_shape_manager::TestCursorShapeManager,
test_data_control_manager::TestDataControlManager,
test_data_device_manager::TestDataDeviceManager, test_dmabuf::TestDmabuf,
@ -50,6 +51,7 @@ pub struct TestRegistrySingletons {
pub zwlr_data_control_manager_v1: u32,
pub zwp_linux_dmabuf_v1: u32,
pub xdg_toplevel_drag_manager_v1: u32,
pub wp_alpha_modifier_v1: u32,
}
pub struct TestRegistry {
@ -73,6 +75,7 @@ pub struct TestRegistry {
pub data_control_manager: CloneCell<Option<Rc<TestDataControlManager>>>,
pub dmabuf: CloneCell<Option<Rc<TestDmabuf>>>,
pub drag_manager: CloneCell<Option<Rc<TestToplevelDragManager>>>,
pub alpha_modifier: CloneCell<Option<Rc<TestAlphaModifier>>>,
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
}
@ -140,6 +143,7 @@ impl TestRegistry {
zwlr_data_control_manager_v1,
zwp_linux_dmabuf_v1,
xdg_toplevel_drag_manager_v1,
wp_alpha_modifier_v1,
};
self.singletons.set(Some(singletons.clone()));
Ok(singletons)
@ -227,6 +231,13 @@ impl TestRegistry {
1,
TestToplevelDragManager
);
create_singleton!(
get_alpha_modifier,
alpha_modifier,
wp_alpha_modifier_v1,
1,
TestAlphaModifier
);
pub fn bind<O: TestObject>(
&self,

View file

@ -68,6 +68,7 @@ impl TestTransport {
data_control_manager: Default::default(),
dmabuf: Default::default(),
drag_manager: Default::default(),
alpha_modifier: Default::default(),
seats: Default::default(),
});
self.send(wl_display::GetRegistry {

View file

@ -70,6 +70,7 @@ mod t0035_scanout_feedback;
mod t0036_idle;
mod t0037_toplevel_drag;
mod t0038_subsurface_parent_state;
mod t0039_alpha_modifier;
pub trait TestCase: Sync {
fn name(&self) -> &'static str;
@ -127,5 +128,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
t0036_idle,
t0037_toplevel_drag,
t0038_subsurface_parent_state,
t0039_alpha_modifier,
}
}

View file

@ -0,0 +1,56 @@
use {
crate::{
it::{test_error::TestResult, testrun::TestRun},
theme::Color,
},
std::rc::Rc,
};
testcase!();
async fn test(run: Rc<TestRun>) -> TestResult {
let _ds = run.create_default_setup().await?;
let client = run.create_client().await?;
let win = client.create_window().await?;
win.set_color(255, 0, 0, 255);
win.map2().await?;
macro_rules! create_surface {
($buf:expr, $x:expr, $y:expr) => {{
let ss = client.comp.create_surface().await?;
let vp = client.viewporter.get_viewport(&ss)?;
vp.set_destination(100, 100)?;
ss.attach($buf.id)?;
ss.commit()?;
let alpha = client
.registry
.get_alpha_modifier()
.await?
.get_surface(&ss)?;
let sub = client.sub.get_subsurface(ss.id, win.surface.id).await?;
sub.set_desync()?;
sub.set_position($x, $y)?;
win.surface.commit()?;
(ss, alpha)
}};
}
let buf1 = client.spbm.create_buffer(Color::from_rgb(0, 255, 0))?;
let (ss1, alpha1) = create_surface!(&buf1, 0, 0);
let buf2 = client.shm.create_buffer(1, 1)?;
buf2.fill(Color::from_rgb(0, 255, 0));
let (ss2, alpha2) = create_surface!(&buf2.buffer, 100, 0);
client.compare_screenshot("1", false).await?;
alpha1.set_multiplier(0.5)?;
ss1.commit()?;
alpha2.set_multiplier(0.5)?;
ss2.commit()?;
client.compare_screenshot("2", false).await?;
Ok(())
}

Binary file not shown.

Binary file not shown.