diff --git a/docs/features.md b/docs/features.md index e6d881ee9..6cd761789 100644 --- a/docs/features.md +++ b/docs/features.md @@ -170,7 +170,7 @@ Jay supports the following wayland protocols: | wp_linux_drm_syncobj_manager_v1 | 1 | | | wp_presentation | 2 | | | wp_security_context_manager_v1 | 1 | | -| wp_single_pixel_buffer_manager_v1 | 1 | | +| wp_single_pixel_buffer_manager_v1 | 2 | | | wp_tearing_control_manager_v1 | 1 | | | wp_viewporter | 1 | | | xdg_activation_v1 | 1 | | diff --git a/release-notes.md b/release-notes.md index 0daeb177c..fb190f3a5 100644 --- a/release-notes.md +++ b/release-notes.md @@ -13,6 +13,7 @@ - Implement cursor-shape-v1 version 2. - Outputs can now optionally use the BT.2020/PQ color space. - Implement ext-shell version 7. +- Implement single-pixel-buffer version 2. # 1.9.1 (2025-02-13) diff --git a/src/ifs/wl_buffer.rs b/src/ifs/wl_buffer.rs index 9c26747f4..d657cfe0a 100644 --- a/src/ifs/wl_buffer.rs +++ b/src/ifs/wl_buffer.rs @@ -41,7 +41,7 @@ pub struct WlBuffer { render_ctx_version: Cell, pub storage: RefCell>, shm: bool, - pub color: Option<[u32; 4]>, + pub color: Option<[f32; 4]>, width: i32, height: i32, pub tracker: Tracker, @@ -130,10 +130,10 @@ impl WlBuffer { pub fn new_single_pixel( id: WlBufferId, client: &Rc, - r: u32, - g: u32, - b: u32, - a: u32, + r: f32, + g: f32, + b: f32, + a: f32, ) -> Self { Self { id, diff --git a/src/ifs/wp_single_pixel_buffer_manager_v1.rs b/src/ifs/wp_single_pixel_buffer_manager_v1.rs index 007735e34..80b5ecebc 100644 --- a/src/ifs/wp_single_pixel_buffer_manager_v1.rs +++ b/src/ifs/wp_single_pixel_buffer_manager_v1.rs @@ -76,13 +76,32 @@ impl WpSinglePixelBufferManagerV1RequestHandler for WpSinglePixelBufferManagerV1 req: CreateU32RgbaBuffer, _slf: &Rc, ) -> Result<(), Self::Error> { + let map = |c: u32| (c as f64 / u32::MAX as f64) as f32; let buffer = Rc::new(WlBuffer::new_single_pixel( req.id, &self.client, - req.r, - req.g, - req.b, - req.a, + map(req.r), + map(req.g), + map(req.b), + map(req.a), + )); + track!(self.client, buffer); + self.client.add_client_obj(&buffer)?; + Ok(()) + } + + fn create_f32_rgba_buffer( + &self, + req: CreateF32RgbaBuffer, + _slf: &Rc, + ) -> Result<(), Self::Error> { + let buffer = Rc::new(WlBuffer::new_single_pixel( + req.id, + &self.client, + f32::from_bits(req.r), + f32::from_bits(req.g), + f32::from_bits(req.b), + f32::from_bits(req.a), )); track!(self.client, buffer); self.client.add_client_obj(&buffer)?; diff --git a/src/renderer.rs b/src/renderer.rs index 16841c338..c42681188 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -472,7 +472,7 @@ impl Renderer<'_> { Some(bounds) => rect.intersect(*bounds), }; if !rect.is_empty() { - let color = Color::from_u32_premultiplied( + let color = Color::new_premultiplied( cd.transfer_function, color[0], color[1], diff --git a/src/theme.rs b/src/theme.rs index 8d78d8140..145a76f2e 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -193,25 +193,6 @@ impl Color { ) } - pub fn from_u32_premultiplied( - transfer_function: TransferFunction, - r: u32, - g: u32, - b: u32, - a: u32, - ) -> Self { - fn to_f32(c: u32) -> f32 { - ((c as f64) / (u32::MAX as f64)) as f32 - } - Self::new_premultiplied( - transfer_function, - to_f32(r), - to_f32(g), - to_f32(b), - to_f32(a), - ) - } - pub fn from_srgba_straight(r: u8, g: u8, b: u8, a: u8) -> Self { let mut c = Self::new(TransferFunction::Srgb, to_f32(r), to_f32(g), to_f32(b)); if a < 255 { diff --git a/wire/wp_single_pixel_buffer_manager_v1.txt b/wire/wp_single_pixel_buffer_manager_v1.txt index 4f4d607f2..11056cb84 100644 --- a/wire/wp_single_pixel_buffer_manager_v1.txt +++ b/wire/wp_single_pixel_buffer_manager_v1.txt @@ -10,3 +10,11 @@ request create_u32_rgba_buffer { b: u32, a: u32, } + +request create_f32_rgba_buffer { + id: id(wl_buffer), + r: u32, + g: u32, + b: u32, + a: u32, +}